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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
26ee14ad116e5fe1a27e896f5bd65c08c4cc73a0 | Rust | killercup/rune | /crates/rune-testing/tests/vm_function.rs | UTF-8 | 1,839 | 3.296875 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use rune_testing::*;
#[test]
fn test_function() {
// ptr to dynamic function.
let function = rune! {
Function => r#"
fn foo(a, b) {
a + b
}
fn main() {
foo
}
"#
};
assert_eq!(function.call::<_, i64>((1i64, 3i64)).unwrap(), 4i64);... | true |
24b7340944a28a6439d78e216b26412644afb63f | Rust | iAklis/heim | /heim-process/src/sys/unix/mod.rs | UTF-8 | 398 | 2.71875 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | use std::io;
pub fn pid_exists(pid: crate::Pid) -> bool {
if pid == 0 {
return true;
}
let result = unsafe { libc::kill(pid, 0) };
if result == 0 {
true
} else {
let e = io::Error::last_os_error();
match e.raw_os_error() {
Some(libc::ESRCH) => false,
... | true |
82a256cf415c590afdf09c799b30cbb1784a1e0a | Rust | L3nn0x/raytracer | /src/hitable_list.rs | UTF-8 | 1,280 | 2.875 | 3 | [
"MIT"
] | permissive | use hitable::{HitRecord, Hitable};
use ray::Ray;
use aabb::{AABB, surrounding_box};
#[derive(Clone)]
pub struct HitableList {
list: Vec<Box<Hitable>>
}
impl HitableList {
pub fn new(list: Vec<Box<Hitable>>) -> HitableList {
HitableList{
list: list
}
}
}
impl Hitable for Hitabl... | true |
506fc8fb7e4e2a7e10044dfdd81aec80daf2acdd | Rust | lakwet/array_generator | /src/main.rs | UTF-8 | 6,750 | 2.96875 | 3 | [] | no_license | use rand::{thread_rng, Rng};
use std::env;
pub fn helper_random_array_uniform_u64(size: usize) -> Vec<u64> {
let mut rng = thread_rng();
let mut array: Vec<u64> = Vec::with_capacity(size);
for _ in 0..size {
let value: u64 = rng.gen();
array.push(value);
}
array
}
// Uniform 10^9
... | true |
4658dfefbdf300b857edd1281aa4a1671fcdc98b | Rust | laysauchoa/rust_samples | /recursion_rust/src/main.rs | UTF-8 | 418 | 3.125 | 3 | [] | no_license | mod fibonnacci;
use std::io;
fn main() {
loop {
println!("Please enter the desired position for fib sequence");
let mut n = String::new();
io::stdin().read_line(&mut n)
.expect("Failed to read line");
let n: i32 = match n.trim().parse() {
Ok(num) => num,
Err(_) => continu... | true |
d8b511873bfccb28e54bc52568d56193700cc831 | Rust | khai-learn-rust/rust_reml_hello_world | /src/main.rs | UTF-8 | 1,627 | 2.84375 | 3 | [
"MIT"
] | permissive | extern crate gtk;
#[macro_use]
extern crate relm;
use gtk::prelude::*;
pub struct Model {
count: i32,
}
#[derive(relm_derive::Msg)]
pub enum Msg {
Decrease,
Increase,
Quit,
}
#[relm_attributes::widget]
impl relm::Widget for Win {
fn model() -> Model {
Model { count: 0 }
}
fn up... | true |
b120651bea2ad612715b432d73397b7c0c899db0 | Rust | alice/advent_2018 | /src/day1.rs | UTF-8 | 736 | 3 | 3 | [] | no_license | use std::collections::HashSet;
pub fn run1(filename: &String) {
let rows = super::input::read_lines(filename.to_string());
let frequency = rows
.iter()
.map(|row| row.parse::<i32>().unwrap())
.fold(0, |acc, x| acc + x);
println!("frequency: {}", frequency);
}
pub fn run2(filename: &String) {
let... | true |
5aa0a9d5a10ac3f31960a7a0fc45276a46837b85 | Rust | emirayka/nia_interpreter_core | /src/interpreter/stdlib/builtin_objects/bit/set.rs | UTF-8 | 3,043 | 3.515625 | 4 | [
"MIT"
] | permissive | use crate::interpreter::environment::EnvironmentId;
use crate::interpreter::error::Error;
use crate::interpreter::interpreter::Interpreter;
use crate::interpreter::value::Value;
use crate::interpreter::library;
pub fn set(
_interpreter: &mut Interpreter,
_environment_id: EnvironmentId,
values: Vec<Value>,... | true |
f9f7e1629d39c345570d12af3f01ddc768bde3f2 | Rust | guilhemSmith/expert-system | /src/resolving/fact.rs | UTF-8 | 2,762 | 2.5625 | 3 | [
"MIT"
] | permissive | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fact.rs :+: :+: :+: ... | true |
00b38e32aaf33e29838c450abc3ea2a3e90237f1 | Rust | danielwippermann/resol-vbus-logger.rs | /src/tick_source.rs | UTF-8 | 849 | 2.53125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | use resol_vbus::chrono::prelude::*;
pub struct TickSource {
interval: i64,
last_interval: i64,
}
impl TickSource {
pub fn new(interval: i64, now: DateTime<UTC>) -> TickSource {
let last_interval = if interval > 0 {
now.timestamp() / interval
} else {
0
};
... | true |
cbc83a10f81efb084b8fc65918160ce18f6cacf8 | Rust | davidsteiner/seq-rs | /src/participant.rs | UTF-8 | 8,362 | 2.53125 | 3 | [
"MIT"
] | permissive | use crate::diagram::{SequenceDiagram, TimelineEvent};
use crate::message::ARROW_DISTANCE_FROM_BOTTOM;
use crate::rendering::layout::{string_width, GridSize};
use crate::rendering::renderer::{RectParams, Renderer, MEDIUM_BLUE};
use nalgebra::Point2;
use std::cell::RefCell;
use std::cmp::Ordering;
use std::rc::Rc;
pub c... | true |
852e085df28f3517d08fb9bbcff8295a0ce9cf59 | Rust | caitlingao/leetcode_rust | /src/cd0021_merge_two_sorted_lists/mod.rs | UTF-8 | 2,765 | 4 | 4 | [] | no_license | //! Merge Two Sorted Lists [leetcode: merge_two_sorted_lists](https://leetcode.com/problems/merge-two-sorted-lists/)
//!
//! Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.
//!
//! **Example1:**
//!
//! ```
//! Input: 1->2->4,... | true |
439c18e0f1242ee687d17128df350d3f7e1101cc | Rust | CamJN/killline | /src/main.rs | UTF-8 | 1,545 | 2.9375 | 3 | [] | no_license | use std::io;
use std::io::prelude::*;
use std::fs;
use std::env;
use std::path;
fn main() {
let default = "Failed to get panic message.".to_string();
std::panic::set_hook(Box::new(move |p|{
eprintln!("{}",p.payload().downcast_ref::<std::string::String>().unwrap_or(&default));
std::process::exit... | true |
38d4a1266a54e2b53ad94502f836539f9f634de9 | Rust | Canop/broot | /src/permissions/permissions_unix.rs | UTF-8 | 1,160 | 2.625 | 3 | [
"MIT"
] | permissive | use {
fnv::FnvHashMap,
once_cell::sync::Lazy,
std::sync::Mutex,
};
pub fn supported() -> bool {
true
}
pub fn user_name(uid: u32) -> String {
static USERS_CACHE_MUTEX: Lazy<Mutex<FnvHashMap<u32, String>>> = Lazy::new(|| {
Mutex::new(FnvHashMap::default())
});
let mut users_cach... | true |
95325935672860cf80bfcedcacfc5c787a890ea5 | Rust | planet0104/android_sdl2_test | /tenprint/src/main.1.rs | UTF-8 | 13,254 | 2.96875 | 3 | [] | no_license | extern crate brainfuck;
extern crate rand;
#[macro_use]
extern crate log;
extern crate env_logger;
mod context;
use brainfuck::parser;
use context::Context;
use std::time::{Duration, Instant};
use rand::random;
use log::LevelFilter;
use std::sync::mpsc::channel;
use std::thread;
use std::sync::{Arc, Mutex};
/*
f64数组... | true |
7ed8ac97180b1244b9deccc692469d275c0de3f0 | Rust | drahnr/yubihsm-rs | /src/client/get_opaque.rs | UTF-8 | 781 | 2.796875 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! Get the public key for an asymmetric key stored on the device
//!
//! <https://developers.yubico.com/YubiHSM2/Commands/Get_Opaque.html>
use command::{Command, CommandCode};
use object::ObjectId;
use response::Response;
/// Request parameters for `command::get_opaque`
#[derive(Serialize, Deserialize, Debug)]
pub(c... | true |
2d872927a2b84bf4d4f33a2999fd0e3f98eb6870 | Rust | rileylyman/pbrtrs | /crates/pbrtrs-lib/src/geometry/aabb.rs | UTF-8 | 1,645 | 3.015625 | 3 | [] | no_license | use crate::geometry::point::*;
use crate::geometry::vector::*;
struct Bounds<T, const N: usize>
where
T: Numeric,
{
p_min: Point<T, N>,
p_max: Point<T, N>,
}
impl<T, const N: usize> Bounds<T, N>
where
T: Numeric,
{
pub fn new(p_min: Point<T, N>, p_max: Point<T, N>) -> Self {
Self {
... | true |
6e8369d16e24f9d91284a04a21f53e7e998804b7 | Rust | AnneKitsune/world_dispatcher | /src/resource.rs | UTF-8 | 685 | 2.875 | 3 | [
"Apache-2.0"
] | permissive | use crate::*;
/// The type of `Resource`s.
/// All types having a 'static lifetime automatically implement this.
#[doc(hidden)]
pub trait Resource: Send + Sync + 'static + Downcast {}
impl<T> Resource for T where T: Send + Sync + 'static {}
impl_downcast!(Resource);
/// Hacky trait to extend the lifetime of a Ref<'a,... | true |
1081c20f670fdf7ea4e3701def9eae65e6671eee | Rust | arruw/aoc-2020 | /src/day_18.rs | UTF-8 | 2,414 | 3.078125 | 3 | [] | no_license | const DAY: u32 = 18;
type Input = Vec<String>;
type Output = u64;
peg::parser! {
grammar math_parser() for str {
rule number() -> u64
= n:$(['0'..='9']+) { n.parse().unwrap() }
rule whitespace() = quiet!{[' ' | '\t']+}
pub rule expression_part1() -> u64 = precedence!{
... | true |
569482700a73bbcb06e356037fb7316ad0008d86 | Rust | nnyx7/tetris-cl | /src/board/tests/move_down.rs | UTF-8 | 5,588 | 3.0625 | 3 | [] | no_license | #[cfg(test)]
mod move_down {
use crate::board::tests::*;
mod can_perform {
use super::*;
fn test_can_perform(block_color: &str, cells_to_fill: &Vec<Cell>) {
let mut color_state = from_char_to_color(&EMPTY_BOARD.clone());
let block = get_block(block_color);
l... | true |
c0e6b4beb1fd18383d67c2f4bb2dacc1308ec37a | Rust | toshokan/misato | /src/proto/wire.rs | UTF-8 | 16,148 | 2.71875 | 3 | [] | no_license | use nom::IResult;
use nom::{
branch::alt,
bytes::streaming::{tag, take},
combinator::map,
number::Endianness,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Endian {
Big,
Little,
}
impl Endian {
#[inline]
fn is_little(&self) -> bool {
match self {
Self::Li... | true |
30529d1f8c58c31fa6444862226c39d3813a7879 | Rust | pessonnier/randomutf8 | /src/main.rs | UTF-8 | 47,739 | 2.609375 | 3 | [] | no_license | // a tester avec unee grosse regex https://regex101.com/r/oyp9Fk/3/codegen?language=rust
use rand::seq::SliceRandom;
//use rand::thread_rng;
use std::iter::FromIterator;
pub enum UnouInter {
Un(u32),
Inter((u32, u32)),
}
fn main() {
// pris dans https://newbedev.com/generate-random-utf-8-string-in-python
... | true |
ae8276e8a4b01c5be0a35c07a20b63938cbd0015 | Rust | mt2721/nym-1 | /common/nymsphinx/params/src/packet_modes.rs | UTF-8 | 1,198 | 2.75 | 3 | [
"CC0-1.0",
"Apache-2.0"
] | permissive | // Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use std::convert::TryFrom;
#[derive(Debug)]
pub struct InvalidPacketMode;
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum PacketMode {
/// Represents 'normal' packet sent through the network that sh... | true |
a2b616873c9c7b6812f13cb6c5c5e8386d5d6499 | Rust | JohnDoneth/wooting-rs | /wooting-keyboard/src/rgb.rs | UTF-8 | 1,572 | 2.875 | 3 | [
"MIT"
] | permissive | use color::RGB8;
use wooting_rgb_sys::wooting_rgb_direct_set_key;
use wooting_rgb_sys::wooting_rgb_direct_reset_key;
use wooting_rgb_sys::wooting_rgb_reset;
pub use wooting_rgb_sys::WOOTING_RGB_COLS;
pub use wooting_rgb_sys::WOOTING_RGB_ROWS;
use ::assert_key_bounds;
/// Directly set and update 1 key on the keyboar... | true |
6143600301bcbe0edc53736ce690e65fbd896dc1 | Rust | sugyan/leetcode | /problems/0074-search-a-2d-matrix/lib.rs | UTF-8 | 1,219 | 3.375 | 3 | [] | no_license | pub struct Solution {}
impl Solution {
pub fn search_matrix(matrix: Vec<Vec<i32>>, target: i32) -> bool {
if matrix.is_empty() || matrix[0].is_empty() {
return false;
}
match matrix.binary_search_by(|row| row[0].cmp(&target)) {
Ok(_) => true,
Err(i) => i ... | true |
7eeae9243b761a1706d573d1f9e3354c26f740d7 | Rust | plungingChode/open-plang | /src/plang/binary_operator.rs | UTF-8 | 1,385 | 3.84375 | 4 | [] | no_license |
pub enum BinaryOperator {
Plus, Minus, Star, Slash,
Hat, At, Lt, Gt, Eq, Ne,
Le, Ge, And, Or, Div, Mod,
Bracket
}
impl BinaryOperator {
pub const fn op(&self) -> &'static str {
match self {
BinaryOperator::Plus => "+",
BinaryOperator::Minus => "-",
Binar... | true |
1e4ccf4d13657b537587bead203f4aed00212a9a | Rust | toyseed/WebServer_2 | /src/util/lines.rs | UTF-8 | 1,518 | 3.75 | 4 | [
"MIT"
] | permissive | pub struct Lines {
src: Vec<u8>,
cursor: usize,
}
impl Lines {
pub fn new(src: Vec<u8>) -> Lines {
Lines {
src,
cursor: 0,
}
}
}
impl Iterator for Lines {
type Item = String;
fn next(&mut self) -> Option<Self::Item> {
let from = self.cursor;
... | true |
32cfbc3dd37b843c040191756b35f590143288f8 | Rust | vischlum/computorv1 | /src/compute.rs | UTF-8 | 4,145 | 3 | 3 | [] | no_license | use colored::*;
fn solver_verbose(simplified: [f32; 3], delta: f32, x1: f32, x2: f32) {
println!(
"{}",
format!(
"Here are the exact values:\n\tx1 = ({} + √{}) / {}\n\tx2 = ({} - √{}) / {}",
simplified[1] * -1.0,
delta,
2.0 * simplified[2],
... | true |
5de0163ce69e1eadd0536e610944be5adb56ba17 | Rust | gliptic/hypgame | /rustweb-code/src/hyp_to_js.rs | UTF-8 | 21,915 | 2.921875 | 3 | [] | no_license | //use serde::{Serialize, Deserialize};
//use std::collections::{HashMap, hash_map};
use crate::js_ast::{JsLit, JsOp, JsUnop, JsAst, JsModule, JsPattern};
use crate::hyp;
pub struct JsEnc {
pub module: JsModule,
pub errors: Vec<hyp::ParseError>,
}
impl JsEnc {
pub fn new() -> JsEnc {
let enc = JsEn... | true |
b20bc53395256697c8dfabff4f52c795d1a78615 | Rust | yeliknewo/dwarves | /src/components/tile.rs | UTF-8 | 266 | 2.984375 | 3 | [] | no_license | pub struct Tile {
walkable: bool,
}
impl_component!(Tile, false, false);
impl Tile {
pub fn new(walkable: bool) -> Tile {
Tile {
walkable: walkable,
}
}
pub fn is_walkable(&self) -> bool {
self.walkable
}
}
| true |
04bae19b2880529b724dde9042418df21dbb1ef3 | Rust | vpzomtrrfrt/deadpool | /src/lib.rs | UTF-8 | 3,133 | 2.828125 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use std::ops::{Deref, DerefMut};
use std::sync::atomic::{AtomicIsize, AtomicUsize, Ordering};
use std::sync::{Arc, Weak};
use async_trait::async_trait;
use tokio::sync::mpsc::{channel, Receiver, Sender};
use tokio::sync::Mutex;
#[cfg(feature = "postgres")]
pub mod postgres;
#[async_trait]
pub trait Manager<T, E> {
... | true |
4566fb4b3a227c1c83ad723e16d36670608c2026 | Rust | svisser/advent-of-code-2018 | /src/02/main.rs | UTF-8 | 1,573 | 3.484375 | 3 | [] | no_license | use std::collections::hash_map::HashMap;
use std::io;
#[derive(Debug)]
struct IdentifierAnalysis {
has_two: bool,
has_three: bool,
}
fn process_box_id(box_id: &str) -> IdentifierAnalysis {
let mut has_two: bool = false;
let mut has_three: bool = false;
let mut counts: HashMap<char, u32> = HashMap:... | true |
2dfe9f66347a58dcc6a98435bbfece91539d96de | Rust | maximbaz/advents-of-code | /src/year2020/day11.rs | UTF-8 | 3,454 | 3.328125 | 3 | [
"ISC"
] | permissive | use super::super::*;
use itertools::iproduct;
use std::convert::TryFrom;
pub struct Task;
pub type Grid = Vec<Vec<char>>;
impl Solution for Task {
type Input = Grid;
type Output = usize;
fn parse_input(&self, input: String) -> Self::Input {
input
.trim()
.lines()
... | true |
fc42309ad3b6b3b42bcf64f625fccf8caad2e0cc | Rust | LyunKi/rust-algorithm | /src/bulb_switch.rs | UTF-8 | 160 | 2.75 | 3 | [] | no_license | #[allow(dead_code)]
pub fn bulb_switch(n: i32) -> i32 {
(n as f64).sqrt() as i32
}
#[test]
pub fn test_bulb_switch() {
assert_eq!(bulb_switch(3), 1)
}
| true |
fb56a0aa9cfb8c6dec01ab8b326fb7a317db4caa | Rust | Munksgaard/mersenne | /src/lib.rs | UTF-8 | 2,589 | 3.234375 | 3 | [] | no_license | use std::u32;
/// Inspired by the pseudocode and python implementation of the mersenne twister
/// on https://en.wikipedia.org/wiki/Mersenne_Twister
pub struct Mersenne<T> {
w: T, n: T, m: T, r: T,
a: T,
u: T, d: T,
s: T, b: T,
t: T, c: T,
l: T,
f: T,
mt: Vec<T>,
index: T,
... | true |
19a7502a23977d3d0af27a64b2811ddb9bd6d441 | Rust | zmack/mogilefsd-rs | /src/common/mod.rs | UTF-8 | 13,017 | 2.796875 | 3 | [] | no_license | use std::collections::HashMap;
use std::sync::{Arc, RwLock};
use super::error::{MogError, MogResult};
use super::storage::Storage;
use url::Url;
pub use self::model::{Domain, FileInfo};
pub mod model;
#[derive(Debug, Default)]
pub struct Backend {
domains: HashMap<String, Domain>,
empty_domain: Domain,
}
im... | true |
3598ce387e7c1cbfa34e9d65b9d29cf239a46b36 | Rust | NathanFlurry/tokio-tungstenite | /examples/server.rs | UTF-8 | 4,903 | 3.09375 | 3 | [
"MIT"
] | permissive | //! A chat server that broadcasts a message to all connections.
//!
//! This is a simple line-based server which accepts WebSocket connections,
//! reads lines from those connections, and broadcasts the lines to all other
//! connected clients.
//!
//! You can test this out by running:
//!
//! cargo run --example s... | true |
5d71bca074325b81a786b2a5bebc092b981e07ca | Rust | jiachengxian/aoc | /2019/day_3/src/main.rs | UTF-8 | 2,445 | 3.4375 | 3 | [] | no_license | use std::collections::HashMap;
use std::collections::HashSet;
use std::io::{BufReader, BufRead};
use std::fs::File;
use std::cmp;
fn get_directional_vector(symbol : &str) -> (i32, i32){
match symbol {
"U" => return (0,1),
"D" => return (0,-1),
"L" => return (-1,0),
"R" => return (1,... | true |
44cd8e393191e48a0b4a9e80831c37efccad47ac | Rust | jcaromiq/codewars-katas-rust | /src/abbreviate_a_two_word_name.rs | UTF-8 | 572 | 3.203125 | 3 | [] | no_license |
//https://www.codewars.com/kata/57eadb7ecd143f4c9c0000a3/train/rust
fn abbrev_name(name: &str) -> String {
name.split(' ')
.map(|x| x.chars().next().unwrap())
.map(|x| x.to_string())
.map(|x| x.to_uppercase())
.collect::<Vec<_>>()
.join(".")
}
// Rust test example:
#[test]
... | true |
7cdbd833016e981efc3a8572ec7ab33fcc041809 | Rust | Polkadex-Substrate/curv | /src/cryptographic_primitives/hashing/ext.rs | UTF-8 | 11,002 | 3.0625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use digest::Digest;
use hmac::crypto_mac::MacError;
use hmac::{Hmac, Mac, NewMac};
use typenum::Unsigned;
use crate::arithmetic::*;
use crate::elliptic::curves::{Curve, ECScalar, Point, Scalar};
/// [Digest] extension allowing to hash elliptic points, scalars, and bigints
///
/// Can be used with any hashing algorith... | true |
6eccef9be62979517186fca1a39458cb2fa14202 | Rust | Razaekel/noise-rs | /src/math/s_curve/cubic.rs | UTF-8 | 1,350 | 3.703125 | 4 | [
"Apache-2.0",
"MIT"
] | permissive | use num_traits::Float;
/// Cubic S-Curve
///
/// Maps the provided value onto the cubic S-curve function -2x<sup>3</sup> + 3x<sup>2</sup>.
/// This creates a curve with endpoints (0,0) and (1,1), and a first derivative of zero at the
/// endpoints, allowing the curves to be combined together without discontinuities.
/... | true |
70c650e17844123a80ec69077c700a2d3952bcd2 | Rust | fossabot/stego | /tests/common.rs | UTF-8 | 956 | 3.03125 | 3 | [
"MIT"
] | permissive | use std::fs::File;
use std::io::prelude::*;
use std::path::{Path};
use stego::*;
use image::DynamicImage;
fn setup() -> LSBStego {
let im: DynamicImage = image::open(&Path::new(&"./tests/img/test.png")).unwrap();
let stego = LSBStego::new(im.clone());
stego
}
#[test]
fn encode_decode_text(){
let mut s... | true |
eab8ab874b836ba3d8591eabb8e3e00cf010740a | Rust | raphaelcohn/security-keys-rust | /workspace/usb-storm/src/interface/smart_card/features/Features.rs | UTF-8 | 3,190 | 2.53125 | 3 | [
"MIT"
] | permissive | // This file is part of security-keys-rust. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/security-keys-rust/master/COPYRIGHT. No part of security-keys-rust, including this file, may be copied, modified, ... | true |
adf9df1a9c1dcf5e08ff7dec53f377bc9895155c | Rust | mandx/redlock-rs | /src/util.rs | UTF-8 | 781 | 3.53125 | 4 | [
"MIT"
] | permissive | use std::time::Duration;
use rand::{distributions::Standard, thread_rng, Rng};
pub fn get_random_string(len: usize) -> String {
thread_rng()
.sample_iter::<char, _>(&Standard)
.take(len)
.collect()
}
pub fn num_milliseconds(duration: &Duration) -> u64 {
let secs_part = duration.as_sec... | true |
02f16ea10a31da625272b4eda7bd2eadb00b78c8 | Rust | notgull/noop-waker | /src/lib.rs | UTF-8 | 2,018 | 3.140625 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | // MIT/Apache2 License
//! A waker that does nothing when it is woken. Useful for "now or never" type scenarioes where a future is
//! unlikely to be polled more than once, or for "spinning" executors.
//!
//! # Example
//!
//! A very inefficient implementation of the `block_on` function that polls the future over and... | true |
9c48a8432c5fcaf894faecb1a8f4e6b15ba0f5a5 | Rust | SymmetricChaos/project_euler_rust | /src/worked_problems/euler_52.rs | UTF-8 | 1,888 | 3.375 | 3 | [] | no_license | // Problem: Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.
/*
We have to search relatively few numbers. 10/6 = 1.666...
So we only need to search 10-16, 100-166, 1000-1666 and so on
*/
use crate::aux_funcs::{int_to_digits,vec_identical};
pub fn euler52() -> u64 {
... | true |
263d63d03a5859d9491238000bb4b8d95855b8e2 | Rust | parcel-bundler/parcel | /packages/transformers/js/core/src/utils.rs | UTF-8 | 11,582 | 2.71875 | 3 | [
"MIT"
] | permissive | use std::cmp::Ordering;
use std::collections::HashSet;
use crate::id;
use serde::{Deserialize, Serialize};
use swc_core::common::{Mark, Span, SyntaxContext, DUMMY_SP};
use swc_core::ecma::ast::{self, Id};
use swc_core::ecma::atoms::{js_word, JsWord};
pub fn match_member_expr(expr: &ast::MemberExpr, idents: Vec<&str>,... | true |
2e6f49ab164004e4453986b9e5c1f2319e4c1c74 | Rust | xtda/dolan | /src/main.rs | UTF-8 | 2,902 | 2.546875 | 3 | [] | no_license | #![warn(
clippy::all,
clippy::pedantic,
clippy::nursery,
clippy::style,
clippy::complexity,
clippy::perf,
clippy::correctness
)]
mod commands;
mod settings;
mod utils;
use crate::settings::SETTINGS;
use commands::{omega::*, ping::*, repl::*, russia::*, time::*, trump::*, weather::*};
use l... | true |
885b974dd7244a8aa2a0cad395eff9cf95089c01 | Rust | jamougha/matasano | /src/bases.rs | UTF-8 | 2,554 | 3.59375 | 4 | [] | no_license | pub struct Bytes<I> where I: Iterator<Item = u8>{
iter: I,
next_byte: Option<u8>,
next_bit: u8,
byte_size: u8,
in_byte_size: u8,
}
impl<I> Iterator for Bytes<I> where I: Iterator<Item = u8> {
type Item = u8;
fn next(&mut self) -> Option<u8> {
let mut out_byte = 0;
let mut o... | true |
d7e7d20807ee372d0afae877c5feb643449d33c8 | Rust | cjmochrie/Advent-of-Code-2017 | /src/utils.rs | UTF-8 | 123 | 2.765625 | 3 | [] | no_license | pub fn string_to_digits(data: &str) -> Vec<u32> {
data
.chars()
.filter_map(|c| c.to_digit(10))
.collect()
}
| true |
c8143351d62afb86b8f5f455b7a73caf7b9f99ae | Rust | leod/catch-rs | /catch_client/src/components.rs | UTF-8 | 5,974 | 2.828125 | 3 | [] | no_license | use na::Vec4;
use ecs::ComponentList;
use shared::util::PeriodicTimer;
use shared::components::{HasPosition, HasOrientation, HasLinearVelocity, HasShape, HasPlayerState,
HasFullPlayerState, HasWallPosition, HasAngularVelocity, HasWall,
HasProjectile};
pub use shared::c... | true |
4a93609fa703d5a6c6fc17f3b6cffb3aa03b2c57 | Rust | projects-graveyard/lalrdoc | /src/reference_builder/ref_render.rs | UTF-8 | 3,791 | 3.109375 | 3 | [] | no_license | use grammar::parse_tree::{Grammar, NonterminalData, RepeatOp, Symbol, SymbolKind};
pub enum RefRendered {
SomeRendered { rendered: String },
NoneRendered,
DontRenderAlternative,
}
impl RefRendered {
pub(crate) fn try_display(&self) -> Option<String> {
match self {
SomeRendered { re... | true |
196fffba3080f24afdacb6173168f54d3dba0485 | Rust | joanrieu/project-euler | /029-distinct-powers.rs | UTF-8 | 985 | 2.78125 | 3 | [] | no_license | fn main() {
let primes = (2..=100)
.filter(|n| (2..*n).all(|i| n % i != 0))
.collect::<Vec<_>>();
println!("{:?}", primes);
let decomposition = (2..=100)
.map(|mut n| {
(
n,
primes
.iter()
.map(move |p| {
let mut count = 0;
while n % p ... | true |
2bae205e1fd98889b3860cbdf6e84e1da24627ee | Rust | adolfogonzalez3/clap_to_gui | /src/main.rs | UTF-8 | 2,611 | 3.171875 | 3 | [] | no_license | //! Demonstrates a mutable application state manipulated over a number of UIs
extern crate clap;
extern crate iui;
extern crate yaml_rust;
use clap_to_gui::arguments::{Argument, ArgumentWidget};
use clap::{App, load_yaml};
use iui::controls::{Button, Group, HorizontalBox, VerticalBox};
use iui::prelude::*;
fn main()... | true |
c6970bc004bbbd2c76506021baecef902ab99968 | Rust | letheed/aoc | /rust/src/y2016/d08.rs | UTF-8 | 4,836 | 2.78125 | 3 | [] | no_license | use std::fmt::{self, Display, Write};
use fnv::FnvHashMap as HashMap;
use self::Instruction::{Rect, RotCol, RotRow};
use crate::{parse::*, Date, Day, OkOrFail, Puzzle, Result};
const DATE: Date = Date::new(Day::D08, super::YEAR);
pub(super) const PUZZLE: Puzzle = Puzzle::new(DATE, solve);
#[allow(clippy::needless_p... | true |
c065625828b5bc07462cb69dde26f14c3d8bec6d | Rust | j-browne/reaction_efficiency | /src/interpolation.rs | UTF-8 | 4,620 | 3.21875 | 3 | [] | no_license | #![allow(dead_code)]
use self::Value::{Extrapolated, Interpolated};
#[derive(PartialEq, Debug)]
pub enum Value {
Interpolated(f64),
Extrapolated(f64),
NoValue,
}
impl Value {
pub fn is_interp(&self) -> bool {
matches!(*self, Interpolated(_))
}
pub fn is_extrap(&self) -> bool {
... | true |
1403353ca4dc474f9538ab4468babc5ef2771adf | Rust | danhdoan/leetcode.rust | /solutions/remove_all_adjacent_duplicates_in_string_ii.rs | UTF-8 | 1,826 | 3.65625 | 4 | [] | no_license | ///
/// Link: https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string-ii
///
// ============================================================================
struct Solution {
}
impl Solution {
pub fn remove_duplicates(s: String, k: i32) -> String {
let mut vec: Vec<(char, usize)> = Vec::ne... | true |
9b4d74b4cda9785d9b971fd9990731e2cb905741 | Rust | davydog187/ramp | /src/secc.rs | UTF-8 | 37,316 | 3.625 | 4 | [
"Apache-2.0"
] | permissive | //! An Skip Enabled Concurrent Channel (SECC) is a channel that allows users to send and receive
//! data from multiple threads and allows the user to skip reading messages if they choose and
//! then reset the skip later to read the messages. In the purest sense the channel is FIFO
//! unless the user intends to skip ... | true |
a29634574f69c0d4cec9a99ea22c1b8b9d74cd10 | Rust | mozilla/gecko-dev | /third_party/rust/yoke/src/erased.rs | UTF-8 | 1,678 | 2.859375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"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/main/LICENSE ).
//! This module contains helper types for erasing Cart types.
//!
//! See the docs of [`Yoke::erase_rc_cart()`](crate... | true |
4ea28dcc36160098f32449b0ade73fa9a2f568a7 | Rust | iafisher/drill | /src/persistence2.rs | UTF-8 | 5,277 | 2.71875 | 3 | [
"MIT"
] | permissive | use std::collections::HashMap;
use std::path::Path;
use rusqlite::Connection;
use super::common::{QuizError, Result};
use super::quiz2::{Answer2, Question2, QuestionType, Quiz2};
pub fn load_quiz(fullname: &Path) -> Result<Quiz2> {
// let exists = fullname.exists();
// let connection = Connection::open(&path... | true |
e6f7c13908acf096b70d9bf7952db974c52dfe29 | Rust | stainless-steel/probability | /src/distribution/beta.rs | UTF-8 | 11,661 | 3.03125 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use alloc::{vec, vec::Vec};
#[allow(unused_imports)]
use special::Primitive;
use distribution;
use source::Source;
/// A beta distribution.
#[derive(Clone, Copy, Debug)]
pub struct Beta {
alpha: f64,
beta: f64,
a: f64,
b: f64,
ln_beta: f64,
}
impl Beta {
/// Create a beta distribution with sh... | true |
9fddfad0c33d41de0f649f9264fc5e00d096026f | Rust | infinyon/fluvio | /crates/fluvio/src/producer/memory_batch.rs | UTF-8 | 6,940 | 2.75 | 3 | [
"Apache-2.0"
] | permissive | use chrono::Utc;
use fluvio_protocol::{
record::{RawRecords, Batch, Offset, MemoryRecords, BATCH_HEADER_SIZE, ProducerBatchHeader},
Encoder,
};
use fluvio_types::Timestamp;
use super::*;
pub struct MemoryBatch {
compression: Compression,
write_limit: usize,
current_size_uncompressed: usize,
i... | true |
a08d2b2e979a67803b3e7b4ca20f001106143884 | Rust | lpxxn/rust_example | /practice/r11cell/src/m2.rs | UTF-8 | 1,851 | 3.625 | 4 | [] | no_license | use std::cell::{Cell, RefCell};
use std::rc::Rc;
pub trait Messenger {
fn send(&self, msg: String);
}
pub struct MsgQueue {
msg_cache: Rc<RefCell<Vec<String>>>,
}
impl Messenger for MsgQueue {
fn send(&self, msg: String) {
self.msg_cache.borrow_mut().push(msg);
}
}
#[test]
fn testMsg() {
... | true |
e2f7089f1c32fbdd696b154d511e3cfe1418018f | Rust | killercup/rune | /crates/rune/src/sources.rs | UTF-8 | 1,572 | 3.28125 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use runestick::{Item, Source};
use std::collections::VecDeque;
use std::sync::Arc;
/// A collection of source files, and a queue of things to compile.
#[derive(Debug, Default)]
pub struct Sources {
sources: Vec<Arc<Source>>,
queue: VecDeque<(Item, usize)>,
}
impl Sources {
/// Construct a new collection o... | true |
73b6ee5d375e5fb4d7f5e53b606c64d335461a11 | Rust | DominusCarnufex/pulp-rs | /src/v0_1_0/segments.rs | UTF-8 | 10,073 | 2.9375 | 3 | [] | no_license | use ::utils::*;
use ::header::HEADER_LENGTH;
#[derive(Clone, Debug, PartialEq)]
pub enum Segment {
Code {
name : String,
symbol_table : Vec<Symbol>,
const_table : Vec<Const>,
code : Vec<Opcode>
},
}
// Petite fonction utilitaire pour pouvoir accéder facileme... | true |
14b7b7f8de7f5839248c993fc5feb77fd7689f2f | Rust | sugyan/leetcode | /problems/0096-unique-binary-search-trees/lib.rs | UTF-8 | 505 | 3.328125 | 3 | [] | no_license | pub struct Solution;
impl Solution {
pub fn num_trees(n: i32) -> i32 {
let mut v: Vec<i32> = vec![0; n as usize + 1];
v[0] = 1;
for i in 1..=n as usize {
v[i] = (0..i).map(|j| v[j] * v[i - j - 1]).sum();
}
v[n as usize]
}
}
#[cfg(test)]
mod tests {
use s... | true |
9f0e192467014ea913272caf33b7c5a041cd722e | Rust | mdzik/hyperqueue | /crates/hyperqueue/src/worker/parser.rs | UTF-8 | 1,110 | 2.6875 | 3 | [
"MIT"
] | permissive | use crate::common::parser::{p_u32, NomResult};
use anyhow::anyhow;
use nom::bytes::complete::tag;
use nom::combinator::{all_consuming, map, opt};
use nom::sequence::{preceded, tuple};
use tako::common::resources::ResourceDescriptor;
fn p_cpu_definition(input: &str) -> NomResult<ResourceDescriptor> {
map(
t... | true |
ba6d65d1f268c838c70c5b780f29d292e5ab41b2 | Rust | monkeylyf/interviewjam | /math/leetcode_smallest_range_i.rs | UTF-8 | 1,057 | 3.609375 | 4 | [] | no_license | /**
* Given an array A of integers, for each integer A[i] we may choose any x with
* -K <= x <= K, and add x to A[i].
*
* After this process, we have some array B.
* Return the smallest possible difference between the maximum value of B and
* the minimum value of B.
*
* Example 1:
* Input: A = [1], K = 0
* Ou... | true |
235ed5836aee3c3aee9e8ead9aa3b341c3fa1b01 | Rust | awesome-archive/pcap2socks | /src/cacher/mod.rs | UTF-8 | 14,046 | 3.171875 | 3 | [
"MIT"
] | permissive | use std::cmp::{max, min};
use std::collections::BTreeMap;
use std::io;
use std::ops::Bound::Included;
/// Represents the initial size of cache.
const INITIAL_SIZE: usize = 64 * 1024;
/// Represents the expansion factor of the cache. The cache will be expanded by the factor.
const EXPANSION_FACTOR: f64 = 1.5;
/// Repr... | true |
505470940cac323bc73fbeeeb581dd6fc46a49a8 | Rust | cambricorp/Dou-dizhu | /src/cards/card.rs | UTF-8 | 2,447 | 3.53125 | 4 | [
"MIT"
] | permissive | use std::cmp::Ordering;
use std::fmt;
#[derive(PartialEq, Copy, Clone)]
pub enum Suit {
Heart,
Spade,
Club,
Diamond,
Joker,
}
#[derive(Copy, Clone)]
pub struct Card {
pub value: u32,
pub suit: Suit,
pub selected: bool,
}
impl Card {
pub fn new(val: u32, s: Suit, sel: bool) -> Card... | true |
9f6be72692a1910cf51139a86e51b25fff64b3ad | Rust | RustWorks/openshift-openapi-codegen | /src/v4_3/api/apps/v1/deployment_details.rs | UTF-8 | 3,849 | 2.84375 | 3 | [
"Apache-2.0"
] | permissive | // Generated from definition com.github.openshift.api.apps.v1.DeploymentDetails
/// DeploymentDetails captures information about the causes of a deployment.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct DeploymentDetails {
/// Causes are extended data associated with all the causes for creating a new depl... | true |
6adeb183dcad40cf2bf7a7cee3bceae48143d019 | Rust | pkgw/slurm-rs | /slurm/examples/rsinfo.rs | UTF-8 | 1,174 | 2.609375 | 3 | [
"MIT"
] | permissive | // Copyright 2018 Peter Williams <peter@newton.cx> and collaborators
// Licensed under the MIT License
/*! Print out information about a job.
*/
#[macro_use]
extern crate clap;
extern crate failure;
extern crate slurm;
use clap::{App, Arg};
use failure::Error;
use std::process;
fn main() {
let matches = App::n... | true |
0fbffcf40a2156c2d0ed5aa8f2b67752784f01c9 | Rust | PistonDevelopers/lup | /src/vector.rs | UTF-8 | 1,177 | 3.28125 | 3 | [
"MIT"
] | permissive | use *;
/// Vector construction loop.
///
/// Example:
///
/// ```
/// #[macro_use]
/// extern crate lup;
///
/// use lup::Vector;
///
/// fn main() {
/// let a = lup!(Vector<[f64; 4]>: i in 0..4 => {i as f64});
/// println!("{:?}", a); // Prints `[0.0, 1.0, 2.0, 3.0]`.
/// }
/// ```
pub struct Vector<T>(pub T)... | true |
9436446b233b12927302830560898a66d7a60b0a | Rust | ICDao/bigmap-poc | /vendor/rust-cdk/src/ic_cdk/src/api/tests.rs | UTF-8 | 681 | 3.0625 | 3 | [
"Apache-2.0"
] | permissive | use super::*;
#[test]
fn canister_id_parse_str() {
let canister_id_bytes = [0xAB, 0xCD, 0x01];
let canister_id = CanisterId::from(Vec::from(canister_id_bytes));
let canister_id_str_expected = "em77e-bvlzu-aq";
assert_eq!(format!("{}", canister_id), canister_id_str_expected);
assert_eq!(
can... | true |
d084ca67a9623631ccaea0a58fa169c32fff0843 | Rust | mattsse/nom-sparql | /src/quads.rs | UTF-8 | 7,380 | 2.640625 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use nom::{
branch::alt,
bytes::complete::{escaped, tag, tag_no_case, take_while1, take_while_m_n},
character::complete::char,
character::is_digit,
combinator::map_res,
combinator::{map, opt},
multi::{many0, many1, separated_nonempty_list},
sequence::{delimited, pair, separated_pa... | true |
78236cde021f19a4edf95b4c6aa88ea995f745fa | Rust | Dunklas/aoc-2020 | /src/solutions/day5.rs | UTF-8 | 1,075 | 3.65625 | 4 | [] | no_license | pub fn run(input: String) {
println!("Part 1: {:?}", part_1(&input));
println!("Part 2: {:?}", part_2(&input));
}
fn part_1(input: &String) -> usize {
input.lines()
.map(|line| seat_to_id(line))
.max()
.unwrap()
}
fn part_2(input: &String) -> usize {
let mut passes: Vec<usize> ... | true |
15d7e741caa66189df9b9d1af29bbd5f5305991d | Rust | sile/erl_tokenize | /examples/tokenize.rs | UTF-8 | 1,045 | 3.078125 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use clap::Parser;
use erl_tokenize::{PositionRange, Tokenizer};
use std::fs::File;
use std::io::Read;
use std::time::{Duration, Instant};
#[derive(Parser)]
struct Opt {
src_file: String,
#[clap(long)]
silent: bool,
}
fn main() -> anyhow::Result<()> {
let opt = Opt::parse();
let mut src = String::... | true |
7af294a60d084a9801491d6b42730a97b12605f6 | Rust | saelay/libharu-rs | /src/lib.rs | UTF-8 | 2,579 | 2.75 | 3 | [] | no_license | //! Rust binding of libharu PDF library.
#![warn(missing_docs)]
mod document;
mod page;
mod outline;
mod destination;
mod encoder;
mod error;
mod context;
mod image;
/// prelude
pub mod prelude;
/// Floating-point type used in libharu.
pub type Real = libharu_sys::HPDF_REAL;
/// RGB color type.
#... | true |
70fff2d9556931e0f8948847a08f783f52600d3a | Rust | aw88/raytracer-rs | /src/sphere.rs | UTF-8 | 1,311 | 3.4375 | 3 | [] | no_license | use crate::vector3::Vector3;
use std::mem::swap;
#[derive(Clone, Debug)]
pub struct Sphere {
pub radius: f32,
pub radius2: f32,
pub origin: Vector3,
}
#[derive(Clone, Copy, Debug)]
pub struct Ray {
pub origin: Vector3,
pub direction: Vector3,
}
impl Ray {
pub fn new(origin: Vector3, direction... | true |
f724034ad72ae2ee630f5be020fa7200abd880e2 | Rust | dimforge/nalgebra | /src/geometry/point_simba.rs | UTF-8 | 1,103 | 2.75 | 3 | [
"Apache-2.0"
] | permissive | use simba::simd::SimdValue;
use crate::base::{OVector, Scalar};
use crate::geometry::Point;
impl<T: Scalar + SimdValue, const D: usize> SimdValue for Point<T, D>
where
T::Element: Scalar,
{
type Element = Point<T::Element, D>;
type SimdBool = T::SimdBool;
#[inline]
fn lanes() -> usize {
... | true |
691aaa67ae54c44e8e2e28fef775c4aee3341a91 | Rust | prz23/zinc | /zargo/src/command/new.rs | UTF-8 | 3,364 | 3.15625 | 3 | [
"Apache-2.0"
] | permissive | //!
//! The Zargo package manager `new` subcommand.
//!
use std::fs;
use std::path::PathBuf;
use std::str::FromStr;
use colored::Colorize;
use structopt::StructOpt;
use crate::error::Error;
use crate::project::src::circuit::Circuit as CircuitFile;
use crate::project::src::contract::Contract as ContractFile;
use crat... | true |
f16b598d32210f6c8a385e38281cf0b52c9a5d32 | Rust | substation-beta/ssb_implementation | /ssb_filter/tests/vapoursynth_tests.rs | UTF-8 | 1,525 | 2.625 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-warranty-disclaimer"
] | permissive | #[cfg(feature = "vapoursynth-interface")]
mod vapoursynth_tests {
// Imports
use vapoursynth::prelude::*;
use std::process::Command;
include!("platform.irs"); // Tests are separated, thus include code
#[test]
fn test_core_available() {
// Create scripting environment
let envi... | true |
344f9e410f41e04ce4fec97da67572654324ae3d | Rust | jrawsthorne/rust-bitcoin-node | /src/primitives/block.rs | UTF-8 | 2,934 | 2.625 | 3 | [
"MIT"
] | permissive | use super::TransactionExt;
use crate::{
error::{BlockHeaderVerificationError, BlockVerificationError},
protocol::consensus::*,
};
use bitcoin::{blockdata::constants::*, Block, VarInt};
pub trait BlockExt {
fn get_claimed(&self) -> u64;
fn validate_pow(&self) -> Result<(), BlockHeaderVerificationError>;... | true |
63747250116db3832798a29057fa3bb32ea39c70 | Rust | mtvu/influxdb_iox | /data_types/src/write_buffer.rs | UTF-8 | 2,475 | 3.34375 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use std::{collections::HashMap, num::NonZeroU32};
/// If the buffer is used for reading or writing.
#[derive(Debug, Eq, PartialEq, Clone)]
pub enum WriteBufferDirection {
/// Writes into the buffer aka "producer".
Write,
/// Reads from the buffer aka "consumer".
Read,
}
pub const DEFAULT_N_SEQUENCERS... | true |
f2b7f1a3d08949f939e6db1587234ab7efdb6940 | Rust | zigguratvertigo/smallpt-rs | /src/ray.rs | UTF-8 | 211 | 2.9375 | 3 | [
"MIT"
] | permissive | use bvh::Vector3;
#[derive(Copy, Clone)]
pub struct Ray {
pub origin: Vector3,
pub direction: Vector3,
}
impl Ray {
pub fn new(origin: Vector3, direction: Vector3) -> Ray {
Ray { origin, direction }
}
}
| true |
e544087e2a2e17034b706ae7cde9e0ebe8a2de43 | Rust | haxelion/bcmp | /src/treematch.rs | UTF-8 | 17,160 | 3.390625 | 3 | [] | no_license | //! TreeMatch is a binary matching algorithm based on a suffix tree to retrieve matching strings.
//!
//! The suffix tree is built in linear time using Ukkonen's algorithm.
use std::collections::HashMap;
use std::iter::Iterator;
use std::usize;
use Match;
/// A node in the [`SuffixTree`](struct.SuffixTree.html)
pub... | true |
05fd5960c15c667d59f0d57b1786535b27023582 | Rust | libc/advent-of-code-2019 | /src/bin/day_six_two.rs | UTF-8 | 1,809 | 3.171875 | 3 | [] | no_license | use std::cmp::Ordering;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::env;
use std::fs::File;
use std::io::prelude::*;
#[derive(PartialEq, Eq)]
struct QueueItem(usize, String);
impl Ord for QueueItem {
fn cmp(&self, other: &Self) -> Ordering {
sel... | true |
cb97dbe0443088b4cd7bc5e9ce2466de0913384b | Rust | bwindels/json-parser-noalloc-rs | /src/tokenizer.rs | UTF-8 | 7,755 | 3.359375 | 3 | [] | no_license | use fallible_iterator::FallibleIterator;
use super::constants::*;
use super::split::split_mut;
#[derive(Debug, PartialEq)]
pub enum Error {
UnterminatedString
}
pub type TokenizeResult<T> = Result<T, Error>;
#[derive(Debug, PartialEq)]
pub enum Token<'a> {
BeginObject,
EndObject,
BeginArray,
EndArray,
Co... | true |
8925ce32e6a1d92c9c6099ba10f8a47a1feac323 | Rust | djmitche/rubbish | /src/prax/raft/server/handlers/append_entries.rs | UTF-8 | 14,051 | 2.71875 | 3 | [] | no_license | use super::utils::*;
use crate::net::NodeId;
use crate::prax::raft::diststate::DistributedState;
use crate::prax::raft::server::inner::Actions;
use crate::prax::raft::server::message::*;
use crate::prax::raft::server::state::{Mode, RaftState};
use std::cmp;
pub(in crate::prax::raft::server) fn handle_append_entries_re... | true |
b45351b44867d800153ddf93486916a393c5f31d | Rust | yangfengzzz/box2d-rs | /src/private/collision/b2_collide_circle.rs | UTF-8 | 3,769 | 2.71875 | 3 | [
"MIT"
] | permissive | use crate::shapes::b2_circle_shape::*;
use crate::b2_collision::*;
use crate::b2_math::*;
use crate::shapes::b2_polygon_shape::*;
use crate::b2_settings::*;
pub fn b2_collide_circles(
manifold: &mut B2manifold,
circle_a: &B2circleShape,
xf_a: &B2Transform,
circle_b: &B2circleShape,
xf_b: &B2Transform,
) {
manifo... | true |
26d1075cb2f5cf128a6b43b87fe40d66e642fd88 | Rust | howeih/Day-63-Zig-zag | /src/main.rs | UTF-8 | 3,712 | 3.28125 | 3 | [] | no_license | use std::cell::Cell;
use std::cell::RefCell;
struct ZigZag {
rows: usize,
cols: usize,
value: Cell<u32>,
array: RefCell<Vec<Vec<u32>>>,
}
impl ZigZag {
fn new(rows: usize, cols: usize) -> ZigZag {
let array = RefCell::new(vec![vec![0u32; cols]; rows]);
ZigZag {
rows,
... | true |
c2c7381bdcea1221f9dcececf3acab2f73809bf0 | Rust | benbrunton/rusteroids | /src/test.rs | UTF-8 | 701 | 2.9375 | 3 | [
"MIT"
] | permissive | mod actor;
mod spaceship;
mod actor_manager;
#[test]
fn actor_manager_get(){
let mut actors = actor_manager::ActorManager::new();
let p = spaceship::Spaceship::new(1, 0, 0, 0.0);
actors.add_spaceship(p);
assert!(actors.get() == actors.get());
}
#[test]
fn actor_get_view(){
let p = spaceship::S... | true |
d30c8d903a710bfa310eb606769986c53d7a36ac | Rust | nilsso/challenge-solutions | /exercism/rust/nth-prime/src/lib.rs | UTF-8 | 972 | 3.4375 | 3 | [] | no_license | pub fn update_sieve(s: &mut Vec<bool>, n: usize) {
s.append(&mut vec![true;n-s.len()]);
s[0] = false;
s[1] = false;
s[2] = true;
for i in 2..s.len()-1 {
if s[i] {
for j in (2*i..s.len()-1).step_by(i) {
s[j] = false;
}
}
}
}
pub fn nth(n: u... | true |
52667f6a734e5a0700733e417de9ebb28562efb4 | Rust | bohadi/simple-rust-soft-ray-tracer | /src/lib.rs | UTF-8 | 3,027 | 2.65625 | 3 | [] | no_license | extern crate image;
extern crate cgmath;
mod scene;
mod render;
use std::fs::OpenOptions;
use image::{DynamicImage, GenericImage, Rgba, ImageFormat};
use cgmath::Point3;
use cgmath::Vector3;
use scene::*;
use render::{Ray, cast_ray};
fn ftou(f: Rgba<f64>) -> Rgba<u8> {
let r = (f.data[0] * 255.0) as u8;
let... | true |
99ce04d014651db71427773ed215ef0689d4d067 | Rust | eldruin/tcs3472-rs | /src/types.rs | UTF-8 | 1,941 | 3.34375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0",
"MIT"
] | permissive | /// All possible errors in this crate
#[derive(Debug)]
pub enum Error<E> {
/// I²C bus error
I2C(E),
/// Invalid input data provided.
InvalidInputData,
}
/// RGB converter gain
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum RgbCGain {
/// 1x gain
_1x,
/// 4x gain
_4x,
/// 16x gai... | true |
a108b0fe3b47d6dfe8374f7b9ca25bd3a2f9c2a5 | Rust | gabrielgatu/mozzie | /src/parser/mod.rs | UTF-8 | 1,527 | 3.78125 | 4 | [
"Apache-2.0"
] | permissive | mod word;
pub use parser::word::Word;
/// Identifies the category the word belongs to.
/// Most words don't belong to any category (it cannot be inferred),
/// so the default `Unknown` is used.
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub enum Category {
Multimedia,
Fitness,
Agenda,
Unknown,
}
impl Categ... | true |
d272339fe7c1eba95bdf56a595b27e1e79aeaeb7 | Rust | leoschwarz/simple_disk_cache | /src/lib.rs | UTF-8 | 7,160 | 2.875 | 3 | [
"Apache-2.0"
] | permissive | extern crate addressable_queue;
extern crate bincode;
#[macro_use]
extern crate failure;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
use addressable_queue::fifo::Queue;
use serde::Serialize;
use serde::de::DeserializeOwned;
use std::fs::{self, File};
use std::hash::Hash;
use st... | true |
4d0d4abb250a883d40b13fa926c25b526e91971e | Rust | arthurDz/algorithm-studies | /leetcode/number_of_steps_to_reduce_a_number_to_zero.rs | UTF-8 | 337 | 2.734375 | 3 | [] | no_license | impl Solution {
pub fn number_of_steps (num: i32) -> i32 {
let mut curr = num;
let mut steps = 0;
while curr != 0 {
if curr % 2 == 0 {
curr /= 2;
} else {
curr -= 1;
}
steps += 1;
}
... | true |
73b9242b657edc6c2f59890d0ee014e5563481e3 | Rust | avp/raest | /src/renderer.rs | UTF-8 | 1,717 | 2.796875 | 3 | [] | no_license | use crate::config::Config;
use crate::geometry::Scene;
use crate::raytrace;
use minifb::{Window, WindowOptions};
use std::sync::mpsc;
use std::sync::Arc;
use std::sync::RwLock;
use std::thread;
pub type Buffer = Vec<u32>;
pub fn render(config: Arc<Config>) {
let mut window = make_window(&config);
let buf = A... | true |
78afad6b54377d8c3aad9c4fd601ab72fcab66b0 | Rust | kas-gui/7guis | /src/counter.rs | UTF-8 | 1,372 | 2.515625 | 3 | [
"BSD-3-Clause"
] | permissive | // 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 in the LICENSE-APACHE file or at:
// https://www.apache.org/licenses/LICENSE-2.0
//! Counter
use kas::event::EventMgr;
use kas::prelude::*;... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.