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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
ff4f257df5599348ac350862743f105aa6f1cff7 | Rust | ubq323/big-fungeus | /bigfungeus/src/main.rs | UTF-8 | 2,578 | 2.84375 | 3 | [] | no_license | use std::fs;
use std::io::Read;
#[derive(Debug)]
struct CmdLineArgs {
filename: String,
}
fn get_args() -> Result<CmdLineArgs,String> {
let mut argobj = CmdLineArgs {
filename: "".to_string(),
};
let mut found_filename = false;
let args: Vec<String> = std::env::args().collect();
let... | true |
60c2cf14cd9be03f884d98b41700a7e90525d740 | Rust | ia7ck/competitive-programming | /Codeforces/r739/src/bin/b/main.rs | UTF-8 | 703 | 3.09375 | 3 | [] | no_license | use procon_reader::ProconReader;
fn main() {
let stdin = std::io::stdin();
let mut rd = ProconReader::new(stdin.lock());
let t: usize = rd.get();
for _ in 0..t {
let a: u64 = rd.get();
let b: u64 = rd.get();
let c: u64 = rd.get();
solve(a, b, c);
}
}
fn solve(a: u6... | true |
0de84410cfba34532587adbd782c5fa1b586dacb | Rust | tylrg/cs451_project4 | /project04/src/lib.rs | UTF-8 | 3,978 | 3.765625 | 4 | [] | no_license | use std::thread;
use std::sync::mpsc; // gives us channel stuff
use std::sync::Arc;
use std::sync::Mutex;
enum Message {
NewJob(Job),
Shutdown,
}
pub struct ThreadPool {
// check to see about <_>
workers: Vec<Worker>,
sender: mpsc::Sender<Message>,
}
impl Drop for ThreadPool {
fn drop(&mut self) {
... | true |
10f4cc31a6257d106c898535f4d6fff93215d629 | Rust | Elena-Qiu/InferSim | /src/bin/infersim/cli.rs | UTF-8 | 3,254 | 2.859375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT",
"Apache-2.0"
] | permissive | use std::fmt;
use std::path::{Path, PathBuf};
use structopt::clap::AppSettings;
use structopt::StructOpt;
use crate::commands::{self, Cmd};
use crate::utils::logging::GlobalLoggingContext;
use crate::utils::prelude::*;
// usage has to be set statically to force `[preset]` appear at the end
#[derive(StructOpt)]
#[str... | true |
2bbf7ad9b1f81250bf8b69ec69c0f03222a5e6e5 | Rust | catalingheorghe/learning-activities | /progr/rust/cmdline-rust-book/hello/tests/cli.rs | UTF-8 | 383 | 2.765625 | 3 | [
"Unlicense"
] | permissive | use assert_cmd::Command;
#[test]
fn runs() {
let mut cmd = Command::cargo_bin("hello").unwrap();
cmd.assert().success().stdout("Hello, world!\n");
}
#[test]
fn true_ok() {
let mut cmd = Command::cargo_bin("true").unwrap();
cmd.assert().success();
}
#[test]
fn false_not_ok() {
let mut cmd = Comman... | true |
de1c38976e9ec9d9c4b4530aa220f9c3d3fe2b4a | Rust | PurpleMyst/factoid_bot | /src/bot.rs | UTF-8 | 3,993 | 2.96875 | 3 | [
"MIT"
] | permissive | use failure::Error;
use irc::{client::prelude::*, error::IrcError};
use simple_redis;
pub struct FactoidBot {
irc_client: IrcClient,
redis_client: simple_redis::client::Client,
}
impl FactoidBot {
pub fn new(cfg: Config) -> Result<Self, Error> {
Ok(Self {
irc_client: IrcClient::from_co... | true |
5e987d1f09060c414605e1a9f83a33eb4a0a3848 | Rust | daholland/grimalpha | /proto/src/input.rs | UTF-8 | 2,511 | 2.53125 | 3 | [] | no_license | pub struct InputState {
pub mouse: MouseState,
}
#[derive(Clone, Copy, Debug, Default)]
pub struct MouseState {
pub pos: (i32, i32),
pub buttons: (bool, bool, bool, bool, bool),
}
#[cfg(feature = "xinput")]
mod xinput {
extern crate winapi;
use super::winapi::*;
#[link(name = "xinput")]
... | true |
e293105bc361e65316caf27c1661e725a9e637be | Rust | jerry73204/tch-typed-tensor | /src/dim/insert.rs | UTF-8 | 4,187 | 2.71875 | 3 | [
"Apache-2.0"
] | permissive | use super::{DCons, DNil, Dim, DimList};
use type_freak::counter::{Counter, Current, Next};
use typenum::{Unsigned, U1};
// insert at
pub trait DInsertAt<Name, Size, Target, Index>
where
Self: DimList,
Name: Dim,
Size: Unsigned,
Target: Dim,
Index: Counter,
Self::Output: DimList,
{
type Out... | true |
5b4020e01e6b6cc6cebafce75d947baea27c72ed | Rust | rust-work/ppshuai_wsserver | /src/wsserver/src/http/test.rs | UTF-8 | 2,675 | 2.78125 | 3 | [] | no_license |
use actix_identity::Identity;
use actix_multipart::Multipart;
use actix_web::{client::{Client, Connector}, Error, HttpRequest, HttpResponse};
use async_std::prelude::*;
use futures::{StreamExt, TryStreamExt};
use openssl::ssl::{SslConnector, SslMethod};
pub async fn test(_req: HttpRequest) -> HttpResponse {
let b... | true |
4f9c77f6a6521de8d5f00da9f2f6f32c91aa68ec | Rust | sftim/s3audit-rs | /src/s3/website.rs | UTF-8 | 1,092 | 2.96875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | // Bucket website
use crate::common::Emoji;
use rusoto_core::RusotoError;
use rusoto_s3::{
GetBucketWebsiteError,
GetBucketWebsiteOutput,
};
use std::fmt;
#[derive(Debug, PartialEq)]
pub enum BucketWebsite {
Enabled,
Disabled,
}
// Type alias to avoid long line in the From impl
type WebsiteResult = Re... | true |
7fa6fc8624152b75f23c1f1e08b72f9b45fd7368 | Rust | dpopacristobal/tracey | /src/materials/mod.rs | UTF-8 | 1,740 | 2.703125 | 3 | [] | no_license | pub use default::DefaultMaterial;
pub use dielectric::Dielectric;
pub use diffuse_light::DiffuseLight;
pub use lambertian::Lambertian;
pub use metal::Metal;
use crate::hittables::HitRecord;
use crate::linalg::{Color, Ray, Vec3};
use crate::pdfs::PDF;
pub mod default;
pub mod dielectric;
pub mod diffuse_light;
pub mod... | true |
1f49665cc5b73e79d8655c4b067eb24ef320d96b | Rust | LaplaceKorea/portable-simd | /crates/core_simd/tests/to_bytes.rs | UTF-8 | 452 | 2.546875 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | #![feature(portable_simd, const_generics, const_evaluatable_checked)]
#![allow(incomplete_features)]
#![cfg(feature = "const_evaluatable_checked")]
use core_simd::SimdU32;
#[test]
fn byte_convert() {
let int = SimdU32::from_array([0xdeadbeef, 0x8badf00d]);
let bytes = int.to_ne_bytes();
assert_eq!(int[0].... | true |
07110192afa4ed09cb981a648a516bbca1220989 | Rust | danicampa90/adventofcode2017 | /libutils/src/lib.rs | UTF-8 | 1,631 | 3.34375 | 3 | [] | no_license |
use std::fs::File;
use std::io::Read;
use std::path::Path;
use std::io::BufReader;
use std::io::BufRead;
pub mod modulo_ops;
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
pub fn read_file_to_str(fname: &str) -> Result<String, std::io::Error> {
println!("Loading ... | true |
3d2acec3c25c9ade8b14b9152eaeea4c8f4b736d | Rust | andpago/tanks | /src/vm/src/program.rs | UTF-8 | 1,707 | 3.390625 | 3 | [] | no_license | use crate::num_traits::{ToPrimitive};
use crate::geom::Direction;
use crate::program::Action::{Fire, Move, Rotate};
use alloc::vec::Vec;
// Actions will be placed into the action register
#[derive(Debug)]
pub enum Action {
Move,
Rotate(Direction),
Fire,
}
impl Into<u8> for Action {
fn into(self: Self)... | true |
12f8bc4b52dc3df83478e6b8bcb8771176664aba | Rust | vadixidav/exifsd | /examples/rewrite.rs | UTF-8 | 712 | 2.546875 | 3 | [
"MIT"
] | permissive | use combine::Parser;
use exifsd::*;
use std::path::PathBuf;
use structopt::*;
#[derive(Debug, StructOpt)]
#[structopt(name = "example", about = "An example of StructOpt usage.")]
struct Opt {
/// Input jpeg
#[structopt(parse(from_os_str))]
input: PathBuf,
}
fn main() {
let Opt { input } = Opt::from_ar... | true |
27942f1f62f1fb5709f916af2c1bf14aff6dd10d | Rust | 8bitslime/rust_gl | /src/mesh.rs | UTF-8 | 3,617 | 2.6875 | 3 | [
"MIT"
] | permissive | #![allow(dead_code)]
use gl::types::*;
use std::mem::size_of;
const MAX_BUFFERS: usize = 8;
pub struct Mesh {
vao: GLuint,
vbo: [GLuint; MAX_BUFFERS],
num_buffers: usize
}
impl Mesh {
pub fn new(buffers: usize) -> Mesh {
unsafe {
let mut mesh = Mesh {
vao: 0,
... | true |
046025d69e15b725d83bda0aaf0af251d2a60bf8 | Rust | samlecuyer/ecumene-rs | /src/bbox.rs | UTF-8 | 2,515 | 3.375 | 3 | [] | no_license | extern crate geo;
use self::geo::{Coordinate};
use std::f64::consts::PI;
pub struct Bbox {
pub min: Coordinate,
pub max: Coordinate,
empty: bool
}
const DEG_TO_RAD: f64 = PI / 180.;
impl Bbox {
pub fn new(x0: f64, y0: f64, x1: f64, y1: f64) -> Bbox {
Bbox{
empty: false,
... | true |
60b37a45f39538d60a62d12c1631c33a835fb6a7 | Rust | chenenjie/sample_rust | /examples/json.rs | UTF-8 | 719 | 2.796875 | 3 | [] | no_license | #[macro_use]
extern crate json;
fn main() {
let parsed = json::parse(r#"
{
"code": 200,
"success": true,
"payload": {
"features": [
"awesome",
"easyAPI",
"lowLearn... | true |
10081910498fe84b214b28bd41a0fdc208fe9f47 | Rust | adam-mcdaniel/chess-engine | /src/piece.rs | UTF-8 | 26,625 | 3.15625 | 3 | [
"MIT"
] | permissive | use super::{Board, Color, Move, Position};
use alloc::string::String;
use alloc::vec::Vec;
use core::convert::TryFrom;
/// A piece on a board.
///
/// Every piece has both a color and a position.
/// These, combined with the type of piece it is,
/// determine things like
/// 1. The validity of legal moves
/// 2. The v... | true |
358354f4865fcf03a6fa96e9505fe5a55928bb9c | Rust | rbspy/rbspy | /src/core/address_finder.rs | UTF-8 | 9,030 | 2.84375 | 3 | [
"MIT"
] | permissive | use anyhow::{anyhow, format_err, Context, Error, Result};
use remoteprocess::{Process, ProcessMemory};
use semver::Version;
use spytools::ProcessInfo;
/// Inspect a running Ruby process, finding key memory addresses that are needed for profiling
pub fn inspect_ruby_process(
process: &Process,
process_info: &Pr... | true |
14d1cd36ffae5797dc65f916def2310222c8b920 | Rust | brdgme/brdgme | /rust/lib/markup/src/ansi.rs | UTF-8 | 1,519 | 2.78125 | 3 | [] | no_license | use brdgme_color::Style;
use crate::ast::TNode;
pub fn render(input: &[TNode]) -> String {
let default_style = Style::default();
format!(
"{}{}",
default_style.ansi(),
render_styled(input, default_style)
)
}
fn render_styled(input: &[TNode], last_style: Style) -> String {
let ... | true |
5d26435b02c43cb36e2aac0e7388b10926e76e9d | Rust | avikuloff/upwd-gtk | /src/config.rs | UTF-8 | 2,105 | 3.171875 | 3 | [] | no_license | use confy::ConfyError;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
uppers: String,
lowers: String,
digits: String,
symbols: String,
#[serde(rename = "default_pool")]
pool: String,
#[serde(rename = "default_length")]
length: u8... | true |
bd946d2f593a5aa65c0fbcb9cac6ecd58274a100 | Rust | weezy20/cargo-whatfeatures | /src/printer/tree.rs | UTF-8 | 3,131 | 3.09375 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use std::{
borrow::Cow,
fmt::Display,
io::{self, Write},
};
use super::{Style, Theme};
pub trait Item: Clone {
type Child: Item;
fn write<W: Write + ?Sized>(&self, writer: &mut W) -> io::Result<()>;
fn children(&self) -> Cow<[Self::Child]>;
}
#[derive(Debug, Clone)]
pub struct Node {
pub ... | true |
f7fe32178ecc4c0032f4470f216399583fb753f1 | Rust | NathanFlurry/femme | /src/ndjson.rs | UTF-8 | 2,348 | 3.046875 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | //! Print logs as ndjson.
use log::{kv, Log, Metadata, Record};
use serde_json::Value;
use std::collections::HashMap;
use std::time;
#[derive(Debug)]
pub struct Logger {
filter: env_logger::filter::Filter,
}
#[derive(serde_derive::Serialize)]
struct Msg {
level: u8,
time: u128,
msg: String,
#[ser... | true |
78d286d8f9fd232ea2ada3329669de254e037636 | Rust | JonathanBrouwer/aoc2019 | /src/day12/main2.rs | UTF-8 | 2,714 | 3.296875 | 3 | [] | no_license | use std::cmp::Ordering;
use std::collections::HashSet;
use num::integer::{Integer};
pub fn main(input: &str) -> i64 {
let mut moons: Vec<Moon> = Vec::new();
for line in input.lines() {
let mut pos: [i64; 3] = [0; 3];
for (i, coord) in line.split(',').enumerate() {
let coordi = coord... | true |
caec2e5ff1da67f19cd50f4b77b0d18ae1f4ef03 | Rust | jnix85/surface-dtx-daemon | /surface-dtx-userd/src/notify.rs | UTF-8 | 3,857 | 2.671875 | 3 | [
"MIT"
] | permissive | use crate::error::{ErrorKind, Result, ResultExt};
use std::borrow::Cow;
use std::collections::HashMap;
use std::time::Duration;
use dbus::arg::{RefArg, Variant};
use dbus::nonblock::{Proxy, SyncConnection};
#[derive(Debug)]
pub struct Notification<'a> {
app_name: Cow<'a, str>,
replaces: u32,
icon: Co... | true |
1e97c78bf84cd426cc641baaae951e61114fdfcd | Rust | MichielMortier/AdventOfCode2020 | /Rust/src/d6.rs | UTF-8 | 1,152 | 3.125 | 3 | [] | no_license | use std::collections::HashSet;
fn parse_answers(ans: &str) -> usize {
ans.split_ascii_whitespace()
.collect::<String>()
.chars()
.collect::<HashSet<_>>()
.len()
}
fn parse_answers2(ans: &str) -> usize {
let vec: Vec<HashSet<char>> = ans
.lines()
.map(|l| l.chars... | true |
86d68092ae7be70fbefdaeaed1d16873e2469aac | Rust | fuyutarow/TeXilla | /src/main.rs | UTF-8 | 2,007 | 3.34375 | 3 | [] | no_license | use std::fs::File;
use std::io::prelude::*;
use structopt::StructOpt;
#[derive(StructOpt, Debug)]
struct Opt {
/// input file path
#[structopt(name = "file", default_value = "entry.tex")]
fpath: String,
/// output file path
#[structopt(short = "o", long = "out")]
out: Option<String>,
}
pub fn... | true |
534e42edc96554b4b0c52970f6fa079c3f547efb | Rust | tajihiro/Rust | /sample04/src/main.rs | UTF-8 | 177 | 3.21875 | 3 | [] | no_license | fn main() {
let my_array = [0,1,2,3,4,5];
//let all = &my_array[..];
let middle = &my_array[1..4];
for val in middle {
println!("{}", val);
}
}
| true |
bc55c403e7dc56533383430209ca11b37b63776b | Rust | Zebfred/ENIT_reference | /Mobile_Laptop/Additional_Resources/code_signal/coding-challenges/Rust/countSumOfTwoRepresentations3.rs | UTF-8 | 165 | 2.78125 | 3 | [] | no_license | // use std::cmp::max;
fn countSumOfTwoRepresentations3(n: i32, l: i32, r: i32) -> i32 {
// max(n / 2 - max(l, n-r) + 1, 0)
0.max(n / 2 - l.max(n-r) + 1)
}
| true |
6533b9b324f3e489d05f0572fc7ee5c426da8ef5 | Rust | Nashenas88/aoc-2019 | /day3/src/main.rs | UTF-8 | 18,006 | 3.234375 | 3 | [
"MIT"
] | permissive | use std::{
collections::HashMap,
fmt::{self, Debug, Formatter},
fs::File,
io::{prelude::*, BufReader},
num::ParseIntError,
str::FromStr,
};
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
struct Point {
x: i64,
y: i64,
}
impl Point {
fn manhattan_distance(&self) -> u64 {
... | true |
9064fe5dab3bf96a46f104cf3dbb2d04151a64ef | Rust | fschutt/LudumDare40 | /src/texture.rs | UTF-8 | 6,636 | 2.65625 | 3 | [
"MIT"
] | permissive | use FastHashMap;
use std::io::{BufRead, Seek};
use glium::texture::CompressedSrgbTexture2d;
use glium::backend::{Context, Facade};
use glium::texture::RawImage2d;
use glium::{DrawParameters, VertexBuffer, Program, Frame};
use ui::UiRect;
use std::rc::Rc;
use ShaderHashMap;
use std::cell::Cell;
#[derive(Debug, Copy, Cl... | true |
2777d58db7fb5cea8bd6b3e0cb266980bdc86880 | Rust | nobbele/ns-engine | /src/resource_manager.rs | UTF-8 | 2,876 | 2.859375 | 3 | [
"MIT"
] | permissive | use std::{cell::RefCell, collections::HashMap, sync::Arc};
use ggez::{
audio::{SoundData, Source},
graphics::Image,
Context,
};
use log::warn;
use crate::config::Config;
#[derive(Debug)]
struct ResourceManagerImpl {
image_cache: HashMap<String, Image>,
sound_cache: HashMap<String, SoundData>,
... | true |
0eac2b93122f737a42cca330d5c28618bf36be28 | Rust | willhug/mmal-sys | /src/lib.rs | UTF-8 | 16,016 | 2.75 | 3 | [
"MIT"
] | permissive | #![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
use std::fmt;
use std::os::raw::c_uint;
// pub const VCOS_ALIGN_DOWN: c_uint = mmal_fourcc!p,n) (((ptrdiff_t)(p)) & ~((n)-1));
// pub const VCOS_ALIGN_UP: c_uint = mmal_fourcc!p,n) VCOS_ALIGN_DOWN((ptrdiff_t)(p)+(n)-1,(n));
pu... | true |
eb1cc81d3b81fc13984fa6b9554b0008199a7de2 | Rust | rustgd/specs-hierarchy | /src/lib.rs | UTF-8 | 23,554 | 3.25 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | /// # `specs-hierarchy`
///
/// Scene graph type hierarchy for use with Specs.
///
/// ## `Parent`
///
/// This crate uses a generic parameter `P` for the parent component. Its bound by the `Parent`
/// trait that only requires a getter for the `Entity` that's the parent.
///
/// ## Usage
///
/// ```rust
/// # extern c... | true |
b4d32ec8a4a4137b93e5cd95f2198469ffc5c629 | Rust | kousukekikuchi1984/books | /algorithm-and-data-structure/src/practices/chapter12.rs | UTF-8 | 1,107 | 3.390625 | 3 | [] | no_license | use superslice::Ext;
pub fn rank(v: Vec<u32>, i: usize) -> usize {
let mut vec = v.to_vec();
let search = vec[i - 1];
vec.sort();
vec.upper_bound(&search)
}
struct Store {
stock: u32,
price: u32,
}
pub fn energy_drink_collector(stocks: Vec<u32>, prices: Vec<u32>, mut amount: u32) -> u32 {
... | true |
4791fa555d3f03aa105b72c819d9f44ae8de68ff | Rust | iCodeIN/turbulence | /tests/unreliable_channel.rs | UTF-8 | 2,742 | 2.515625 | 3 | [
"CC0-1.0",
"Apache-2.0",
"MIT",
"LicenseRef-scancode-public-domain"
] | permissive | use futures::{channel::mpsc, executor::LocalPool, task::SpawnExt};
use turbulence::{buffer::BufferPacketPool, unreliable_channel::UnreliableChannel};
mod util;
use self::util::SimpleBufferPool;
#[test]
fn test_unreliable_channel() {
let packet_pool = BufferPacketPool::new(SimpleBufferPool(1200));
let mut po... | true |
5b35f0e6ebf17b806d32b73b097f7cd907660e27 | Rust | augustotimm/MoonInvaders | /OO/classes/src/game_world/game_object.rs | UTF-8 | 15,246 | 3.4375 | 3 | [
"MIT"
] | permissive | use super::Direction;
use super::errors;
pub enum GameImages{
Alien,
Player,
Shot,
AShot,
Blank,
SpaceGuide,
SAlien,
None,
}
impl GameImagesT for GameImages{
fn value(&self)-> char{
match *self{
GameImages::Alien=> 'ゴ',
GameImages::Player=>'ヒ',
... | true |
357f4c6ad902eae521752d32ca325af747d51c6e | Rust | princjef/regex-rust | /src/re/charclass.rs | UTF-8 | 6,195 | 3.015625 | 3 | [
"MIT"
] | permissive | use parse::{Expr, RangeExpr, RangeTable, NegatedRangeTable};
use std::char::{from_u32, MAX};
use std::cmp::{Less, Greater};
pub type Range = (char, char);
/// Static Character Classes
pub mod perl {
pub fn get_escape_table(escape_char: char) -> Option<&'static [(char, char)]> {
match escape_char {
'd' | '... | true |
860a22938c1489dd026978d9dcc3d50a955ef893 | Rust | steveklabnik/cionc | /src/util/is_any_of.rs | UTF-8 | 368 | 3.296875 | 3 | [
"MIT"
] | permissive | use std::cmp::PartialEq;
pub trait IsAnyOf<T : PartialEq> {
fn is_any_of(&self, options: &[T]) -> bool;
fn is_none_of(&self, options: &[T]) -> bool;
}
impl<T> IsAnyOf<T> for T where T: PartialEq {
fn is_any_of(&self, options: &[T]) -> bool {
options.iter().any(|v| *v == *self)
}
fn is_none_of(&self, options:... | true |
f0ea6a8cbe47d35cdb3c7201a94faa4a937eb97d | Rust | GopherSecurity/plonky | /src/field/bls12_377_scalar.rs | UTF-8 | 11,953 | 2.84375 | 3 | [] | no_license | //! This module implements field arithmetic for BLS12-377's scalar field.
use std::cmp::Ordering::Less;
use std::convert::TryInto;
use std::ops::{Add, Div, Mul, Neg, Sub};
use rand::Rng;
use unroll::unroll_for_loops;
use crate::{add_no_overflow, cmp, Field, sub, field_to_biguint, rand_range, rand_range_from_rng};
us... | true |
d7e099eb419e887233124a27f39af97fe61ce3b0 | Rust | skatsuta/rust-book | /string/src/main.rs | UTF-8 | 467 | 3.28125 | 3 | [
"MIT"
] | permissive | fn main() {
{
let s1 = String::from("hello");
let s2 = "hello".to_string();
}
{
let mut s1 = "foo".to_string();
let s2 = s1.push_str("bar");
}
{
let mut s = "lo".to_string();
s.push('l');
}
{
let s1 = String::from("hello, ");
le... | true |
4b1d7350f4c38ad4e0c472e257cbe88b0e6e32e2 | Rust | aoki-soft/CryptoTool | /src/cli_arg_accepter.rs | UTF-8 | 1,127 | 3 | 3 | [
"MIT"
] | permissive | //! CLI引数を受け取るモジュール
// Cli ArgumentParser
use clap::*;
use log::debug;
pub enum Mode {
CliCrypto,
Gui,
}
/// # CLI引数を受け取る関数
pub fn accept_cli_arg() -> (Option<String>, Option<String>, Mode) {
let matches = app_from_crate!()
.arg(
Arg::with_name("input_file")
.short("i"... | true |
bd1219aecc79a61a3b0a48157a4d204d21f19939 | Rust | rgreenblatt/apma_1941b_final | /src/projected_graph.rs | UTF-8 | 4,259 | 2.953125 | 3 | [] | no_license | use crate::{
connection_strength::ConnectionStrength,
dataset::{Contribution, Dataset, Lens},
edge_vec::EdgeVec,
progress_bar::get_bar,
ItemType,
};
use fnv::FnvHashMap as Map;
use indicatif::{ParallelProgressIterator, ProgressIterator};
use rayon::prelude::*;
use std::sync::Mutex;
#[derive(Copy, Clone, Hash... | true |
fb71c5fcc22fdf7ff034e14a8ac2b855cab8bc76 | Rust | NobodyNada/advent2020 | /day18/src/part2.rs | UTF-8 | 6,793 | 4.03125 | 4 | [
"MIT"
] | permissive | use std::io::{self, BufRead};
// Token definitions
/// A token in the input stream.
#[derive(Clone, Copy, Debug)]
enum Token {
Operator(Operator),
OpenParen,
CloseParen,
Value(i64)
}
#[derive(Clone, Copy, Debug)]
enum Operator {
Add,
Subtract,
Multiply,
Divide
}
impl Operator {
/... | true |
9d8f2d7e2fe66735eab8bfc639c8b72f19eef1fa | Rust | shoobinger/mgs | /mgs-be/mgs_back/src/db/models/asset.rs | UTF-8 | 3,257 | 2.78125 | 3 | [] | no_license | use chrono::{NaiveDate, NaiveDateTime};
use rusqlite::{params, named_params, Connection, Error};
use std::io;
use std::io::Write;
use crate::conn;
use mgs_common::{AddAsset, AssetType};
use std::ops::Deref;
use rusqlite::types::{FromSql, FromSqlError, ValueRef};
use std::collections::HashMap;
#[derive(Debug)]
pub stru... | true |
017b606cd90a4fa5dae730400352e6661971921c | Rust | oysterpack/oysterpack-near-stake-token | /contract/src/near.rs | UTF-8 | 1,367 | 2.734375 | 3 | [
"MIT"
] | permissive | //! NEAR specific constants and logging support
pub mod storage_keys;
use crate::domain::{EpochHeight, YoctoNear};
use near_sdk::env;
use std::fmt::Debug;
/// YOCTO = 10^24
pub const YOCTO: u128 = 1_000_000_000_000_000_000_000_000;
/// Used to indicate that no deposit is being attached to a cross contract func call... | true |
e97c52873211c0039ad24a2102c17971e18df5cb | Rust | thiagopromano/rust-calculator | /src/main.rs | UTF-8 | 2,856 | 2.9375 | 3 | [] | no_license | use std::{env, process};
use compilador_de_calculos::{run, Config};
// fn main() {
// // let args: Vec<String> = env::args().collect();
// //
// // let config = Config::new(&args).unwrap_or_else(|err| {
// // println!("Problem parsing arguments: {}", err);
// // process::exit(1);
// // ... | true |
0754d501c9622af0ff57fd686af77b88ca42d6da | Rust | timvermeulen/rust | /compiler/rustc_resolve/src/effective_visibilities.rs | UTF-8 | 8,792 | 2.625 | 3 | [
"Apache-2.0",
"MIT",
"LLVM-exception",
"NCSA",
"LicenseRef-scancode-other-permissive",
"BSD-2-Clause"
] | permissive | use crate::{ImportKind, NameBindingKind, Resolver};
use rustc_ast::ast;
use rustc_ast::visit;
use rustc_ast::visit::Visitor;
use rustc_ast::Crate;
use rustc_ast::EnumDef;
use rustc_hir::def_id::LocalDefId;
use rustc_hir::def_id::CRATE_DEF_ID;
use rustc_middle::middle::privacy::Level;
use rustc_middle::ty::{DefIdTree, V... | true |
50823e4985a9f98e54d705df062666d1b1d37783 | Rust | Nu-SCPTheme/tag-guard | /src/test/check.rs | UTF-8 | 3,016 | 2.546875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | /*
* test/check.rs
*
* tag-guard - Configurable tag enforcement library
* Copyright (c) 2019 Ammon Smith
*
* tag-guard is available free of charge under the terms of the MIT
* License. You are free to redistribute and/or modify it under those
* terms. It is distributed in the hopes that it will be useful, but
... | true |
c32c268470dcdf4cafe6eca161cfb978a2587c97 | Rust | 4lDO2/ioslice-rs | /src/lib.rs | UTF-8 | 1,562 | 2.875 | 3 | [
"MIT"
] | permissive | //! `#![no_std]`-friendly wrappers over the [`std::io::IoSlice`] and [`std::io::IoSliceMut`], which
//! are shared slices and exclusive slices, respectively, and ABI-compatible with system types for
//! I/O vectors.
//!
//! Internally, the struct will store the following based on crate features:
//!
//! * `std` - wrapp... | true |
49179226f65b4f6b7cf0caa482f83426a41f8da4 | Rust | Cj-bc/playground | /rust/minigrep/src/lib.rs | UTF-8 | 9,901 | 3.015625 | 3 | [] | no_license | #![feature(iter_intersperse)]
use std::env;
use std::io::prelude::*;
use std::fs::File;
use std::error::Error;
use std::collections::HashMap;
use std::str::FromStr;
pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
let mut f = File::open(&config.filename)?;
let mut content = String::new();
f.read... | true |
f0f74080e2c41054a14df82eca00edf542cd5600 | Rust | museun/twitchchat | /src/util.rs | UTF-8 | 3,859 | 2.71875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | #[allow(dead_code)]
pub fn timestamp() -> u64 {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_secs()
}
cfg_async! {
use futures_lite::future::{ready, Ready};
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
};
// TODO if we make th... | true |
48497a1be7e22786b7e962407d5c98b77b0eec71 | Rust | LuisBarroso37/kvs | /src/kvs/writer.rs | UTF-8 | 1,292 | 3.375 | 3 | [] | no_license | use std::io::{self, BufWriter, Write, Seek, SeekFrom};
use crate::Result;
/// BufWriter from std::io with byte's position tracking
#[derive(Debug)]
pub struct BufWriterWithPos<W: Write + Seek> {
pub writer: BufWriter<W>,
pub pos: u64 // Save current byte's position
}
impl<W: Write + Seek> BufWriterWithPos<W> {
... | true |
5c03c4385185513866bf0512cb48720a8bf1a115 | Rust | bestrauc/memory_map | /src/proc_utils/io.rs | UTF-8 | 3,528 | 3.09375 | 3 | [] | no_license | use std::fs::{read_dir, File};
use std::path::PathBuf;
use std::io::prelude::*;
use std::io;
use super::process::ProcessInformation;
/// Parse process metadata from the `/proc/[pid]/stat` file
///
/// Precondition: dir_entry must be a valid process information directory.
fn get_process_metadata(dir_path: PathBuf) -> ... | true |
8b74b61c44e75dd139e099b813190b1c6dfd5a03 | Rust | nikhilsidhu/rust_guessing_game | /src/main.rs | UTF-8 | 1,709 | 3.84375 | 4 | [] | no_license | use rand::Rng;
use std::cmp::Ordering;
use std::io;
fn main() {
println!("Guess the number!");
// :: -> refers to an associated f'n or handle
let secret_num = rand::thread_rng().gen_range(1..=100);
// {} -> placeholders for printing the ensuing variables
// println!("The secret number is: {}", se... | true |
7fc6b9a31f79a404cfe4a3a7b2e664a5f46d8adf | Rust | TeamNumio/zksync | /core/tests/loadtest/src/api/data_pool.rs | UTF-8 | 6,066 | 3.125 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | //! A pool of data required for api tests.
// Built-in uses
use std::{
cmp::max,
collections::{BTreeMap, HashMap, VecDeque},
sync::Arc,
};
// External uses
use rand::{thread_rng, Rng};
use tokio::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard};
// Workspace uses
use zksync_types::{tx::TxHash, AccountId,... | true |
4200cdab06bdaf0097432993de44bfc6eee9698b | Rust | pangpangguy/learnrust | /rustTDTP/TP2_algo_parallel/fichiers_fournis/tri_fusion/src/lib.rs | UTF-8 | 2,924 | 3.34375 | 3 | [] | no_license | #![warn(clippy::all)]
use itertools::kmerge;
use std::iter::repeat_with;
use std::mem::swap;
/// Renvoie un vecteur de u32 aleatoire (valeurs comprises entre 0 et 99) de la taille donnee.
pub fn vecteur_aleatoire(taille: usize) -> Vec<u32> {
repeat_with(|| rand::random::<u32>() % 100)
.take(taille)
... | true |
70c3fa7dfa2c47e5815582234d3a363e3c8ef879 | Rust | VBota1/project_booking | /project_booking_backend/formaters/src/lib.rs | UTF-8 | 1,761 | 3.0625 | 3 | [
"BSD-3-Clause",
"LGPL-2.0-or-later",
"LicenseRef-scancode-other-copyleft",
"LicenseRef-scancode-unknown-license-reference",
"LGPL-2.1-or-later",
"MIT",
"GPL-3.0-only",
"GPL-2.0-only",
"GPL-1.0-or-later"
] | permissive | use std::time::{Duration, SystemTime, UNIX_EPOCH};
use chrono::{NaiveDate, NaiveDateTime};
extern crate chrono;
pub trait AsDMY {
fn as_dmy(&self) -> String;
}
impl AsDMY for NaiveDate {
fn as_dmy(&self) -> String {
self.format(dmy_format().as_str()).to_string()
}
}
pub fn dmy_format() -> String... | true |
3a755059a13b4e25b88e586c9c390d789360759c | Rust | iainh/rocket_oidc | /src/guard.rs | UTF-8 | 3,794 | 2.84375 | 3 | [] | no_license | use openidconnect::{core, EndUserName, EndUserUsername, LocalizedClaim};
use rocket::{
http::{Cookie, Status},
request::{self, FromRequest, Outcome, Request},
State,
};
use crate::{
application::{OidcApplication, OidcSessionCookie},
errors::IdTokenError,
};
/// Rocket request guard for OpenID Conn... | true |
3efcc3fc6e7da047f099d2c8d1f47e1033aed45d | Rust | OwenTuz/advent-of-code-2018 | /src/lib.rs | UTF-8 | 308 | 2.859375 | 3 | [] | no_license | pub fn input_string_to_integer_vec(input: &str) -> Vec<i64> {
input.trim()
.split("\n")
.map(|x| x.parse::<i64>().unwrap())
.collect::<Vec<i64>>()
}
pub fn input_string_to_str_vec(input: &str) -> Vec<&str> {
input.trim()
.split("\n")
.collect::<Vec<&str>>()
}
| true |
0704d0ee66ffdb096c68d381129842358558ff65 | Rust | segeljakt/swag | /src/foa/stack.rs | UTF-8 | 2,132 | 3.828125 | 4 | [] | no_license | use std::rc::Rc;
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum List<Value> {
Nil,
Cons(Value, Rc<List<Value>>),
}
impl<Value: Clone> List<Value> {
pub fn empty() -> List<Value> {
List::Nil
}
pub fn is_empty(&self) -> bool {
match self {
List::Nil => true,
... | true |
bd193fee1fe63a44b7c6d964253ed228990680dd | Rust | blahgeek/Minions | /src/actions/utils/open.rs | UTF-8 | 579 | 2.765625 | 3 | [] | no_license | use std::io::Result;
use crate::actions::utils::subprocess;
use crate::mcore::action::{Action, ActionResult};
use crate::mcore::errors::*;
pub fn that(path: &str) -> Result<()> {
info!("Opening URL: {}", path);
let args: Vec<&str> = vec![path];
subprocess::spawn("xdg-open", &args)
}
pub struct OpenAction ... | true |
dbe4fe7b1b11d48b5d33a4aba3610c0c308b87b1 | Rust | pnxguide/infiny_discord_bot | /src/handler/handler.rs | UTF-8 | 1,097 | 3.0625 | 3 | [] | no_license | use serenity::{
model::{channel::Message, id::ChannelId},
prelude::*,
};
use rand::RngCore;
use rand::rngs::OsRng;
pub async fn handle_message(ctx: Context, msg: Message) {
let channel_id = msg.channel_id;
if msg.content == "!hello" {
greet(ctx, channel_id).await;
}
}
async fn greet(ctx... | true |
b2f45e4d94b1973f618c34ba3cde050330f9b1f4 | Rust | simonsan/OxidizeBot | /bot/src/idle.rs | UTF-8 | 1,072 | 3.296875 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! Idle detection for incoming messages.
use parking_lot::RwLock;
use std::sync::{
atomic::{AtomicUsize, Ordering},
Arc,
};
#[derive(Clone)]
pub struct Idle {
/// Number of messages seen.
seen: Arc<AtomicUsize>,
/// Last time we saw enough messages to not be considered idle.
last: Arc<AtomicU... | true |
9bea9e1274ecfce6c091db21c9fdb1a247126cb7 | Rust | songww/lc-rs | /examples/518-coin-change-2.rs | UTF-8 | 441 | 2.921875 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | struct Solution;
impl Solution {
pub fn change(amount: i32, coins: Vec<i32>) -> i32 {
let mut dp = vec![0; amount as usize + 1];
dp[0] = 1;
for coin in coins {
for j in coin..=amount {
let j = j as usize;
dp[j] += dp[j - coin as usize];
... | true |
1ed82689508301ab0ffe34ce7b5d852d67cdb43a | Rust | tylerXMD/advent_of_code_2019 | /day8/part1/src/main.rs | UTF-8 | 1,368 | 3.15625 | 3 | [] | no_license | use std::fs::File;
use std::io::Read;
use std::error::Error;
const WIDTH: usize = 25;
const HEIGHT: usize = 6;
fn main() -> Result<(), Box<dyn Error>> {
let mut f = File::open("../input.txt")?;
let mut layers: Vec<[[u32; HEIGHT]; WIDTH]> = Vec::new();
let mut s = String::new();
f.read_to_string(&mut... | true |
ec24b7bcbc5168222a5efa7e7c29fff324819dd1 | Rust | aweary/swc | /crates/swc_plugin_runner/src/imported_fn/set_transform_result.rs | UTF-8 | 1,484 | 2.765625 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use std::sync::Arc;
use parking_lot::Mutex;
use wasmer::{LazyInit, Memory};
use crate::memory_interop::copy_bytes_into_host;
/// Environment states allow to return guest's transform result back to the
/// host, using a buffer `transform_result` attached to the environment.
///
/// When plugin performs its transform ... | true |
7359abbd6b3da2627233505c6bbc68d28ac7bf82 | Rust | hukumka/dirstat | /src/main.rs | UTF-8 | 3,721 | 3.640625 | 4 | [] | no_license | //! Simple utility to display total size of all files in directory
//!
//! Usage:
//!
//! `dirstat [FLAGS] <input_dir>`
//!
//! | Flags | |
//! |:----------|------------------------:|
//! |-h, --help | Prints help information |
//! |-n, --nice | Display result in readable units |
//! |-V, --version | Prints version inf... | true |
b7eb84be0a1e0eb436227339f3c9247b61e235cd | Rust | metacall/core | /source/ports/rs_port/tests/metacall_test.rs | UTF-8 | 11,249 | 2.796875 | 3 | [
"Apache-2.0",
"Python-2.0",
"GPL-2.0-or-later",
"MPL-1.1",
"NCSA",
"LicenseRef-scancode-proprietary-license",
"GPL-1.0-or-later",
"BSD-3-Clause",
"MPL-2.0",
"Ruby",
"BSD-2-Clause",
"MIT"
] | permissive | use metacall::{
loaders, switch, MetacallClass, MetacallException, MetacallFunction, MetacallFuture,
MetacallNull, MetacallObject, MetacallPointer, MetacallThrowable, MetacallValue,
};
use std::{collections::HashMap, env, fmt::Debug};
fn generate_test<T: MetacallValue + PartialEq + Debug + Clone>(
name: im... | true |
48ac5a8d17f1cd132aa71e51f2127a0df5b5c663 | Rust | travbid/cborg | /src/lib.rs | UTF-8 | 9,715 | 2.84375 | 3 | [
"MIT"
] | permissive | pub mod value;
use core::fmt;
use core::iter::Iterator;
use core::result;
use std::error;
pub use value::FromValue;
pub use value::KeyVal;
pub use value::Simple;
pub use value::ToValue;
pub use value::Value;
pub use value::ValueInto;
pub type Result<T> = result::Result<T, CborError>;
pub enum ErrorKind {
Unexpected... | true |
ac79ff77392460d39378d22b0f4ca720c8b2abd8 | Rust | keeslinp/advent_of_code_2018 | /day_1/src/main.rs | UTF-8 | 928 | 3 | 3 | [] | no_license | use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::collections::HashMap;
fn main() {
let args: Vec<String> = env::args().collect();
let filename = &args[1];
let mut f = File::open(filename).expect("File not Found");
let mut contents = String::new();
f.read_to_string(&mut contents).... | true |
bf522af218d142c401e1498496ce3c1c1ca7132e | Rust | saskenuba/SteamHelper-rs | /crates/steam-trading/src/types/asset_collection.rs | UTF-8 | 1,178 | 2.859375 | 3 | [
"MIT"
] | permissive | use crate::types::trade_offer_web::{Asset, AssetList};
#[derive(Debug, PartialEq, Clone)]
pub struct AssetCollection(pub(crate) Vec<Asset>);
impl AssetCollection {
pub(crate) fn dump_to_asset_list(self) -> AssetList {
AssetList {
assets: self.0,
..Default::default()
}
}... | true |
d35f993b3362ee1abeb148fc4dda718cf6073f32 | Rust | NaomiLea/ji-cloud | /frontend/build-utils/templates-builder/src/options.rs | UTF-8 | 1,710 | 2.71875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use structopt::StructOpt;
use std::env;
use std::path::{Path, PathBuf};
use config::RemoteTarget;
#[derive(Debug, StructOpt)]
#[structopt(name = "database migrations", about = "A little util to run database migrations")]
pub struct Opts {
// local, sandbox, or release
#[structopt(short, long)]
pub remote... | true |
684fe78e62b648fe639f2e0fa78c820e3e2844fd | Rust | dospro/adx_tools | /src/bin/afs_extract/main.rs | UTF-8 | 2,204 | 3.078125 | 3 | [] | no_license | use std::env;
use std::fs;
use std::fs::File;
use std::path::{Path, PathBuf};
use std::io::{Read, Write, BufReader, Seek, SeekFrom};
extern crate clap;
use clap::{Arg, App, SubCommand};
use adx_tools::afs_file::AfsFile;
fn main() {
let matches = App::new("Afs Extract")
.version("1.0")
.author("R... | true |
8c9244b162e81f5f0785b1171a95b2df8d9b90ed | Rust | mnts26/aws-sdk-rust | /sdk/sagemakeredge/src/client.rs | UTF-8 | 10,635 | 2.515625 | 3 | [
"Apache-2.0"
] | permissive | // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
#[derive(Debug)]
pub(crate) struct Handle<
C = smithy_client::erase::DynConnector,
M = aws_hyper::AwsMiddleware,
R = smithy_client::retry::Standard,
> {
client: smithy_client::Client<C, M, R>,
conf: crate::Config,
}
//... | true |
647dce351bc6c7ff8896881159de86b1838ee22a | Rust | bagar0x60/sandsim | /src/model/mod.rs | UTF-8 | 2,725 | 2.515625 | 3 | [] | no_license | pub mod embedding;
pub mod sand_graph;
pub mod lattice;
pub mod region;
use self::embedding::EmbeddingToR3;
use self::sand_graph::{SandGraph};
use self::region::Region;
use self::lattice::Lattice;
#[derive(Debug)]
pub struct SandPileModel {
pub graph: SandGraph,
pub embedding: EmbeddingToR3,
}
impl SandPileM... | true |
4ff664844c4ccb682c92bb456af8d2ab68b0a469 | Rust | StardustDL/Algorithms-in-Rust | /src/math/real.rs | UTF-8 | 442 | 3.25 | 3 | [
"Apache-2.0"
] | permissive | pub fn trichotomy<O, F>(lower: f64, upper: f64, eps: f64, func: F) -> f64
where
O: PartialOrd,
F: Fn(f64) -> O,
{
let mut lower = lower;
let mut upper = upper;
while lower + eps < upper {
let delta = (upper - lower) / 3.0;
let ml = lower + delta;
let mr = upper - delta;
... | true |
82fcb0c6ce58225be0c2f3b3859dcc49f0f038e8 | Rust | isgasho/galangua | /galangua-wasm/src/wasm_system.rs | UTF-8 | 1,159 | 2.578125 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use wasm_bindgen::prelude::*;
use galangua_common::framework::SystemTrait;
#[wasm_bindgen]
extern "C" {
fn play_se(channel: u32, filename: &str);
}
pub struct WasmSystem<
F: Fn(&str) -> Option<JsValue>,
G: Fn(&str, JsValue)
> {
get_item: F,
set_item: G,
is_touch_device: bool,
}
impl<
F: ... | true |
27499688c7b8536bae33d5909126fcf4b8c26c82 | Rust | HyeockJinKim/RustPython | /vm/src/obj/objslice.rs | UTF-8 | 3,619 | 2.75 | 3 | [
"MIT"
] | permissive | use crate::function::{OptionalArg, PyFuncArgs};
use crate::pyobject::{IdProtocol, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol};
use crate::vm::VirtualMachine;
use crate::obj::objint::PyInt;
use crate::obj::objtype::{class_has_attr, PyClassRef};
use num_bigint::BigInt;
#[derive(Debug)]
pub struct Py... | true |
c2922a5edbffce15454792c973f63fb0f13bd3ab | Rust | icyJoseph/advent-of-code | /2020/six/src/lib.rs | UTF-8 | 1,909 | 3.125 | 3 | [] | no_license | use std::collections::{HashMap, HashSet};
pub fn part_one(groups: &Vec<String>) -> usize {
groups
.into_iter()
.fold(vec![], |mut prev, curr| {
if curr.is_empty() {
prev.push("".to_string());
return prev;
}
let last = match prev.po... | true |
55e56946fb266ab4f40bf293bc98f75e2c80bc70 | Rust | shibaiqian/porus | /src/capacity.rs | UTF-8 | 980 | 3 | 3 | [
"MIT"
] | permissive | pub trait Policy {
fn initial(capacity: usize) -> usize;
fn grow(capacity: usize) -> usize;
fn shrink(size: usize, capacity: usize) -> usize;
}
pub struct FixedPolicy {}
impl Policy for FixedPolicy {
fn initial(size: usize) -> usize {
size
}
fn grow(capacity: usize) -> usize {
... | true |
c18a8189d88544261efbbf875f6b090b8738ec22 | Rust | brandonhamilton/quicksilver | /src/error.rs | UTF-8 | 3,756 | 2.546875 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | #[cfg(not(target_arch="wasm32"))]
extern crate image;
#[cfg(feature="serde_json")]
extern crate serde_json;
#[cfg(all(not(target_arch="wasm32"), feature="rodio"))]
extern crate rodio;
use graphics::{AtlasError, ImageError};
#[cfg(feature="rusttype")] use rusttype::Error as FontError;
#[cfg(feature="serde_json")] use... | true |
f86e2e03ca097f1b70e4a49bafe95df9db233584 | Rust | arizuk/programming-contest-solutions | /misc/bitmask.rs | UTF-8 | 339 | 3.109375 | 3 | [] | no_license | fn main() {
let a = 15;
println!("{:#06b}", a);
for i in 0..3 {
let mask = (1 << i);
println!("mask={} {:#06b}", i, a & !mask);
}
for i in 0..3 {
let mask = (1 << i) - 1;
println!("mask={} {:#06b}", i, a & mask);
}
for i in 0..3 {
let mask = -1 << i;
println!("mask={} {:#06b}", ... | true |
cabb2e33bfae464cc45e0fa907fdf603e22c9c17 | Rust | ros2rust/realsense-rust | /src/kind/option.rs | UTF-8 | 18,051 | 2.953125 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! Enumeration of RS2 sensor options.
//!
//! Not all options apply to every sensor. In order to retrieve the correct options,
//! one must iterate over the `sensor` object for option compatibility.
//!
//! Notice that this option refers to the `sensor`, not the device. However, the device
//! used also matters; senso... | true |
a682c692d49acb30c33776623f2e6f75c07d60be | Rust | knarz/class-groups | /src/primitives/mod.rs | UTF-8 | 7,003 | 2.515625 | 3 | [] | no_license | use super::{ABDeltaTriple, BinaryQF};
use crate::gmul;
use crate::pari_init;
use curv::arithmetic::traits::Samplable;
use curv::BigInt;
use paillier::keygen;
pub struct PK {
pub q: BigInt,
pub delta_k: BigInt,
pub delta_q: BigInt,
pub gq: BinaryQF,
pub h: BinaryQF,
stilde: BigInt,
}
pub struct ... | true |
4e7f5a3e931c23e7c07d49bcf04c4ef5fd77876a | Rust | dmolokanov/iotedge-aad | /src/main.rs | UTF-8 | 3,637 | 2.6875 | 3 | [
"MIT"
] | permissive | use clap::{App, Arg};
use reqwest::Client;
use std::{
path::{Path, PathBuf},
sync::Arc,
};
use iotedge_aad::{Auth, Context, Identity, Result, TokenSource};
// TODO add example from device ID creation to module access Azure resource
#[tokio::main]
async fn main() -> Result<()> {
let app = App::new("iotedge... | true |
2629e0e6671f8642774a9460298c68692311fed6 | Rust | jmeischner/todoco | /export/src/lib.rs | UTF-8 | 1,469 | 2.53125 | 3 | [] | no_license | use appconfig::AppConfig;
use serde_json;
use std::fs;
use std::fs::File;
use std::io::Result as IOResult;
use std::io::Write;
use std::path::PathBuf;
use types::Project;
pub mod format;
pub fn project_to_path(project: &Project, path: PathBuf) -> IOResult<()> {
init_project_dir(path.clone())?;
write_project_t... | true |
974523ae074ec0897f0bba5a6f3f643c8f5583c4 | Rust | leomarssilva/prometheus-wire-parser | /src/parser/label.rs | UTF-8 | 2,207 | 3.734375 | 4 | [] | no_license | use std::collections::HashMap;
use std::str::FromStr;
/// List of labels for a [SampleData](super::SampleData). See examples at [try_read_sample](super::try_read_sample) for more details.
#[derive(Debug, PartialEq)]
pub struct LabelList(HashMap<String, String>);
impl LabelList {
pub fn new() -> Self {
Lab... | true |
387ba08a54ad8661a61a14375227658b2f20732c | Rust | stardreamer/rust-raytrace | /src/materials/dielectric.rs | UTF-8 | 1,811 | 2.796875 | 3 | [] | no_license | use crate::structs::ray::Ray;
use crate::structs::vec3::Vec3;
use super::Scatterable;
use crate::obj::HitRecord;
#[derive(Debug, Clone)]
pub struct Dielectric {
pub reflection_index: f64,
}
impl Scatterable for Dielectric {
fn scatter(
&self,
ray: &Ray,
hit: &HitRecord,
rng: &... | true |
43b04338ba2dcd586a4fd93c320cf235623fbe36 | Rust | K-REBO/map | /src/modules/utils.rs | UTF-8 | 998 | 2.765625 | 3 | [
"MIT"
] | permissive | pub fn classify_floor_by_node(node: u16) -> Option<u8> {
// from utils.NodeFloor in canvas.js
if 0 < node && node <= floor_bounds_node(2)? as u16 {
Some(1)
} else if (floor_bounds_node(2)? as u16) < node && node <= (floor_bounds_node(3)? as u16) {
Some(2)
} else if (floor_bounds_node(3)? as u16) < node && node... | true |
15e7ed45a07a57477ac320a47d8b77e8692531b9 | Rust | yigarashi-9/mini_python | /src/core/object/longobj.rs | UTF-8 | 4,008 | 2.65625 | 3 | [
"MIT"
] | permissive | use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use std::cell::RefCell;
use std::rc::Rc;
use error::*;
use eval::PyRes;
use object::{PyObject, PyInnerObject};
use object::excobj::*;
use object::typeobj::*;
thread_local! (
pub static PY_LONG_TYPE: Rc<PyObject> = {
let longtp ... | true |
ce429805308106e8f8cd8c2d785d87df8a550a91 | Rust | avborhanian/rust-clippy | /tests/ui/uninlined_format_args.rs | UTF-8 | 7,432 | 2.625 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | //@aux-build:proc_macros.rs
//@run-rustfix
#![warn(clippy::uninlined_format_args)]
#![allow(named_arguments_used_positionally, unused)]
#![allow(
clippy::eq_op,
clippy::format_in_format_args,
clippy::print_literal,
clippy::unnecessary_literal_unwrap
)]
extern crate proc_macros;
use proc_macros::with_sp... | true |
ac4bef02be138cacea592916919ef49b4abafa17 | Rust | ajcarvajal/adventofcode | /aoc2020/day4/src/main.rs | UTF-8 | 3,932 | 2.9375 | 3 | [] | no_license | use std::convert::TryFrom;
use std::fs::File;
use std::io::{self, BufRead};
use std::path::Path;
use std::collections::HashMap;
fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
where
P: AsRef<Path>,
{
let file = File::open(filename)?;
Ok(io::BufReader::new(file).lines())
}
fn ge... | true |
3dc7143cbc6ef86da47d474a185731e33e26b3e3 | Rust | panicbit/sd3 | /firmtool/src/builder.rs | UTF-8 | 3,242 | 3.09375 | 3 | [] | no_license | use std::io::Write;
use std::convert::TryFrom;
use sha2::{Sha256, Digest};
use crate::{Result, CopyMethod, signature};
use crate::header::{self, Header, SectionHeader};
#[derive(Default)]
pub struct Builder {
arm9_entrypoint: Option<u32>,
arm11_entrypoint: Option<u32>,
sections: Vec<Section>,
}
impl Build... | true |
d9cadf3c81790d723978da31a6e5167a60a97121 | Rust | akhramov/newseek | /src/binary_format/de.rs | UTF-8 | 5,620 | 2.875 | 3 | [] | no_license | use serde::de::{self, Deserialize, Visitor};
use byteorder::{ LittleEndian, ByteOrder };
use std::io::Read;
use std::str;
use errors::*;
macro_rules! not_implemented {
($($method:ident )*) => {
$(fn $method<V>(self, _: V) -> Result<V::Value>
where V: Visitor<'de>,
{
Err... | true |
45e1e990c7cfa4dfb4520edba27e9f21e9cd7c6c | Rust | griba2001/rust-monadic | /src/state_trans.rs | UTF-8 | 4,377 | 3.015625 | 3 | [] | no_license | // state_trans.rs
use crate::monad::Monad;
use std::iter::FromIterator;
pub struct StateT<'a, S, M, A>
where
M: 'a + Monad<Item=(A, S)>,
{
pub run_state_t: Box<dyn 'a + Fn(S) -> M>,
}
impl<'a, A, S, M> StateT<'a, S, M, A>
where
A: 'a + Clone,
S: 'a + Clone,
M: 'a + Monad<Item =(A, S... | true |
19823f902c1c4ce20a86c7a1c71e9d7a10ec4f9a | Rust | Arnaud-D/resarith | /src/parse.rs | UTF-8 | 2,333 | 3.703125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | use crate::defs::{Expr, Token};
pub fn parse(tokens: &mut Vec<Token>) -> Expr {
tokens.reverse();
parse_expr(tokens)
}
// Expr -> Expr1 Expr2
fn parse_expr(tokens: &mut Vec<Token>) -> Expr {
let expr = parse_expr1(tokens);
parse_expr2(tokens, expr)
}
// Expr1 -> value | '(' Expr ')'
fn parse_expr1(t... | true |
eb617deec01bbb13b683519eebfb28a0611e5875 | Rust | klaxit/heroku_rs | /examples/src/logs_examples.rs | UTF-8 | 2,483 | 2.734375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | extern crate heroku_rs;
use super::print_response;
use heroku_rs::endpoints::logs;
use heroku_rs::framework::apiclient::HerokuApiClient;
pub fn run<ApiClientType: HerokuApiClient>(api_client: &ApiClientType) {
let app_name = "mycoolherokuappname";
// create_log_drain(api_client, app_name);
get_log_drains(... | true |
3dfac2def144e1282c45d3f9f411ca50be498fb5 | Rust | svend/advent-of-code | /aoc-2019/src/day8.rs | UTF-8 | 3,642 | 3.40625 | 3 | [] | no_license | // https://adventofcode.com/2019/day/8
use std::fmt;
type Layer = Vec<u32>;
fn flatten_layers(top: &[u32], bottom: &[u32]) -> Layer {
assert_eq!(top.len(), bottom.len());
let mut layer = Layer::new();
for (p1, p2) in top.iter().zip(bottom.iter()) {
let p = if *p1 == 2 { p2 } else { p1 };
... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.