blob_id stringlengths 40 40 | language stringclasses 1
value | repo_name stringlengths 5 140 | path stringlengths 5 183 | src_encoding stringclasses 6
values | length_bytes int64 12 5.32M | score float64 2.52 4.94 | int_score int64 3 5 | detected_licenses listlengths 0 47 | license_type stringclasses 2
values | text stringlengths 12 5.32M | download_success bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|
9bc16e206a322fee601d4d31f7c566dfab371a34 | Rust | ur0/rust-asn1 | /src/deserializer.rs | UTF-8 | 14,868 | 3.015625 | 3 | [
"BSD-2-Clause"
] | permissive | use std::{convert};
use std::io::{self, BufRead, Cursor};
use byteorder::{ReadBytesExt};
use common::{Tag};
use utils::{BitString, Integer, ObjectIdentifier};
#[derive(Debug, PartialEq, Eq)]
pub enum DeserializationError {
UnexpectedTag {expected: u8, actual: u8},
ShortData,
ExtraData,
IntegerOverfl... | true |
328e37637c808767fc7c790b6e4b90a559399061 | Rust | airmash-refugees/airmash-server-eu | /server/src/systems/admin/crash.rs | UTF-8 | 1,394 | 2.515625 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use specs::*;
use types::*;
use std::env;
use component::event::*;
use systems::PacketHandler;
use SystemInfo;
use utils::{EventHandler, EventHandlerTypeProvider};
/// Crash the server (for testing purposes)
#[derive(Default)]
pub struct Crash;
#[derive(SystemData)]
pub struct CrashData<'a> {
name: ReadStorage<'a... | true |
c555e25953645f720e17ec61afcc4f1148da79f9 | Rust | inda20plusplus/mvid-chess | /lib/src/pieces/moves.rs | UTF-8 | 1,724 | 2.6875 | 3 | [] | no_license | use crate::{Move, Point};
pub const ALL: [Move; 16] = [
Move(Point(-1, 1), true),
Move(Point(0, 1), true),
Move(Point(1, 1), true),
Move(Point(-1, 0), true),
Move(Point(1, 0), true),
Move(Point(-1, -1), true),
Move(Point(0, -1), true),
Move(Point(1, -1), true),
Move(Point(-2, 1), fa... | true |
2f478a9904663c73a22e34aac13ff38570c83dac | Rust | norlen/clox-rust | /src/memory/object/mod.rs | UTF-8 | 4,423 | 3.25 | 3 | [
"MIT"
] | permissive | mod class;
mod closure;
mod function;
mod native_fn;
mod upvalue;
use std::fmt;
use super::GC;
pub use class::{BoundMethod, Class, Instance};
pub use closure::Closure;
pub use function::Function;
pub use native_fn::{NativeFn, NativeFunction};
pub use upvalue::Upvalue;
/// Object is a garbage collected object. When ... | true |
f9ad6d0d06fdb5a9c3cb10abff13a5a27e5fa5ba | Rust | rustkas/error-index | /main_tests/tests/e0281.rs | UTF-8 | 1,231 | 2.796875 | 3 | [
"MIT"
] | permissive | /*
You tried to supply a type which doesn't implement some trait in a location which expected that trait.
*/
// cargo test --test e0276 without_error1 -- --nocapture
#[cfg(test)]
mod tests {
#[allow(dead_code)]
#[allow(non_snake_case)]
#[allow(unused_imports)]
#[test]
fn with_error1() {
// ... | true |
2d8950a7fd0588836819ad849ed50ae565084fd2 | Rust | exscape/Rust | /euler/29.rs | UTF-8 | 403 | 3.1875 | 3 | [] | no_license | extern crate num;
use num::bigint::{BigUint, ToBigUint};
use std::iter::range_inclusive;
fn main() {
// BigUint doesn't support hashing, so we can't use HashSet.
let mut v : Vec<BigUint> = Vec::new();
for a in range_inclusive(2u, 100u) {
for b in range_inclusive(2u, 100) {
v.push(std::num::pow(a.to_biguint().... | true |
af18e211e6e6646b5362a371591ca4ec8cd5d231 | Rust | gsson/adventofcode2020 | /src/bin/aoc11b.rs | UTF-8 | 7,005 | 3.21875 | 3 | [] | no_license | #![feature(test)]
use std::io::Read;
use std::fmt::{Debug, Formatter, Write};
fn main() {
let mut f = std::fs::File::open("src/bin/aoc11.txt").unwrap();
let mut input = Vec::new();
f.read_to_end(&mut input).unwrap();
let mut grid = parse(&input);
loop {
let next_grid = grid.simulate();
... | true |
0a2d62d3b7fd2bcffa1227aeb8bd735ba47b5623 | Rust | multijump/rust-web-backend | /src/utils/cli.rs | UTF-8 | 589 | 2.828125 | 3 | [] | no_license | use clap::{Arg, App};
use dotenv::from_filename;
pub fn read_cli(){
let app = App::new("rust-app")
.arg(Arg::with_name("environment")
.short("e")
.long("env")
.value_name("ENV_NAME")
.help("Load env file")
.takes_value(true)
)
.get_matches();
let env = app.v... | true |
117d834f53889f64b6dbbcbf2bf7c6a1c7f093d5 | Rust | Gogomoe/LeetCodeSolutions | /src/0060.rs | UTF-8 | 800 | 3.46875 | 3 | [] | no_license | impl Solution {
pub fn get_permutation(n: i32, mut k: i32) -> String {
let mut numbers: Vec<i32> = (1..=n).collect();
let mut factorial = Vec::new();
factorial.push(1);
factorial.push(1);
for i in 2..=n {
factorial.push(i * (*factorial.last().unwrap()));
}... | true |
c5695322bdccd418aad34b623b57368c75adf7d1 | Rust | bauhaus93/optimizer | /src/resource_handler.rs | UTF-8 | 2,872 | 2.890625 | 3 | [] | no_license | use resource_error::ResourceError;
use db_client::DBClient;
use mkm_client::mkm_client::MKMClient;
use mkm_client::query::query_builder::QueryBuilder;
use mkm_client::entities::metaproduct::Metaproduct;
use mkm_client::entities::article::Article;
use mkm_client::entities::user::User;
pub struct ResourceHandler {
... | true |
e6e8f7326209f848740f9bf7983e97ebdd44ef95 | Rust | impuls71/grammers | /lib/grammers-client/examples/echo.rs | UTF-8 | 1,909 | 2.671875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | //! Example to echo user text messages. Runnable as:
//!
//! ```sh
//! cargo run --example echo -- API_ID API_HASH BOT_TOKEN
//! ```
use async_std::task;
use grammers_client::ext::{MessageExt, UpdateExt};
use grammers_client::{AuthorizationError, Client, Config};
use grammers_session::Session;
use log;
use simple_logg... | true |
e786db65a1d09fcda44d3796455d5ad28573d9cf | Rust | Kampfkarren/advent-of-code-2018-rust | /src/main.rs | UTF-8 | 805 | 3.15625 | 3 | [] | no_license | use std::env;
use std::fs;
mod day1;
mod day2;
mod day3;
mod day4;
mod day5;
// mod day6;
mod day7;
mod day8;
// mod day9;
mod day10;
fn main() {
let day: u8 = env::args().nth(1).expect("Day needs to be passed.")
.parse::<u8>().expect("Day was not a number.");
let input = &fs::read_t... | true |
d365bc94f98d1aa7b70609ab354bac632998bce3 | Rust | tower-rs/tower | /tower/src/timeout/future.rs | UTF-8 | 1,236 | 2.796875 | 3 | [
"MIT"
] | permissive | //! Future types
use super::error::Elapsed;
use pin_project_lite::pin_project;
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
};
use tokio::time::Sleep;
pin_project! {
/// [`Timeout`] response future
///
/// [`Timeout`]: crate::timeout::Timeout
#[derive(Debug)]
pub struct ... | true |
f01d4d7a572bfeb2c96903d14af3818fb47ad947 | Rust | phernst/chanvese | /src/lib.rs | UTF-8 | 15,230 | 2.796875 | 3 | [] | no_license | //! This crate provides an implementation of Chan-Vese level-sets
//! described in [Active contours without edges](http://ieeexplore.ieee.org/document/902291/)
//! by T. Chan and L. Vese.
//! It is a port of the Python implementation by Kevin Keraudren on
//! [Github](https://github.com/kevin-keraudren/chanvese)
//! an... | true |
50d94a384898c193544969498ce88c21c45d63fd | Rust | max-ym/rust-asm-x86_64 | /src/xsave.rs | UTF-8 | 4,099 | 2.765625 | 3 | [] | no_license | pub use msr::Xss as XssMsr;
pub use cr::Xcr0;
/// Check XSAVE support through CPUID instruction.
pub fn is_supported() -> bool {
fast_is_supported(::cpuid::Features::get())
}
/// Check XSAVE support by using already read CPUID value.
pub fn fast_is_supported(f: ::cpuid::Features) -> bool {
f.xsave_supported()... | true |
58dfdc1f4eaf71bfa8a49e6f2cb3bd6dab9f5d68 | Rust | owen8877/leetcode-rs | /src/problem_51.rs | UTF-8 | 1,517 | 3.34375 | 3 | [] | no_license | pub fn solve_n_queens(n: i32) -> Vec<Vec<String>> {
if n < 4 {
if n == 1 {
return vec![vec!["Q".to_string()]]
}
return vec![]
}
let n = n as usize;
let mut result = vec![];
fn core(index: usize, v: &mut Vec<usize>, r: &mut Vec<Vec<usize>>, push_two: bool) {
... | true |
6f548dbf234804ffdfe5fa71fa145c2f14e14983 | Rust | scott113341/advent_of_code_2020 | /day_08/src/program.rs | UTF-8 | 1,285 | 3.4375 | 3 | [] | no_license | use crate::instruction::{Instruction, Operation};
pub type Accumulator = i64;
pub type Instructions = Vec<Instruction>;
#[derive(Eq, PartialEq, Debug)]
pub struct Program {
pub accumulator: Accumulator,
pub pointer: i64,
pub instructions: Instructions,
}
impl Program {
pub fn new(instructions: Instru... | true |
534b81cc5c3d2d41b9c033bc28761e21b79c2663 | Rust | Telixia/leetcode-2 | /src/_969.rs | UTF-8 | 1,853 | 3.484375 | 3 | [
"MIT"
] | permissive | pub struct Solution;
impl Solution {
pub fn pancake_sort(mut a: Vec<i32>) -> Vec<i32> {
let mut ans: Vec<i32> = Vec::new();
while a.len() > 1 {
// find the largest element in a, which is equal to len(a)
let len = a.len() as i32;
let maxi = a.iter().position(|&x| ... | true |
a45eac919630ed2d7ceff2a07600bce8f23e937e | Rust | dbjnbnrj/til | /rust/chap4/src/main.rs | UTF-8 | 221 | 3.171875 | 3 | [] | no_license | fn main() {
let s = String::from("Hello, world!");
let bytes = s.as_bytes();
for (i, &item) in bytes.iter().enumerate() {
if item == b' ' {
print!("{} \n", &s[0..i]);
}
}
print!("{} \n",&s[..]);
}
| true |
fbd5c2b9f4c926463f3cc1380146b42c67084f25 | Rust | Lymia/th_dnh_archiver | /src/main.rs | UTF-8 | 2,777 | 2.734375 | 3 | [
"Apache-2.0"
] | permissive | #![windows_subsystem = "console"]
#[macro_use]
extern crate anyhow;
#[macro_use]
extern crate lazy_static;
mod error {
pub use anyhow::Error;
pub type Result<T> = ::std::result::Result<T, Error>;
}
mod archive;
mod output;
// Main method
//////////////
use std::{
env,
ffi::OsString,
fs::File,
... | true |
b00317d9001483741bb1e23039e4a50de60572c8 | Rust | glennpratt/retry | /src/retry_command/src/lib.rs | UTF-8 | 4,113 | 3.234375 | 3 | [] | no_license | pub mod exit_code_ext;
use exit_code_ext::ExitCodeExt;
use std::io;
use std::io::Write;
use std::process::{Command, ExitStatus};
use std::time::{Duration, Instant};
use std::thread::sleep;
//#[derive(Debug)]
pub struct RetryCommand {
command: Command,
retry_delay: Duration,
retry_timeout: Duration,
r... | true |
d1c09c14e2f7fdd2ba175b54f62eeb0b72d96535 | Rust | skarrman/AdventOfCode | /2020/advent_of_code/src/25/main.rs | UTF-8 | 1,048 | 3.1875 | 3 | [] | no_license | use std::fs;
const DIVIDER: i64 = 20201227;
fn get_data() -> (i64, i64) {
let path = "src/25/input.txt";
let file_contents = fs::read_to_string(path).expect("Could not read file");
let keys: Vec<i64> = file_contents
.split("\n")
.map(|row| row.parse().unwrap())
.collect();
(key... | true |
8f7fbf8fb49c7070226835652b61d1924405724c | Rust | vanhtuan0409/exercism | /rust/anagram/src/lib.rs | UTF-8 | 678 | 3.21875 | 3 | [
"MIT"
] | permissive | use std::collections::{BTreeMap, HashSet};
fn get_chars_stat(input: &str) -> BTreeMap<char, i32> {
let mut ret = BTreeMap::new();
for c in input.to_lowercase().chars() {
*ret.entry(c).or_insert(0) += 1;
}
ret
}
fn is_anagram(input1: &str, input2: &str) -> bool {
input1.to_lowercase() != in... | true |
52b70569960ab1ceaf4cc7fd73b20466fe1b462f | Rust | teloxide/teloxide | /crates/teloxide-core/src/types/message_id.rs | UTF-8 | 1,440 | 3.453125 | 3 | [
"MIT"
] | permissive | use serde::{Deserialize, Serialize};
/// A unique message identifier.
#[derive(Clone, Copy, Debug, derive_more::Display, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(from = "MessageIdRaw", into = "MessageIdRaw")]
pub struct MessageId(pub i32);
// N.B. we [de]serialize `MessageId` as `{"message_id":n}`, which... | true |
4ecb8b26ccf915879b8604d1c1cd2ed1800ebe50 | Rust | matsune/heif | /src/bbox/meta/idat.rs | UTF-8 | 1,196 | 2.859375 | 3 | [] | no_license | use crate::bbox::header::BoxHeader;
use crate::bbox::BBox;
use crate::bit::{Byte4, Stream};
use crate::Result;
#[derive(Debug)]
pub struct ItemDataBox {
box_header: BoxHeader,
data: Vec<u8>,
}
impl Default for ItemDataBox {
fn default() -> Self {
Self {
box_header: BoxHeader::new("idat... | true |
517c5e4236a27201cf9e73d941b7cb62368737e6 | Rust | bbants/composite | /src/simpledsp.rs | UTF-8 | 2,318 | 3.40625 | 3 | [] | no_license | use std::f32::consts::PI;
/// Window functions
pub enum WindowType {
Rectangular,
Hamming,
BlackmanHarris
}
/// Generate a window function
/// Only odd orders are accepted
pub fn generate_window(window_type: WindowType, window_len: u32) -> Vec<f32> {
assert!(window_len % 2 == 1);
let samples = (1... | true |
2d3c279c1badd9b5cb3105d3ac92c80bb247da5d | Rust | Luro02/path-sanitizer | /src/platforms/linux.rs | UTF-8 | 1,219 | 2.796875 | 3 | [] | no_license | use crate::constant_arrays;
use crate::sanitizer::Sanitizer;
use crate::sanitizers::Replacer;
use crate::Platform;
// TODO: make default const RP = '\u{FFFD}'
// NOTE: currently rustfmt destroys any defaults
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Linux<const RP: char> {}
impl<const RP: char> De... | true |
f50ca7f6a7e22669146631b916c38c2e27988a49 | Rust | vmiklos/osm-gimmisn | /src/context/tests.rs | UTF-8 | 13,867 | 2.578125 | 3 | [
"BSD-3-Clause",
"MIT",
"Unicode-DFS-2016",
"CC0-1.0",
"Apache-2.0",
"BSD-2-Clause"
] | permissive | /*
* Copyright 2022 Miklos Vajna
*
* SPDX-License-Identifier: MIT
*/
#![deny(warnings)]
#![warn(clippy::all)]
#![warn(missing_docs)]
//! Tests for the context module.
use super::*;
use std::collections::HashMap;
use std::io::Cursor;
use std::io::Seek;
use std::io::SeekFrom;
use std::ops::DerefMut;
/// Creates a... | true |
f7742c42a404c26a7b6db11c00d36dd0b0068a80 | Rust | hgzimmerman/cortex-m0plus-emu | /src/value/mod.rs | UTF-8 | 641 | 2.84375 | 3 | [] | no_license | use bit_vec::BitVec;
use word::Word;
/// Allows a value to be encoded and decoded to a part of ByteCode.
pub trait ByteCodeEncodable {
fn encode_to_bitvector(&self, bit_vec: &mut BitVec<u32>, offset: usize);
fn decode_from_bitvector(bit_vec: &BitVec<u32>, offset: usize) -> Self;
}
/// Extends a given value wi... | true |
1132faf854a47ae5f0889053d6a87f74c3e23529 | Rust | AlexanderEkdahl/pbr | /src/energy.rs | UTF-8 | 583 | 3.140625 | 3 | [] | no_license | use vector3::Vector3;
use rand::{Rng, ThreadRng};
pub type Energy = Vector3;
impl Energy {
pub fn merged(&self, b: &Energy, signal: &Energy) -> Energy {
self + &(b * signal)
}
pub fn amplified(&self, n: f64) -> Energy {
self * n
}
pub fn random_gain(&self, rng: &mut ThreadRng) ->... | true |
de54c3670e43aaa4a240110ae986cef9cad2112e | Rust | johanlindblad/advent-of-code-2018 | /src/day9.rs | UTF-8 | 1,702 | 3.15625 | 3 | [] | no_license | use std::boxed::Box;
use std::collections::VecDeque;
// TODO: separate list for elements moved from back?
#[aoc_generator(day9)]
pub fn input_generator(input: &str) -> Box<(usize, usize)> {
let mut iter = input.split(" ");
let num_players = iter.next().unwrap().parse::<usize>().unwrap();
let highest_marbl... | true |
9862248ebe6d3a9c2d328c0c8bd5cd19a8daa526 | Rust | BenViridian/trashy_bot | /src/models/fav_block.rs | UTF-8 | 2,188 | 2.890625 | 3 | [
"MIT"
] | permissive | use tokio_postgres::{row::Row, Client};
pub type DbError = Box<dyn std::error::Error + Send + Sync>;
#[derive(Debug, Clone)]
pub struct FavBlock {
pub id: i64,
pub server_id: i64, // server on which this fav is blocked
pub channel_id: i64, // blocked channel id
pub msg_id: i64, // blocked message... | true |
7d9d0bf54d2c19d1be44dc895ace9ba657524bc1 | Rust | sunfishcode/cranelift | /lib/cretonne/src/ir/libcall.rs | UTF-8 | 3,221 | 3.671875 | 4 | [
"Apache-2.0"
] | permissive | //! Naming well-known routines in the runtime library.
use ir::{types, Opcode, Type};
use std::fmt;
use std::str::FromStr;
/// The name of a runtime library routine.
///
/// Runtime library calls are generated for Cretonne IL instructions that don't have an equivalent
/// ISA instruction or an easy macro expansion. A... | true |
5ede46ee42ff5c41429e895951d9e9d20abf48a3 | Rust | SahandFarhoodi/icu4x | /components/provider/src/structs/mod.rs | UTF-8 | 881 | 2.578125 | 3 | [
"Apache-2.0",
"ICU",
"MIT",
"LicenseRef-scancode-unicode"
] | permissive | // This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/master/LICENSE ).
//! Collection of data structures for `DataProvider`.
pub mod dates;
pub mod decimal;
pub mod plurals;
#[cfg(featur... | true |
2e8ff8414b5bad42e390f896a92adcde25051b56 | Rust | lfkeitel/asml-rust | /asml_vm/src/lib.rs | UTF-8 | 15,529 | 2.953125 | 3 | [
"BSD-3-Clause"
] | permissive | pub mod opcodes;
use std::io;
use std::process;
use crate::opcodes::OpCode as opc;
const NUM_OF_MEMORY_CELLS: usize = 65536;
const NUM_OF_REGISTERS: usize = 10;
const PRINTER_ADDR: usize = NUM_OF_MEMORY_CELLS - 3;
// Double width registers
const REG_A: u8 = 0xA;
const REG_B: u8 = 0xB;
const REG_C: u8 = 0xC;
const R... | true |
4225a7c6033a1ab9cf9340531f3950e261c2d41b | Rust | t-matsudate/sheave | /sheave-core/src/handshake/mod.rs | UTF-8 | 16,572 | 3.21875 | 3 | [
"MIT"
] | permissive | //! # Types for the handshake step in RTMP.
//!
//! In RTMP, first, both sides are required doing handshake.
//! It is done respectively following steps:
//!
//! 1. Specifies RTMP version.
//! 2. Exchanges handshake data each other.
//! 3. Returns partner's handshake data.
//!
//! ## RTMP version
//!
//! 1 byte to spec... | true |
9137dee0980192456f5f8325607231e75fcf473f | Rust | linkerd/linkerd2-proxy | /linkerd/http-route/src/http/match/tests.rs | UTF-8 | 4,196 | 3.046875 | 3 | [
"Apache-2.0"
] | permissive | use super::*;
use crate::Match;
use http::header::{HeaderName, HeaderValue};
// Empty matches apply to all requests.
#[test]
fn empty_match() {
let m = MatchRequest::default();
let req = http::Request::builder().body(()).unwrap();
assert_eq!(m.match_request(&req), Some(RequestMatch::default()));
let ... | true |
5ce15c0368a610894106a50bb53157359dab25ab | Rust | c0gent/coding-challenge | /rust_code/gen_numbers.rs | UTF-8 | 1,743 | 2.96875 | 3 | [] | no_license | #![allow(experimental)]
extern crate debug;
use std::io;
use std::rand;
use std::rand::distributions::{IndependentSample, Range};
use std::collections;
fn main() {
let mut files: collections::HashMap<&str, io::IoResult<io::File>> = collections::HashMap::new();
files.insert("Paris", io::File::create(&Path::new("Par... | true |
36f5529adb98f7aba11313a63e2c28ae78f54423 | Rust | edenzik/MEcs146a | /gashShell/crap/file_io.rs | UTF-8 | 2,627 | 3.484375 | 3 | [
"MIT"
] | permissive | use std::fs::File;
use std::io::{self, Read, Write};
use std::path::Path;
use std::sync::mpsc::{channel, Sender, Receiver};
use std::thread::{JoinHandle, spawn};
use std::str;
fn main() {
}
// This method to read from file and write to channel
fn create_thread_io(channel : Sender<String>, file_name: Box<String>)
... | true |
429829f6cd270d6a0ed38d59257c8fc34be08ae1 | Rust | bevyengine/bevy | /crates/bevy_ecs/src/system/function_system.rs | UTF-8 | 24,958 | 2.96875 | 3 | [
"Apache-2.0",
"MIT",
"Zlib",
"LicenseRef-scancode-free-unknown",
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-other-permissive"
] | permissive | use crate::{
archetype::{ArchetypeComponentId, ArchetypeGeneration, ArchetypeId},
component::{ComponentId, Tick},
prelude::FromWorld,
query::{Access, FilteredAccessSet},
system::{check_system_change_tick, ReadOnlySystemParam, System, SystemParam, SystemParamItem},
world::{unsafe_world_cell::Unsa... | true |
32eaed5176815f5923aa3a0b6a3e08ead67dd997 | Rust | mzgoddard/tessel-audio-graph | /graph_utils/src/capture.rs | UTF-8 | 1,535 | 2.984375 | 3 | [] | no_license | use super::{Node, RingBuffer, copy_out_ring};
type CaptureFn = Box<FnMut(&mut RingBuffer)>;
pub struct Capture {
tmp_state: Option<(RingBuffer, Vec<i16>)>,
callback: CaptureFn,
}
impl Capture {
pub fn new(callback: CaptureFn) -> Capture {
Capture {
tmp_state: Some((RingBuffer::new(), ... | true |
665d87cdb6f4a1bd85b11efb7a1996e6d69bb5bd | Rust | wujinderead/MyGoProjects | /gotest/leet_rust/tests/leet2134_minimum_swaps_to_group_all_1s_together_i_i.rs | UTF-8 | 3,139 | 3.640625 | 4 | [] | no_license | // https://leetcode.com/problems/minimum-swaps-to-group-all-1s-together-ii/
// A swap is defined as taking two distinct positions in an array and swapping the values in them.
// A circular array is defined as an array where we consider the first element
// and the last element to be adjacent.
// Given a binary circul... | true |
217a29212bf6dfcb864109405e969e4bfece3785 | Rust | chengchangwu/k | /src/ik.rs | UTF-8 | 7,085 | 2.546875 | 3 | [
"Apache-2.0"
] | permissive | /*
Copyright 2017 Takashi Ogura
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in w... | true |
93157af6b1408d5e9844c99c2f9e1e1ca1c3d682 | Rust | Tsutomu-Ikeda/rust-dfa | /src/main.rs | UTF-8 | 3,189 | 3.640625 | 4 | [] | no_license | use std::fmt;
use std::io::{self, Read};
fn get_input_value() -> String {
let mut buffer = String::new();
let stdin = io::stdin();
let mut handle = stdin.lock();
handle.read_to_string(&mut buffer).unwrap();
return String::from(buffer.trim());
}
enum States {
S0,
S1,
S2,
S3,
S4,
S5,
S6,
}
imp... | true |
bb9531ce07aa52923bf90bb85182bfda37742b49 | Rust | ratijas/windows-rust-counters | /win-high/src/perf/useful.rs | UTF-8 | 8,600 | 2.671875 | 3 | [] | no_license | use std::convert::TryFrom;
use std::hash::{Hash, Hasher};
use win_low::winperf::*;
use crate::perf::provide::{PerfCounterDefinitionTemplate, PerfInstanceDefinitionTemplate};
use crate::perf::values::*;
use crate::prelude::v1::*;
use std::sync::{Arc, Mutex};
use std::collections::HashMap;
use crate::perf::nom::PerfIns... | true |
cd00d7b04d68a7d62428e0c46ae9ae5041173fb5 | Rust | Janonard/lv2rs | /core/src/feature.rs | UTF-8 | 3,570 | 3.234375 | 3 | [
"LicenseRef-scancode-warranty-disclaimer",
"LicenseRef-scancode-mit-taylor-variant",
"ISC"
] | permissive | use std::ffi::CStr;
use std::os::raw::*;
/**
Feature.
Features allow hosts to make additional functionality available to plugins
without requiring modification to the LV2 API. Extensions may define new
features and specify the `uri` and `data` to be used if necessary.
Some features, such as `lv2:isLiv... | true |
0290d10e6d4801be98b46cf333dbd8ad6c229189 | Rust | isabella232/Evokit | /src/metrics/mod.rs | UTF-8 | 13,982 | 3.09375 | 3 | [
"Apache-2.0"
] | permissive | //! Metrics
//! ---
//! Contains a set of optimization metrics
//!
//! These are useful for different scorers
extern crate es_data;
extern crate float_ord;
extern crate hashbrown;
use self::es_data::dataset::types::{MetaType, Metadata};
use self::hashbrown::HashMap;
use self::float_ord::FloatOrd;
/// Computes DCG@K ... | true |
f41d5ec47c3d2b818e1a1e23f61680c9d232f04e | Rust | sssilver/tetrust | /src/game/polyomino.rs | UTF-8 | 3,707 | 3.46875 | 3 | [] | no_license | use std::collections::HashSet;
use std::vec::Vec;
use renderer::{Point, Renderable, Renderer};
use std::cmp::min;
use std::fmt;
pub type Cell = (i8, i8);
type Coord = (i8, i8);
pub struct Polyomino {
cells: HashSet<Cell>
}
impl Polyomino {
pub fn new(cells: HashSet<Cell>) -> Polyomino {
// Translat... | true |
878bd2804958180df76663078d2583aa98d539ad | Rust | gp-97/image-conv | /src/conv.rs | UTF-8 | 6,220 | 2.625 | 3 | [
"Apache-2.0"
] | permissive | //! Image convolution
use crate::{Filter, PaddingType};
use photon_rs::transform::padding_uniform as uniform;
use photon_rs::PhotonImage;
use photon_rs::Rgba;
fn convolve(img_padded: &PhotonImage, filter: &Filter, width_conv: u32, height_conv: u32, stride: u32) -> PhotonImage {
let raw_pixel_padded = img_padded.g... | true |
702835672995ccc827728a99d4039aee8b21d919 | Rust | Akagi201/learning-rust | /misc/array/array.rs | UTF-8 | 215 | 3.65625 | 4 | [
"MIT"
] | permissive | fn main() {
let mut array: [i32; 3] = [0; 3];
array[1] = 1;
array[2] = 2;
assert_eq!([1, 2], &array[1..]);
// This loop prints: 0 1 2
for x in &array {
println!("{:?}", x);
}
} | true |
54e03db1b55e1e7026d0b0bea995f1b1f159066d | Rust | j39m/zakopane | /src/checksum.rs | UTF-8 | 8,023 | 2.703125 | 3 | [
"BSD-3-Clause"
] | permissive | // Implements the `zakopane checksum` subcommand.
use std::convert::TryInto;
use std::io::Read;
use std::io::Write;
use crate::structs::ChecksumCliOptions;
use crate::structs::ZakopaneError;
const READ_SIZE: usize = 1 << 20;
struct ChecksumWithPath {
checksum: String,
path: std::path::PathBuf,
}
impl Check... | true |
5324a3ff1bb4d558cd402e24f602e51845007c54 | Rust | rfuest/embedded-graphics | /tinytga/src/packet/raw_packet.rs | UTF-8 | 2,958 | 3.46875 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use super::pixel_count;
use nom::{
bits::{bits, complete::tag},
bytes::complete::take,
sequence::preceded,
IResult,
};
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct RawPacket<'a> {
/// Number of pixels of this packet
pub num_pixels: u8,
/// Pixel data in th... | true |
4258affca9c3b90238a14fe1241ded51b8603173 | Rust | top501/rust-process-mgr | /watchdog/src/process/mod.rs | UTF-8 | 1,068 | 2.578125 | 3 | [] | no_license | #[derive(Clone, Debug)]
pub enum ProcessStatus {
Starting,
Running,
Stoped,
Failed(String),
QuickExit,
Unknow
}
const process_status_starting: &str = "starting";
const process_status_running: &str = "running";
const process_status_stoped: &str = "stoped";
const process_status_failed: &str = "fa... | true |
b895b4c4abd6db87f292b03f67ed4d6308935587 | Rust | tpayet/MeiliSearch | /meilisearch-schema/src/lib.rs | UTF-8 | 1,542 | 2.625 | 3 | [
"MIT"
] | permissive | mod error;
mod fields_map;
mod schema;
pub use error::{Error, SResult};
pub use fields_map::FieldsMap;
pub use schema::Schema;
use serde::{Deserialize, Serialize};
use zerocopy::{AsBytes, FromBytes};
#[derive(Serialize, Deserialize, Debug, Copy, Clone, Default, PartialOrd, Ord, PartialEq, Eq, Hash)]
pub struct Indexe... | true |
19b813f55c8e14b273ac1b8923d50aa77fec46e9 | Rust | manpat/common-rs | /src/math/vector/vec3.rs | UTF-8 | 1,683 | 3.015625 | 3 | [] | no_license | use crate::math::vector::{Vec2, Vec4};
use rand_derive2::RandGen;
#[repr(C)]
#[derive(Copy, Clone, Debug, RandGen)]
pub struct Vec3 {
pub x: f32,
pub y: f32,
pub z: f32,
}
impl Vec3 {
pub const fn new(x: f32, y: f32, z: f32) -> Vec3 { Vec3{x, y, z} }
pub const fn splat(x: f32) -> Vec3 { Vec3::new(x, x, x) }
pu... | true |
c4d8308d0f469f99d58522f1b95b9c7da120de9a | Rust | doytsujin/yew | /packages/yew-macro/tests/derive_props/fail.rs | UTF-8 | 2,051 | 2.828125 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | #![recursion_limit = "128"]
use yew::prelude::*;
mod t1 {
use super::*;
#[derive(Clone)]
struct Value;
#[derive(Clone, Properties, PartialEq)]
pub struct Props {
// ERROR: optional params must implement default
#[prop_or_default]
value: Value,
}
}
mod t2 {
use supe... | true |
2bf0c253d623b31af3ed927eb60d27b05349a0b3 | Rust | Strongman86/Rust-Learning | /chapter5/5_7.rs | UTF-8 | 121 | 2.875 | 3 | [] | no_license | #[derive(Debug,Copy,Clone)]
struct A{
a:i32,
b:i32,
}
fn main(){
let a=A{ a:1,b:2};
let b=a;
println!("{:?}",a);
}
| true |
6a0b251fc09684236cd8e0fd996d2ebaa69784b2 | Rust | Jswizzy/hyper-microservice | /src/main.rs | UTF-8 | 4,676 | 2.515625 | 3 | [] | no_license | use hyper::service::{make_service_fn, service_fn};
use hyper::{Body, Error, Method, Request, Response, Server, StatusCode};
use lazy_static::lazy_static;
use regex::Regex;
use slab::Slab;
use std::fmt;
use std::net::SocketAddr;
use std::sync::{Arc, Mutex};
type UserId = u64;
struct UserData;
type UserDb = Arc<Mutex<... | true |
3912e8c1cb8844408504039fea1fe1abb43e6fa3 | Rust | filippixavier/AoC2020 | /src/days/day15.rs | UTF-8 | 1,630 | 3.1875 | 3 | [] | no_license | use std::error::Error;
use std::fs;
use std::path::Path;
fn prepare_input(input: String) -> Vec<usize> {
input
.trim()
.split(',')
.map(str::parse)
.collect::<Result<Vec<usize>, _>>()
.unwrap()
}
pub fn first_star() -> Result<(), Box<dyn Error + 'static>> {
use std::col... | true |
df0d106dda1bcd1900aa3b8ef33fb07a8caef261 | Rust | achen9/matrix_library | /tests/matrix_unit_tests_fraction.rs | UTF-8 | 12,692 | 3.34375 | 3 | [] | no_license | //! NAME
//! matrix_unit_tests_fraction.rs
//!
//! DESCRIPTION
//! Unit test file for complex class methods
//!
//! PARAMETERS
//! See specific method
//!
//! RETURN
//! See specific method
//!
//! EXAMPLE
//! See specific method
//!
//! NOTES
//! Make sure the Cargo.toml file is available to compile the code
//!... | true |
814360652b501d6b84c49e47326c8eeb01317274 | Rust | sabahtalateh/rust_by_example | /primitives/src/bin/arrays.rs | UTF-8 | 356 | 3.3125 | 3 | [] | no_license | use std::mem;
fn analyze_slice(slice: &[i32]) {
println!("first element = {}", slice[0]);
println!("{} elements at all", slice.len());
}
fn main() {
let xs: [i32; 5] = [1, 2, 3, 4, 5];
let ys: [i32; 500] = [0; 500];
println!("array occupied {} bytes", mem::size_of_val(&xs));
analyze_slice(&... | true |
f371afc76cadab5f39e7713d5eb48e65120c4610 | Rust | kunicmarko20/ghnotifier-rs | /src/ui/cli/command/uninstall.rs | UTF-8 | 1,550 | 2.640625 | 3 | [
"MIT"
] | permissive | use structopt::StructOpt;
use super::Command;
use std::path::Path;
use super::Output;
use crate::ui::asset::Asset;
#[derive(Debug, StructOpt)]
#[structopt(rename_all = "kebab-case")]
pub struct Uninstall {}
impl Command for Uninstall {
fn execute(&self, output: Box<Output>) {
output.write("Started uninsta... | true |
72fde42053a218262e3a7827525abe09f92ed74b | Rust | YonasJ/esp32-hello | /esp32-hal/src/ets.rs | UTF-8 | 1,337 | 2.953125 | 3 | [] | no_license | use embedded_hal::blocking::delay::{DelayMs, DelayUs};
extern "C" {
fn ets_delay_us(us: u32);
fn ets_printf(fmt: *const i8, ...) -> i32;
}
pub struct Ets;
impl DelayUs<u8> for Ets {
fn delay_us(&mut self, us: u8) {
unsafe { ets_delay_us(u32::from(us)) };
}
}
impl DelayUs<u16> for Ets {
fn delay_us(&mu... | true |
d513b021aafa396b58868499a1f25e5417176596 | Rust | deliangyang/leetcode.rs | /src/main.rs | UTF-8 | 1,129 | 3.34375 | 3 | [] | no_license | use std::thread;
use std::sync::mpsc::channel;
use demo::Test;
static NUM: i32 = 18;
fn coerce_static() -> i32 {
NUM
}
// FnOnce() 只可以调用一次哦
fn tt<F>(f: F)
where F: FnOnce() {
f();
// f(); 只可以调用一次,重复调用会报错
}
// Fn() 可以重复的调用,且状态不可的重复调用
fn apply<F>(f: F)
where F: Fn() {
f();
f();
}
// 所谓的... | true |
129aea7334d84439223c5858cfc519f18dd571ad | Rust | glalonde/spout | /src/load_image.rs | UTF-8 | 1,214 | 2.546875 | 3 | [] | no_license | // Loads a fixed demo texture to show UV coordinates.
pub fn load_image_to_texture(
device: &wgpu::Device,
queue: &wgpu::Queue,
) -> Result<wgpu::TextureView, image::ImageError> {
let image = image::load_from_memory(include_bytes!("../assets/texture_coordinates2.png"))?;
let image = image.into_bgra8();
... | true |
cdc43bf42d60be4ac1171dd212504acddf3ada9a | Rust | JosephCW/Survey-Project-1 | /src/main.rs | UTF-8 | 8,023 | 3.1875 | 3 | [] | no_license | use rand::Rng;
use std::cmp;
use std::io;
use std::time::SystemTime;
fn main() {
main_screen();
}
// This is so we can get it later and loop as many times as we want.
fn main_screen() {
println!("Enter 0 to run the hardcoded tests against brute force algorithm.");
println!("Enter 1 to run the hardcoded te... | true |
a3ef5f2b46d96473e98fc9aec35fdef8f972b21d | Rust | 18616378431/myCode | /rust/test6-17/src/main.rs | UTF-8 | 367 | 3.390625 | 3 | [] | no_license | //函数做为返回值,并与参与计算的值进行绑定
fn sum(a : i32, b : i32) -> i32 {
a + b
}
fn product(a : i32, b : i32) -> i32 {
a * b
}
type MathOp = fn(i32, i32) -> i32;
fn math(op : &str, a : i32, b : i32) -> MathOp {
match op {
"sum" => sum(a, b),
_ => product(a, b)
}
}
fn main() {
println!("Hello, wor... | true |
4ec71f1ccdfce37c31a5dfbe895c46aeaf7e4a17 | Rust | sagan-software/eosstrawpoll | /website/src/router/types.rs | UTF-8 | 2,952 | 3.234375 | 3 | [] | no_license | use eos::types::*;
use std::str::FromStr;
use stdweb::web::error::SecurityError;
use stdweb::web::Location;
use types::*;
#[derive(Clone, PartialEq)]
pub enum Route {
Home(Option<ChainIdPrefix>),
Profile(ChainIdPrefix, AccountName),
PollVoting(ChainIdPrefix, PollId),
PollResults(ChainIdPrefix, PollId),... | true |
617023888bc038acb69d3b6c754aa993648ee49e | Rust | SymmetricChaos/project_euler_rust | /src/worked_problems/euler_46.rs | UTF-8 | 1,849 | 3.828125 | 4 | [] | no_license | // What is the smallest odd composite that cannot be written as the sum of a prime and twice a square?
use crate::aux_funcs::{is_prime};
fn prime_diff(n: u64, v: &Vec<u64>) -> bool {
for s in v {
if s < &n {
if is_prime(n-s) {
return true
}
}
}
retur... | true |
b5c65f9ee8f642ab241589c6cd286db700e3cd94 | Rust | Jikstra/miniserve | /src/archive.rs | UTF-8 | 4,372 | 3.28125 | 3 | [
"MIT"
] | permissive | use actix_web::http::ContentEncoding;
use libflate::gzip::Encoder;
use serde::Deserialize;
use std::path::Path;
use strum_macros::{Display, EnumIter, EnumString};
use tar::Builder;
use crate::errors::ContextualError;
/// Available compression methods
#[derive(Deserialize, Clone, Copy, EnumIter, EnumString, Display)]
... | true |
85c2479e85c49d981fdd9d6426cda55868cf4852 | Rust | DanielKeep/rust-custom-derive | /newtype_derive/tests/deref_index.rs | UTF-8 | 902 | 2.6875 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | /*
Copyright ⓒ 2015 macro-attr contributors.
Licensed under the MIT license (see LICENSE or <http://opensource.org
/licenses/MIT>) or the Apache License, Version 2.0 (see LICENSE of
<http://www.apache.org/licenses/LICENSE-2.0>), at your option. All
files in the project carrying such notice may not be copied, modified,... | true |
b2ed156e66e694d423efc25c398e15fb6c979189 | Rust | zhyu/vim-clap | /crates/matcher/src/line_splitter.rs | UTF-8 | 4,085 | 2.59375 | 3 | [
"MIT"
] | permissive | use crate::{
fzy, skim::fuzzy_indices as fuzzy_indices_skim, substring::substr_indices, MatcherResult,
};
use pattern::{file_name_only, strip_grep_filepath, tag_name_only};
use structopt::clap::arg_enum;
// Implement arg_enum so that we could control it from the command line.
arg_enum! {
/// Sometimes we hope to... | true |
e5cd67fcf06836759b99fdf2fa1e9113b86b8ce7 | Rust | iqlusioninc/canister | /src/gcp/gcr.rs | UTF-8 | 2,601 | 2.625 | 3 | [
"Apache-2.0"
] | permissive | use super::oauth::{self, AuthHeader};
use crate::{
error::{Error, ErrorKind::*},
prelude::*,
};
use reqwest::header::ACCEPT;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use std::fmt;
#[derive(Serialize, Deserialize, Debug)]
pub struct Manifest {
#[serde(rename = "schemaVersion")]
p... | true |
7df9d4de2054c2ad93ccca642e576551e12b2eea | Rust | randomPoison/cs-bindgen | /cs-bindgen-cli/src/generate/enumeration.rs | UTF-8 | 13,512 | 2.859375 | 3 | [] | no_license | //! Code generation for exported enum types that are marshaled by value.
use crate::generate::{binding, quote_primitive_type, strukt, TypeMap, TypeNameExt};
use cs_bindgen_shared::{schematic::Enum, schematic::Variant, BindingStyle, NamedType, TypeName};
use proc_macro2::{Literal, TokenStream};
use quote::*;
use syn::I... | true |
32e0f1dc46eef0dcf7d7363f0f26303d366c918a | Rust | CaioTeixeira95/Euler | /problem_12/problem_12.rs | UTF-8 | 725 | 3.46875 | 3 | [
"MIT"
] | permissive | use std::collections::HashMap;
fn triangle_number(before: u32, n: u32) -> u32 {
before + n
}
fn factors(n: u32) -> u32 {
let mut step = 2;
if n % 2 == 0 {
step = 1;
}
let mut facs = HashMap::new();
for i in (1..((n as f64).sqrt() as u32) + 1).step_by(step) {
if n % i == 0 {
... | true |
35f315490b7d2f4885a82be2ad172cbab0daed73 | Rust | Kolsky/variant | /src/lib.rs | UTF-8 | 6,130 | 2.84375 | 3 | [] | no_license | #![no_std]
#![allow(unreachable_patterns)]
use core::marker::PhantomData;
pub trait Is<T>: Sized {
fn mov(self) -> T;
fn lend(&self) -> &T;
fn lend_mut(&mut self) -> &mut T;
}
impl<T> Is<T> for T {
fn mov(self) -> T {
self
}
fn lend(&self) -> &T {
self
}
fn lend_mut(&... | true |
04a6a24c88d693dfe89e2bcf2c9490cf56a739d6 | Rust | vbeffa/rust-book | /fibonacci/src/main.rs | UTF-8 | 840 | 3.875 | 4 | [] | no_license | use std::collections::HashMap;
use std::io;
fn main() {
println!("Fibonacci calculator");
let mut fibs: HashMap<u32, u64> = HashMap::new();
fibs.insert(1, 1);
fibs.insert(2, 1);
loop {
println!("Enter the value of N:");
let mut n = String::new();
io::stdin().read_line(&m... | true |
69845bdfae70c6c3c2a141dc0bb8b51d5de7f77c | Rust | russmack/rustylifx | /src/request.rs | UTF-8 | 11,397 | 2.890625 | 3 | [
"BSD-3-Clause"
] | permissive | #![allow(dead_code)]
type Bit = bool;
#[derive(Debug)]
pub struct Request {
header: Header,
payload: Payload,
}
impl Request {
pub fn new(header: Header, payload: Payload) -> Request {
Request { header, payload }
}
}
#[derive(Debug)]
pub struct Payload(pub Vec<u8>);
// RequestBin newtype
pu... | true |
7f4bbb40d60659496568200df1a75a928883b48d | Rust | zargony/advent-of-code-2019 | /src/bin/day01.rs | UTF-8 | 1,444 | 3.125 | 3 | [] | no_license | use advent_of_code_2019::Input;
use async_std::io;
use futures_util::stream::TryStreamExt;
fn fuel_for_mass(mass: u32) -> u32 {
match mass / 3 {
0..=2 => 0,
x => x - 2,
}
}
fn fuel_for_mass_including_fuel(mass: u32) -> u32 {
match fuel_for_mass(mass) {
0 => 0,
fuel => fuel ... | true |
25e3f1ce9f8f4769488fd5070b2e4750f574a3db | Rust | Razican/vsop87-rs | /benches/vsop87e.rs | UTF-8 | 2,244 | 2.53125 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! VSOP87e benchmarks.
#[macro_use]
extern crate criterion;
extern crate rand;
extern crate vsop87;
use criterion::Criterion;
use rand::{thread_rng, Rng};
use vsop87::vsop87e;
fn vsop87e_sun(c: &mut Criterion) {
let mut rng = thread_rng();
c.bench_function("VSOP87e Sun", move |b| {
b.iter(|| vsop87e... | true |
af2987103c8a594dda3a1feea34aac9ed26674fb | Rust | undo76/raytracer-rust | /core/src/cube.rs | UTF-8 | 4,918 | 3.078125 | 3 | [
"MIT"
] | permissive | use crate::*;
#[derive(Debug)]
pub struct Cube {
base: BaseShape,
}
impl Cube {
pub fn new(transform: Transform, material: Material) -> Cube {
Cube {
base: BaseShape::new(transform, material),
}
}
}
impl Default for Cube {
fn default() -> Cube {
Cube::new(Transform... | true |
dbc031900ad4d90a13997735f56c56f0689f76a6 | Rust | renesugar/webml | /src/ast/pp.rs | UTF-8 | 19,052 | 2.859375 | 3 | [] | no_license | use crate::ast::*;
use crate::util::{nspaces, PP};
use std::fmt;
use std::io;
impl<Ty: PP, DE: PP, DS: PP> PP for Context<Ty, DE, DS> {
fn pp<W: io::Write>(&self, w: &mut W, indent: usize) -> io::Result<()> {
self.1.pp(w, indent)
}
}
impl<Ty: fmt::Display, DE: fmt::Display, DS: fmt::Display> fmt::Disp... | true |
4a6ee915a8d7e09b6de31d73ae120466d636ef9c | Rust | zn3x/rusty-zenith | /src/stream.rs | UTF-8 | 1,858 | 2.875 | 3 | [] | no_license | use tokio::net::TcpStream;
use std::error::Error;
use tokio::io::{ AsyncReadExt, AsyncWriteExt };
use std::io::ErrorKind;
pub async fn write_to_client( stream: &mut TcpStream, sent_count: &mut usize, metalen: usize, data: &[ u8 ], metadata: &[ u8 ] )
-> Result< (), std::io::Error > {
let new_sent = *sent... | true |
75d4846fd809156df9846eb4da28202d4a6b392b | Rust | lusamreth/my_first_cli_app | /src/interface/printer.rs | UTF-8 | 2,504 | 3.28125 | 3 | [] | no_license | use console::{Attribute, Color};
use std::io::{self, Write};
pub struct TermCfg {
color: Color,
background: Color,
attribute: Attribute,
}
pub type Printer<'a> = Box<dyn FnMut(&str) -> io::Result<()> + 'a>;
impl TermCfg {
pub fn new() -> Self {
TermCfg {
color: Color::Green,
... | true |
257d71a11ca4b4ed87fdaee875c08988b066b54a | Rust | rcore-os-infohub/ossoc2020-chibinz-daily | /step0/15_programming_exericise/ex18_function_pointers.rs | UTF-8 | 720 | 3.8125 | 4 | [
"MIT"
] | permissive | /// Rust allows you to write function pointer(type) in an elegant and simple way
type CmpFn = fn(i32, i32) -> bool;
fn bubble_sort(numbers: &mut [i32], cmp: CmpFn) {
let len = numbers.len();
for _ in 0..len {
for j in 0..(len - 1) {
if cmp(numbers[j], numbers[j+1]) {
let te... | true |
6fef2518593b79440ccb9de49929021984f50044 | Rust | librespot-org/librespot | /core/src/audio_key.rs | UTF-8 | 3,215 | 2.625 | 3 | [
"MIT",
"LicenseRef-scancode-warranty-disclaimer"
] | permissive | use std::{collections::HashMap, io::Write};
use byteorder::{BigEndian, ByteOrder, WriteBytesExt};
use bytes::Bytes;
use thiserror::Error;
use tokio::sync::oneshot;
use crate::{packet::PacketType, util::SeqGenerator, Error, FileId, SpotifyId};
#[derive(Debug, Hash, PartialEq, Eq, Copy, Clone)]
pub struct AudioKey(pub... | true |
e9efb3562110c015c48f32a6af8ed9e31dcb34ca | Rust | leun4m/colorful | /src/models/rgb/rgb24.rs | UTF-8 | 12,006 | 3.59375 | 4 | [
"MIT"
] | permissive | use crate::{converter, RGB48};
use crate::models::hsv::HSV;
use crate::models::rgb::RGBColor;
use crate::models::Color;
use crate::number_utils;
use std::fmt::{Display, Formatter, Result};
/// 24-bit RGB color
///
/// This is the most widespread variant of RGB called
/// [True color (24-bit)](https://en.wikipedia.org/... | true |
d41934100edb2c388929f15b73aa7fae5857f672 | Rust | Logicalshift/flo_curves | /src/bezier/mod.rs | UTF-8 | 1,775 | 2.71875 | 3 | [
"Apache-2.0"
] | permissive | //!
//! # Routines for describing, querying and manipulating Bezier curves
//!
//! Bezier curves are described by types that implement the `BezierCurve` trait, as a start point, an end point
//! and two control points. The `Curve` type is provided as a base implementation but as with the other traits,
//! the primary ... | true |
954e18e9f90b67fb1976104a0233f4b7f97f863d | Rust | liaowang11/effective-leetcode | /rust/solutions/src/p9_palindrome_number.rs | UTF-8 | 889 | 3.59375 | 4 | [
"MIT"
] | permissive | struct Solution {}
/// TODO: don't convert to str..
impl Solution {
pub fn is_palindrome(x: i32) -> bool {
if x < 0 {
false
} else {
Self::is_palindrome_str(&x.to_string())
}
}
fn is_palindrome_str(s: &str) -> bool {
let len = s.len();
let char... | true |
40a9c59b4497e91db9974c38d7256d890cb70ef6 | Rust | solana-labs/solana | /zk-token-sdk/src/instruction/ciphertext_commitment_equality.rs | UTF-8 | 4,828 | 2.546875 | 3 | [
"Apache-2.0"
] | permissive | //! The ciphertext-commitment equality proof instruction.
//!
//! A ciphertext-commitment equality proof is defined with respect to a twisted ElGamal ciphertext
//! and a Pedersen commitment. The proof certifies that a given ciphertext and a commitment pair
//! encrypts/encodes the same message. To generate the proof, ... | true |
c8ee8334d7e92402549882e9752cbd505b3ec0fe | Rust | d3lio/BattleTanks | /engine/src/core/data_ptr.rs | UTF-8 | 1,853 | 3.640625 | 4 | [
"MIT"
] | permissive | /// Powerful raw pointer wrapper.
///
/// It has the semantics of the C `void*` type but since it's a tuple struct it
/// should not be confused with `libc::c_void`, ZSTs or empty types.
///
/// **This structure hides great unsafety because it can dereference an invalid raw pointer
/// and thus it should be used with c... | true |
2511de3105de119e207eacf3946e307bba2cad50 | Rust | LongJohnCoder/moxie | /topo/macro/src/lib.rs | UTF-8 | 3,382 | 2.765625 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | //! Procedural macro support crate for the `topo` crate.
#![deny(missing_docs)]
extern crate proc_macro;
use {proc_macro::TokenStream, syn::export::TokenStream2};
/// Transforms a function declaration into a topologically-nested function invoked with macro syntax
/// to attach its call tree's (sub)topology to the pa... | true |
dfd70373f4e66605b8bd49bed0f20d660f4fe007 | Rust | scrblue/transaction-processor | /src/main.rs | UTF-8 | 2,328 | 2.8125 | 3 | [] | no_license | mod db_layer;
mod fixed_point_util;
mod model;
mod reader;
mod transaction_processing;
mod writer;
use db_layer::DbLayer;
use model::*;
use reader::TransactionReader;
use writer::ClientWriter;
/// The number of [`Transaction`]s to allow in the [`tokio::sync::mpsc::Receiver`]'s queue. Each
/// [`Transaction`] will be ... | true |
5229461e85aab4ceac7468ffc849fa4b6f093aaf | Rust | wotsushi/competitive-programming | /arc/090/d.rs | UTF-8 | 1,825 | 2.890625 | 3 | [
"MIT"
] | permissive | #![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]
fn main() {
let (N, M): (usize, usize) = {
let mut line: String = String::new();
std::io::stdin().read_line(&mut line).unwrap();
let mut iter = line.split_whitespace();
(
iter.next().unwrap().pars... | true |
97a679a0e8829bec70c33e5f0452a427ceab926f | Rust | jkallio/advent-of-code-2020 | /day5/src/jk/file_reader.rs | UTF-8 | 398 | 3.203125 | 3 | [] | no_license | use std::fs::File;
use std::io::{BufRead, BufReader};
pub fn read_to_vec(path: &str) -> Result<Vec<String>, std::io::Error> {
// Open the file from given path
let file = File::open(path)?;
// Wrap the file into BufReader to increase performance
let br = BufReader::new(file);
let mut vec = Vec::new... | true |
24b8da6c779125b0a070299f442e1d7345eb1de5 | Rust | MaxOhn/Bathbot | /bathbot-cache/src/key/set.rs | UTF-8 | 1,740 | 2.65625 | 3 | [
"ISC"
] | permissive | use std::borrow::Cow;
use itoa::Buffer;
use twilight_model::id::{marker::GuildMarker, Id};
#[derive(Clone, Debug)]
pub(crate) enum SetEntry {
Channels,
Guilds,
GuildChannels { guild: Id<GuildMarker> },
GuildMembers { guild: Id<GuildMarker> },
GuildRoles { guild: Id<GuildMarker> },
Roles,
U... | true |
7c0109e8ddfc1fc9f42012b5b78dbbe8004e09a5 | Rust | Checkmate50/rust99problems | /src/bin/03.rs | UTF-8 | 326 | 3.296875 | 3 | [
"MIT"
] | permissive | // Find kth element of a list
fn my_but_last<T>(v : &[T], i : usize) -> Option<&T> {
if v.len() < i {
return None;
}
Some(&v[i-1])
}
fn main() {
let v = vec![1, 2, 3, 4];
r99p::print_option(my_but_last(&v, 2));
let v2 = vec!['x', 'y', 'z'];
r99p::print_option(my_but_last(&v2, ... | true |
e189d17ca18bb701195f205090b379415ac1f76d | Rust | ethereumproject/evm-dev | /src/rpc/serialize.rs | UTF-8 | 2,794 | 3.28125 | 3 | [
"Apache-2.0"
] | permissive | use serde::{Serialize, Serializer, Deserializer, Deserialize, de};
use std::fmt::{self, LowerHex};
use std::marker::PhantomData;
use std::str::FromStr;
use hexutil::*;
#[derive(Debug, Hash, Clone, Eq, PartialEq)]
pub struct Hex<T>(pub T);
#[derive(Debug, Clone)]
pub struct Bytes(pub Vec<u8>);
impl<T: LowerHex> Serial... | true |
bd4df5ae00c847a1ea7618deb4d993842268f739 | Rust | wyhaya/see | /src/matcher/ip.rs | UTF-8 | 1,342 | 3.25 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | use crate::matcher::WildcardMatcher;
use crate::util;
use std::net::IpAddr;
#[derive(Debug, Clone)]
pub struct IpMatcher {
allow: Vec<MatchMode>,
deny: Vec<MatchMode>,
}
#[derive(Debug, Clone)]
enum MatchMode {
Ip(IpAddr),
Wildcard(WildcardMatcher),
}
impl MatchMode {
fn new(s: &str) -> Result<Se... | true |
2af351d40d62ec97c681105ec27eee62c3326ad4 | Rust | gillett-hernandez/minesweeper_rs | /src/solver.rs | UTF-8 | 11,002 | 3.078125 | 3 | [] | no_license | use rayon::iter::{
IndexedParallelIterator, IntoParallelRefIterator, IntoParallelRefMutIterator, ParallelIterator,
};
use crate::game::*;
pub trait Strategy {
fn attempt(&mut self, game_state: &GameState) -> Vec<Event>;
fn update(&mut self, game_state: &GameState, event: Event);
}
pub struct BijectionDet... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.