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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
73462ee055e4aec906ff8d244854bd68852baf37 | Rust | warner/tock | /chips/sam4l/src/dac.rs | UTF-8 | 3,250 | 2.78125 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | //! Implementation of the SAM4L DACC.
//!
//! Ensure that the `ADVREFP` pin is tied to `ADDANA`.
//!
//! - Author: Justin Hsieh <hsiehju@umich.edu>
//! - Date: May 26th, 2017
use core::cell::Cell;
use core::mem;
use kernel::ReturnCode;
use kernel::common::VolatileCell;
use kernel::hil;
use nvic;
use pm::{self, Clock, ... | true |
0ddb0151734212e4b5b4d20bffe1f45562d51295 | Rust | moshg/rust-std-ja | /src/test/run-pass/u128-as-f32.rs | UTF-8 | 2,617 | 2.6875 | 3 | [
"MIT",
"BSD-3-Clause",
"NCSA",
"Apache-2.0",
"LicenseRef-scancode-other-permissive",
"BSD-2-Clause"
] | permissive | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or ... | true |
4f665c1e7d62802ec72a17b547a40c025af6b456 | Rust | kharenzze/rust-steering-example | /src/keyboard.rs | UTF-8 | 2,006 | 3.140625 | 3 | [] | no_license | use ggez::event::KeyCode;
use glam::Vec2;
use std::convert::TryFrom;
#[repr(usize)]
pub enum Direction {
Up = 0,
Right = 1,
Down = 2,
Left = 3,
}
impl DirPressedStatus {
fn iter_direction(&self) -> impl Iterator<Item = (Direction, bool)> {
let value = self.0;
(0..4_usize).into_iter().map(move |i| {
... | true |
76021bee2211ec6857013dcd0387e31523cd07b3 | Rust | hilam8899/stm32hal | /templates/rcc/peripherals.rs | UTF-8 | 1,778 | 3.015625 | 3 | [] | no_license | {{!
// Add the following API for all the peripherals that are managed by the RCC:
// - `rcc.enable_peripheral()` method,
// - `rcc.disable_peripheral()` method,
// - `rcc.reset_peripheral()` method,
//
// See the generated documentation for the exact list of provided methods.
~}}//! The RCC peripherals API
//... | true |
6a5346118cedcdd2b6b1528a6c215224725f6590 | Rust | potatosalad/exercism | /rust/word-count/src/lib.rs | UTF-8 | 475 | 3.140625 | 3 | [] | no_license | use std::collections::HashMap;
pub fn word_count(words: &str) -> HashMap<String, u32> {
let mut counts: HashMap<String, u32> = HashMap::new();
for word in words
.split(|c: char| c.is_whitespace() || c == ',' || c == ';')
.map(|s| s.trim_matches(|c: char| !c.is_alphanumeric()))
.filter(|... | true |
168ffdb478d44dfabd5d9f0e39387f087cbbbc96 | Rust | MugenU/rust-callgraph-benchmark | /src/structs/src/lib/fat.rs | UTF-8 | 1,463 | 3.34375 | 3 | [
"MIT"
] | permissive | use traits::lib::FooTrait;
use traits::lib::BarTrait;
use traits::lib::BazTrait;
use traits::lib::DefaultTrait;
pub struct Fat(pub u32);
impl Fat {
pub fn method(&self) -> u32 {
self.0
}
// Note the mut modifier on self. Method lookup is done for each type in order as described in
// https://... | true |
c92b13967e179ca8616d87edaa85a7d8b9df1ed0 | Rust | alextanhongpin/rust-book | /08-common-collections/02-strings.rs | UTF-8 | 1,070 | 3.859375 | 4 | [] | no_license | fn main() {
// Initializing a new string
// let mut s = String::new();
let data = "initial contents";
let s = data.to_string();
println!("s is now {}", s);
let s = "initial contents".to_string();
println!("s is now {}", s);
// Appending a string with push_str
let mut s = String::from("foo");
s.pu... | true |
8c410dc09569850f23016223e48840b018eb55a5 | Rust | willsalz/linked_list | /src/main.rs | UTF-8 | 1,591 | 3.65625 | 4 | [
"MIT"
] | permissive | use std::mem;
#[derive(Debug)]
enum Node<T> {
Head(T, Box<Node<T>>),
Tail
}
impl<T> Node<T> {
fn new(data: T) -> Self {
Node::Head(data, Box::new(Node::Tail))
}
}
#[derive(Debug)]
struct List<T> {
head: Node<T>
}
impl<T> List<T> {
fn new(data: T) -> Self {
List{head: Node::... | true |
2613e21ae5cffea970f5e646584352e9076360bc | Rust | jrheard/advent_2019 | /src/fourteen.rs | UTF-8 | 6,235 | 3.15625 | 3 | [] | no_license | use once_cell::sync::Lazy;
use regex::Regex;
use std::collections::{HashMap, VecDeque};
use std::fs;
static OUTER_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"(.*) => (.*)").unwrap());
static COMPONENT_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"([0-9]*) ([A-Z]*)").unwrap());
static ONE_TRILLION: u64 = 1_000_000_000_0... | true |
54ea96f0ddc968b259eb87c853fc41d56d26c278 | Rust | tomjakubowski/hyper | /src/header/common/etag.rs | UTF-8 | 2,728 | 3.328125 | 3 | [
"MIT"
] | permissive | use header::{EntityTag, Header, HeaderFormat};
use std::fmt::{self, Display};
use header::parsing::from_one_raw_str;
/// The `Etag` header.
///
/// An Etag consists of a string enclosed by two literal double quotes.
/// Preceding the first double quote is an optional weakness indicator,
/// which always looks like thi... | true |
fe38894ac21c08c19e05004db0243078558f212b | Rust | crsaracco/parks-mcclellan-rs | /src/pm/lagrange_interpolation.rs | UTF-8 | 2,704 | 2.8125 | 3 | [] | no_license | use super::ExtremalFrequencies;
use super::DenseGrid;
use super::PI2;
pub fn lagrange_x_coordinates(
num_coefficients: usize,
grid: &DenseGrid,
extremal_frequencies: &ExtremalFrequencies,
) -> [f64; 66] {
let mut x = [0.0; 66];
let last_coefficient_index = num_coefficients + 1;
for j in 1..(las... | true |
6c342005bbefd622639c308721bb48cc3e44626d | Rust | blacktemplar/lighthouse | /crypto/eth2_hashing/src/lib.rs | UTF-8 | 3,064 | 3.03125 | 3 | [
"Apache-2.0"
] | permissive | //! Provides a simple hash function utilizing `ring::digest::SHA256`.
//!
//! The purpose of this crate is to provide an abstraction to whatever hash function Ethereum
//! 2.0 is using. The hash function has been subject to change during the specification process, so
//! defining it once in this crate makes it easy to ... | true |
d3a393561a92866d30b71392736567d0c6f115f1 | Rust | pmuens/t2f | /src/dispatcher.rs | UTF-8 | 1,976 | 2.5625 | 3 | [] | no_license | use crossbeam;
use tokio;
use regex::Regex;
use hyper_tls::HttpsConnector;
use futures::{future, Future};
use hyper::{Client, Uri, Request, Body, Method, header};
use config::{Config, Mapping};
pub struct Dispatcher<'a> {
config: &'a Config
}
impl<'a> Dispatcher<'a> {
pub fn new(config: &Config) -> Dispatche... | true |
8c1bd01ed036e133d4978d6f436c8017bd55ec7f | Rust | FloydATC/rlox | /src/lox/compiler/tokenizer/test/base16numbers.rs | UTF-8 | 2,800 | 2.828125 | 3 | [] | no_license |
use scanner::Scanner;
use crate::lox::compiler::{Tokenizer, Tokenize, TokenKind};
#[test]
fn tokenizer_base16number_lowercase_digits() {
for digit in ('0'..='9').chain('a'..='f') {
let code = format!("0x{}", digit);
let want = format!("0x{}", digit);
println!("digit={} code={} want={}"... | true |
a3f74ebea76f84b7f7fa05d90b3fa7eb4d2926e4 | Rust | mozilla/gecko-dev | /third_party/rust/crash-context/src/mac.rs | UTF-8 | 1,027 | 2.765625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0",
"MIT"
] | permissive | pub mod guard;
pub mod ipc;
pub mod resource;
use mach2::mach_types as mt;
/// Information on the exception that caused the crash
#[derive(Copy, Clone, Debug)]
pub struct ExceptionInfo {
/// The exception kind
pub kind: u32,
/// The exception code
pub code: u64,
/// Optional subcode with different... | true |
6f2eda64e0431524586ba9e3d85d33040c82652c | Rust | copygirl/farm | /src/controls.rs | UTF-8 | 1,258 | 2.625 | 3 | [] | no_license | use std::convert::TryFrom;
use amethyst::{
ecs::prelude::*,
input::{InputHandler, StringBindings},
};
use crate::components::{Direction, Movement};
#[derive(Default)]
pub struct Player;
impl Component for Player {
type Storage = NullStorage<Self>;
}
#[derive(Default)]
pub struct ControlsSystem;
impl<'... | true |
781254ca255bda74582247071d8d9149c533aad4 | Rust | str4d/zebra | /zebra-network/src/address_book.rs | UTF-8 | 6,809 | 3.046875 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! The addressbook manages information about what peers exist, when they were
//! seen, and what services they provide.
use std::{
collections::{BTreeSet, HashMap},
iter::Extend,
net::SocketAddr,
};
use chrono::{DateTime, Utc};
use tracing::Span;
use crate::{
constants,
types::{MetaAddr, PeerSer... | true |
2b4c61c064e00f0bd6c2c23aa0fb38019d3dc050 | Rust | tfdiaz/Advent2018 | /day5/src/main.rs | UTF-8 | 2,010 | 3.21875 | 3 | [] | no_license |
use std::io::prelude::*;
use std::fs::File;
use std::collections::VecDeque;
fn main() {
let mut f = File::open("inputday5.txt").expect("Error in file");
let mut content = String::new();
f.read_to_string(&mut content).expect("Eror");
let mut buf: VecDeque<char> = content.chars().collect();
let mut ... | true |
e614987149a69a8c4a9c3f868f24bad87f388a89 | Rust | mun-lang/mun | /crates/mun_language_server/src/completion/item.rs | UTF-8 | 3,343 | 3.5 | 4 | [
"Apache-2.0",
"MIT"
] | permissive | use crate::SymbolKind;
/// A `CompletionItem` describes a single completion variant in an editor.
#[derive(Clone, Debug)]
pub struct CompletionItem {
/// Used for tests to filter certain type of completions
#[allow(unused)]
pub completion_kind: CompletionKind,
/// Label in the completion pop up which ... | true |
bcc113cde316e024adfdf42d6d2a775073b5730f | Rust | reeshogue/Experiments | /Rust/langton/langton.rs | UTF-8 | 1,567 | 3.5625 | 4 | [
"MIT"
] | permissive | struct Ant {
x: usize,
y: usize,
dir: Direction
}
#[derive(Copy, Clone)]
enum Direction {
North,
South,
East,
West
}
use Direction::*;
impl Ant {
fn mv(&mut self, grid: &mut Vec<Vec<u8>>) {
let pointer = &mut grid[self.x][self.y];
match *pointer {
... | true |
b797bee7ca3b2cc1a3306926f0744339e1c5e8e7 | Rust | frostRed/rust-rosetta | /src/dns_query.rs | UTF-8 | 1,525 | 3 | 3 | [
"Unlicense"
] | permissive | // http://rosettacode.org/wiki/DNS_query
#![feature(lookup_host)]
use std::io;
use std::net::{Ipv4Addr, Ipv6Addr};
#[derive(PartialEq)]
enum Ips {
IpV4(Ipv4Addr),
IpV6(Ipv6Addr),
}
fn get_ips(host: &str) -> io::Result<Vec<Ips>> {
use std::net::{self, SocketAddr};
use Ips::{IpV4, IpV6};
let hosts ... | true |
078c2b2b7489e0038dd8fafef5dacb2bf8cc7e4c | Rust | Logicalshift/flowbetween | /animation/src/serializer/vector/motion.rs | UTF-8 | 3,396 | 3.25 | 3 | [
"Apache-2.0"
] | permissive | use super::super::source::*;
use super::super::target::*;
use super::super::super::traits::*;
use std::sync::*;
impl MotionElement {
///
/// Generates a serialized version of this motion element on the specified data target
///
pub fn serialize<Tgt: AnimationDataTarget>(&self, data: &mut Tgt) {
... | true |
79a40b34177bd5a32dc6b37824953442bb552c1b | Rust | akazukin5151/koneko-rs | /koneko-rs/src/colors.rs | UTF-8 | 2,434 | 2.90625 | 3 | [
"MIT"
] | permissive | pub const RED: &str = "\x1b[31m";
pub const MAGENTA: &str = "\x1b[35m";
pub const BLUE: &str = "\x1b[34m";
pub const RESET: &str = "\x1b[39m";
#[allow(non_snake_case)]
pub fn BLUE_N() -> String {
format!("{}[{}n{}]{}", RED, BLUE, RED, RESET)
}
#[allow(non_snake_case)]
fn COORDS() -> String {
format!(
... | true |
793b542e5170051bb1d7c55429fc353665d940ce | Rust | thorncp/rusticbot | /irc.rs | UTF-8 | 1,466 | 2.875 | 3 | [] | no_license | use std::io::net::ip::SocketAddr;
use std::io::net::addrinfo::get_host_addresses;
use std::io::net::tcp::TcpStream;
use std::os;
fn main() {
let args = os::args();
if args.len() < 5 {
fail!("usage: ./irc <server> <port> <nick> <channel>");
}
// TODO figure out better args usage
let server = args[1].clo... | true |
72131d0007cd9c9a07a1fd86862215b235883a82 | Rust | dphm/convert_temp | /tests/integration_test.rs | UTF-8 | 1,581 | 3 | 3 | [] | no_license | extern crate convert_temp;
#[macro_use]
mod common;
use convert_temp::to_fahrenheit;
use convert_temp::to_celsius;
const DELTA: f64 = 1.0e-7;
const ABSOLUTE_ZERO_F: f64 = -459.67;
const ABSOLUTE_ZERO_C: f64 = -273.15;
macro_rules! test_from_fahrenheit {
($test_name: ident, $from: expr, $to: expr) => (
#... | true |
85a4b039e0c94077a2e23ce8f3dff617f64faad8 | Rust | wiltonlazary/wasmer | /lib/api/src/js/resolver.rs | UTF-8 | 5,416 | 3.328125 | 3 | [
"MIT"
] | permissive | use crate::js::export::Export;
/// Import resolver connects imports with available exported values.
pub trait Resolver {
/// Resolves an import a WebAssembly module to an export it's hooked up to.
///
/// The `index` provided is the index of the import in the wasm module
/// that's being resolved. For ... | true |
6b1b52906a8f2dec9d43d4b6e8135a55d15ce643 | Rust | lpeterse/rsynth | /src/signal.rs | UTF-8 | 1,156 | 2.828125 | 3 | [] | no_license | mod amp;
mod boxed;
mod clock;
mod factor;
mod multiple;
mod saw;
mod sequence;
mod sine;
mod square;
mod sum;
pub use self::amp::*;
pub use self::boxed::*;
pub use self::clock::*;
pub use self::factor::*;
pub use self::multiple::*;
pub use self::saw::*;
pub use self::sequence::*;
pub use self::sine::*;
pub use self::... | true |
994b1c4c06475e3f850315374baf6fa34a6718e9 | Rust | royswale/leetcode | /src/bin/sort-colors.rs | UTF-8 | 738 | 3.15625 | 3 | [
"MIT"
] | permissive | fn main() {
let mut v = vec![2, 0, 2, 1, 1, 1, 1, 1, 0, 2, 2, 2, 2, 0, 0, 2, 1, 0];
Solution::sort_colors(&mut v);
let mut v = vec![1, 0];
Solution::sort_colors(&mut v);
}
struct Solution;
impl Solution {
pub fn sort_colors(nums: &mut Vec<i32>) {
let (mut p1, mut p2, mut cursor) = (0, 0, ... | true |
7ff408b563bc1e2faedd2f3d9b217841b391d468 | Rust | aemino/mun-relay | /src/main.rs | UTF-8 | 13,989 | 2.515625 | 3 | [
"MIT"
] | permissive | use std::{collections::HashSet, fs::File, sync::Arc, time::Duration};
use anyhow::{Context as _, Result};
use serenity::{
async_trait,
client::bridge::gateway::GatewayIntents,
framework::standard::{
macros::{command, group},
Args, CommandResult, StandardFramework,
},
futures::Stream... | true |
af07771b68be48a5b6a5076a9c4f692ff016e9b7 | Rust | asny/tri-mesh | /src/mesh.rs | UTF-8 | 1,531 | 2.78125 | 3 | [
"MIT"
] | permissive | pub use crate::math::*;
mod io;
#[doc(inline)]
pub use io::*;
mod utility;
#[doc(inline)]
pub use utility::*;
mod append;
#[doc(inline)]
pub use append::*;
mod cleanup;
#[doc(inline)]
pub use cleanup::*;
mod ids;
#[doc(inline)]
pub use ids::*;
mod iterators;
#[doc(inline)]
pub use iterators::*;
mod traversal;
#[... | true |
783b648d8019d80863831d5a1f7d658d28adf696 | Rust | I3ck/rust-3d | /src/test_helper.rs | UTF-8 | 4,576 | 2.640625 | 3 | [
"MIT",
"LicenseRef-scancode-warranty-disclaimer"
] | permissive | /*
Copyright 2017 Martin Buck
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublice... | true |
d6efe311accbe05ea70f38a1fe0d5c0329f597ee | Rust | bolcom/libunftp | /src/server/controlchan/commands/dele.rs | UTF-8 | 2,425 | 2.84375 | 3 | [
"Apache-2.0"
] | permissive | //! The RFC 959 Delete (`DELE`) command
//
// This command causes the file specified in the pathname to be
// deleted at the server site. If an extra level of protection
// is desired (such as the query, "Do you really wish to delete?"),
// it should be provided by the user-FTP process.
use crate::{
auth::UserDet... | true |
06f40d75f000318c04063d3e28b9ca021c0c86ec | Rust | KieronJ/rnes | /src/nes/ricoh2a03/mod.rs | UTF-8 | 633 | 2.59375 | 3 | [
"MIT"
] | permissive | mod addressing;
mod functions;
mod instructions;
mod status;
use nes::bus::Bus;
use nes::ricoh2a03::status::Status;
#[derive(PartialEq)]
pub enum InterruptType {
NMI,
RESET,
IRQ,
BRK,
}
pub struct Ricoh2A03 {
pc: u16,
a: u8,
x: u8,
y: u8,
s: u8,
p: Status,
bus: Bus,
}
impl Ricoh2A03 ... | true |
3ec9664fbc3c7804711b590955d72dd3b364ebd0 | Rust | chrisbutcher/gameboy | /src/gb.rs | UTF-8 | 2,142 | 2.59375 | 3 | [] | no_license | pub use super::bootrom;
pub use super::cartridge;
pub use super::cpu;
pub use super::fps;
pub use super::input;
pub use super::mmu;
pub use super::ppu;
pub use super::timer;
pub use super::window_set;
pub struct GameBoy {
pub cpu: cpu::CPU,
pub mmu: mmu::MMU,
}
impl GameBoy {
pub fn new() -> Box<GameBoy> {
... | true |
fcc618d3e4d94242efda7d5d3dae017068f0a828 | Rust | betseg/aoc20 | /src/day02.rs | UTF-8 | 1,527 | 3.359375 | 3 | [
"LicenseRef-scancode-warranty-disclaimer"
] | no_license | use scan_fmt::scan_fmt;
#[derive(Debug)]
pub struct Password {
lo: usize,
hi: usize,
letter: char,
pw: String,
}
#[aoc_generator(day2)]
pub fn input_generator(input: &str) -> Vec<Password> {
let mut pws = Vec::new();
for pw in input.lines() {
if let Ok((lo, hi, letter, pw)) = scan_fmt!... | true |
e45cd3f4ccda12694e933d817daf944f4a559649 | Rust | sbrocket/serenity | /src/model/interactions/ping.rs | UTF-8 | 651 | 2.59375 | 3 | [
"ISC"
] | permissive | use crate::model::id::{ApplicationId, InteractionId};
use crate::model::interactions::InteractionType;
/// A ping interaction, which can only be received through an endpoint url.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PingInteraction {
/// Id of the interaction.
pub id: In... | true |
d85a22cb3f181f853c9d1b3d10971c5697fd2ed1 | Rust | redox-os/kernel | /src/arch/x86/consts.rs | UTF-8 | 1,417 | 2.53125 | 3 | [
"MIT"
] | permissive | // Because the memory map is so important to not be aliased, it is defined here, in one place
// The lower 256 PML4 entries are reserved for userspace
// Each PML4 entry references up to 512 GB of memory
// The second from the top (510) PML4 is reserved for the kernel
/// Offset of kernel (256 MiB max)
pub con... | true |
008ab53398900d4b44b0b433cf8a76566ae198b4 | Rust | tonnylyz/geometry-sketchpad | /src/components/line.rs | UTF-8 | 571 | 2.875 | 3 | [] | no_license | use specs::prelude::*;
use crate::utilities::Color;
pub use crate::utilities::Line;
#[derive(Debug, Copy, Clone)]
pub struct LineStyle {
pub width: f64,
pub color: Color,
}
impl Component for LineStyle {
type Storage = VecStorage<Self>;
}
#[derive(Debug, Copy, Clone)]
#[allow(dead_code)]
pub enum SymbolicLine ... | true |
52b8a0c2f9153a9c7c34a9c43985dee63bec8695 | Rust | AGolumbovsky/jr | /src/main.rs | UTF-8 | 640 | 2.765625 | 3 | [] | no_license | use std::io;
fn main() {
loop{
println!("enter something");
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("patronum!");
println!("your input was: {}", input);
}
}
// following code is from nazioverflow
// can be modified... | true |
92bdbacfe1154fdacb61c99115ed1a01ad6517d1 | Rust | pbspbsingh/RLox | /src/main.rs | UTF-8 | 579 | 2.734375 | 3 | [] | no_license | use std::env;
use std::fs;
use std::time::Instant;
use rlox::RLox;
fn main() {
println!("Hello World, rlox version: {}", env!("CARGO_PKG_VERSION"));
let mut rlox = RLox::default();
match env::args().nth(1) {
None => eprintln!("Usage: rlox <script file>"),
Some(f) => {
let src ... | true |
890f05eb86fbd39de3a89415725e0577450312a7 | Rust | clchiou/garage | /rust/bittorrent/metainfo/src/sanity.rs | UTF-8 | 8,569 | 2.828125 | 3 | [
"MIT"
] | permissive | use std::ops::RangeInclusive;
use snafu::prelude::*;
use crate::{Error, Info, InsaneSnafu, Metainfo, Mode};
const PIECE_LENGTH_RANGE: RangeInclusive<u64> = 512..=(2 * MB);
const MB: u64 = 1 << 20;
#[derive(Clone, Debug, Eq, PartialEq, Snafu)]
pub enum Insanity {
// Field: announce and announce_list
EmptyAnn... | true |
003d61c731a757e8224a833c23a9e07655e39d70 | Rust | jcaesar/unmemftp | /src/lib.rs | UTF-8 | 6,152 | 2.734375 | 3 | [] | no_license | use libunftp::storage::Error as FtpError;
use libunftp::storage::Result as FtpResult;
use libunftp::storage::StorageBackend;
use libunftp::storage::{ Metadata, Fileinfo, ErrorKind };
use std::collections::HashMap;
use std::io::Cursor;
use std::net::{ SocketAddr, TcpListener };
use std::path::{ Path, PathBuf };
use std:... | true |
ce09982afb1dc9a381f493e68ea6db111404c4af | Rust | yurket/prepare_subs_for_common_voice | /src/main.rs | UTF-8 | 4,560 | 3.328125 | 3 | [] | no_license | use std::env;
use std::fs;
use std::path::Path;
use colored::*;
fn count_quotes(s: &str) -> usize {
s.chars().filter(|&c| c == '"').collect::<Vec<char>>().len()
}
fn check_string_conformance(s: &str) -> bool {
if s.len() == 0 {
println!("{}: {}", "skipping due to zero length".yellow(), s);
r... | true |
a4b1e2c3f1ca544db7c2054dc1b5b4c83ceb2971 | Rust | iqlusioninc/tmkms | /src/commands/init/networks.rs | UTF-8 | 2,827 | 3.3125 | 3 | [
"Apache-2.0"
] | permissive | //! Tendermint KMS configuration file networks
use crate::prelude::*;
use std::{
fmt::{self, Display},
process,
};
/// Tendermint networks we have config networks for
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum Network {
/// Terra `columbus` chain
Columbus,
/// Cosmos `cosmoshub` chain
... | true |
a95fd5ef9da93bf8f7bca0977478c34527d751dc | Rust | aschaeffer/rust-ecs-poc | /src/behaviour/relation/connectors/behaviour.rs | UTF-8 | 1,752 | 2.609375 | 3 | [
"MIT"
] | permissive | use std::sync::Arc;
use crate::behaviour::BehaviourCreationError;
use crate::behaviour::relation::RelationBehaviour;
use crate::model::{ReactiveRelationInstance, ReactiveEntityInstance, ReactiveRelationInstanceFactory};
use crate::reactive::relation::connector::{Connector, ConnectorFunction};
use crate::reactive::rela... | true |
814d0ab2a9ca0bf84efb2b53c53f0bd916c66f4b | Rust | ojeo/yyx | /yyx-types/src/hero_equip.rs | UTF-8 | 1,300 | 3.109375 | 3 | [] | no_license | use serde_derive::{Deserialize, Serialize};
/// 御魂属性类型
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
pub enum HeroEquipAttrType {
/// 生命
Hp,
/// 防御
Defense,
/// 攻击
Attack,
/// 生命加成
HpRate,
/// 防御加成
DefenseRate,
/// 攻击加成
AttackRate,
/// 速度
Speed,
/// 暴击
CritRate,
/// 暴击伤害
Cri... | true |
33108332e314369d765f633960ca99f4c445c88b | Rust | qiufengshe/algorithms | /rust/algorithms.rs | UTF-8 | 2,598 | 4.15625 | 4 | [] | no_license | /*
给定一个整数数组 nums和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那两个整数,并返回它们的数组下标。
你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。
你可以按任意顺序返回答案。
示例 1:
输入:nums = [2,7,11,15], target = 9
输出:[0,1]
解释:因为 nums[0] + nums[1] == 9 ,返回 [0, 1]
*/
pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
let mut map: std::collections::... | true |
5ef8ac549b8ab06848c4d46d82dddcc8c7d35f36 | Rust | devin909/regex-rust-file | /exec.rs | UTF-8 | 5,210 | 3.09375 | 3 | [
"MIT"
] | permissive | use std::vec::with_capacity;
use std::util::swap;
use compile::Instruction;
use compile::{InstLiteral, InstRange, InstMatch, InstJump,
InstCaptureStart, InstCaptureEnd, InstSplit, InstNoop};
// object containing implementation
// details for executing compiled
// instructions
struct Prog {
strat: ~ExecStrategy
... | true |
18fb0f001d1eaae11daa4c366af917835c91ba83 | Rust | grogers0/advent_of_code | /2021/day5/src/main.rs | UTF-8 | 2,550 | 3.6875 | 4 | [
"MIT"
] | permissive | use std::collections::HashMap;
use std::io::{self, Read};
#[derive(Hash, Eq, PartialEq)]
struct Point {
x: i32,
y: i32
}
impl Point {
fn parse(input: &str) -> Point {
let mut split_iter = input.split(",");
let x = split_iter.next().unwrap().parse().unwrap();
let y = split_iter.next... | true |
3258d76dbc39d1da399d805388691955adffdd68 | Rust | PLSysSec/haybale | /src/return_value.rs | UTF-8 | 711 | 3.40625 | 3 | [
"MIT"
] | permissive | /// A simple enum describing the value returned from a function
#[derive(PartialEq, Eq, Clone, Copy, Debug, Hash)]
pub enum ReturnValue<V> {
/// The function or call returns this value
Return(V),
/// The function or call returns void
ReturnVoid,
/// The function or call throws this value (using the ... | true |
14f475146dec87155e271853e77ca0c97c6edb56 | Rust | Defman/feather | /server/src/load.rs | UTF-8 | 1,996 | 3.359375 | 3 | [
"Apache-2.0"
] | permissive | //! Implements the loading of entities.
use ahash::AHashMap;
use feather_core::entity::{EntityData, EntityDataKind};
use fecs::EntityBuilder;
pub trait EntityLoaderFn:
Fn(EntityData) -> anyhow::Result<EntityBuilder> + Send + Sync + 'static
{
}
impl<F> EntityLoaderFn for F where
F: Fn(EntityData) -> anyhow::R... | true |
c3f7a808e7a4808950e84005fd3cec11bc6f2edf | Rust | ityy/rust_study | /src/book_study_notes/book01_the_tao_of_programming/src/c02_outline/t2_9_0_smart_pointer.rs | UTF-8 | 789 | 3.71875 | 4 | [] | no_license | //! # 智能指针
//! 智能指针源自C++语言,Rust将其引入,并成为Rust语言中最重要的一种数据结构。
//!
//! ## 本节只介绍Box指针 。
//! Rust中的值类型默认被分配到栈内存。可以通过Box<T>将值移动到堆内存(装箱)。
//! 当Box<T>离开作用域时,将调用析构函数,销毁内部对象,并自动释放堆中的内存。
/// ## 测试 Box<T> 智能指针
#[test]
fn test_box() {
#[derive(PartialOrd, PartialEq, Debug)]
struct Point {
x: f64,
y: f64,
... | true |
d5a315ea5461be3788e7297d77ee06ba889be6c9 | Rust | ygyzys/bzip2-rs | /src/lib.rs | UTF-8 | 2,583 | 2.515625 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! `bzip2_rs` is a pure Rust bzip2 decoder.
//!
//! ## Main APIs
//!
//! ### Single-threaded decoder
//!
//! * [`Decoder`]: low-level, Sans I/O, bzip2 decoder
//! * [`DecoderReader`]: high-level synchronous bzip2 decoder
//!
//! ### Multi-threaded decoder
//!
//! * [`ParallelDecoder`]: low-level, Sans I/O, bzip2 decod... | true |
e5117aa83fec4b169ed3926ceddda5ec0a98d715 | Rust | ZoranPandovski/al-go-rithms | /search/binary_search/Rust/binary_search.rs | UTF-8 | 679 | 3.75 | 4 | [
"CC0-1.0"
] | permissive | fn binary_search(arr :Vec<i32>, n :i32) -> i32{
let mut low = 0;
let mut high = arr.len()-1;
loop {
let mid = (low + high) / 2;
if n == arr[mid] {
return mid as i32;
}else if n > arr[mid] {
low = mid + 1;
}else {
high = mid -1;
}
... | true |
b0e4419c9d86a04f354c186489b7b6b91e81120d | Rust | laopo001/raytrace-parallel | /src/main.rs | UTF-8 | 6,975 | 2.71875 | 3 | [] | no_license | #[macro_use]
extern crate lazy_static;
use std::f32::consts::PI;
use wasm_math::vec3::Vec3;
use rand::Rng;
use rand::prelude::ThreadRng;
#[macro_use]
extern crate nameof;
lazy_static! {
static ref NUMBER: u32 = 123;
static ref spheres: Vec<Sphere> = vec![
Sphere::new(1e5, Vec3::new(1e5 + 1., 40.8, 81... | true |
383b564b2e74e26ee16d49db1aaa1561aa804bb1 | Rust | stefanluethi/rust-3d-orientation-demo | /crates/kalman_nostd/src/lib.rs | UTF-8 | 6,433 | 2.65625 | 3 | [] | no_license | #![no_std]
#![feature(const_generics)]
mod math;
use math::{one::One, linalg};
use core::ops::{Add, Sub, Mul, Div, Neg};
use core::mem::MaybeUninit;
/// # Generic Kalman filter
/// *Note: this crate very generic and extremely inefficient!*
///
/// ## Nightly Features
/// ### Const Generics
/// A generic Kalman filte... | true |
db320d7a203e1f0aa094d83ac35542f61178b99a | Rust | AndrewMendezLacambra/rust-programming-contest-solutions | /atcoder/agc016_b.rs | UTF-8 | 1,862 | 3.375 | 3 | [] | no_license | fn main() {
let s = std::io::stdin();
let mut sc = Scanner { stdin: s.lock() };
let n: usize = sc.read();
let a: Vec<usize> = sc.vec(n);
let max: usize = a.iter().cloned().max().unwrap();
let mut count = vec![0; max + 1];
for a in a.into_iter() {
count[a] += 1;
}
let candid... | true |
ae42dd5fbbdafa2be927a77b1af7c4313a84c04b | Rust | timClicks/lucky | /src/daemon/hook_handlers.rs | UTF-8 | 4,551 | 2.515625 | 3 | [
"MIT"
] | permissive | //! Built-in handlers for Juju hooks that are executed by the daemon
use std::time::Duration;
use super::*;
use crate::docker::ContainerInfo;
use crate::rt::block_on;
use crate::types::{ScriptState, ScriptStatus};
pub(super) fn handle_pre_hook(daemon: &LuckyDaemon, hook_name: &str) -> anyhow::Result<()> {
match ... | true |
be21fec8e0d4043131eb9b6696e79f37af9d5eff | Rust | mluluz/lighthouse | /eth2/attester/src/test_utils/simulated_beacon_node.rs | UTF-8 | 1,628 | 2.65625 | 3 | [
"Apache-2.0"
] | permissive | use crate::traits::{BeaconNode, BeaconNodeError, PublishOutcome};
use std::sync::RwLock;
use types::{AttestationData, FreeAttestation, Slot};
type ProduceResult = Result<Option<AttestationData>, BeaconNodeError>;
type PublishResult = Result<PublishOutcome, BeaconNodeError>;
/// A test-only struct used to simulate a B... | true |
ea28f83c4d07b2c4cb0e82ca96ae8abbe9ebb6cd | Rust | mikejsavage/rspt | /src/maths/sampling/cdf.rs | UTF-8 | 757 | 3.234375 | 3 | [] | no_license | use rand;
pub struct CDF< T > {
elems : Vec< T >,
weights : Vec< f64 >,
total_weight : f64,
}
impl< T > CDF< T > {
pub fn new( elems : Vec< T >, weights : Vec< f64 > ) -> CDF< T > {
let mut total = 0.0;
for w in weights.iter() {
total = total + *w;
}
return CDF {
elems : elems,
weights : weight... | true |
4b68beac8473815f6f7f2980d06883791281dbc3 | Rust | tock/tock | /kernel/src/deferred_call.rs | UTF-8 | 10,498 | 3.1875 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | // Licensed under the Apache License, Version 2.0 or the MIT License.
// SPDX-License-Identifier: Apache-2.0 OR MIT
// Copyright Tock Contributors 2022.
//! Hardware-independent kernel interface for deferred calls
//!
//! This allows any struct in the kernel which implements
//! [DeferredCallClient](crate::deferred_ca... | true |
587a35b7206efec8d9013fd2c609812930b56736 | Rust | idle-z/sheika-glyph-renderer | /src/main.rs | UTF-8 | 4,104 | 2.53125 | 3 | [] | no_license | #[macro_use]
extern crate gfx;
extern crate gfx_window_glutin;
extern crate glutin;
use gfx::traits::FactoryExt;
use gfx::Device;
pub type ColorFormat = gfx::format::Rgba8;
pub type DepthFormat = gfx::format::DepthStencil;
gfx_defines!{
vertex Vertex {
pos: [f32; 2] = "a_Pos",
color: [f32; 3] = "... | true |
7d729c0b5ea62a6cb32b3118a9b4b6f9e6472163 | Rust | declanvk/scalable-concurrent-containers | /src/hash_table/cell.rs | UTF-8 | 28,724 | 2.71875 | 3 | [
"Apache-2.0"
] | permissive | use super::wait_queue::WaitQueue;
use crate::ebr::{Arc, AtomicArc, Barrier, Ptr, Tag};
use std::borrow::Borrow;
use std::mem::MaybeUninit;
use std::ptr;
use std::sync::atomic::fence;
use std::sync::atomic::AtomicU32;
use std::sync::atomic::Ordering::{Acquire, Relaxed, Release};
/// The fixed size of [`DataArray`].
/... | true |
777528682a7be8b3e485003a1b636a98f17f583e | Rust | fits/try_samples | /blog/20230106/rust_nested_closure/src/main.rs | UTF-8 | 1,821 | 3.546875 | 4 | [] | no_license |
fn sample1() {
fn a1() -> fn(i32) -> i32 {
|x| x * 2
}
println!("a1 = {}", a1()(11));
fn b1() -> impl Fn(i32) -> i32 {
|x| x * 2
}
println!("b1 = {}", b1()(12));
fn c1() -> Box<dyn Fn(i32) -> i32> {
Box::new(|x| x * 2)
}
println!("c1 = {}", c1()(13));
}... | true |
2a950166a9398b6f6300a516b07b00dd4b7715dd | Rust | tower-rs/tower | /tower/src/retry/layer.rs | UTF-8 | 536 | 2.75 | 3 | [
"MIT"
] | permissive | use super::Retry;
use tower_layer::Layer;
/// Retry requests based on a policy
#[derive(Debug, Clone)]
pub struct RetryLayer<P> {
policy: P,
}
impl<P> RetryLayer<P> {
/// Creates a new [`RetryLayer`] from a retry policy.
pub fn new(policy: P) -> Self {
RetryLayer { policy }
}
}
impl<P, S> Lay... | true |
099d22763a5fd3a069a7c53f877a7cba362c6ac8 | Rust | Lakret/aoc2020 | /src/d05.rs | UTF-8 | 2,527 | 3.484375 | 3 | [] | no_license | use std::collections::HashSet;
pub fn solve(input: &str) -> Option<Box<u32>> {
input
.trim_end()
.split_ascii_whitespace()
.map(|pass| seat_id(pass))
.max()
.map(|max_seat_id| Box::new(max_seat_id))
}
pub fn solve2(input: &str) -> Option<Box<u32>> {
let all_seat_ids = input
.trim_end()
... | true |
08b9a4d3c2671e9e8361afabe466694479010c0c | Rust | mdv3kt/cs4414-ps2 | /zhttpto.rs | UTF-8 | 3,807 | 2.890625 | 3 | [
"MIT"
] | permissive | //Altered by Mark Valeiras --- MDV3KT
// zhttpto.rs
//
// Starting code for PS1
// Running on Rust 0.9
//
// Note that this code has serious security risks! You should not run it
// on any system with access to sensitive files.
//
// University of Virginia - cs4414 Spring 2014
// Weilin Xu and David Evans
// Version... | true |
890468de23cf5bc9e206d2d0ffe3acefcbf7a318 | Rust | Chacix/rust-raspberrypi-OS-tutorials | /12_integrated_testing/src/memory.rs | UTF-8 | 1,941 | 2.890625 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | // SPDX-License-Identifier: MIT OR Apache-2.0
//
// Copyright (c) 2018-2021 Andre Richter <andre.o.richter@gmail.com>
//! Memory Management.
pub mod mmu;
use core::ops::RangeInclusive;
//--------------------------------------------------------------------------------------------------
// Public Code
//-------------... | true |
d1abb52e195fc6509c271e8291928acfc4fe0c86 | Rust | tpayet/MeiliSearch | /meilisearch-http/tests/search.rs | UTF-8 | 59,184 | 2.546875 | 3 | [
"MIT"
] | permissive | use std::convert::Into;
use meilisearch_http::routes::search::{SearchQuery, SearchQueryPost};
use assert_json_diff::assert_json_eq;
use serde_json::json;
use serde_json::Value;
mod common;
macro_rules! test_post_get_search {
($server:expr, $query:expr, |$response:ident, $status_code:ident | $block:expr) => {
... | true |
64b1d5d95778399724523d065207ead52dc050ba | Rust | crestonbunch/reticulated | /parser/trees/parse/src/stmt.rs | UTF-8 | 1,283 | 2.609375 | 3 | [
"MIT"
] | permissive | use std::cell::RefCell;
use std::rc::Rc;
use crate::node::{Child, NodeProxy, PNode, ParseConstruct, ParseNode};
use crate::{CompoundStmt, SimpleStmt};
use lexer::tokens::Token;
use lexer::Span;
use syntax::{SNode, Stmt as SyntaxStmt};
enum StmtChild {
Simple(PNode<SimpleStmt>),
Compound(PNode<CompoundStmt>),
... | true |
6e992adac477f8275f680ca3fbc598bd40807f30 | Rust | tgandrews/synacor-rs | /src/main.rs | UTF-8 | 8,187 | 3 | 3 | [] | no_license | extern crate byteorder;
use std::error::Error;
use std::fs::File;
use std::io::prelude::*;
use std::io::{self, Cursor};
use std::path::Path;
use byteorder::{LittleEndian, ReadBytesExt};
use std::num::Wrapping;
fn get_value(val:usize, memory:&Vec<u16>, registry: &[u16]) -> u16 {
let res = memory[val];
if res ... | true |
e3dad5af0f781697119b05942e91a4de67ef0090 | Rust | zwhitchcox/rust-lc | /solutions/1.two-sum.rs | UTF-8 | 512 | 2.921875 | 3 | [] | no_license | use std::collections::HashMap;
/*
* @lc app=leetcode id=1 lang=rust
*
* [1] Two Sum
*/
impl Solution {
pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
let mut hashmap = HashMap::with_capacity(nums.len());
for (idx, &n) in nums.iter().enumerate() {
let y = target - n;
... | true |
f0cf8b03937130a2d6868cc7f8cf2753dfea6af7 | Rust | multun/gateway | /gateway/src/runtime_config.rs | UTF-8 | 1,421 | 2.59375 | 3 | [] | no_license | use std::env;
use std::error;
use std::fs::File;
use std::io::BufReader;
use std::path::Path;
use std::process::exit;
use serde::Deserialize;
use once_cell::sync::OnceCell;
use hyper::http::Uri;
#[derive(Debug, Deserialize)]
pub struct PermUri {
#[serde(with = "http_serde::uri")]
pub uri: Uri,
}
#[derive(D... | true |
7651218170a6cc67bad063b04f890e953ba43e0a | Rust | wulu90/leetcode | /src/reverse_integer.rs | UTF-8 | 1,229 | 3.359375 | 3 | [] | no_license | //use std::i32;
pub struct Solution;
impl Solution {
pub fn reverse(x: i32) -> i32 {
let mut x = x;
let mut rev = 0;
while x != 0 {
let temp = x % 10;
x = x / 10;
if rev > i32::max_value() / 10 || (rev == i32::max_value() / 10 && temp > 7) {
... | true |
d4d5713fa666fbeec3c8912d7398ad0cc9c88d7a | Rust | danhper/diem | /language/diem-vm/parallel-executor/src/outcome_array.rs | UTF-8 | 1,938 | 2.625 | 3 | [
"Apache-2.0"
] | permissive | // Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0
use crate::{
errors::{Error, Result},
task::{ExecutionStatus, TransactionOutput},
};
use once_cell::sync::OnceCell;
pub(crate) struct OutcomeArray<T, E> {
// Hold the execution results for each individual transactions. Each... | true |
a7d58d68c88f5daab17305f867ba1e72a38f412a | Rust | joelarmstrong/maf_stream | /src/lib.rs | UTF-8 | 6,336 | 3.390625 | 3 | [] | no_license | use itertools::Itertools;
use std::cmp::Ordering;
use std::collections::BTreeSet;
use std::io::BufRead;
#[derive(PartialEq, Eq, Debug)]
pub struct Range {
pub seq: String,
pub start: u64,
pub end: u64,
}
impl Ord for Range {
fn cmp(&self, other: &Self) -> Ordering {
(&self.seq, &self.start, &s... | true |
5c8ff163ea7b696bb320f61ce1ce5061182a039b | Rust | Graviton-Code-Editor/Graviton-App | /core_api/src/filesystems/mod.rs | UTF-8 | 2,556 | 3.171875 | 3 | [
"MIT"
] | permissive | use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use std::path::Path;
mod local;
pub use local::LocalFilesystem;
use crate::Errors;
/// Filesystem errors
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub enum FilesystemErrors {
FilesystemNotFound,
FileNotFound,
FileNotSu... | true |
3d1c882fd73569adb4be36d621436b23e7c8bdcd | Rust | hummans/feeless | /src/rpc/calls/work_validate.rs | UTF-8 | 1,873 | 2.875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0",
"MIT"
] | permissive | use crate::blocks::BlockHash;
use crate::rpc::calls::{as_str, from_str};
use crate::rpc::client::{RPCClient, RPCRequest};
use crate::{Difficulty, Result, Work};
use async_trait::async_trait;
use clap::Clap;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Clap)]
pub struct WorkValidateReque... | true |
aff7b6b7e04ec78d449612dccee3def1c23fe463 | Rust | mre/live | /hotel/src/main.rs | UTF-8 | 3,054 | 3.46875 | 3 | [
"Apache-2.0"
] | permissive | extern crate rand;
extern crate rayon;
use std::collections::BTreeSet;
use rand::Rng;
use rayon::prelude::*;
#[derive(PartialOrd, Ord, Clone, Debug, Hash)]
struct City {
name: String,
prices: Vec<Option<u64>>,
}
impl PartialEq for City {
fn eq(&self, other: &City) -> bool {
self.name == other.nam... | true |
b71d3f6403369ee3b18216b772a68c60f2c76677 | Rust | bishan-batel/flocking-sim | /src/plugins/flockplugin.rs | UTF-8 | 2,520 | 2.5625 | 3 | [] | no_license | use crate::plugins::flock::*;
use bevy::prelude::*;
use rand::prelude::*;
pub struct FlockPlugin;
#[derive(Debug, Clone, PartialEq, Eq, Hash, SystemLabel)]
pub enum FlockPluginSystems {
Setup,
}
impl FlockPlugin {
fn setup(
mut commands: Commands,
mut materials: ResMut<Assets<ColorMaterial>>,... | true |
7ccafd15e42ee31999f2d0ed4723d9a6e83ade5f | Rust | Thermatix/cyber_rogue_old | /old_src/main.rs | UTF-8 | 3,326 | 2.578125 | 3 | [] | no_license | pub extern crate tcod;
pub extern crate rand;
extern crate nanoid;
use tcod::colors;
use tcod::*;
mod game;
use game::entity::*;
use game::mapping::*;
use game::entity::contextual::*;
use self::gen;
mod sys;
use sys::*;
use self::controls::PlayerAction;
const CONFIG: config::Options = config::Options {
// actual... | true |
7fba5a7ce72634789de3287d779768d3dfb44bee | Rust | at-robins/oben | /src/evolution/helper.rs | UTF-8 | 9,623 | 3.171875 | 3 | [
"MIT"
] | permissive | //! The `helper` module contains helper constructs for general workflow.
use rand::{thread_rng, Rng};
use rand_distr::{Distribution, Standard};
use serde::{Deserialize, Serialize};
use std::{
borrow::Borrow,
convert::TryFrom,
ops::{Add, AddAssign, Sub, SubAssign},
};
use super::{
binary::{as_u64, flip... | true |
6586a4fa6dcbae2348502b420c6ad077d800980c | Rust | CLomanno/crc-rs | /src/util.rs | UTF-8 | 4,756 | 3.734375 | 4 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | /// Builds a CRC16 table using the standard or reflected method.
/// If reflect==true, flip the individual byte bitwise, then flip the table value bitwise.
pub fn make_table_crc16(poly: u16, reflect: bool) -> [u16; 256] {
let mut table = [0u16; 256];
let mut byte: u16;
let top_bit = 1u16 << 15; //15 is 16bi... | true |
a8631fcf1e01176877feb3278043c5b5c7dbed84 | Rust | MrWWheat/datenlord | /async_fuse/src/test/integration_tests.rs | UTF-8 | 10,799 | 2.734375 | 3 | [
"MIT"
] | permissive | use log::info; // debug, warn
use nix::dir::Dir;
use nix::fcntl::{self, OFlag};
use nix::sys::stat::Mode;
use nix::unistd::{self, Whence};
use std::collections::HashSet;
use std::fs;
use std::iter;
use std::path::Path;
use super::test_util::{self, DEFAULT_MOUNT_DIR, FILE_CONTENT};
fn test_file_manipulation_rust_way(m... | true |
aeb60e2921f364a505ed4f41d938b9b45340cffa | Rust | ZachBray/llsl | /tool/src/input.rs | UTF-8 | 3,367 | 2.9375 | 3 | [] | no_license | use std::u32;
use std::collections::BTreeMap;
use serde::{Deserialize, Deserializer};
#[derive(Debug, Deserialize, Eq, PartialEq)]
pub enum Endianness {
#[serde(rename = "big")]
Big,
#[serde(rename = "little")]
Little,
}
#[serde(deny_unknown_fields)]
#[derive(Debug, Deserialize, Eq, PartialEq)]
pub st... | true |
3a25fea0fab6d229a89279f59f53a6b33f6176b5 | Rust | magiclen/leveled-hash-map | /examples/country_city.rs | UTF-8 | 2,575 | 3.109375 | 3 | [
"MIT"
] | permissive | use std::{collections::HashMap, sync::Arc};
use leveled_hash_map::LeveledHashMap;
#[allow(dead_code)]
#[derive(Debug)]
struct MultiName {
us: &'static str,
tw: &'static str,
cn: &'static str,
}
fn main() {
let earth_map: LeveledHashMap<&'static str, MultiName> = {
let mut map = LeveledHashMap... | true |
34d235cdf6d8218012ba2357dcfea23dc1c1b52d | Rust | sonald/lxxtcode-rs | /src/powx_n.rs | UTF-8 | 1,534 | 3.703125 | 4 | [
"MIT"
] | permissive | pub struct Solution;
impl Solution {
pub fn my_pow(x: f64, n: i32) -> f64 {
Self::by_iter(x, n)
}
fn by_iter(x: f64, n: i32) -> f64 {
let mut res = 1.0;
let mut m = n.abs() as u32;
let mut k = x;
while m > 0 {
if m & 1 == 1 {
res *= k;... | true |
4c631c66b71e11dcf89811f2b7e32ac2c3186416 | Rust | zetalog/terminus | /src/devices/htif.rs | UTF-8 | 5,571 | 2.578125 | 3 | [
"MIT"
] | permissive | use terminus_spaceport::memory::prelude::*;
use terminus_spaceport::EXIT_CTRL;
use terminus_spaceport::devices::TERM;
use std::sync::Mutex;
use std::io::{Write, ErrorKind, Read};
use terminus_macros::*;
use std::borrow::{BorrowMut, Borrow};
// test refer to top_tests/htif_test
struct HTIFDesp {
tohost: u64,
fr... | true |
f50e6fe41a5ca5575e89a041ef732109f6746d98 | Rust | madmax28/aoc2019 | /src/day14/mod.rs | UTF-8 | 3,974 | 3.046875 | 3 | [] | no_license | use std::collections::HashMap;
#[derive(Debug)]
enum Error {
InvalidInput,
}
type ChemId = i32;
#[derive(PartialEq, Eq, Hash)]
struct Component {
id: ChemId,
cnt: i64,
}
type Reactions = HashMap<Component, Vec<Component>>;
type IdMap = HashMap<String, ChemId>;
fn scan_for<I>(i: &mut I) -> crate::Result... | true |
6a0707486496ea608c390c0c99ffd446c5fd90a2 | Rust | aticu/nuefil | /src/text.rs | UTF-8 | 10,332 | 3.15625 | 3 | [
"MIT"
] | permissive | //! This protocol is used to handle input and output of
//! text-based information intended for the system user during the operation of code in the boot
//! services environment. Also included here are the definitions of three console devices: one for input
//! and one each for normal output and errors.
use core::fmt;... | true |
814caae0832dba684cc3f2018152a7a4220822a0 | Rust | LuoZijun/netlink | /rtnetlink/src/link/get.rs | UTF-8 | 1,523 | 2.5625 | 3 | [
"MITNFA"
] | permissive | use futures::Stream;
use crate::netlink_packet_route::{link::LinkMessage, RtnlMessage};
use netlink_packet_core::{
header::flags::{NLM_F_DUMP, NLM_F_REQUEST},
NetlinkFlags, NetlinkMessage, NetlinkPayload,
};
use crate::{Error, ErrorKind, Handle};
lazy_static! {
// Flags for `ip link get`
static ref G... | true |
99d726c8aad7bfa2fc0e7259c7c9dbbd45452847 | Rust | christat/trace-rs | /rusty-math/src/matrix4.rs | UTF-8 | 18,340 | 3.046875 | 3 | [] | no_license | use std::ops::Mul;
use crate::Matrix3;
use crate::Tuple4;
use crate::errors::{MatrixInversionError, SubmatrixIndexError};
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Matrix4 {
pub c0: Tuple4,
pub c1: Tuple4,
pub c2: Tuple4,
pub c3: Tuple4
}
impl Matrix4 {
pub fn new(c0: Tuple4, c1: Tuple4, c2: Tuple... | true |
6a973a9447091f096f2d38d729907824234a4283 | Rust | BearingMe/exercicios-CeV | /exs/mundo_1/rust/011.rs | UTF-8 | 922 | 3.890625 | 4 | [
"MIT"
] | permissive | /*
Desafio 011
Problema: Faça um programa que leia a largura e a altura de uma
parede em metros, calcule a sua área e a quantidade de
tinta necessária para pintá-la, sabendo que cada litro
de tinta pinta uma área de 2 metros quadrados.
*/
fn main() {
let mut largura = String::new();
... | true |
df6684c2f2cc29c6500c4b6e88a5c7cfa43be0eb | Rust | indeterminateoutcomesstudios/gemini | /src/gui/tab/market.rs | UTF-8 | 4,000 | 2.734375 | 3 | [
"MIT"
] | permissive | use super::*;
use termion::event as keyevent;
use tui::layout::Rect;
use tui::style::{Color, Style};
use tui::widgets::{Block, Borders, Row, Table, Widget};
use super::GUIEvent;
use player::PlayerState;
lazy_static! {
/// Styling for selected item.
static ref SELECTED_STYLE: Style = Style::default().fg(Color:... | true |
d8babe4bc7b1f0e87a30766d376d4d914661660d | Rust | universeroc/udp-dtls | /src/midhandshake_dtls_steam.rs | UTF-8 | 1,981 | 3.03125 | 3 | [
"MIT"
] | permissive | use crate::{DtlsStream, HandshakeError};
use openssl::ssl::MidHandshakeSslStream;
use std::{fmt, io};
/// A DTLS stream which has been interrupted midway through the handshake process.
pub struct MidHandshakeDtlsStream<S>(MidHandshakeSslStream<S>);
impl<S> MidHandshakeDtlsStream<S> {
/// Returns a shared referenc... | true |
d5f58babb01d893560bad3e906a513f95a116780 | Rust | lo48576/soft-ascii-string | /src/soft_char.rs | UTF-8 | 4,042 | 3.21875 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | use std::cmp::PartialEq;
use std::fmt::{self, Display};
use std::str;
use std::char::{
self,
ToUppercase, ToLowercase,
EscapeDebug, EscapeDefault, EscapeUnicode
};
#[allow(unused_imports, deprecated)]
use std::ascii::AsciiExt;
use error::FromSourceError;
///a `char` wrapper with a "is us-ascii" soft cons... | true |
6f9a56ea1010c4a4c676e005c5a90a25f9535dcb | Rust | svmnotn/upgraded-pancake | /server/src/main.rs | UTF-8 | 5,728 | 3.3125 | 3 | [
"MIT"
] | permissive | #![feature(decl_macro, proc_macro_hygiene)]
//! # Upgraded Pancake Server
//!
//! This is the default backend for the upgraded-pancakes library. The library was made
//! with this project as its goal, but left aside for use by others.
//!
//! ## Methods
//!
//! The following HTTP methods are supported by the server, w... | true |
804bcf04c28b38d84021a8ce0d8177e797776ee7 | Rust | tbarusseau/aoc-2020 | /src/days/y2020/day7.rs | UTF-8 | 1,927 | 3.328125 | 3 | [] | no_license | use std::collections::HashMap;
use itertools::Itertools;
type Color = String;
type Rules = HashMap<Color, Vec<(usize, Color)>>;
fn parse_rules(input: &str) -> Rules {
input
.lines()
.map(|line| {
let color = line.split_ascii_whitespace().take(2).join(" ");
let contains: V... | true |
95f5968222cd048f45dd6fa8f1d22da9ca505ff5 | Rust | kgtkr/procon | /atcoder/rust/arc087_a/src/main.rs | UTF-8 | 1,315 | 3.265625 | 3 | [] | no_license | extern crate core;
use std::io::{self, Read};
use std::collections::HashMap;
fn main() {
let mut input = String::new();
io::stdin().read_to_string(&mut input).unwrap();
let output = run(input);
println!("{}", output);
}
fn run(input: String) -> String {
let vec: Vec<i64> = input
.split("\... | true |
f715f480489d312b10233c54432a753b6bd2731a | Rust | asilkro/PracticeSession | /src/error.rs | UTF-8 | 560 | 2.921875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use crate::consts::msg;
use std::ffi::OsString;
use thiserror::Error;
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Clone, Debug, Error, PartialEq)]
pub enum Error {
#[error("{}: {:?}", msg::ERR_ARG_NOT_CONVERTIBLE_TO_UTF_8, 0)]
ArgNotConvertibleToUtf8(std::ffi::OsString),
}
// Note: `s... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.