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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
9da271273278e3aab6899e0061e74884b7584b7d | Rust | sigp/lighthouse | /consensus/types/src/subnet_id.rs | UTF-8 | 8,028 | 2.640625 | 3 | [
"Apache-2.0"
] | permissive | //! Identifies each shard by an integer identifier.
use crate::{AttestationData, ChainSpec, CommitteeIndex, Epoch, EthSpec, Slot};
use safe_arith::{ArithError, SafeArith};
use serde_derive::{Deserialize, Serialize};
use std::ops::{Deref, DerefMut};
use swap_or_not_shuffle::compute_shuffled_index;
const MAX_SUBNET_ID: ... | true |
cd6569b257566e9245f2d53c23a50e8603b24638 | Rust | gandhivj/rustprgm | /pascals-triangle/src/lib.rs | UTF-8 | 960 | 3.015625 | 3 | [] | no_license | pub struct PascalsTriangle(u32);
impl PascalsTriangle {
pub fn new(row_count: u32) -> Self {
Self(row_count)
}
pub fn rows(&self) -> Vec<Vec<u32>> {
let mut result = vec![];
let rc = self.0;
let mut prev_row: Vec<u32> = vec![];
let mut prev_row_ext: Vec<u32> = ... | true |
fe7a786ef40db8ccd393089542c0a03322a2ffeb | Rust | attilahorvath/exercism-rust | /robot-name/src/lib.rs | UTF-8 | 667 | 3.125 | 3 | [
"MIT"
] | permissive | extern crate rand;
use rand::Rng;
fn rand_char(from: char, to: char) -> char {
rand::thread_rng().gen_range(from as u8, to as u8 + 1) as char
}
pub struct Robot {
name: String,
}
impl Robot {
pub fn new() -> Self {
let mut robot = Robot { name: String::new() };
robot.reset_name();
... | true |
54b8212d4528e256bb4f7c49891474115f899d39 | Rust | bvanrijn/imgshow | /src/inline_image_builder.rs | UTF-8 | 2,502 | 3.15625 | 3 | [] | no_license | use base64::encode;
use std::fmt;
use std::fmt::Display;
#[derive(Debug, Default)]
pub struct InlineImageBuilder {
name: String,
size: usize,
width: String,
height: String,
preserve_aspect_ratio: bool,
inline: bool,
data: Vec<u8>,
}
impl InlineImageBuilder {
pub fn new() -> Self {
... | true |
98f4a3a1e42dd586369e8acd91dba8a0c43f8612 | Rust | yoshuawuyts/omnom | /src/read_bytes.rs | UTF-8 | 3,166 | 3.25 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT",
"Apache-2.0"
] | permissive | use std::io::{self, Read};
use std::mem;
/// Trait to enable writing bytes to a reader.
pub trait ReadBytes: Sized {
/// Read bytes from a reader as big endian.
///
/// Returns the amount of bytes read.
fn read_be_bytes<R: Read>(reader: &mut R) -> io::Result<Self>;
/// Read bytes from a reader as ... | true |
b21fc9156e4b57fbd0ef3ebe3ff87d1bfc85588f | Rust | wapm-packages/coreutils | /src/tail/platform/redox.rs | UTF-8 | 551 | 2.671875 | 3 | [
"MIT"
] | permissive | extern crate syscall;
use self::syscall::{Error, EPERM, ENOSYS};
pub type Pid = usize;
pub struct ProcessChecker {
pid: self::Pid,
}
impl ProcessChecker {
pub fn new(process_id: self::Pid) -> ProcessChecker {
ProcessChecker { pid: process_id }
}
// Borrowing mutably to be aligned with Windo... | true |
f35cffaf5f36a5ded57ba7bf042f795811e89e1f | Rust | jelipo/tcp-listener | /src/main.rs | UTF-8 | 1,140 | 2.59375 | 3 | [] | no_license | use async_std::{io, task};
use async_std::net::TcpListener;
use async_std::prelude::*;
use fantasy_util::time::system_time::SystemLocalTime;
async fn say_hello() -> io::Result<()> {
let listener = TcpListener::bind("0.0.0.0:3391").await?;
let mut incoming = listener.incoming();
while let Some(Ok(mut strea... | true |
9b25d03ca83ac97987166ac500b2fa86b0cf5007 | Rust | klausondrag/advent-of-code | /2020/src/day_09_part_2.rs | UTF-8 | 2,433 | 3.59375 | 4 | [] | no_license | use std::fs::File;
use std::io::{BufRead, BufReader};
pub(crate) fn process(input_filename: &str) {
let file = File::open(input_filename).unwrap();
let reader = BufReader::new(file);
let mut input_numbers = Vec::new();
for line in reader.lines() {
let line = line.unwrap();
let input_nu... | true |
8d7b237bed801ccbb10dc1448f923b8eae47057e | Rust | kitchen/aoc2020 | /day11/src/bin/part2.rs | UTF-8 | 4,925 | 2.953125 | 3 | [
"LicenseRef-scancode-public-domain",
"Unlicense"
] | permissive | use std::collections::HashMap;
use std::env;
use std::fmt;
use std::fs::File;
use std::io::{self, stdin, BufRead, Read};
fn main() {
let args: Vec<String> = env::args().collect();
let filename = &args[1]; // this will panic if there's no argument which is fine for this
let file = File::open(filename).expec... | true |
f74efe89837c46e89d11b812a4c7c59e660e0b13 | Rust | masaxsuzu/rson | /src/combinator.rs | UTF-8 | 8,695 | 3.015625 | 3 | [] | no_license | use std::collections::HashMap;
use std::fmt;
use std::fmt::Display;
use std::fmt::Formatter;
#[derive(Debug, PartialEq, Eq)]
pub enum Error {
FoundUnTerminatedError,
ParseError,
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
Error::FoundUnTer... | true |
a0d52277dfcd78c557efa5475aa953a1889703b2 | Rust | Arkoniak/advent_of_code | /Rust/2018/day01/src/lib.rs | UTF-8 | 2,806 | 3.625 | 4 | [] | no_license | use std::fs;
use std::str;
use std::collections::HashSet;
pub struct Config {
pub filename: String,
pub part: i32,
}
impl Config {
pub fn new(args: &[String]) -> Result<Config, &'static str> {
if args.len() < 2 {
return Err("Not enough arguments");
}
let filename = arg... | true |
fd9ee1bf5934900275c66a9e5ed18259fe83e45e | Rust | dati91/gecko-dev | /third_party/rust/smithay-client-toolkit/src/utils/mempool.rs | UTF-8 | 4,274 | 2.75 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use std::fs::File;
use std::io;
use std::os::unix::io::AsRawFd;
use tempfile::tempfile;
use wayland_client::protocol::{wl_buffer, wl_shm, wl_shm_pool};
use wayland_client::{NewProxy, Proxy};
use wayland_client::protocol::wl_shm::RequestsTrait as ShmRequests;
use wayland_client::protocol::wl_shm_pool::RequestsTrait a... | true |
337250e9e840d595a62621bea4101fc22bca0a52 | Rust | zachjs/vfront | /vfront_verilog_parser/src/preproc.rs | UTF-8 | 23,760 | 2.640625 | 3 | [] | no_license | use crate::diags;
use crate::include::IncludeProvider;
use crate::lang::LangMode;
use crate::lex::Lexer;
use crate::literal::make_string_literal;
use crate::token::{parse_keyword, LexMode, Token, TokenKind};
use std::collections::{hash_map::Entry, HashMap};
use vfront_basics::diag::DiagSystem;
use vfront_basics::source... | true |
0ad1f96ddc495975d814042069ef0926615af156 | Rust | majkcramer/imageproc | /src/regionlabelling.rs | UTF-8 | 5,837 | 3.0625 | 3 | [
"MIT"
] | permissive | //! Functions for finding and labelling connected components of an image.
use image::{
GenericImage,
ImageBuffer,
Luma
};
use definitions::{
VecBuffer
};
use unionfind::DisjointSetForest;
use std::cmp;
use std::collections::HashMap;
/// Whether we consider the NW, NE, SW, and SE neighbors of
/// a ... | true |
dca3c51dcbd440f6c3cadfdb466f43b14b7df57c | Rust | jamwaffles/movements | /realtime-test/src/bin/histo.rs | UTF-8 | 6,321 | 2.65625 | 3 | [
"Apache-2.0"
] | permissive | use crossbeam::tick;
use embedded_graphics::{
pixelcolor::Rgb888,
prelude::*,
primitives::{Line, PrimitiveStyle},
};
use embedded_graphics_simulator::{
OutputSettingsBuilder, SimulatorDisplay, SimulatorEvent, Window,
};
use histogram::Histogram;
use realtime_test::{set_thread_prio, SchedPolicy};
use std... | true |
0af6bdf9fe2ac069c25313b31e0d502ce83fb2a5 | Rust | xiabo0816/Tutorials | /rust/error_rust/src/main.rs | UTF-8 | 4,748 | 3.515625 | 4 | [
"Unlicense"
] | permissive | // 可恢复的错误
// 不可恢复的错误
fn main() {
println!("Hello, world!");
// thread 'main' panicked at 'crash and burn',
// panic!("crash and burn");
let v = vec![1,2,3];
// thread 'main' panicked at 'index out of bounds: the len is 3 but the index is 99'
// v[99];
// Result
use std::fs::File;
... | true |
183b6f67c1d0b687331af29c2349cc360847f19e | Rust | lanocci/algorithm-and-data-struscture-in-rust | /data_structure/priority_queue/src/main.rs | UTF-8 | 903 | 2.921875 | 3 | [] | no_license | use std::io::*;
use util::{Scanner, Joinable};
use complete_binary_tree::CompleteBinaryTree;
fn main() {
std::thread::Builder::new()
.stack_size(1048576)
.spawn(solve)
.unwrap()
.join()
.unwrap();
}
fn solve() {
let cin = stdin();
let cin = cin.lock();
let mut s... | true |
4c49c2f7cf9add7291b6b9fa2602f5acd6a23810 | Rust | cambricorp/smol | /src/lib.rs | UTF-8 | 6,073 | 2.921875 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! A small and fast async runtime.
//!
//! # Examples
//!
//! Connect to an HTTP website, make a GET request, and pipe the response to the standard output:
//!
//! ```
//! use async_net::TcpStream;
//! use smol::{io, prelude::*, Unblock};
//!
//! fn main() -> io::Result<()> {
//! smol::run(async {
//! let ... | true |
f67a88b077a2a867f900579431ba2e16a6071361 | Rust | yred/euler | /rust/problem_007.rs | UTF-8 | 513 | 3.734375 | 4 | [] | no_license | // Problem 7 - 10001st prime
//
// By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see
// that the 6th prime is 13.
//
// What is the 10001st prime number?
fn main() {
println!("{}", solution());
}
fn solution() -> i32 {
(2..).filter(|&n| is_prime(n)).skip(10000).take(1).next().unwrap()... | true |
5cf5d1154a6e684481924182a0e894219e3af7fc | Rust | ytyaru/Rust.Mod.OutFile.20190618180526 | /src/mod_outfile_9/src/my_mod_1/my_mod_2/my_mod_3/my_mod_4/mod.rs | UTF-8 | 587 | 2.59375 | 3 | [
"CC0-1.0"
] | permissive | pub fn public() -> String { String::from("my_mod_1::my_mod_2::my_mod_3::my_mod_4::public()") }
fn private() -> String { String::from("my_mod_1::my_mod_2::my_mod_3::my_mod_4::private()") }
#[cfg(test)]
mod tests {
// use super; // error[E0432]: unresolved import `super`
// use super::*;
#[test]
fn test_pu... | true |
57f66f1ebc9dd434d2d1ede0f316658cceb9eb4f | Rust | PrzemoRevolve/aoc2020_rust | /src/days/day5.rs | UTF-8 | 1,611 | 3.125 | 3 | [] | no_license | use crate::{first_answer, read_input, second_answer};
pub fn run() {
let input = read_input(5);
first_answer(&first_problem(&input));
second_answer(&second_problem(&input));
}
fn first_problem(input: &Vec<String>) -> String {
let answer = parse_seats(input).iter().map(|t| t.2).max().unwrap();
Str... | true |
ce04a9412c7730f7a6c3eb616b37ef5952d6a0b0 | Rust | billyoung/actor-interfaces | /http-server/rust/src/generated.rs | UTF-8 | 4,380 | 2.609375 | 3 | [
"Apache-2.0"
] | permissive | extern crate rmp_serde as rmps;
use rmps::{Deserializer, Serializer};
use serde::{Deserialize, Serialize};
use std::io::Cursor;
extern crate log;
#[cfg(feature = "guest")]
extern crate wapc_guest as guest;
#[cfg(feature = "guest")]
use guest::prelude::*;
#[cfg(feature = "guest")]
use lazy_static::lazy_static;
#[cfg(f... | true |
4dda456bb7a27b1f4035865058e78920c89baef3 | Rust | flyq/datastruct-algorithm | /leetcode/p1184/src/main.rs | UTF-8 | 1,073 | 3.140625 | 3 | [
"MIT"
] | permissive | fn main() {
println!("Hello, world!");
let a = vec![7,10,1,12,11,14,5,0];
println!("{}",Solution::distance_between_bus_stops(a, 7, 2));
}
pub struct Solution{}
impl Solution {
pub fn distance_between_bus_stops(distance: Vec<i32>, start: i32, destination: i32) -> i32 {
let len = distance.len();
... | true |
3937c0a5f2b0c0fec30bf03eeb8bfe9122635fd7 | Rust | iotacommunity/iota-rdb | /src/worker/error.rs | UTF-8 | 1,673 | 2.8125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | use mapper;
use message;
use mysql;
use std::{error, fmt, result, time};
#[derive(Debug)]
pub enum Error {
Message(message::Error),
Mapper(mapper::Error),
SystemTime(time::SystemTimeError),
Mysql(mysql::Error),
}
pub type Result<T> = result::Result<T, Error>;
impl fmt::Display for Error {
fn fmt(&self, f: ... | true |
c75d40e853176623294bbf5a4073917e0e278a13 | Rust | johnnygames/hyper | /src/header/common/transfer_encoding.rs | UTF-8 | 788 | 2.6875 | 3 | [
"MIT"
] | permissive | use header::Encoding;
/// The `Transfer-Encoding` header.
///
/// This header describes the encoding of the message body. It can be
/// comma-separated, including multiple encodings.
///
/// ```notrust
/// Transfer-Encoding: gzip, chunked
/// ```
///
/// According to the spec, if a `Content-Length` header is not inclu... | true |
9b015d82be770c6583220f473f550ada4a6010a1 | Rust | osklunds/Distributed-SWMR-register | /application/src/responsible_cell.rs | UTF-8 | 988 | 3.453125 | 3 | [
"BSD-3-Clause"
] | permissive | use std::cell::UnsafeCell;
/*
Interior mutability is needed when Mediator is created. RefCell would
do, but it's not thread-safe. Mutex and RwLock are, but they have a
performance overhead. This responsible cell is thread safe and doesn't
have a performance overhead, but, it must be used responsibly.
That means that m... | true |
df7afe3ffd8ec3c76831f0587821cc8bb4b832f3 | Rust | ben0x539/filething | /src/main.rs | UTF-8 | 1,776 | 2.8125 | 3 | [] | no_license | use std::collections::HashMap;
use std::ffi::OsString;
use std::env;
use std::io;
use std::fmt;
mod walk;
struct ByteSize(u64);
impl fmt::Display for ByteSize {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
let mut n = self.0;
let mut scale = 0;
while n >= 1024 && scal... | true |
5dc4be644c26c4f3c81b915c3116a41c6ce88fe8 | Rust | Daniel-del-Castillo/daa_p6 | /src/problem_solver/grasp/stop_criterion/total_iterations.rs | UTF-8 | 737 | 3.375 | 3 | [] | no_license | use super::StopCriterion;
/// A stop criterion that stops after a fixed number of iterations
#[derive(Clone)]
pub struct TotalIterations {
total_iterations: usize,
max_iterations: usize,
}
impl StopCriterion for TotalIterations {
fn stop(&mut self, _actual: usize, _new: usize) -> bool {
self.total... | true |
2e9af40c6b0870a3ea21be52671264be14aa363c | Rust | dethos/rgit | /src/remote.rs | UTF-8 | 2,016 | 2.796875 | 3 | [] | no_license | use std::collections::HashMap;
#[path = "data.rs"]
mod data;
#[path = "base.rs"]
mod base;
static REMOTE_REFS_BASE: &'static str = "refs/heads/";
static LOCAL_REFS_BASE: &'static str = "refs/remote/";
pub fn fetch(path: String) {
// Get refs from server
let refs = get_remote_refs(path.clone(), REMOTE_REFS_B... | true |
1db50365493463cc13d26521b4cd1626a34bd36a | Rust | jrybicki-jsc/rusty | /dup/src/main.rs | UTF-8 | 1,976 | 3.78125 | 4 | [] | no_license | fn largest<T: PartialOrd + Copy>(list: &[T]) -> T {
let mut largest = list[0];
for &item in list {
if item > largest {
largest = item;
}
}
largest
}
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
if x.len() > y.len() {
x
} else {
y
}
}
fn m... | true |
9bb6103a29e31a82e5601285a80e94e7b84a7b17 | Rust | kalleakerblom/arcs | /arcs/src/components/bounding_box.rs | UTF-8 | 5,016 | 3.125 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use crate::{algorithms::Bounded, DrawingSpace, Length, Point, Vector};
use aabb_quadtree::Spatial;
use euclid::{num::Zero, Size2D};
use quadtree_euclid::{TypedPoint2D, TypedRect, TypedSize2D};
use specs::prelude::*;
/// An axis-aligned bounding box.
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct BoundingBox {
... | true |
55319289cc013e5fb33c68afbbee47c9688c8970 | Rust | emakryo/cmpro | /src/past202104/src/bin/a.rs | UTF-8 | 464 | 2.765625 | 3 | [] | no_license | #![allow(unused_macros)]
macro_rules! dbg {
($($xs:expr),+) => {
#[cfg(debug_assertions)]
std::dbg!($($xs),+)
}
}
fn main() {
proconio::input!{
s: String,
}
let mut ok = true;
for (i, c) in s.chars().enumerate() {
if i == 3 {
ok = ok && c == '-';
... | true |
65e8a80feaf60e1c31d414dc1f9e8f2e111c65ae | Rust | longfangsong/naivedb | /src/common/chunk.rs | UTF-8 | 2,859 | 3 | 3 | [] | no_license | use std::sync::Arc;
use sqlparser::ast::DataType;
use super::types::EncodeValue;
#[derive(Clone, Debug)]
pub enum DataColumnarValue {
// Array of values.
Array(DataArrayRef),
// A Single value.
Constant(EncodeValue, usize),
}
impl DataColumnarValue {
pub fn to_array(&self) -> Result<DataArrayRef> ... | true |
6cae422a77a499f908aed75ec2fffcdbb2423042 | Rust | abhijeetbhagat/boa | /boa/src/builtins/property/mod.rs | UTF-8 | 6,847 | 3.828125 | 4 | [
"Unlicense",
"MIT"
] | permissive | //! This module implements the Property Descriptor.
//!
//! The Property Descriptor type is used to explain the manipulation and reification of Object property attributes.
//! Values of the Property Descriptor type are Records. Each field's name is an attribute name
//! and its value is a corresponding attribute value ... | true |
7f722ce77b18b50505c69502890470430d139608 | Rust | vans163/lumen | /liblumen_codegen/src/mlir/builder/ops.rs | UTF-8 | 5,422 | 2.9375 | 3 | [
"Apache-2.0"
] | permissive | mod builder;
pub(super) mod builders;
use std::fmt;
use libeir_intern::Ident;
use libeir_ir as ir;
use libeir_ir::FunctionIdent;
pub use self::builder::OpBuilder;
use crate::Result;
use super::block::Block;
use super::ffi::{self, Type};
use super::value::Value;
use super::ScopedFunctionBuilder;
/// Represents the... | true |
f59cea3e2865f8dc22a8c83a48b8699091f3d5e0 | Rust | Anaisdg/flux | /libflux/flux-core/src/parser/tests/types.rs | UTF-8 | 52,766 | 2.8125 | 3 | [
"MIT"
] | permissive | use pretty_assertions::assert_eq;
use super::*;
use crate::ast::{self, tests::Locator};
#[test]
fn test_parse_type_expression() {
let mut p = Parser::new(r#"(a:T, b:T) => T where T: Addable + Divisible"#);
let parsed = p.parse_type_expression();
let loc = Locator::new(&p.source[..]);
assert_eq!(
... | true |
2eb5e5a7e63157a6da099bef12349c0c92e1c2df | Rust | hcdenbakker/colorid | /src/build.rs | UTF-8 | 18,939 | 2.515625 | 3 | [
"MIT"
] | permissive | extern crate bit_vec;
extern crate rayon;
use bit_vec::BitVec;
use fnv;
use kmer;
use rayon::prelude::*;
use simple_bloom;
use std;
use std::collections::HashMap;
use std::fs::File;
use std::io;
use std::io::prelude::*;
pub fn tab_to_map(filename: String) -> fnv::FnvHashMap<std::string::String, Vec<String>> {
let... | true |
97cc66700c5acd6621bfd54a6ee524adeb588fc4 | Rust | nyarly/teddiff | /lib/ted/src/lib.rs | UTF-8 | 300 | 2.609375 | 3 | [] | no_license | mod tree;
mod demaine;
mod shasha;
mod rted;
type Cost = u64;
type Table = Vec<Vec<Option<Cost>>>
pub fn exact(left: impl tree::Node, right: impl tree::Node) -> Cost {
rted::compute(left, right)
}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
| true |
d68ffe5526c023a9b7261aec243ec03328875d90 | Rust | eviltak/physics2d-rs | /examples/stacks.rs | UTF-8 | 4,387 | 2.515625 | 3 | [
"MIT"
] | permissive | extern crate physics2d;
mod testbed;
use physics2d::*;
use physics2d::debug::DebugCollision;
struct StacksTestbed {
world: World,
}
impl StacksTestbed {
pub fn new(config: &testbed::Config) -> StacksTestbed {
let window_width = config.window_width as f32 / config.pixels_per_unit;
let window... | true |
a303b3084bdd8f6d6ae61e5e5562f8fb80cd828e | Rust | fqliao/rust_lab | /geektime/ch01/src/lexical.rs | UTF-8 | 744 | 3.484375 | 3 | [] | no_license | /// 函数中定义宏
pub fn macro_show() {
macro_rules! calculate {
($e:expr) => {
let val: usize = $e; // Force types to be integers
println!("{} = {}", stringify!{$e}, val);
};
}
calculate!(1 + 2 + 7);
calculate!((1 + 2) * (8 / 4));
}
/// 定义宏并导出
#[macro_export]
macro_rules! create... | true |
a526c5e3e1a9fbf0364cd8386a16873bb14ecab9 | Rust | dvdnglnd/project-euler | /2/solution.rs | UTF-8 | 518 | 3.5625 | 4 | [] | no_license | struct Fibonacci {
curr: u32,
next: u32,
}
impl Iterator for Fibonacci {
type Item = u32;
fn next(&mut self) -> Option<u32> {
let new_next = self.curr + self.next;
self.curr = self.next;
self.next = new_next;
Some(self.curr)
}
}
fn fibonacci() -> Fibonacci {
F... | true |
6f4f52f05e00affb5b425a0e9fd6d7bffa4de408 | Rust | ryanjackgit/rustunsafedatastruct | /src/tree.rs | UTF-8 | 4,473 | 3.1875 | 3 | [] | no_license | use crate::list::List;
use crate::vec::ManVec;
use std::alloc::{self, dealloc, Layout};
use std::ptr;
use std::mem;
use std::fmt::Debug;
pub struct TreeNode<T: std::fmt::Debug> {
data: T,
left: *mut TreeNode<T>,
right: *mut TreeNode<T>,
}
pub struct Tree<T: std::fmt::Debug>{
root:Option<*mut TreeN... | true |
eb8e5084d99d212b42066979544b767f3689be85 | Rust | koivunej/aoc | /2019/intcode/src/lib.rs | UTF-8 | 7,206 | 3 | 3 | [] | no_license | mod instr;
mod error;
pub mod util;
mod env;
mod exec;
pub use error::*;
pub use util::{ParsingError, parse_stdin_program, with_parsed_program};
pub use env::Environment;
pub use exec::{Program, ExecutionState};
pub type Word = i64;
#[derive(Default, Debug, Clone)]
pub struct Registers {
ip: usize,
relbase: ... | true |
b798b3da44294da53496e1438605c174a5281427 | Rust | Technici4n/seven-wonders | /backend/src/game.rs | UTF-8 | 12,250 | 3.046875 | 3 | [] | no_license | use rand::prelude::*;
use serde::{Deserialize, Serialize};
use crate::cards::CardRegistry;
/// The state of a single game.
#[derive(Debug, Clone, Serialize)]
pub struct Game {
#[serde(skip)]
card_registry: CardRegistry,
#[serde(skip)]
pub plays: Vec<Play>,
player_count: usize,
pub players: Vec<... | true |
21e52c9a60d498a7ec238e158da39c9e221a5e4a | Rust | mineo/edabo-rs | /tests/playlist.rs | UTF-8 | 1,467 | 2.640625 | 3 | [] | no_license | extern crate chrono;
extern crate edabo;
extern crate serde_json;
extern crate uuid;
use edabo::types::{Playlist, Track};
use std::collections::HashSet;
fn get_playlist() -> Playlist {
let track = Track {
release_track_id: Some(
uuid::Uuid::parse_str("d71b7b2d-075c-3c09-8a3f-d050b121f3ab").unw... | true |
665c278cea30c74c142732bfa83f4daa2ce9ffe5 | Rust | dpc/rhex | /src/curses/mod.rs | UTF-8 | 1,258 | 2.6875 | 3 | [] | no_license | use ncurses as nc;
use std::cell::RefCell;
use game;
/// Working with 256 color palette
mod color;
mod consts;
mod map;
mod error;
pub use self::error::*;
mod ui;
pub use self::ui::*;
pub struct Window {
pub window: nc::WINDOW,
}
impl Window {
pub fn new(w: i32, h: i32, x: i32, y: i32) -> Window {
... | true |
7b347da2817050e05591e75f1a3713745f582fb1 | Rust | worace/exercism | /rust/hamming/src/lib.rs | UTF-8 | 418 | 3.390625 | 3 | [] | no_license | pub fn hamming_distance(left: &str, right: &str) -> Result<i32, String> {
if left.chars().count() != right.chars().count() {
Err("Strings must be same length".to_string())
} else {
Ok(left.chars().zip(right.chars()).fold(0, |distance, (lchar, rchar)| {
if lchar != rchar {
... | true |
41347788217dceeb5dcf1238c424b8bfc2c803d5 | Rust | kyutech-programming-club/rust_quiz_2021 | /src/august/q_0820/tanacchi/mod.rs | UTF-8 | 1,866 | 2.984375 | 3 | [] | no_license | use std::io;
use std::f64::consts::PI;
use anyhow::{ensure, Result};
use crate::utils::tanacchi::{error::Error as MyError, stream};
fn calc_volume(input: &str) -> Result<f64> {
let r = input.parse::<f64>()?;
ensure!(
r >= 0.0,
MyError::InvalidInputError("Radian must be greater than 0.")
);
... | true |
06241cd59fecf6ce1b3bb14a438cf61b5ec02670 | Rust | tkshnwesper/Project-Euler | /10-19/18/18.rs | UTF-8 | 1,187 | 3.015625 | 3 | [
"Unlicense"
] | permissive | use std::cmp::max;
fn main() {
const pyramid: &str =
"75
95 64
17 47 82
18 35 87 10
20 04 82 47 65
19 01 23 75 03 34
88 02 77 73 07 63 67
99 65 04 28 06 16 70 92
41 41 26 56 83 40 80 70 33
41 48 72 33 47 32 37 16 94 29
53 71 44 65 25 43 91 52 97 51 14
70 11 33 28 77 73... | true |
8b2c556d53d1b527cbb5714c517726e3cd5ae929 | Rust | FaydSpeare/Celestial | /src/mcts.rs | UTF-8 | 2,616 | 2.84375 | 3 | [] | no_license | use crate::types::*;
use crate::bitboard::*;
use crate::position::*;
use crate::movegen::*;
use crate::hashkey::*;
use crate::parsing::*;
use crate::motion::*;
use crate::attack::*;
use crate::domotion::*;
use crate::io::*;
use rand::Rng;
pub fn run_mcts(pos: &mut Position, list: &Vec<Motion>) -> usize {
let mut ... | true |
27e58310655e90f8c92bf4420008745a704c8763 | Rust | Miniwoffer/Timetracker-rs | /src/main.rs | UTF-8 | 11,105 | 2.78125 | 3 | [] | no_license | //! A simple demonstration of how to construct and use Canvasses by splitting up the window.
#[macro_use] extern crate conrod;
#[macro_use] extern crate serde_derive;
extern crate chrono;
extern crate serde;
mod support;
fn main() {
feature::main();
}
mod feature {
const FILENAME : &str = "timetracker.json"... | true |
5145b24ad28c3e54261483a0e41e5c42ee67534b | Rust | max-wittig/todo | /src/main.rs | UTF-8 | 2,261 | 2.703125 | 3 | [
"MIT"
] | permissive | /*
* Copyright (c) 2017 Max Wittig
*
* SPDX-License-Identifier: MIT
*/
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate prettytable;
extern crate serde_yaml;
extern crate clap;
extern crate chrono;
mod todo;
use clap::{Arg, App};
use std::process::exit;
fn main() {
let matches = App::n... | true |
e39fa8ffb9c1517053c0f93cc5c9015e36e55174 | Rust | blakesmith/arrow2 | /examples/csv_read_parallel.rs | UTF-8 | 2,545 | 2.703125 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | use crossbeam_channel::unbounded;
use std::sync::Arc;
use std::thread;
use std::time::SystemTime;
use arrow2::{error::Result, io::csv::read, record_batch::RecordBatch};
fn parallel_read(path: &str) -> Result<Vec<RecordBatch>> {
let batch_size = 100;
let has_header = true;
let projection = None;
// p... | true |
763f0603c5fe5bc42a8b89b788668b7a4ce49c10 | Rust | chridou/nakadion | /nakadion/src/handler/mod.rs | UTF-8 | 10,149 | 3.046875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | //! Kit for creating a a handler for batches of events
//!
//! Start here if you want to implement a handler for processing of events
use std::fmt;
use std::time::{Duration, Instant};
pub use bytes::Bytes;
use futures::future::BoxFuture;
pub type BatchHandlerFuture<'a> = BoxFuture<'a, BatchPostAction>;
use crate::na... | true |
b9301a65d344262c2b73156f8c74de838e32f95b | Rust | LimaEchoCharlie/cwb | /rust-overview/src/cbor.rs | UTF-8 | 420 | 3.078125 | 3 | [] | no_license | use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug)]
struct Point {
x: i32,
y: i32,
}
pub fn run() {
let point = Point { x: 1, y: 2 };
let serialized = serde_cbor::to_vec(&point).unwrap();
println!("cbor serialized = {:?}", serialized);
let deserialized: Point = serd... | true |
1999dbd8896fb1da408b87105cab780a1f71be4b | Rust | runcom/adventofcode2018-rs | /src/bin/1/main.rs | UTF-8 | 1,151 | 3.0625 | 3 | [
"Apache-2.0"
] | permissive | use std::collections::HashMap;
use std::fs::File;
use std::io::BufRead;
use std::io::BufReader;
fn main() {
sol1();
sol2();
}
fn sol1() {
let f = File::open("inputs/1.txt").unwrap();
let file = BufReader::new(&f);
let mut solution: i32 = 0;
for line in file.lines() {
let l: i32 = line.... | true |
d999e74b8b3cc170c649f23fa211ceacffd4f8dd | Rust | abingham/pyo3 | /src/callback.rs | UTF-8 | 3,778 | 2.578125 | 3 | [
"Apache-2.0",
"Python-2.0"
] | permissive | // Copyright (c) 2017-present PyO3 Project and Contributors
//! Utilities for a Python callable object that invokes a Rust function.
use crate::err::PyResult;
use crate::exceptions::OverflowError;
use crate::ffi::{self, Py_hash_t};
use crate::IntoPyPointer;
use crate::{IntoPy, PyObject, Python};
use std::isize;
use s... | true |
7deeab749ad4dce665195798f176d408f47a9fb7 | Rust | wcrbrm/geo-continent | /src/antarctica.rs | UTF-8 | 362 | 2.5625 | 3 | [
"MIT"
] | permissive | extern crate geo;
pub fn get_polygon() -> geo::Polygon<f32> {
let exterior = geo::LineString::from(vec![
(-180.000000, -90.000000),
(180.000000, -90.000000),
(180.000000, -60.000000),
(-180.000000, -60.000000),
(-180.000000, -90.000000),
]);
let interior = vec![];
... | true |
6ddea9ce874950a60ba8f5f2b265ab020e8d71d3 | Rust | barreyo/robofill | /src/components/input.rs | UTF-8 | 4,631 | 2.765625 | 3 | [] | no_license |
use std::collections::HashMap;
use ggez::event::Keycode;
use specs::{System, HashMapStorage, VecStorage, Fetch, ReadStorage, WriteStorage, World,
DispatcherBuilder};
use components::graphics::GameBoard;
use core::grid;
use components::positioning::{Direction, Animating, Position, TargetPosition};
/// Ho... | true |
981fd3f4bb98490857d48dad5d3ede55bed6507b | Rust | rrbutani/fatfs | /src/fat/cache.rs | UTF-8 | 38,256 | 3.203125 | 3 | [] | no_license | //! Home of the `SectorCache` type; that which all writes and reads to `Storage`
//! flow through.
use super::types::SectorIdx;
use crate::util::{BitMap, BitMapLen};
use storage_traits::Storage;
use generic_array::{ArrayLength, GenericArray};
use core::cell::{RefCell, RefMut, Ref};
use core::cmp::Ordering;
use core:... | true |
3f4c983e5d3443f5ac6c695560c8a8bb71b4c1ae | Rust | CasperN/drug | /src/lib.rs | UTF-8 | 5,246 | 2.5625 | 3 | [
"MIT"
] | permissive | //! # ∂rug - Differentiable Rust Graph
//!
//! This crate is a collection of utilities to build build neural networks (differentiable
//! programs). See [examples](https://github.com/CasperN/drug/tree/master/examples)
//! for implementations of canonical neural networks. You may need to download those datasets
//! your... | true |
3f3359f478e2e378bff7342824854a4f348c60ef | Rust | mokomull/adventofcode_2018 | /day_01/src/main.rs | UTF-8 | 832 | 3.078125 | 3 | [] | no_license | use std::io::BufRead;
fn main() {
let stdin = std::io::stdin();
let lock = stdin.lock();
let data: Vec<_> = lock
.lines()
.map(|line| {
line.expect("file should be readable")
.parse::<i64>()
.expect("file should contain integers")
})
... | true |
0ad116e52dfddb49bf9f6a6d274ad7ab9aafbf52 | Rust | hyone/rust_by_example | /chapter8/8_1_methods.rs | UTF-8 | 2,256 | 4.15625 | 4 | [] | no_license | struct Point {
x: f64,
y: f64,
}
// Implementation block,
// all `Point` methods go in here
impl Point {
// This is a static method.
// Static methods don't need to be called by an instance
// These methods are generally used as constructors
fn new(x: f64, y: f64) -> Point {
Point { x: ... | true |
d6b91e0268f5ec81ea26626c8564f3aede43cf52 | Rust | jofas/yata | /api/src/errors.rs | UTF-8 | 1,196 | 2.640625 | 3 | [] | no_license | use mongodb::bson::document::ValueAccessError;
use mongodb::bson::de::Error as BsonDeserializationError;
use mongodb::bson::ser::Error as BsonSerializationError;
use std::convert::From;
use std::option::NoneError;
#[derive(Debug)]
pub enum ParseDocumentError {
NotPresent,
UnexpectedType,
BsonDeserializationErro... | true |
440f0febdea5e357ca0623651cabba622b702f21 | Rust | jamestthompson3/birb | /src/screen.rs | UTF-8 | 740 | 2.9375 | 3 | [] | no_license | use std::io::{Stdout, Write};
static CLEAR_SCREEN: &[u8] = b"\x1b[2J";
static POSITION_CURSOR: &[u8] = b"\x1b[H";
pub struct Screen<'a> {
stdio: &'a Stdout,
}
// io::stdout().write(&[char]).unwrap();
impl<'a> Screen<'a> {
pub fn refresh(stdout: &'a mut Stdout) {
stdout
.write(CLEAR_SCREEN)... | true |
8ac9205c298a89a071273ce3fce9955283d8fc91 | Rust | ryanpbrewster/rust-project-euler | /src/util/prime/iter.rs | UTF-8 | 1,737 | 3.53125 | 4 | [] | no_license | pub struct Primes {
sieve_arr: Vec<bool>,
sieve_start: usize,
idx: usize,
past: Vec<usize>,
}
impl Primes {
pub fn all() -> Primes {
Primes {
sieve_arr: vec![true],
sieve_start: 2,
idx: 2,
past: Vec::new(),
}
}
fn end(&self) -... | true |
fc7755d6164e1c17bb8a58dcfc40fda54923ea32 | Rust | daviswahl/leaky-raft | /src/util.rs | UTF-8 | 830 | 2.546875 | 3 | [] | no_license | use crate::futures::new::*;
use failure::Fail;
use std::io;
/// Convenience function for spawning a Future03 on the tokio executor.
pub fn spawn_compat<F: StdFuture<Output = ()> + Send + 'static>(fut: F) {
let fut = fut.boxed().unit_error().compat();
tokio_executor::spawn(fut)
}
/// Collect a vec or comma-se... | true |
2c8cc78ede7f3877b7f346abf7d01ab03c11bdcc | Rust | karuna/hangar | /src/generator/templates/libs_logger.rs | UTF-8 | 1,873 | 2.890625 | 3 | [
"MIT"
] | permissive | pub static TEXT: &'static str = "use std::fs::File;
use std::io::Error;
use std::path::Path;
use slog::Logger;
use sloggers::Build;
use sloggers::terminal::{Destination, TerminalLoggerBuilder};
use sloggers::file::FileLoggerBuilder;
use sloggers::types::Severity;
use rocket::config::Environment;
use super::settings:... | true |
a98b77294121bdafcb24b04657056137a4e3c7f4 | Rust | kitesoft/mug-club | /src/error.rs | UTF-8 | 2,095 | 2.546875 | 3 | [] | no_license | use actix_web::error::ResponseError;
use actix_web::Error as ActixError;
use authy::AuthyError;
use diesel::r2d2;
use diesel::result::Error as DieselError;
use futures::channel::oneshot::Canceled as FutureCanceled;
use std::convert::From;
use std::error::Error as StdError;
pub type Result<T> = ::std::result::Result<T,... | true |
2805cb35b8459419f7ad495db2434201029cd554 | Rust | Delamare2112/AdventOfCode2018 | /day_8/src/main.rs | UTF-8 | 2,357 | 3.1875 | 3 | [] | no_license | #[derive(Default, Debug)]
struct Node {
children: Vec<Node>,
metadata: Vec<usize>,
}
impl Node {
fn new(input: &Vec<usize>) -> Node {
Node::parse(input).0
}
fn parse(input: &[usize]) -> (Node, usize) {
let mut head = Node::default();
let children_count = input[0];
let... | true |
08fdd0a06d908a406246b397625fa24d3c21238f | Rust | yusuke-ota/nand2tetris_rust | /ch6_assembler/src/tools/parser.rs | UTF-8 | 5,029 | 3.34375 | 3 | [
"MIT"
] | permissive | use crate::tools::{classification_symbol, CommandType, CompType, DestType, JumpType, Symbol};
use crate::{IParser, Parser};
use std::convert::TryFrom;
use std::fs::File;
use std::io::{BufRead, BufReader};
impl IParser for Parser {
fn new(file: File) -> Self {
let mut buf_reader = BufReader::new(file);
... | true |
a5ce16f0eae38b023c9fd4fcc9fbf06ebcbf10f6 | Rust | sotrh/learn-wgpu | /code/showcase/pong/src/system.rs | UTF-8 | 8,262 | 3.109375 | 3 | [
"MIT"
] | permissive | use crate::any;
use crate::input;
use crate::state::{self, GameState};
use crate::util;
pub trait System {
#[allow(unused_variables)]
fn start(&mut self, state: &mut state::State) {}
fn update_state(
&self,
input: &input::Input,
state: &mut state::State,
events: &mut Vec<sta... | true |
c77fed779f5131afb2a0aa1a44e29fce52aee3aa | Rust | PooyaEimandar/VulkanRust | /examples/src/bin/1_hello_vulkan.rs | UTF-8 | 956 | 2.71875 | 3 | [
"MIT"
] | permissive | extern crate ash;
fn main() {
unsafe {
//create ash entry
let entry_res = ash::Entry::new();
match entry_res {
Ok(entry) => {
//create instance create info
let instance_create_info = ash::vk::InstanceCreateInfo::builder();
//create... | true |
714b31bfd0a0649da00f7ae96c0797101a642307 | Rust | MarcelRaschke/rust-book | /use-key/src/lib.rs | UTF-8 | 340 | 3 | 3 | [
"MIT"
] | permissive | enum TrafficLight {
Red,
Yellow,
Green,
}
use crate::TrafficLight::{Red, Yellow};
pub fn f() {
let _red = Red;
let _yellow = Yellow;
let _green = TrafficLight::Green; // because we didn’t `use` TrafficLight::Green
}
#[cfg(test)]
mod tests {
use crate::f;
#[test]
fn it_works() {
... | true |
56fbe513bd3d6be52e384a574424821ae30fd049 | Rust | nical/vodk.rs | /math/src/cgmath_glue.rs | UTF-8 | 11,223 | 3.140625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT",
"Apache-2.0"
] | permissive |
use cgmath;
use std;
// unit should be an empty struct but for some reason rustc requires the unit
// to implement all of the numeric traits (~200 lines of silly boilerplate) so
// lets reuse types that alredy do implement those traits for now.
macro_rules! declare_unit (
($module:ident, $silly_work_around_type: ... | true |
ce0c6080c623cc02588893e7646d17de51d6fda4 | Rust | falconre/osprey | /lib/il.rs | UTF-8 | 29,882 | 2.75 | 3 | [] | no_license | use falcon;
use gluon::vm::api::{Userdata, VmType};
use gluon::vm::thread::{Traverseable};
use gluon;
falcon_type_wrapper!(falcon::il::Constant, IlConstant);
fn constant_new(value: u64, bits: usize) -> IlConstant {
IlConstant { x: falcon::il::Constant::new(value, bits) }
}
fn constant_format(constant: &IlConst... | true |
41d7b4d8f8d8dd2a704f21dfa659ebdeb79a36e9 | Rust | shashankhacker730/feroxbuster | /src/message.rs | UTF-8 | 4,716 | 3.21875 | 3 | [
"MIT"
] | permissive | use anyhow::Context;
use console::{style, Color};
use serde::{Deserialize, Serialize};
use crate::traits::FeroxSerialize;
use crate::utils::fmt_err;
#[derive(Serialize, Deserialize, Default)]
/// Representation of a log entry, can be represented as a human readable string or JSON
pub struct FeroxMessage {
#[serde... | true |
bf6de66e1e2f48ba556230b2c5d1597b610a3922 | Rust | hidekatsu-izuno/josekit-rs | /src/jwe/enc/aescbc_hmac.rs | UTF-8 | 6,437 | 2.796875 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use std::{fmt::Display, ops::Deref};
use anyhow::bail;
use openssl::{
hash::MessageDigest,
pkey::{PKey, Private},
sign::Signer,
symm::{self, Cipher},
};
use crate::{jwe::JweContentEncryption, JoseError};
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub enum AescbcHmacJweEncryption {
/// AES_128_C... | true |
1a6e7943272a898161752815309806985bb9b609 | Rust | martinvonz/jj | /cli/src/time_util.rs | UTF-8 | 3,227 | 3.03125 | 3 | [
"Apache-2.0"
] | permissive | use chrono::format::StrftimeItems;
use chrono::{DateTime, FixedOffset, LocalResult, TimeZone, Utc};
use jj_lib::backend::Timestamp;
use once_cell::sync::Lazy;
/// Parsed formatting items which should never contain an error.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct FormattingItems<'a> {
items: Vec<chrono::... | true |
34e54017f93f49e52d44dc9453cc18bf40d2bf39 | Rust | yueguanyu/mikudos-rust-app | /src/my_mod/collection.rs | UTF-8 | 500 | 3.125 | 3 | [
"MIT"
] | permissive | use std::collections::HashMap;
pub fn test_collection() {
let mut instance_name: HashMap<&str, &str> = HashMap::new();
instance_name.insert("name", "testName");
for (key, val) in instance_name.iter() {
println!("elem: {} value: {}", key, val);
}
match instance_name.get(&"name") {
So... | true |
10acec934483587fbf1cc9fb47ae1bbb42405832 | Rust | crazy-genius/rusty-rocket-chat | /src/rocket/mod.rs | UTF-8 | 2,315 | 2.734375 | 3 | [] | no_license | pub mod model;
mod client;
mod decoder;
use self::model::{Auth, Result, RocketChatErrorType, ErrorKind};
use self::client::{get_client, get_authenticated_client, do_req};
use self::decoder::{do_decode};
use curl::easy::{Easy, List};
use serde_json::Value;
pub fn authenticate() -> Result<Auth> {
let data = Vec::f... | true |
f5ec7d785463da4aaee6059704bce530d7a3d5ad | Rust | yyotti/euler_rust | /src/p0041.rs | UTF-8 | 1,150 | 3.1875 | 3 | [
"MIT"
] | permissive | //! [Problem 41](https://projecteuler.net/problem=41)([JP](http://www.odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2041))
use super::common;
pub fn solve() -> i64 {
// パンデジタルになる必要があるので、1~Nまでの整数(1 <= N <= 9)の順列を
// 求め、それを整数とみなして素数判定を行えばよい。
//
// ここで、N=9の場合は1~9の順列になるが、
// 1+2+3+4+... | true |
9167f17847d091750414dcc5570c3d16cd63c5b7 | Rust | wanimaru47/project_euler | /src/p044.rs | UTF-8 | 816 | 3.703125 | 4 | [] | no_license | fn pentagonal(n: i64) -> i64 {
return n * (n * 3 - 1) / 2;
}
#[test]
fn test_pentagonal() {
assert_eq!(1, pentagonal(1));
assert_eq!(5, pentagonal(2));
assert_eq!(12, pentagonal(3));
}
fn is_pentagonal(n: i64) -> bool {
let mut i = 1;
while pentagonal(i) < n {
i += 1;
}
return n... | true |
42035b27c1ea64c678b07047b1a8f9a1684f1fcf | Rust | Eduardo-Vinicius/Estudo-Linguagem-RUST | /src/Funcao/Recursive.rs | UTF-8 | 299 | 2.90625 | 3 | [] | no_license |
pub fn e2_Fatorial_InterativoHelper(mut n:f64,mut fat:f64) -> f64{
if n == 1_f64 {
return fat;
}
else{
return e2_Fatorial_InterativoHelper(n - 1_f64, fat * n);
}
}
pub fn e2_Fatorial_Interativo(mut n:f64) -> f64{
return e2_Fatorial_InterativoHelper(n,1_f64);
} | true |
6961ab617c1fb12b9786a9e454e64f0fef481908 | Rust | usarekoski/aoc-2019 | /src/day6.rs | UTF-8 | 2,435 | 3.59375 | 4 | [] | no_license | use std::cmp::Reverse;
use std::collections::{BinaryHeap, HashMap, VecDeque};
fn parse(orbits: &Vec<String>) -> Vec<(&str, &str)> {
orbits
.iter()
.map(|orbit| {
let mut split = orbit.split(')');
let up = split.next().unwrap();
let down = split.next().unwrap();
... | true |
d54ef0dd4e79711dde600aa87e650c73e781f10f | Rust | tomaka/eui | /src/predefined/label.rs | UTF-8 | 2,120 | 3.21875 | 3 | [] | no_license | use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;
use Alignment;
use HorizontalAlignment;
use Layout;
use Matrix;
use Shape;
use VerticalAlignment;
use Widget;
pub struct Label {
text: String,
needs_refresh: AtomicBool,
}
impl Label {
/// Initializes a new label.
#[inline]
pub f... | true |
503311e43569f172c7a0a17dcd231c4c0e0da00b | Rust | rustic-games/bulletin | /src/main.rs | UTF-8 | 3,458 | 3.40625 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use reqwest;
use serde::{Deserialize, Deserializer, Serialize};
use std::collections::HashMap;
use std::fs;
use std::path::PathBuf;
use structopt::StructOpt;
use tera::Tera;
#[derive(StructOpt, Debug)]
#[structopt(name = "bulletin")]
struct Opt {
/// Pinboard API token
#[structopt(short = "t", long = "token")]... | true |
d1d7c40a467e814357e0e4d6f0f9535e29a0c59d | Rust | leshow/twilio-async | /src/recording.rs | UTF-8 | 3,316 | 2.609375 | 3 | [
"MIT"
] | permissive | use super::{Execute, Twilio, TwilioErr, TwilioJson, TwilioRequest, TwilioResp};
use async_trait::async_trait;
use hyper::{self, Method};
use serde::Deserialize;
#[derive(Debug, Default)]
pub struct Recording<'a> {
sid: &'a str,
}
impl<'a> Recording<'a> {
pub fn new(sid: &'a str) -> Recording<'a> {
Rec... | true |
499da0ae5a9bc784b69e9bed5fe78edb9422353f | Rust | chip2n/dragonroll | /src/dice/eval.rs | UTF-8 | 6,451 | 3.265625 | 3 | [] | no_license | use super::tokenizer::{tokenize, Token};
use rand::Rng;
trait DiceRoller {
fn roll(&mut self, sides: u32) -> u32;
}
impl<R: Rng> DiceRoller for R {
fn roll(&mut self, sides: u32) -> u32 {
self.gen_range(0, sides) + 1
}
}
#[derive(Debug)]
struct EvalError {
msg: String,
}
impl EvalError {
... | true |
2ed6931a8af837409139d7d594f7dd8ea2d0323a | Rust | prangel-git/tictactoe | /src/agentid.rs | UTF-8 | 345 | 3.1875 | 3 | [] | no_license | use std::fmt::{Display, Formatter, Result};
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
pub enum AgentId {
X,
O,
}
impl Display for AgentId {
fn fmt(&self, f: &mut Formatter) -> Result {
match self {
AgentId::X => write!(f, "Player X"),
AgentId::O => write!(f, "Playe... | true |
1d0bfa3ba16cdfe6a83d373e15698b6c623e0708 | Rust | btabram/AdventOfCode2018 | /18/src/main.rs | UTF-8 | 6,057 | 3.375 | 3 | [] | no_license | use std::fs;
type ErrorHolder = Box<std::error::Error>;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum TileType {
Open,
Wooded,
LumberYard,
}
use self::TileType::*;
#[derive(Debug, Clone, PartialEq)]
struct Grid {
vec: Vec<TileType>,
width: usize,
height: usize,
}
impl Grid {
fn get_m... | true |
906e658c5a9edfff52a55aef2ff70b3d31b1c849 | Rust | aqrun/rustbyexample | /src/guess_number/guess_number_mod.rs | UTF-8 | 626 | 3.375 | 3 | [] | no_license | use std::io;
use std::str::FromStr;
use rand::{thread_rng, Rng};
pub fn get_input() -> i32 {
println!("Input a number: ");
let mut line = String::new();
let mut num: i32 = 0;
io::stdin().read_line(&mut line).expect("invalid input");
line = line.trim().to_string();
match i32::from_str(line.as_... | true |
df619b3c742a2cc26d155b433ad557c5f26208f4 | Rust | duanjp8617/async | /rust/rcbytes/src/stdtest/slice_test.rs | UTF-8 | 10,799 | 3.65625 | 4 | [] | no_license | use std::mem;
fn print_slice(slice : &[i32]) {
for i in slice{
println!("{}", i);
}
}
fn move_in_array(mut arr : [i32; 8]) {
for i in &mut arr {
*i = *i + 1;
println!("{} ", i);
}
}
pub fn slice_size_len() {
println!("{}", mem::size_of::<&[i32]>());
// println!("{}", m... | true |
c14c90f7656f7114495f2320a377ddc28582065f | Rust | cmyr/amanga-rs | /src/edit_dist.rs | UTF-8 | 2,684 | 3.546875 | 4 | [] | no_license | #[derive(Debug, Clone, Default)]
pub struct EditDistance {
storage: Vec<usize>,
}
impl EditDistance {
// substantially based on https://github.com/febeling/edit-distance,
// but with fewer allocations
pub fn distance<A, B>(&mut self, a: A, b: B) -> usize
where A: AsRef<str>,
B: As... | true |
a4761a3c0ee4ae819ebb020d72e58a470b9e5241 | Rust | lbrande/red-black-tree | /src/lib.rs | UTF-8 | 16,953 | 3.234375 | 3 | [] | no_license | use crate::LinkColor::*;
use std::cmp::Ordering::*;
use std::mem;
use std::ptr::*;
type Link<T> = Option<Box<Node<T>>>;
type UnsafeLink<T> = *mut Node<T>;
#[derive(Copy, Clone, Debug, PartialEq)]
enum LinkColor {
Red,
Black,
}
#[derive(Debug, Default)]
pub struct TreeSet<T: Ord> {
root: Link<T>,
}
impl<... | true |
2b943c3465fdced81dbe444861baf379a16ba421 | Rust | dputhier/pwm_phylo | /src/pwmlib/pwm.rs | UTF-8 | 1,390 | 2.75 | 3 | [] | no_license | extern crate regex;
use std::collections::HashMap;
use std::fs::File;
use std::io::BufRead;
use std::io::BufReader;
use regex::Regex;
pub fn read_pwm_as_tab(input_file: &str,
pwm_to_score: &mut HashMap<(char, i32), f64>) -> i32 {
// pwm size
let mut pwm_size = 0;
// open the fil... | true |
0b90f3cf349992829a700edbfa5c0861f6f30fb7 | Rust | prince-pascoe/easigrow | /src/dadn.rs | UTF-8 | 26,202 | 2.6875 | 3 | [
"MIT"
] | permissive | //! Collection of da/dn equations for calculating crack growth.
//!
//! So far these subroutines are history independant and only depend
//! on $\Delta K$ and $R$.
use table;
use std::f64::consts::FRAC_PI_2;
use std::{fmt, process, f64};
use log::{info, warn, error};
/// Defines the state of the crack for any dadn eq... | true |
9dee92946336834049d8a7557093a5e0fc468076 | Rust | copterust/asm-delay | /src/lib.rs | UTF-8 | 1,778 | 3.203125 | 3 | [
"MIT"
] | permissive | //! no_std implementation of DelayMs and DelayUs for cortex-m
#![deny(missing_docs)]
#![no_std]
pub use bitrate;
use bitrate::*;
use cortex_m::asm::delay;
use embedded_hal::blocking::delay::DelayMs;
use embedded_hal::blocking::delay::DelayUs;
/// asm::delay based Timer
pub struct AsmDelay {
freq_base_ms: u32,
... | true |
11ae33c32199dd1069217fccaa15df3d955fd28e | Rust | AxelMontini/game-of-life | /src/term.rs | UTF-8 | 1,410 | 3.125 | 3 | [] | no_license | fn run() -> Result<(), Box<dyn Error>> {
let mut board = Board::<128, 64>::new();
for _i in 0..1000 {
print_board(&board);
next_step(&mut board);
std::thread::sleep(Duration::from_millis(250));
}
Ok(())
}
fn print_board<const W: usize, const H: usize>(board: &Board<W, H>) {
... | true |
0175d0c899ba404d371732081f7a979bb650e439 | Rust | Pear0/Alphametic | /src/permutation.rs | UTF-8 | 1,304 | 3.40625 | 3 | [] | no_license |
pub struct Permutation {
elements: Vec<usize>,
swappings: Vec<usize>,
valid: bool
}
impl Permutation {
pub fn new(elements: &Vec<usize>, num: usize) -> Permutation {
Permutation {
elements: elements.clone(),
swappings: (0..num).collect::<Vec<_>>(),
valid: t... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.