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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
c9f80026729765ea09b34701749c55aa9e3e1552 | Rust | bk138/groovemaster5000 | /src/note_sheet.rs | UTF-8 | 7,294 | 2.84375 | 3 | [] | no_license | use std::{
fs,
io::{BufRead, BufReader, Error},
};
use ghakuf::messages::*;
use ghakuf::reader::*;
use std::path;
use crate::sound;
#[derive(Debug)]
pub struct Note {
pub on_time: f64,
pub on_sample: u64,
pub length_time: f64,
pub length_sample: u32,
pub note: i32,
pub freq: f64,
... | true |
5e854c94f1b4e88e690cbe06d74d2295be51fb2f | Rust | ynaka81/in_memory_db_comparison | /rust/src/main.rs | UTF-8 | 2,068 | 2.75 | 3 | [] | no_license | use clap::{arg_enum, value_t, App, Arg};
use std::net::SocketAddr;
use tokio::runtime;
use tonic::transport::Server;
use rust_server::{
db::db_server::{Db, DbServer},
AsyncStdDb, DbDesc, StdDb, TokioDb,
};
arg_enum! {
#[derive(PartialEq, Debug)]
pub enum DbImpl {
AsyncStd,
Std,
... | true |
ee8e36d281c8df8073ebfe85c06ac0f7e627c672 | Rust | buratina/Mastering-Rust-Build-Robust-Concurrent-and-Fast-Applications | /Section 1/Video 1.5/tut3.rs | UTF-8 | 106 | 2.625 | 3 | [
"MIT"
] | permissive | fn main(){
let k = String::from("Hi");
let b = String::from("!");
let z = k + &b;
println!("{}", z);
} | true |
40f0c93b88b69cdebe6a09de1282612f1361db38 | Rust | optimalstrategy/ppga | /ppga/src/lib/frontend/parser.rs | UTF-8 | 43,575 | 2.84375 | 3 | [] | no_license | //! Implements the PPGA parser using the recursive descent algorithm and an EBNF-like grammar .
use logos::Lexer as RawLexer;
use super::{super::errors::*, ast::*, lexer::*};
use crate::{
codegen::snippets::{DEFAULT_OP_NAME, ERR_CALLBACK_NAME, ERR_HANDLER_NAME},
PPGAConfig,
};
/// The lexer type expected by t... | true |
61eed1bae802d0d38d0ad6436c947bd3aa30beea | Rust | ToferC/pendragon-rust | /src/background.rs | UTF-8 | 925 | 3.015625 | 3 | [] | no_license | use serde::{Serialize, Deserialize};
#[derive(Debug)]
pub enum Homeland {
Salisbury,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Culture {
name: String,
modifier: String,
value: u32,
}
impl Default for Culture {
fn default() -> Culture {
Culture {
name: String::from(... | true |
625207a21766bc98dc369534866f50f21536a590 | Rust | ovh/rust-serde_gelf | /src/record.rs | UTF-8 | 12,147 | 2.71875 | 3 | [
"BSD-3-Clause"
] | permissive | // Copyright 2019-present, OVH SAS
// All rights reserved.
//
// This OVH Software is licensed to you under the MIT license <LICENSE-MIT
// https://opensource.org/licenses/MIT> or the Modified BSD license <LICENSE-BSD
// https://opensource.org/licenses/BSD-3-Clause>, at your option. This file may not be copied,
// modi... | true |
ca27bd67381ea3cf42fb4e9bc1ed4d9b28379e58 | Rust | 8BitMate/reflect | /src/global_data.rs | UTF-8 | 2,528 | 2.65625 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use crate::{Invoke, Lifetime, MacroInvoke, Push, TypeParam, TypedIndex, ValueNode};
use std::cell::{Cell, RefCell};
use std::thread::LocalKey;
thread_local! {
pub(crate) static VALUES: RefCell<Vec<ValueNode>> = RefCell::new(Vec::new());
pub(crate) static INVOKES: RefCell<Vec<Invoke>> = RefCell::new(Vec::new())... | true |
50313b7ab2c054cce9738f3b81cd59b2bf1a1ae5 | Rust | 18616378431/myCode | /rust/test4-2/src/main.rs | UTF-8 | 211 | 2.828125 | 3 | [] | no_license | //结构体对齐
//Rust中编译期会对结构体进行重排,以减少空间浪费
//b,c,a
struct A {
a : u8,
b : u32,
c : u16,
}
fn main() {
println!("{:?}", std::mem::size_of::<A>());//8
}
| true |
f4860eafc2a4e4631b7f64b19df00321db316532 | Rust | varesa/adventofcode-2020 | /day2a/src/main.rs | UTF-8 | 1,037 | 3.1875 | 3 | [] | no_license |
#[macro_use]
extern crate lazy_static;
use std::env;
use std::fs;
use regex::Regex;
fn get_password(s: &str) -> Option<String> {
lazy_static! {
static ref RE: Regex = Regex::new(r"^(.*)-(.*) (.): (.*)$").unwrap();
}
if let Some(captures) = RE.captures(s) {
//dbg!(&captures);
le... | true |
8e27d85054e56f11ac868a663ba867f2aef321bf | Rust | kldtz/graph-editor-app | /src/node/routes.rs | UTF-8 | 1,136 | 2.625 | 3 | [] | no_license | use crate::api_error::GraphError;
use crate::node::{Node, NodeInit, NodePatch};
use actix_web::{delete, get, post, web, HttpResponse};
use serde_json::json;
#[get("/nodes/{id}")]
async fn find(id: web::Path<i32>) -> Result<HttpResponse, GraphError> {
let node = Node::find(id.into_inner())?;
Ok(HttpResponse::Ok... | true |
3bd45861eac5a190668d4747654de45a8d5f147d | Rust | regonn/AOJ | /ALDS1/1/B.rs | UTF-8 | 752 | 3.3125 | 3 | [] | no_license | use std::io::*;
use std::str::FromStr;
fn read<T: FromStr>() -> T {
let stdin = stdin();
let stdin = stdin.lock();
let token: String = stdin
.bytes()
.map(|c| c.expect("failed to read char") as char)
.skip_while(|c| c.is_whitespace())
.take_while(|c| !c.is_whitespace())
... | true |
98740d16b2d64fd8608634a53c0245777e5d2b96 | Rust | kdrakon/topiks-kafka-client | /src/kafka_protocol/protocol_responses/listoffsets_response.rs | UTF-8 | 1,720 | 2.578125 | 3 | [
"MIT"
] | permissive | use crate::kafka_protocol::protocol_serializable::*;
/// Version 2
#[derive(Debug)]
pub struct ListOffsetsResponse {
pub throttle_time_ms: i32,
pub responses: Vec<Response>,
}
#[derive(Debug)]
pub struct Response {
pub topic: String,
pub partition_responses: Vec<PartitionResponse>,
}
#[derive(Debug, ... | true |
cefd227abd9484f0bd4deed7a4ba622338b553d5 | Rust | rhubarbwu/cellrs | /src/widget/blink/mod.rs | UTF-8 | 1,404 | 3.234375 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | extern crate battery;
use battery::{Battery, State};
use std::i16;
pub struct BlinkState {
val: u16,
max: u16,
custom: u16,
reset: bool,
}
impl BlinkState {
/// Internal constructor with default values.
pub fn new() -> BlinkState {
BlinkState {
val: 0,
max: 1,
... | true |
d9d7ab4e13aa16adf00c5d096759f4fa960085c1 | Rust | AndrewMendezLacambra/rust-programming-contest-solutions | /atcoder/bitflyer2018_qual_d.rs | UTF-8 | 5,263 | 3.1875 | 3 | [] | no_license | use std::cmp;
fn main() {
let mut sc = Scanner::new();
let h: usize = sc.read();
let w: usize = sc.read();
let n: usize = sc.read();
let m: usize = sc.read();
let is_black: Vec<Vec<usize>> = (0..n)
.map(|_| {
sc.read::<String>()
.chars()
.map(... | true |
0fc8444ad26b74d77508637608225f23d313d174 | Rust | Luro02/source-span | /examples/highlights.rs | UTF-8 | 3,228 | 3.125 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use source_span::{
fmt::{Color, Formatter, Style},
Position, Span,
};
use std::fs::File;
use std::io::Read;
use utf8_decode::UnsafeDecoder;
#[derive(Clone, Default)]
pub struct Token {
string: String,
span: Span,
}
#[derive(PartialEq)]
pub enum Kind {
Space,
Separator,
Alphabetic,
Nume... | true |
8ba9be0a716cccd135648b716d1cb2b85b4a6816 | Rust | NilSet/fc-primes | /src/main.rs | UTF-8 | 3,049 | 3.59375 | 4 | [] | no_license | use std::iter::Iterator;
use std::ops::Range;
struct Sieve {
base: usize,
is_prime: Vec<bool>,
}
impl Sieve {
pub fn new(range: Range<usize>) -> Sieve {
//println!("sieve from {} to {}", range.start, range.end);
Sieve {
base: range.start,
is_prime: vec![true; range.en... | true |
7ad9309dc7b5b7a873e6db7074a5521b5bf4d6d9 | Rust | nikolads/tree-sitter-hl | /src/bindings.rs | UTF-8 | 1,559 | 2.796875 | 3 | [
"MIT"
] | permissive | use std::iter;
use neon::prelude::*;
use neon::result::Throw;
use crate::Highlighter;
impl Finalize for Highlighter {}
fn constructor(mut cx: FunctionContext) -> JsResult<JsBox<Highlighter>> {
Ok(cx.boxed(Highlighter::new()))
}
fn highlight(mut cx: FunctionContext) -> JsResult<JsString> {
let this = cx.arg... | true |
7286ee83b1c221a14b4e791deb8cc81379316665 | Rust | NLnetLabs/bcder | /src/string/octet.rs | UTF-8 | 31,113 | 3.4375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"BSD-3-Clause"
] | permissive | //! A BER-encoded OCTET STRING.
//!
//! This is an internal module. It’s public types are re-exported by the
//! parent.
//!
//! XXX This currently panics when trying to encode an octet string in
//! CER mode. An implementation of that is TODO.
use std::{cmp, hash, io, mem};
use std::convert::Infallible;
use bytes... | true |
273dba5b28ad9f13920348667c0f43b6f30a22b0 | Rust | JimFawcett/BasicBites | /RustFuncts/src/main.rs | UTF-8 | 1,500 | 3.1875 | 3 | [] | no_license | #![allow(non_snake_case)]
fn pass_val_by_val(mut i:i32) -> i32 {
print!("\n pass_val_by_val");
i += 3;
print!("\n mutated value, i = {:?}", i);
i
}
fn pass_val_by_ref(i:&mut i32) -> i32 {
print!("\n pass_val_by_ref");
*i += 3;
print!("\n mutated value, i = {:?}", i);
*i
}
fn pass_... | true |
f677df0bd2e8c4ef851cb9b667c8e6607585696c | Rust | LucioFranco/CompGeo | /hw2/src/main.rs | UTF-8 | 2,800 | 3.0625 | 3 | [] | no_license | // Sam Windham, Lucio Franco
mod util;
use util::util::{Polygon, is_left};
// returns index of left tangenet to point q
fn left_tangent(n: u64, p: &[(f64, f64)], q: (f64, f64)) -> u64 {
// first point is the left tangent
if is_left(q, p[(n - 1) as usize], p[0]) && !is_left(q, p[0], p[1]) {
0
} else... | true |
0fd37d25f91d69b473f6b80f41376037b54b23d9 | Rust | rbalicki2/scoped_css | /crates/scoped_css/src/lib.rs | UTF-8 | 4,417 | 2.59375 | 3 | [] | no_license | extern crate proc_macro;
mod attribute;
mod class;
mod core;
mod id;
mod modifier;
mod rule;
mod selector;
mod parser_types;
mod types;
mod util;
use proc_macro2::{
Ident,
Span,
TokenStream,
};
use std::{
collections::{
hash_map::DefaultHasher,
HashMap,
},
hash::{
Hash,
Hasher,
},
};
... | true |
90e880664743f0dc6313fe1c41430b62bfe72a41 | Rust | endrin/exercism.io | /rust/run-length-encoding/src/lib.rs | UTF-8 | 976 | 3.15625 | 3 | [] | no_license | pub fn encode(input: &str) -> String {
let order = {
let mut cs = input.chars().collect::<Vec<_>>();
cs.dedup();
cs
};
let mut remaining_input = input;
order
.iter()
.map(|c| match remaining_input.find(|i| i != *c) {
Some(idx) => {
le... | true |
a2c0350db07e3d83d75126a3c423064858b6d5b9 | Rust | Dengjianping/proc-macro-examples | /src/main.rs | UTF-8 | 1,586 | 3.484375 | 3 | [] | no_license | use proc_macro_example::{ my_proc_macro, Show, rust_decorator };
// use crate::{ Show, builtin_decorator }; // crate doesn't work,因为目前过程宏只能作为单独的crate存在
use std::time::{self, Duration, SystemTime};
use std::thread;
// 过程宏不能作为语句放在main里面,只能放在main外面。
// 这样我们生成了一个名为test_proc的函数,可以在main里面调用了。
my_proc_macro!(proc);
// 生成了一... | true |
58603f52782f0de09b88be14d6c63a689f58b508 | Rust | DalavanCloud/kythe | /kythe/rust/indexer/testdata/variants/struct_tuple.rs | UTF-8 | 207 | 2.5625 | 3 | [
"Apache-2.0",
"NCSA"
] | permissive | // Checks that the indexer finds and emits nodes for tuple struct initialization.
//- @Foo defines/binding SFoo
//- SFoo.node/kind record
struct Foo(u32);
fn foo() {
//- @Foo ref SFoo
let _ = Foo(1);
}
| true |
49ad6d72c32c18d6c7fc9afbba173007b9d3a095 | Rust | Armiixteryx/conversion_temperatura | /src/main.rs | UTF-8 | 1,216 | 3.953125 | 4 | [] | no_license | use std::io;
fn main() {
loop {
let opcion = menu();
if opcion == 3 {
println!("Adiós.");
break;
}
println!("Introduce la cantidad que deseas convertir: ");
let convertir = leer_entrada();
if opcion == 1 {
let resultado = fahrenheit(convertir);
println!("El re... | true |
b7d4bf995ee9ddeeb73c3abcd31390127685c02f | Rust | AlexApps99/egui | /egui/src/context.rs | UTF-8 | 36,131 | 2.796875 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | // #![warn(missing_docs)]
use std::sync::{
atomic::{AtomicU32, Ordering::SeqCst},
Arc,
};
use crate::{
animation_manager::AnimationManager,
data::output::Output,
frame_state::FrameState,
input_state::*,
layers::GraphicLayers,
mutex::{Mutex, MutexGuard},
*,
};
use epaint::{stats::*,... | true |
a2535daaa651b64073824a71d3ee195b06086c4f | Rust | wenley/AdventOfCode2020 | /src/day09.rs | UTF-8 | 2,769 | 3.078125 | 3 | [] | no_license | extern crate regex;
use std::io;
use std::fs;
use std::io::BufRead;
use std::path::Path;
use std::collections::VecDeque;
fn main() {
let input = parse_input();
let nums = input.rows;
let invalid_num = invalid_number(&nums).unwrap();
println!("Found invalid number {}", invalid_num);
let bad_window... | true |
4f72920f698a9762877828b743f194ef0ef3ae0a | Rust | dkudernatsch/mle-nn-rs | /src/parser.rs | UTF-8 | 2,052 | 2.703125 | 3 | [
"MIT"
] | permissive | use nom::{be_u32, be_u8, count, do_parse, map, map_res, named, tag, take};
use std::convert::TryFrom;
use crate::nn::DynMatrix;
named!(mnist_label_magic_num, tag!([0x00, 0x00, 0x08, 0x01]));
named!(
pub mnist_label_parser<Vec<DynMatrix>>,
do_parse!(
mnist_label_magic_num
>> length: be_u32... | true |
af4ba2f5025782bb0401fcdecb6da29988625103 | Rust | grogers0/advent_of_code | /2022/day21/src/main.rs | UTF-8 | 5,124 | 3.171875 | 3 | [
"MIT"
] | permissive | use std::collections::HashMap;
use std::io::{self, Read};
enum Op {
Add, Sub, Mul, Div
}
enum Yell {
Num(i64),
Math(String, String, Op),
}
// Our solutions to both parts rely on the structure of the input being such that any monkey is
// referenced by at most one other monkey. This means we don't have to... | true |
0f550bd3dbe1f36e7ddfd8e5b03114123fdb35ad | Rust | aohan237/http_router | /src/http_router/url_match.rs | UTF-8 | 951 | 2.84375 | 3 | [
"MIT"
] | permissive | extern crate regex;
pub struct UrlMatcher {
urls: Vec<&'static str>,
match_set: regex::RegexSet,
}
impl UrlMatcher {
pub fn new() -> UrlMatcher {
UrlMatcher {
urls: Vec::new(),
match_set: regex::RegexSet::new(&[""]).unwrap(),
}
}
pub fn add_url(&mut self, url... | true |
79953a2f33c6e89fc8cf99aa8426725595ddd193 | Rust | flip1995/comprakt | /compiler-cli/tests/integration.rs | UTF-8 | 6,230 | 2.8125 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | //! Checks for regresssions in the CLI interface code
//!
//! To skip unit tests, and only run integration tests, execute:
//!
//! ```sh
//! cargo test --test integration
//! ```
//!
//! By default, the main binary is used. But you can specify another
//! binary by setting the `COMPILER_BINARY` environment flag. For
//... | true |
6028e7b259f4a5a2622bb87b275bf8a603b11d68 | Rust | Julian-Wollersberger/mandelbrot-gpu-glium | /src/complex_plane.rs | UTF-8 | 3,230 | 3.5 | 4 | [] | no_license | use glium::uniforms::{UniformValue, AsUniformValue};
/// Representation of the coordinate space of the mandelbrot set.
/// Has upper and lower real and imaginary boundaries.
#[derive(Clone, Debug)]
pub struct ComplexPlane {
min_re: f32,
min_im: f32,
max_re: f32,
max_im: f32,
// image size in pixel
... | true |
c8f72d9565526efb94d143f3483e5d0695546d0c | Rust | Steelbirdy/poise | /macros/src/command/prefix.rs | UTF-8 | 4,334 | 2.53125 | 3 | [
"MIT"
] | permissive | use syn::spanned::Spanned as _;
use super::{wrap_option, Invocation};
pub fn generate_prefix_command_spec(
inv: &Invocation,
) -> Result<proc_macro2::TokenStream, darling::Error> {
let description = wrap_option(inv.description);
let explanation = match &inv.more.explanation_fn {
Some(explanation_f... | true |
c84fc08d8bec491139a6562111ab51ce328a10a0 | Rust | dennybritz/rust-analyzer-issue3667 | /src/main.rs | UTF-8 | 153 | 2.78125 | 3 | [] | no_license | use mylib;
fn main() {
println!("Hello ");
let thing = mylib::Thing {
obj: String::from("world!"),
};
thing.do_the_thing();
}
| true |
3efb66d5287f68c1395be4a9a9200e31fef3f751 | Rust | Michael0x2a/impo | /src/lexer/lex_simple.rs | UTF-8 | 7,435 | 3.3125 | 3 | [] | no_license | use super::char_stream::CharStream;
use super::core::is_not_newline;
use crate::tokens::*;
pub fn match_simple_operator(stream: &mut CharStream, c: char) -> Option<TokenKind> {
Some(match c {
'+' => TokenKind::Plus,
'-' => {
if stream.read_if_char('>') {
TokenKind::Arrow... | true |
bd67dac3ac6a7cf9d705c4dd1284ce58e2b7ff83 | Rust | suvash/alpa | /src/core.rs | UTF-8 | 12,147 | 3.015625 | 3 | [] | no_license | use std::collections::HashMap;
use std::fs;
use crate::environment::{self, Env};
use crate::evaluator;
use crate::ntypes::Sankhya;
use crate::parser;
use crate::types::{Boolean, Error, Expr, ExprsOp, Function, NumOp, QExprOp, QExprsOp, Symbol};
pub type CoreFn = fn(&mut Env, &[Box<Expr>]) -> Result<Expr, Error>;
pub... | true |
c9fe3ab766c48384ec6419b52da2d63667a7a8f3 | Rust | alistairbill/bluenrg1 | /src/rtc/cwdlr.rs | UTF-8 | 9,549 | 2.625 | 3 | [] | no_license | #[doc = r" Value read from the register"]
pub struct R {
bits: u32,
}
#[doc = r" Value to write to the register"]
pub struct W {
bits: u32,
}
impl super::CWDLR {
#[doc = r" Modifies the contents of the register"]
#[inline]
pub fn modify<F>(&self, f: F)
where
for<'w> F: FnOnce(&R, &'w mut... | true |
6e6ba31ecf3bc06d6aedd942e955887c397f9426 | Rust | DeLion13/DataBases | /lab2/src/models/entities/category.rs | UTF-8 | 592 | 3 | 3 | [] | no_license | use postgres::Row;
#[derive(Debug)]
pub struct Category {
pub categories_id : i32,
pub category_name : String,
pub table_name : String
}
impl From<Row> for Category {
fn from(row: Row) -> Self {
Self {
categories_id : row.get("categories_id"),
category_name : row.ge... | true |
c7638ec95e95eecdc9597c9d4ccc2b1728d68142 | Rust | cedrickchee/rust-webserver | /src/lib.rs | UTF-8 | 5,014 | 3.8125 | 4 | [] | no_license | use std::sync::mpsc;
use std::sync::{Arc, Mutex};
use std::thread;
/// Modified ThreadPool that hold Worker instances instead of holding threads directly
pub struct ThreadPool {
workers: Vec<Worker>,
sender: mpsc::Sender<Message>,
}
impl ThreadPool {
/// Create a new ThreadPool.
///
/// The size i... | true |
daeab5cf6ccf52efb6d8f3b3d50d3cf541c8f310 | Rust | omerbenamram/evtx | /src/string_cache.rs | UTF-8 | 1,517 | 2.671875 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use crate::binxml::name::{BinXmlName, BinXmlNameLink};
use crate::err::DeserializationResult;
use crate::ChunkOffset;
use log::trace;
use std::borrow::BorrowMut;
use std::collections::HashMap;
use std::io::{Cursor, Seek, SeekFrom};
#[derive(Debug)]
pub struct StringCache(HashMap<ChunkOffset, BinXmlName>);
impl Strin... | true |
7feb6ee3572fb8d54cb290ee7b08ea723d467ffe | Rust | crumblingstatue/soledit | /src/lib.rs | UTF-8 | 11,345 | 2.84375 | 3 | [] | no_license | use byteorder::{ReadBytesExt, WriteBytesExt, BE};
use std::error::Error;
use std::fmt::Display;
use std::io::{self, Read, Seek, SeekFrom, Write};
use std::path::Path;
/// AMF version used by the Sol.
pub trait AmfVer {
/// The id used to identify this AMF version in the Sol.
const ID: u8;
/// Type used to ... | true |
95028750f01b36525daccd2d990bb70311c9b5be | Rust | id4ho/crustopals | /src/crustopals/problem11.rs | UTF-8 | 1,616 | 2.9375 | 3 | [] | no_license | extern crate rand;
use self::rand::Rng;
use crustopals::problem8;
use crustopals::tools::*;
pub fn aes_ecb_cbc_oracle(ciphertext: &[u8]) -> String {
if problem8::has_repeat_blocks(ciphertext) {
"ecb".to_string()
} else {
"cbc".to_string()
}
}
pub fn random_aes_encryption(message: String) -> (String, Ve... | true |
237f9e7c712058df1875a7e3d967c74dd5577f4f | Rust | mozamimy/salmon | /src/paginator.rs | UTF-8 | 1,732 | 3.46875 | 3 | [
"MIT"
] | permissive | #[derive(Debug)]
pub struct Paginator<'a, T> {
container: &'a [T],
curr_page: usize,
per_page: usize,
}
impl<'a, T> Paginator<'a, T> {
pub fn new(container: &'a [T], per_page: usize) -> Self {
Paginator {
container: container,
curr_page: 0,
per_page: per_page... | true |
4cffd5fa52ade3af3133f51385bc122bde70050e | Rust | naodroid/bevy_game_tutorial | /src/tutorial02.rs | UTF-8 | 1,624 | 2.75 | 3 | [] | no_license | use bevy::prelude::*;
use bevy::app::*;
use bevy::utils::Duration;
struct Block;
struct Wall;
struct Position(i32);
//
fn setup(
mut commands: Commands,
) {
commands.spawn()
.insert(Position(1))
.insert(Block);
commands.spawn()
.insert(Position(10))
.insert(Block);
co... | true |
b56a4b04ff2d8dc5767399ec16113a5f1335ff46 | Rust | trentfridey/rust-waves | /crate/src/colors.rs | UTF-8 | 4,103 | 3.15625 | 3 | [
"MIT"
] | permissive | extern crate num;
use num::complex::Complex;
use utils::{ALPHA, to_amp};
use std::f32::consts::PI;
pub trait HexColor {
fn to_rgba(self, norm_only: bool) -> u32;
}
impl HexColor for i32 {
fn to_rgba(self, norm_only: bool) -> u32 {
let mut val: i32 = self >> 22;
if val > 0 {
let r... | true |
a8c8f3f331a6984771620fe309e7b0dcaeed1b04 | Rust | isgasho/laminar | /src/packet/header/heart_beat_header.rs | UTF-8 | 1,505 | 2.8125 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use super::{HeaderReader, HeaderWriter};
use crate::error::Result;
use crate::net::constants::HEART_BEAT_HEADER_SIZE;
use crate::packet::PacketTypeId;
use crate::protocol_version::ProtocolVersion;
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io::Cursor;
#[derive(Copy, Clone, Debug)]
/// This heade... | true |
2a11ace33e52774f132f8f1a5be65db9c968e82d | Rust | aristotle9/qt_generator-output | /qt_core/src/locale.rs | UTF-8 | 214,138 | 2.953125 | 3 | [] | no_license | /// C++ type: <span style='color: green;'>```QLocale::Country```</span>
#[derive(Debug, PartialEq, Eq, Clone)]
#[repr(C)]
pub enum Country {
/// C++ enum variant: <span style='color: green;'>```AnyCountry = 0```</span>
AnyCountry = 0,
/// C++ enum variant: <span style='color: green;'>```Afghanistan = 1```</span>
... | true |
8bf7e34569a49e89d8d5373260b9ddac5f235319 | Rust | GPSnoopy/RayTracingInOneWeekend | /rust/src/lambertian.rs | UTF-8 | 609 | 2.921875 | 3 | [] | no_license | use super::hit_record::HitRecord;
use super::material::*;
use super::random::*;
use super::ray::Ray;
use super::vec3::Vec3;
pub struct Lambertian {
pub albedo: Vec3,
}
impl Lambertian {
pub fn new(albedo: Vec3) -> Lambertian {
Lambertian { albedo }
}
}
impl Material for Lambertian {
fn scatte... | true |
ec339f64750d94a559d1d412b590cd14fd1482ef | Rust | kali/wolframite | /url_aggregator/src/lib.rs | UTF-8 | 1,978 | 3.21875 | 3 | [] | no_license | use std::collections::{ BTreeSet, BTreeMap };
#[allow(dead_code)]
fn lineage(url:&str) -> Vec<String> {
let mut result = vec!();
let splits:Vec<&str> = url.split("/").collect();
let mut prefix = splits[0..1].join("/");
for token in splits[1..].iter() {
prefix.push('/');
prefix.push_str(... | true |
c253d055e1e7800c751c82e34ce97bc46be9a8b8 | Rust | jamesmarva/The-Rust-Programming-Language | /code/ch10/c_10_15_better/src/main.rs | UTF-8 | 618 | 3.4375 | 3 | [] | no_license | fn main() {
let v0 = vec![1, 3, 4, 5123, 11, 3, 4, 66];
println!("larget: {}", largest(&v0))
}
fn largest<T: PartialOrd>(list: &[T]) -> &T {
let mut rst: &T = &list[0];
let len = list.len();
let mut idx = 1;
while idx < len {
if &list[idx] > rst {
rst = &list[idx]
}
... | true |
0eae5624500e2917f55188d05f6ec918581c7511 | Rust | wbrickner/webster-rs | /src/lib.rs | UTF-8 | 2,727 | 3.515625 | 4 | [
"MIT",
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-gutenberg-2020"
] | permissive | //! # webster-rs
//! A Rust library containing an offline version of webster's dictionary.
//!
//! Add to Cargo.toml
//! ```
//! webster = 0.2.1
//! ```
//!
//! Simple example:
//! ```rust
//! fn main() {
//! let word = "silence";
//!
//! let definition = webster::definition(word).unwrap();
//!
//! println!... | true |
432a4ebad9aa29be47657b2adabb06f4ad20fbd6 | Rust | SamGinzburg/COS518 | /src/lib/keys.rs | UTF-8 | 1,492 | 2.78125 | 3 | [] | no_license | use crate::onion;
use std::{fs, io, path::PathBuf};
/// Read and write keys to hard-coded locations
pub enum PartyType {
Client,
Server,
}
pub struct Party {
party_type: PartyType,
id: usize,
}
impl PartyType {
pub fn with_id(self, id: usize) -> Party {
Party {
party_type: s... | true |
ae4a5c54e42324f385de4decac7606f8e122be98 | Rust | gunjunlee/ps | /baekjoon/src/bin/11657.rs | UTF-8 | 1,684 | 2.71875 | 3 | [] | no_license | macro_rules! parse_line { ($($t: ty),+) => ({
let mut line = String::new();
std::io::stdin().read_line(&mut line).unwrap();
let mut iter = line.split_whitespace();
($(iter.next().unwrap().parse::<$t>().unwrap()),+)
})}
fn main() {
let (n, m) = parse_line!(usize, usize);
let mut edges: Vec<Vec<i... | true |
4799eec9207acdfd401375405099eaed5b4be427 | Rust | antunius/blog | /src/article.rs | UTF-8 | 1,375 | 2.5625 | 3 | [] | no_license | use chrono::NaiveDateTime;
use crate::schema::article;
use diesel;
use diesel::prelude::*;
use diesel::mysql::MysqlConnection;
#[table_name = "article"]
#[derive(AsChangeset, Serialize, Deserialize, Queryable, Insertable)]
pub struct Article {
pub id: Option<i32>,
pub title: String,
pub body: String,
p... | true |
d2413833726bf8ce3e4247675dff8d84b81bd106 | Rust | TechGuard/advent_of_code_2018 | /day01/src/main.rs | UTF-8 | 728 | 3.609375 | 4 | [] | no_license | use std::collections::HashSet;
use std::io::{self, Read};
fn main() {
let mut input = String::new();
io::stdin()
.read_to_string(&mut input)
.expect("Expected input");
let numbers: Vec<i32> = input
.lines()
.map(|line| line.parse::<i32>().unwrap())
.collect();
... | true |
97ea521eaf20b65909fa0520c4e8dd191298debb | Rust | robinhundt/rust-workshop | /aufgaben-2/caesar/src/lib.rs | UTF-8 | 1,107 | 3.328125 | 3 | [] | no_license | // === Caesar-Verschlüsselung
fn caesar(text: &str, key: u8, encode: bool) -> String {
todo!()
}
// === Bonus: Vigenere-Verschlüsselung
fn vigenere(text: &str, key: &str, encode: bool) -> String {
todo!()
}
// === Tests
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_caesar() {
... | true |
5e798d54eb43620ba723ebd3249f943180d7c946 | Rust | lazear/adventofcode2017 | /aoc2/src/main.rs | UTF-8 | 2,209 | 3.03125 | 3 | [] | no_license | // Advent of Code 2017 Exercise 2
// Copyright Michael Lazear (C) 2017
//
// For example, given the following spreadsheet:
// 5 1 9 5
// 7 5 3
// 2 4 6 8
// The first row's largest and smallest values are 9 and 1, and their difference is 8.
// The second row's largest and smallest values are 7 and 3, and their differen... | true |
68e886f7b9aab3a53722b1a40752a785992e09a3 | Rust | udoprog/quickcfg | /src/packages.rs | UTF-8 | 4,022 | 2.953125 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | //! Package abstraction.
//!
//! Can check which packages are installed.
mod cargo;
mod debian;
mod fedora;
mod python;
mod ruby;
mod rustup_components;
mod rustup_toolchains;
mod winget;
use crate::facts::{self, Facts};
use anyhow::{bail, Error};
use log::warn;
use std::fmt;
use std::sync::Arc;
/// Information abou... | true |
c5a9dab346f0d88cd6c0a5ec97cb421ed70bd756 | Rust | eira-fransham/generic-array | /src/arr.rs | UTF-8 | 494 | 2.859375 | 3 | [
"MIT"
] | permissive | //! Implementation for `arr!` macro.
/// Macro allowing for easy generation of Generic Arrays.
/// Example: `let test = arr![u32; 1, 2, 3];`
#[macro_export]
macro_rules! arr {
($T:ty; $($rest:tt)*) => {{
let out: $crate::GenericArray<$T, _> = $crate::arr![$($rest)*];
out
}};
($first:expr $(... | true |
850d1af8787985865f00467681f192685a5ba98d | Rust | carlmartus/rscsg | /src/tests/mod.rs | UTF-8 | 1,690 | 2.890625 | 3 | [] | no_license | mod bounding_box;
mod dim2;
mod plane;
use self::bounding_box::BoundBox;
use dim3::{BspNode, Csg, Plane, Polygon, Vector, Vertex};
#[test]
fn types() {
Csg::new();
BspNode::new(Some(vec![]));
Plane::from_points(Vector(0., 0., 0.), Vector(1., 0., 0.), Vector(0., 1., 0.));
Polygon::new(vec![
Ver... | true |
114f0ad83658db1172c2c3d8709a558ad80520c4 | Rust | gnoliyil/fuchsia | /src/lib/intl/unicode_utils/char_collection/src/macros.rs | UTF-8 | 1,648 | 3.21875 | 3 | [
"BSD-2-Clause"
] | permissive | // Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/// Generate a [CharCollection] from a sequence of `char`s,
/// [CharRanges](unic_char_range::CharRange), or Unicode [Blocks](unic_ucd_block::Block).
///
/... | true |
7dab4c27552ab77dcf64ec2cae372b60dc2cd379 | Rust | alistairbill/bluenrg1 | /src/uart/fbrd.rs | UTF-8 | 3,613 | 2.90625 | 3 | [] | no_license | #[doc = r" Value read from the register"]
pub struct R {
bits: u8,
}
#[doc = r" Value to write to the register"]
pub struct W {
bits: u8,
}
impl super::FBRD {
#[doc = r" Modifies the contents of the register"]
#[inline]
pub fn modify<F>(&self, f: F)
where
for<'w> F: FnOnce(&R, &'w mut W)... | true |
1ae5d9fef9d75f19a5ffb934c893fd69e32f6d5f | Rust | imos/icfpc2021 | /src/tree_decomposition.rs | UTF-8 | 1,285 | 2.921875 | 3 | [
"MIT"
] | permissive | use std::io::BufRead;
#[derive(Debug)]
pub struct TreeDecomposition {
pub bag_vs: Vec<Vec<usize>>,
pub es: Vec<(usize, usize)>,
}
pub fn read_tree_decomposition(path: impl AsRef<std::path::Path>) -> TreeDecomposition {
let file = std::fs::File::open(path).unwrap();
let reader = std::io::BufReader::ne... | true |
3365e9616dd3b06bbd32e0cb18eafd947b314657 | Rust | raphaelrobert/hpke-rs | /src/aead_impl.rs | UTF-8 | 2,543 | 2.515625 | 3 | [] | no_license | use evercrypt::prelude::*;
use crate::aead::{AeadTrait, Error};
macro_rules! implement_aead {
($name:ident, $algorithm:expr, $key_length:literal) => {
#[derive(Debug)]
pub(crate) struct $name {}
impl AeadTrait for $name {
fn new() -> Self {
Self {}
... | true |
bc64bd8d71ce7cc1c09c993201497a637b1b73ed | Rust | potapovDim/classes | /basics/src/main.rs | UTF-8 | 658 | 3.515625 | 4 | [] | no_license | fn _is_divisible_by(or_num: i32, divisible: i32) -> bool {
if or_num == 0 {
return false;
}
or_num % divisible == 0
}
fn _fizzbuzz_question(num_fb: i32) {
for num in 1..num_fb + 1 {
let (by_three, by_five) = (_is_divisible_by(num, 3), _is_divisible_by(num, 5));
if by_five && by_three {
printl... | true |
ba216d53d81c679711e10b36cd2bc1bf00572eee | Rust | ethanabrooks/autograder | /autograder/src/cargo_test_output.rs | UTF-8 | 3,923 | 2.65625 | 3 | [] | no_license | use crate::error::ReadError;
use crate::report::TestReport;
use crate::score_map::ScoreMap;
use crate::Result;
use either::{Either, Left, Right};
use serde::{Deserialize, Serialize};
use snafu::ResultExt;
use std::cmp::Ordering;
use std::fs;
use std::path::Path;
//{ "type":"suite", "event": "started", "test_count": 5 }... | true |
8d76764c314959cd4a67036b5e2fdc437e555326 | Rust | kornelski/dupe-krill | /src/scanner.rs | UTF-8 | 14,337 | 2.59375 | 3 | [] | no_license | use crate::file::{FileContent, FileSet};
use crate::metadata::Metadata;
use std::cell::RefCell;
use std::cmp;
use std::collections::btree_map::Entry as BTreeEntry;
use std::collections::hash_map::Entry as HashEntry;
use std::collections::BTreeMap;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std... | true |
28017f7519840116d8876c8ed0bcea2d5d76d46e | Rust | AbdulRhmanAlfaifi/CryptnetURLCacheParser-rs | /src/utils.rs | UTF-8 | 627 | 2.625 | 3 | [
"MIT"
] | permissive | use data_encoding::HEXUPPER;
use ring::digest::{Context, SHA256};
use std::{fs::File, io, io::BufReader, io::Read};
/// Calculates the `SHA256` hash for a file and return it as `String` in hex format.
pub fn sha256(filepath: &str) -> io::Result<String> {
let file = File::open(filepath)?;
let mut reader = BufRe... | true |
ff56575a83ac0d1646d57625cc49b73a3ac96210 | Rust | nushell/nushell | /crates/nu-protocol/tests/test_config.rs | UTF-8 | 2,921 | 2.71875 | 3 | [
"MIT"
] | permissive | use nu_test_support::{nu, nu_repl_code};
#[test]
fn filesize_metric_true() {
let code = &[
r#"$env.config = { filesize: { metric: true, format:"mb" } }"#,
r#"20mib | into string"#,
];
let actual = nu!(nu_repl_code(code));
assert_eq!(actual.out, "21.0 MB");
}
#[test]
fn filesize_metric_... | true |
1d54a0b775a4f9c0a5cfdcbdc2085bbe5fefe7b1 | Rust | ityy/rust_study | /src/book_study_notes/book01_the_tao_of_programming/src/c11_concurrence/t11_2_5_atomic.rs | UTF-8 | 6,292 | 3.375 | 3 | [] | no_license | //! # 原子类型 (atomic)
//! 由于锁会影响性能,且有死锁的风险,因此引入了原子类型。
//! 原子类型是编程语言和操作系统的“契约”,基于此契约实现的自带原子操作的类型。原子操作指绝对完整不可打断的操作。
//! 使用原子类型可以实现无锁并发。锁相当于白盒操作,原子类型就是黑盒操作。原子类型有多种操作和需要给定内存顺序参数。
//!
//! Rust已实现的原子类型:
//! - Structs
//! - AtomicBool A boolean type which can be safely shared between threads.
//! - AtomicI8 An integer typ... | true |
6e45a4d7df2a40b910a8bf6496bfd6452be8f217 | Rust | ckampfe/stlite | /src/lib.rs | UTF-8 | 1,988 | 2.53125 | 3 | [
"BSD-3-Clause"
] | permissive | use rusqlite::{params, NO_PARAMS};
pub fn create_stl_db(
conn: &mut rusqlite::Connection,
index_stl: &nom_stl::IndexMesh,
) -> rusqlite::Result<()> {
let triangles = index_stl.triangles();
let vertices = index_stl.vertices();
conn.execute(
"CREATE TABLE IF NOT EXISTS vertices (
id ... | true |
d585fce19a8cc58af9248572f7d7f110e45e2026 | Rust | ysk24ok/leetcode-submissions | /0441/binary_search.rs | UTF-8 | 707 | 3.21875 | 3 | [] | no_license | struct Solution;
impl Solution {
pub fn arrange_coins(n: i32) -> i32 {
let (mut ok, mut ng): (i64, i64) = (0, n as i64 + 1);
while ok + 1 < ng {
let mid = (ng - ok) / 2 + ok;
let total = (1 + mid) * mid / 2;
if total <= n as i64 {
ok = mid;
... | true |
4a288c5d9c7659f0e7a79f58f0ba5176ed30d3e3 | Rust | nwn/Advent-of-Code-2018 | /src/04b.rs | UTF-8 | 1,924 | 3.078125 | 3 | [] | no_license | extern crate regex;
use std::io::{self, prelude::*};
use std::collections::HashMap;
fn main() {
let stdin = io::stdin();
let lines = stdin.lock().lines().map(Result::unwrap);
let mut lines: Vec<_> = lines.collect();
lines.sort();
let regex_number = regex::Regex::new(r"(\d+)").unwrap();
let re... | true |
f1a92066b6d74e1f569b175a8c1882f470f86a76 | Rust | djc/askama | /testing/tests/inheritance.rs | UTF-8 | 5,551 | 2.625 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use std::ops::Deref;
use askama::Template;
#[derive(Template)]
#[template(path = "base.html")]
struct BaseTemplate<'a> {
title: &'a str,
}
#[derive(Template)]
#[template(path = "child.html")]
struct ChildTemplate<'a> {
_parent: &'a BaseTemplate<'a>,
}
impl<'a> Deref for ChildTemplate<'a> {
type Target =... | true |
b796aa45f7c7128edec429bcea8a626d4e40dc88 | Rust | diwic/inner-rs | /src/lib.rs | UTF-8 | 10,019 | 4.4375 | 4 | [
"Apache-2.0"
] | permissive | //! The `inner!` macro makes descending into an enum variant
//! more ergonomic.
//!
//! The `some!` and `ok!` macros turn your enum into an `Option` and `Result`, respectively.
//!
//! # Helpful unwrap
//! The simplest case for `inner!` is almost like unwrap:
//!
//! ```
//! # #[macro_use] extern crate inner;
//! # fn... | true |
0e667de2ac27596d51176ebb9fd320b1e65531a4 | Rust | tmokenc/tomoka-rs | /src/commands/pokemon/nature.rs | UTF-8 | 3,735 | 3.21875 | 3 | [
"MIT"
] | permissive | use crate::commands::prelude::*;
use crate::traits::ChannelExt;
use pokemon_core::{Flavor, Nature, Stat};
use std::fmt::Write;
use std::str::FromStr;
#[derive(Default, Debug)]
pub struct Filter {
natures: Vec<Nature>,
data: Vec<FilterData>,
}
#[derive(Debug)]
pub enum FilterData {
Increase(Stat),
Decr... | true |
5f075a2fc85444e8bc7fbe4e6010bfd05825385d | Rust | raiker/only-connect-trivia | /src/questions.rs | UTF-8 | 6,320 | 2.75 | 3 | [] | no_license | use std::fs::File;
use std::io::prelude::*;
use std::{io::BufReader, path::Path};
use lazy_static::lazy_static;
use rand::prelude::*;
use regex::Regex;
use sdl2::image::LoadSurface;
use sdl2::surface::Surface;
lazy_static! {
static ref PICTURE_CLUE_REGEX: Regex = Regex::new(r"^ picture: (\S+) (\S.+)$").unw... | true |
77f9864618028cfbd1bde4fbfdf545b83114d8cf | Rust | mitermayer/augmented-audio | /crates/augmented/gui/webview-transport/src/websockets/mod.rs | UTF-8 | 5,185 | 2.53125 | 3 | [
"MIT"
] | permissive | use std::error::Error;
use std::fmt::Debug;
use std::sync::Arc;
use async_trait::async_trait;
use serde::de::DeserializeOwned;
use serde::Serialize;
use tokio::sync::broadcast::{Receiver, Sender};
use tokio::sync::Mutex;
pub use tokio_websockets::create_transport_runtime;
use tokio_websockets::run_websockets_transpor... | true |
d35f3e07ff910f6307c83325f0de4eabaca0a9ef | Rust | geo-engine/geoengine | /operators/src/engine/query.rs | UTF-8 | 6,276 | 2.53125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | use std::{
any::{Any, TypeId},
collections::HashMap,
task::{Context, Poll},
{pin::Pin, sync::Arc},
};
use crate::util::Result;
use crate::{error, util::create_rayon_thread_pool};
use futures::Stream;
use geoengine_datatypes::util::test::TestDefault;
use pin_project::pin_project;
use rayon::ThreadPool;
... | true |
680ef2a45c79a8400677d5b1325a2ca49077cff4 | Rust | GuillaumeGomez/process-viewer | /src/utils.rs | UTF-8 | 3,847 | 2.984375 | 3 | [
"MIT"
] | permissive | use gtk::gio;
use gtk::prelude::*;
use std::ops::Index;
pub const MAIN_WINDOW_NAME: &str = "main-window";
#[derive(Debug)]
pub struct RotateVec<T> {
data: Vec<T>,
start: usize,
}
impl<T> RotateVec<T> {
pub fn new(d: Vec<T>) -> RotateVec<T> {
RotateVec { data: d, start: 0 }
}
pub fn len(... | true |
244b7790de1b7d47bb539675be9cf541968d0f48 | Rust | chibby0ne/exercism | /rust/magazine-cutout/src/lib.rs | UTF-8 | 554 | 2.859375 | 3 | [
"MIT"
] | permissive | // This stub file contains items that aren't used yet; feel free to remove this module attribute
// to enable stricter warnings.
#![allow(unused)]
use std::collections::HashMap;
pub fn can_construct_note(magazine: &[&str], note: &[&str]) -> bool {
let mut map = magazine.iter().fold(HashMap::new(), |mut m, word| {... | true |
d17bb42a9b25b7882aa6d9fbee16661728111e31 | Rust | RamAddict/INE5426 | /src/token_type.rs | UTF-8 | 651 | 2.765625 | 3 | [] | no_license | use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub enum TokenType {
KwDef,
KwBreak,
KwNew,
KwFor,
KwIf,
KwElse,
KwPrint,
KwRead,
KwReturn,
KwParenOpen,
KwParenClose,
KwBracketOpen,
KwBracketClo... | true |
c31120299c978efcdf2cc995c04ed88890c72319 | Rust | pbajsarowicz/url_shortener__rust | /src/main.rs | UTF-8 | 4,404 | 2.546875 | 3 | [] | no_license | #![feature(proc_macro_hygiene, decl_macro)]
#[macro_use] extern crate rocket;
#[macro_use] extern crate diesel;
#[macro_use] extern crate diesel_migrations;
#[macro_use] extern crate log;
#[macro_use] extern crate serde_derive;
#[macro_use] extern crate rocket_contrib;
extern crate rand;
use rocket::Rocket;
use rocke... | true |
b42c5d89622a6b7843a1c2210e6b4037c1f36cec | Rust | rust-num/num-traits | /src/ops/wrapping.rs | UTF-8 | 11,260 | 3.078125 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use core::num::Wrapping;
use core::ops::{Add, Mul, Neg, Shl, Shr, Sub};
macro_rules! wrapping_impl {
($trait_name:ident, $method:ident, $t:ty) => {
impl $trait_name for $t {
#[inline]
fn $method(&self, v: &Self) -> Self {
<$t>::$method(*self, *v)
}
... | true |
d3d256afd203c44120f20e6eefd33cf3eaacbad3 | Rust | rednithin/LeetCode | /Normal/Add Two Numbers.rs | UTF-8 | 1,044 | 3.203125 | 3 | [] | no_license | // Definition for singly-linked list.
// #[derive(PartialEq, Eq, Clone, Debug)]
// pub struct ListNode {
// pub val: i32,
// pub next: Option<Box<ListNode>>
// }
//
// impl ListNode {
// #[inline]
// fn new(val: i32) -> Self {
// ListNode {
// next: None,
// val
// }
// }
// }
impl Solutio... | true |
b6556ba59e0114143bee426f369ac0644b486ec5 | Rust | liqcomb/os | /src/common/bitmap.rs | UTF-8 | 1,960 | 3.71875 | 4 | [] | no_license | use alloc::vec::Vec;
/// Simple bitmap
#[derive(Clone)]
pub struct Bitmap {
length: usize,
storage: Vec<u8>,
}
impl Bitmap {
pub fn new(size: usize) -> Self {
let mut vec: Vec<u8> = Vec::new();
vec.resize((size / 8) + 1, 0);
Self {
length: size,
storage: vec... | true |
b9a9e1485c6912dc9fa5e926efa217636ba35392 | Rust | trivektor/aletheia | /src/db/connection.rs | UTF-8 | 2,510 | 2.59375 | 3 | [
"MIT"
] | permissive | use crate::db::sql_types::ActionType;
use diesel::pg::PgConnection;
use rocket::fairing::AdHoc;
use rocket::fairing::Fairing;
use rocket::logger::error;
use rocket::{http::Status, Outcome};
use rocket_contrib::databases::database_config;
use rocket_contrib::databases::r2d2::{Pool, PooledConnection};
use rocket_contrib:... | true |
9ed389bad3a0470394779950e03e6221c556777c | Rust | jaburns/rustycast | /src/render.rs | UTF-8 | 8,698 | 2.6875 | 3 | [
"MIT"
] | permissive | use sdl2::surface::Surface;
use world::{RayCastResult};
use math::{LineSeg, Vec2, Mat3};
use game::{Game};
use core::ops::Range;
const MAP_SCALE: f32 = 2.0;
const VISPLANE_DIST: f32 = 300.0;
const PERSON_HEIGHT: f32 = 5.0;
struct RenderContext<'a> {
pub pixels: &'a mut [u8],
pub width: isize,
pub height... | true |
09c6ce661cf55dfc6d85e030557a24f181e5e38f | Rust | remram44/dhstore | /src/errors.rs | UTF-8 | 1,672 | 3.40625 | 3 | [] | no_license | //! # Error definitions
//!
//! This module contains the `Error` and `Result` types used throughout the
//! whole software.
use std::fmt::{Display, Formatter};
use std::io;
/// An error from dhstore.
///
/// This represents all the errors that can happen anywhere.
#[derive(Debug)]
pub enum Error {
IoError(&'stati... | true |
87519a464c59e2815bc54218fdaef40fb957405e | Rust | crypto-com/jellyfish-merkle-tree | /secure/key-manager/src/lib.rs | UTF-8 | 9,967 | 2.5625 | 3 | [
"Apache-2.0"
] | permissive | // Copyright (c) The Libra Core Contributors
// SPDX-License-Identifier: Apache-2.0
//! The purpose of KeyManager is to rotate consensus key and eventually the network key. It is not
//! responsible for generating the first key and fails if the stores have not been properly setup.
//! During rotation, it first updates... | true |
296ab4b8269cd2109a8153568b8ff326c367a53a | Rust | musec/clowder | /src/html/tables.rs | UTF-8 | 9,641 | 2.96875 | 3 | [] | no_license | /*
* Copyright 2017-2018 Jonathan Anderson
*
* Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
* http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
* http://opensource.org/licenses/MIT>, at your option. This file may not be
* copied, modified, or distributed except accor... | true |
bb30ee95c2c8cfd42f58175b5256e45a3ca01d1a | Rust | cyber-meow/ReactiveRs | /src/signal/single_thread/mpmc_signal.rs | UTF-8 | 6,622 | 2.8125 | 3 | [
"MIT"
] | permissive | use std::rc::Rc;
use std::cell::RefCell;
use runtime::SingleThreadRuntime;
use continuation::ContinuationSt;
use signal::Signal;
use signal::signal_runtime::{SignalRuntimeRefBase, SignalRuntimeRefSt};
use signal::valued_signal::{ValuedSignal, MpSignal, CanEmit, GetValue};
/// A shared pointer to a signal runtime.
pub... | true |
88e3c43077fc2c0fca10e2f61b1af9a473393e0d | Rust | dmgolembiowski/RustyKitchen | /projects/looping_while/main.rs | UTF-8 | 127 | 3.28125 | 3 | [] | no_license | fn main() {
let a = [1, 2, 3, 4, 5];
for element in a.iter() {
println!("the value is {}", element);
}
}
| true |
c9fa82f80491847403fe6d082aceeddc0d72b1e4 | Rust | mmai/webtarot | /webtarot_protocol/src/deal.rs | UTF-8 | 2,863 | 2.75 | 3 | [] | no_license | use serde::{Deserialize, Serialize};
use tarotgame::{bid, cards, pos, deal, trick, AnnounceType};
/// Describe a single deal.
#[derive(Clone, Serialize, Deserialize)]
pub enum Deal {
/// The deal is still in the auction phase
Bidding(bid::Auction),
/// The deal is in the main playing phase
Playing(dea... | true |
95f965b6126bbf10c1d818416eb713c8a7c28109 | Rust | NotGyro/Gestalt | /gestalt-core/src/net/reliable_udp.rs | UTF-8 | 5,317 | 2.84375 | 3 | [] | no_license | use std::{collections::VecDeque, net::SocketAddr, time::Instant};
use laminar::{Connection, VirtualConnection};
use log::trace;
/// Thin wrapper used to pretend, from the perspective of Laminar,
/// that Noise protocol encryption and async UDP are a transparent synchronous UDP socket.
#[derive(Default)]
pub(in crate:... | true |
34817d2e3ee5b704e406c2ea220f7775780688ec | Rust | oberzs/duku | /examples/3d-examples/rotating_cube.rs | UTF-8 | 1,329 | 3.09375 | 3 | [
"Apache-2.0"
] | permissive | // Oliver Berzs
// https://github.com/oberzs/duku
// This example draws a cube in the center of the window,
// rotating and coloring it based on the time that has passed.
use duku::Camera;
use duku::Duku;
use duku::Hsb;
use duku::Light;
use duku::Result;
use std::time::Instant;
fn main() -> Result<()> {
// creat... | true |
0c2c1e73b4e2a2288105fd7cb52bea9ff75b81d9 | Rust | yurrriq/exercism | /rust/role-playing-game/src/lib.rs | UTF-8 | 978 | 3.328125 | 3 | [] | no_license | use std::cmp::min;
pub struct Player {
pub health: u32,
pub mana: Option<u32>,
pub level: u32,
}
impl Player {
pub fn revive(&self) -> Option<Player> {
match *self {
Player {
health: 0, level, ..
} if level >= 10 => Some(Player {
health: ... | true |
85176da3e724744be5da1ff817ad1d86ae7c221f | Rust | kvakvs/Quokka | /qk_term/src/atom.rs | UTF-8 | 2,377 | 3.296875 | 3 | [] | no_license | use std::collections::{HashMap};
use std::sync::{RwLock};
use std::fmt::Debug;
use std::fmt;
struct AtomIndex {
pub next_index: usize,
pub str_to_index: HashMap<String, usize>,
pub index_to_str: Vec<String>,
}
lazy_static! {
static ref ATOM_INDEX: RwLock<AtomIndex> = RwLock::new(AtomIndex {
next_index... | true |
4eb04fce374c01fd4e65457e09cf4765aeed16ee | Rust | SolidTux/ndarray-linalg | /ndarray-linalg/src/tridiagonal.rs | UTF-8 | 21,408 | 2.90625 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-proprietary-license"
] | permissive | //! Vectors as a Tridiagonal matrix
//! &
//! Methods for tridiagonal matrices
use super::convert::*;
use super::error::*;
use super::layout::*;
use cauchy::Scalar;
use lax::*;
use ndarray::*;
use num_traits::One;
pub use lax::{LUFactorizedTridiagonal, Tridiagonal};
/// An interface for making a Tridiagonal struct.
... | true |
e34caebccdad12937b1bbb2697541181ffdaf67e | Rust | DSRCorporation/milagro-crypto-rust | /src/ff/mod.rs | UTF-8 | 20,867 | 2.71875 | 3 | [] | no_license | #![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
extern crate libc;
use self::libc::{c_int};
use std::fmt;
use std::cmp;
pub mod wrappers;
pub mod overloading;
use big::wrappers::{BIG, MODBYTES};
use randapi::wrappers::{octet};
use ff::wrappers::*;
use randapi::Random;
use... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.