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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
71ab0bfcbe04301a4e8b5d8d853b6f4bf29369ae | Rust | blue-yonder/vikos | /examples/mean.rs | UTF-8 | 851 | 2.859375 | 3 | [
"MIT"
] | permissive | use vikos::{cost, learn_history, teacher};
fn main() {
// mean is 9, but of course we do not know that yet
let history = [1.0, 3.0, 4.0, 7.0, 8.0, 11.0, 29.0];
// The mean is just a simple number ...
let mut model = 0.0;
// ... which minimizes the square error
let cost = cost::LeastSquares {};
... | true |
dcb94b53ba8b09b982417a2239edaf52193ab098 | Rust | pygaur/Rust-Training | /examples/10-generics-traits-lifetimes/simple_generics.rs | UTF-8 | 787 | 3.890625 | 4 | [] | no_license | use std::fmt::Debug;
fn display<T: Debug>(x: T) {
println!("{:?}", x);
}
// fn largest<T>(i: T, j: T) -> T {
// if i > j {
// return i
// } else {
// return j
// }
// }
// fn largest(i: i32, j: i32) -> i32 {
// if i > j {
// return i
// } else {
// return j
// ... | true |
8ecdd5e0b59aec505a41d053b04281018f94a0b7 | Rust | FranklinChen/immutable-list-rust | /src/lib.rs | UTF-8 | 8,083 | 3.515625 | 4 | [] | no_license | //! Immmutable, persistent list as in FP languages.
use std::mem;
/// Use reference counting instead of GC for sharing.
use std::rc::Rc;
/// Simplest possible definition of an immutable list as in FP.
///
/// A `List` is either empty or a shared pointer to a `Cons` cell.
#[derive(PartialEq, Debug)]
pub struct List<T>... | true |
d47e09f0392b9c3e9aa64dbbb20c0d8773f3c982 | Rust | 5HT-ST0LE-THIS-PROJECT/n2o-1 | /src/io/unix/errno.rs | UTF-8 | 9,042 | 2.953125 | 3 | [] | no_license |
use libc::{c_int, c_char};
use std::ffi::CStr;
use libc;
use std::{self, fmt};
use core;
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Error {
Sys(Errno),
InvalidPath,
}
impl Error {
pub fn from_errno(errno: Errno) -> Error {
Error::Sys(errno)
}
pub fn last() -> Error {
Error... | true |
ff0d5229fb6b76c5370dabf0296b56b3a80042a0 | Rust | mdesmet/kvstore | /src/kv.rs | UTF-8 | 6,939 | 3.359375 | 3 | [] | no_license | use failure::Error;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::fs;
use std::io::{BufRead, BufReader, Seek, SeekFrom, Write};
use std::path::{Path, PathBuf};
/// `Result` will contain the result of a `KvStore` operation
pub type Result<T> = std::result::Result<T, Error>;
/// `KvStore... | true |
38a69360da046c6507fc23894794c831f78f4148 | Rust | xacrimon/dashmap | /src/try_result.rs | UTF-8 | 1,665 | 3.640625 | 4 | [
"MIT"
] | permissive | /// Represents the result of a non-blocking read from a [DashMap](crate::DashMap).
#[derive(Debug)]
pub enum TryResult<R> {
/// The value was present in the map, and the lock for the shard was successfully obtained.
Present(R),
/// The shard wasn't locked, and the value wasn't present in the map.
Absent... | true |
d9390fcd3c455271ec95e6c5aaaf7f60574f92e0 | Rust | erglabs/arti | /crates/tor-dirmgr/src/docid.rs | UTF-8 | 6,915 | 2.859375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | //! Declare a general purpose "document ID type" for tracking which
//! documents we want and which we have.
use std::{borrow::Borrow, collections::HashMap};
use tor_dirclient::request;
use tor_netdoc::doc::{
authcert::AuthCertKeyIds, microdesc::MdDigest, netstatus::ConsensusFlavor, routerdesc::RdDigest,
};
/// ... | true |
5f7a02be1c14f5492881bcba27076e0142c695bd | Rust | mesalock-linux/crates-sgx | /vendor/sgx_tstd/src/io/buffered.rs | UTF-8 | 23,971 | 3.0625 | 3 | [
"Apache-2.0"
] | permissive | // Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may... | true |
d58757446fed2183d9793266ebcd311ac924b4f3 | Rust | sagarnayak/RustTestWebApp | /src/controllers/multi_thread_task.rs | UTF-8 | 472 | 2.765625 | 3 | [] | no_license | use std::time::Duration;
use rand::Rng;
use std::thread::sleep;
#[get("/startMultiThreading")]
pub async fn start_multi_thread() -> &'static str {
for i in 0..1000 {
tokio::spawn(
async move {
// println!("Start timer {}.", &i);
sleep(Duration::from_secs(rand::t... | true |
5111fbaaec8afce95e4dee79f2b88f429b5ea1e4 | Rust | clinuxrulz/ilc_ecs | /src/ecs/scene_ctx.rs | UTF-8 | 632 | 2.609375 | 3 | [] | no_license | use crate::ecs::ComponentType;
use crate::ecs::EntityId;
use crate::ecs::IsComponent;
pub trait SceneCtx {
// for Undo/Redo capabilities
fn create_entity_with_id(&mut self, entity_id: EntityId);
fn create_entity(&mut self) -> EntityId;
fn destroy_entity(&mut self, entity_id: EntityId);
fn get_... | true |
547015b6a1dcf7b6330f33d652a7832b3a16a4b1 | Rust | mida-hub/hobby | /atcoder/rust/beginner/contest/abc234/src/bin/c.rs | UTF-8 | 486 | 3.046875 | 3 | [] | no_license | fn to_bin(v: i64) -> String {
format!("{:b}", v).to_string()
}
fn to_int(s: String) -> i64 {
s.parse::<i64>().unwrap()
}
fn main() {
proconio::input! {
k: i64,
};
let str_bin_k = to_bin(k);
let mut ans = "".to_string();
for s in str_bin_k.chars() {
// println!("{}", s);
... | true |
a5d16aee67d71d26698a4be1acc3bb894647543c | Rust | ferrous-systems/imxrt1052 | /src/pwm1/sm2octrl/mod.rs | UTF-8 | 26,271 | 2.734375 | 3 | [] | no_license | #[doc = r" Value read from the register"]
pub struct R {
bits: u16,
}
#[doc = r" Value to write to the register"]
pub struct W {
bits: u16,
}
impl super::SM2OCTRL {
#[doc = r" Modifies the contents of the register"]
#[inline]
pub fn modify<F>(&self, f: F)
where
for<'w> F: FnOnce(&R, &'w ... | true |
037a9e08538f832e5baa1f77071f19c23ee4b4ce | Rust | Frixxie/weatherlogger | /src/main.rs | UTF-8 | 3,146 | 3.296875 | 3 | [
"MIT"
] | permissive | mod weather;
use futures::future::try_join_all;
use reqwest::get;
use serde::Deserialize;
use serde_json::Value;
use std::io;
use std::path::PathBuf;
use std::sync::Arc;
use structopt::StructOpt;
use tokio::fs;
#[derive(Debug, StructOpt)]
#[structopt(
name = "weatherlogger",
about = "Logs the weather from htt... | true |
a55bb237e21f47c3e8d1adf77c09c338a344ae87 | Rust | nimiq/core-rs | /utils/tests/throttled_queue/mod.rs | UTF-8 | 1,100 | 3.21875 | 3 | [
"Apache-2.0"
] | permissive | use std::thread::sleep;
use std::time::Duration;
use nimiq_collections::queue::Queue;
use nimiq_utils::throttled_queue::*;
#[test]
fn it_can_enqueue_dequeue() {
let mut queue = ThrottledQueue::new(1000, Duration::default(), 0, None);
queue.enqueue(1);
queue.enqueue(2);
queue.enqueue(8);
queue.rem... | true |
2012974c8d0f471060bd4d345c6c26ed1e5cd0bf | Rust | vishalbelsare/sss-cli | /src/bin/split.rs | UTF-8 | 9,035 | 2.53125 | 3 | [
"MIT"
] | permissive | #[macro_use]
extern crate clap;
extern crate env_logger;
#[macro_use]
extern crate log;
extern crate rand;
extern crate shamirsecretsharing_cli;
extern crate shamirsecretsharing;
use std::env;
use std::fmt;
use std::fs::File;
use std::io::prelude::*;
use std::process::exit;
use clap::{App, Arg, ArgMatches};
use rand:... | true |
7a6779e848ccd6af1f659c10771e50d06163c610 | Rust | rust-lang/rust | /tests/ui/suggestions/dont-wrap-ambiguous-receivers.rs | UTF-8 | 499 | 2.875 | 3 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"BSD-2-Clause",
"LicenseRef-scancode-unicode",
"MIT",
"LicenseRef-scancode-other-permissive"
] | permissive | mod banana {
//~^ HELP the following traits are implemented but not in scope
pub struct Chaenomeles;
pub trait Apple {
fn pick(&self) {}
}
impl Apple for Chaenomeles {}
pub trait Peach {
fn pick(&self, a: &mut ()) {}
}
impl<Mango: Peach> Peach for Box<Mango> {}
impl... | true |
131582dda70e3eb164c27f7b8369005853ddfc19 | Rust | nfrasser/lasgun | /src/scene/node.rs | UTF-8 | 3,739 | 3.25 | 3 | [
"MIT"
] | permissive | // This module contains structures for providing a simple representation of the
// contents of a scene. The elements here are later used to build up a full scene
use cgmath::{prelude::*, Deg};
use crate::{space::*, Material};
use super::{ObjRef as Obj};
pub enum SceneNode {
/// A geometric shape its material
G... | true |
c77f55d97069e2f9bcf96befc8bf08b2c047cb24 | Rust | necrobious/aws-kms-ca | /aws-kms-ca-x509/src/certificate/validity.rs | UTF-8 | 3,718 | 2.921875 | 3 | [] | no_license | use yasna::models::UTCTime;
use time::OffsetDateTime;
use yasna::{
ASN1Result,
DERWriter,
DEREncodable,
BERReader,
BERDecodable,
};
#[cfg(feature = "tracing")]
use tracing::{debug};
#[derive(Clone, Debug, PartialEq,)]
pub struct Validity {
pub not_before: OffsetDateTime,
pub not_after: Off... | true |
b51a9707d1c919cd7663a4659374f32aa7973122 | Rust | matt-thomson/advent-of-code | /2019/src/day02.rs | UTF-8 | 1,516 | 3.328125 | 3 | [
"MIT"
] | permissive | use std::path::PathBuf;
use structopt::StructOpt;
use crate::intcode::Program;
use crate::problem::Problem;
#[derive(Debug, StructOpt)]
pub struct Day02 {
#[structopt(parse(from_os_str))]
input: PathBuf,
target: i64,
}
impl Problem for Day02 {
type Output = i64;
fn part_one(&self) -> i64 {
... | true |
0b76b64ee69f0fa5bff2499ee3a3719a33ad6c22 | Rust | bumzack/godot | /game-physics/src/particle_contacts/particle_rod_constraint.rs | UTF-8 | 2,182 | 2.796875 | 3 | [] | no_license | use math::prelude::*;
use crate::force::particle_force_types::ParticleIdx;
use crate::{ParticleConstraintOps, ParticleContact, ParticleForceRegistry, ParticleForceRegistryOps, ParticleOps};
pub struct ParticleRodConstraint {
length: f32,
particle: Option<ParticleIdx>,
anchor: Tuple4D,
}
impl ParticleCons... | true |
d7c094fcdf2c3ae533371eb08762348ee131b73a | Rust | lamafab/serde-scale | /serde-scale-tests/tests/conformance.rs | UTF-8 | 5,133 | 2.578125 | 3 | [
"Zlib"
] | permissive | // Copyright (C) 2020 Stephane Raux. Distributed under the zlib license.
use parity_scale_codec::{Encode, OptionBool};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::{
error::Error,
fmt::Debug,
};
fn roundtrips<T>(v: &T) -> Result<(), Box<dyn Error>>
where
T: Debug + Serialize + Deser... | true |
0148f930886345f1011217658ca45b8298f304d5 | Rust | LeonardoRiojaMachineVentures/Varied | /Cargoless/sum.rs | UTF-8 | 2,413 | 3.4375 | 3 | [] | no_license | enum Paren {
Open,
Close,
}
impl Paren {
fn validate(x : Vec<Paren>) -> Result<bool, ()> {
let mut count = 0usize;
for i in x.iter() {
match i {
Paren::Open => {
count = match count.checked_add(1) {
Some(a) => {a},
... | true |
612b4e35133809bece5082a83ff9758ad2d47ee7 | Rust | jDomantas/ccg | /crates/game/src/loader/config.rs | UTF-8 | 1,117 | 2.796875 | 3 | [] | no_license | use std::collections::HashMap;
use serde::Deserialize;
#[derive(Deserialize, Debug)]
pub struct Card {
pub icon: String,
pub title: String,
pub description: Vec<String>,
pub effect: CardEffect,
}
#[derive(Deserialize, Debug)]
pub enum CardEffect {
None,
Enemy {
icon: String,
at... | true |
af7a7ea6d1fd26c15257fdcae105708ec6402ea3 | Rust | sgrowe/advent-of-code-2019 | /src/int_code.rs | UTF-8 | 9,139 | 3.46875 | 3 | [] | no_license | use std::num::ParseIntError;
use std::str::FromStr;
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
enum Mode {
Position,
Immediate,
}
impl Mode {
fn from_i64(int: i64) -> Mode {
if int == 0 {
Mode::Position
} else {
Mode::Immediate
}
}
}
#[derive(Debug, C... | true |
563f23a15a2f49bda873c09c5885bb0a7b614aba | Rust | youngqqcn/RustNotes | /examples/ch16/rust_mutex_1.rs | UTF-8 | 1,770 | 3.75 | 4 | [] | no_license | use std::sync::{
Mutex, Arc
};
use std::rc::Rc;
/*
fn foo1() {
let counter_mtx = Mutex::new(0);
let mut threads = Vec::new();;
for i in 0..10 {
let hd = std::thread::spawn( move || {
let mut num = counter_mtx.lock().expect("lock error");
*num += 1;
});
... | true |
cfa88732e6efc51100fa3f2a3c7c23c368ac1911 | Rust | AreebSiddiqui/ONSITE-PIAIC- | /chapter6_1/e1/src/main.rs | UTF-8 | 223 | 2.515625 | 3 | [] | no_license | use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
fn main () {
let localhost_v4 = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
let localhost_v6 = IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1));
println!("{}",localhost_v4);
}
| true |
5ecb9d4a7006de26e896ee349d8bfb91c53cbf1f | Rust | neutronest/GynooR | /tests/test_geometry.rs | UTF-8 | 454 | 2.71875 | 3 | [
"MIT"
] | permissive | extern crate gynoo_r;
use gynoo_r::geometry;
#[test]
fn test_gvector() {
let mut v1 = geometry::GVector{x:1.0, y:2.0, z:3.0};
let mut v2 = geometry::GVector{x:2.0, y:3.0, z:4.0};
let mut v3 = v1 + v2;
let mut v4 = geometry::GVector{x:20.0, y:30.0, z:40.0};
println!("v3: {:?}", v3);
println!("v... | true |
cfdc86a6ed383f02ddfb55b58133e6cd7a13324f | Rust | mkalam-alami/advent-of-code | /2020-rust/day18parser.rs | UTF-8 | 3,620 | 3.796875 | 4 | [] | no_license | use std::fmt::Display;
pub struct Expression {
left: ExpressionHand,
right: ExpressionHand,
operator: char
}
impl Expression {
pub fn evaluate(&self) -> usize {
match self.operator {
'*' => self.left.evaluate() * self.right.evaluate(),
'+' => self.left.evaluate() + self.right.evaluate(),
... | true |
cdab1d372d1f898b2084aefb18494dfd1324e694 | Rust | geokala/korama | /src/music_library.rs | UTF-8 | 4,650 | 2.8125 | 3 | [] | no_license | use id3::Tag;
use std::ffi::OsStr;
use std::fs::read_to_string;
use std::path::{Path, PathBuf};
use crate::delimiters::{END_OF_FIELD, END_OF_HEADER};
use crate::shared::{DynamicSource, Saveable};
use crate::track::Track;
const EXTENSION: &str = "lib";
#[derive(Clone)]
pub struct MusicLibrary {
name: String,
... | true |
53deacfbdac894cafd0b6dfce895f2bfb5948fed | Rust | GiorgiBeriashvili/cli-timer | /src/color.rs | UTF-8 | 562 | 3.140625 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use std::io::Write;
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
pub fn apply_color(colored: bool, text: String, color: Color) {
if colored {
print_colored(color, text);
} else {
print_colored(Color::White, text);
}
}
pub fn print_colored(color: Color, text: ... | true |
9760023f9c23b3ff1ffc5b98e3de11dc14eb5449 | Rust | Gregoor/bevy_contrib_bobox | /examples/outline_2d.rs | UTF-8 | 4,239 | 2.609375 | 3 | [
"MIT"
] | permissive | use bevy::prelude::*;
use bevy_contrib_bobox::{Outline2dPlugin, OutlineConfiguration, OutlineMaterial};
fn main() {
//env_logger::init();
App::build()
.add_resource(WindowDescriptor {
width: 600,
height: 400,
..Default::default()
})
.add_plugins(Defaul... | true |
1c45d33d0cddad7d617990e5167f5acd44ff132f | Rust | Amdrel/nes-rs | /src/nes/instruction.rs | UTF-8 | 92,863 | 2.78125 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | // Copyright 2016 Walter Kuppens.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according... | true |
837b86f4e994d7fb2466c46fae0f52f08969c604 | Rust | LevitatingOrange/oblivious-transfer | /src/common/digest/mod.rs | UTF-8 | 1,045 | 2.875 | 3 | [] | no_license | use generic_array::{ArrayLength, GenericArray};
pub mod sha3;
/// A simple trait to generalize hashing functions used by this library.
/// It is very similiar to the trait from the crate digest but customized to fit this library's needs.
/// One can use any hash function to initialize the BaseOT and OTExtensions thou... | true |
488c296bbfe749e9b9e2a4baed077b45341fe1ce | Rust | danleechina/Leetcode | /Rust_Sol/src/archive0/s307.rs | UTF-8 | 1,361 | 3.3125 | 3 | [] | no_license | struct NumArray {
sum_nums: Vec<i32>,
}
use std::cmp::min;
use std::cmp::max;
impl NumArray {
fn new(nums: Vec<i32>) -> Self {
return NumArray {
sum_nums: NumArray::sum(nums),
};
}
fn sum(nums: Vec<i32>) -> Vec<i32> {
let mut res = vec![0; nums.len()];
if nums.is_empty()... | true |
e035d708b17b849307f5bb7ffd7421bf17061f32 | Rust | ryban/rust-noise | /examples/step.rs | UTF-8 | 1,160 | 2.765625 | 3 | [
"MIT"
] | permissive | // step.rs
extern crate noise;
extern crate image;
extern crate time;
use noise::gen::NoiseGen;
use noise::gen::fbm::FBM;
use noise::utils::step;
use image::GenericImage;
use std::io::File;
use time::precise_time_s;
fn main() {
let mut ngen = FBM::new_rand(24, 0.5, 2.5, 175.0);
let steps: &[f64] = [0.0, 0.2,... | true |
5b9494cbf2cbadfe743a7423b5c60ffdcc041680 | Rust | bevyengine/bevy-website | /generate-release/src/migration_guide.rs | UTF-8 | 2,874 | 2.640625 | 3 | [
"MIT"
] | permissive | use crate::{
github_client::{GithubClient, GithubIssuesResponse},
helpers::{get_merged_prs, get_pr_area},
markdown::write_markdown_section,
};
use std::{collections::BTreeMap, fmt::Write, path::PathBuf};
pub fn generate_migration_guide(
title: &str,
weight: i32,
from: &str,
to: &... | true |
2084f8277ef8665a45ddbd50447581e6ccc17cf4 | Rust | stalwartlabs/mail-builder | /src/encoders/encode.rs | UTF-8 | 3,832 | 2.53125 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | /*
* Copyright Stalwart Labs Ltd. See the COPYING
* file at the top-level directory of this distribution.
*
* Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
* https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
* <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
* optio... | true |
043e6f1c29ce342503edaea539cda2d75ca020a6 | Rust | SCRTHodl/blockchain | /dmbc/src/currency/offers/offers.rs | UTF-8 | 4,465 | 3.203125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use currency::offers::Offer;
use exonum::crypto::{PublicKey, Hash};
#[derive(Debug, Eq, PartialEq)]
pub struct CloseOffer {
pub wallet: PublicKey,
pub price: u64,
pub amount: u64,
pub tx_hash: Hash,
}
encoding_struct! {
#[derive(Eq, PartialOrd, Ord)]
struct Offers {
price: u64,
... | true |
5f474337b8c824f98175ca33eb7ad730c4f3714d | Rust | VisionistInc/advent-of-code-2020 | /cicavey/10/src/main.rs | UTF-8 | 1,733 | 3.375 | 3 | [
"MIT"
] | permissive | use std::collections::HashMap;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::Path;
fn lines_from_file(filename: impl AsRef<Path>) -> Vec<String> {
let file = File::open(filename).expect("no such file");
let buf = BufReader::new(file);
buf.lines()
.map(|l| l.expect("Could not ... | true |
783e934f743af60f924efcca913d81e53baf0caa | Rust | ghcom275/unsafe-io | /src/raw_handle_or_socket.rs | UTF-8 | 4,587 | 3.09375 | 3 | [
"Apache-2.0",
"LLVM-exception",
"MIT"
] | permissive | //! The `RawHandleOrSocket` type, providing a minimal Windows analog for the
//! Posix-ish `AsRawFd` type.
#[cfg(feature = "os_pipe")]
use os_pipe::{PipeReader, PipeWriter};
use std::{
fmt,
fs::File,
io::{Stderr, StderrLock, Stdin, StdinLock, Stdout, StdoutLock},
net::TcpStream,
os::windows::io::{A... | true |
1e660ec705c46aa248a6552dab381ea38231632d | Rust | pseudo-social/nymdex | /src/main.rs | UTF-8 | 1,359 | 2.515625 | 3 | [
"MIT"
] | permissive | mod application;
mod logger;
mod producer;
use producer::{amqp::AMQPProducer, kafka::KafkaProducer, Producer};
#[actix::main]
#[doc(hidden)]
/// Where the magic happens 🌌
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Setup the indexer
application::initialize()?;
// Setup the producer
... | true |
95508caf1f3ba2be3ed9ae9d7d50794f90648eed | Rust | grogers0/advent_of_code | /2019/day14/src/main.rs | UTF-8 | 5,628 | 3.0625 | 3 | [
"MIT"
] | permissive | use std::cmp::Ordering;
use std::collections::HashMap;
use std::io::{self, Read};
#[derive(Debug)]
struct Reaction {
inputs: HashMap<String, u64>,
output_amount: u64
}
fn parse(puzzle_input: &str) -> HashMap<String, Reaction> {
puzzle_input.trim().lines().map(|line| {
let mut sp = line.split("=>")... | true |
3ce191b17235166a4fa94fe19033d9190bd116b2 | Rust | davideGiovannini/rust_sdl2_engine | /leek/src/font/mod.rs | UTF-8 | 3,522 | 3.359375 | 3 | [] | no_license | use sdl2::rect::Rect;
use sdl2::render::{Texture, WindowCanvas};
pub struct BitmapFont {
texture: Texture,
char_width: u32,
char_height: u32,
}
impl BitmapFont {
// TODO maybe create from Path instead of from Texture
// TODO also could be useful to have a function on Engine that returns the bitmap... | true |
4c676ab989d73ee08e32ad929f5db6c78e6f6c3d | Rust | timvermeulen/advent-of-code | /src/solutions/year2015/day05.rs | UTF-8 | 1,193 | 3.375 | 3 | [] | no_license | fn part1(input: &str) -> usize {
input.lines().filter(|&s| is_nice1(s)).count()
}
fn is_nice1(string: &str) -> bool {
string.chars().filter(|&c| "aeiou".contains(c)).count() >= 3
&& string
.chars()
.zip(string.chars().skip(1))
.any(|(a, b)| a == b)
&& !["ab",... | true |
cfe1aa8bfec31520a804c8ba65015c70adfc774d | Rust | kccqzy/ucla-cs-111-spring2018 | /lab1a-rust/src/main.rs | UTF-8 | 5,988 | 2.578125 | 3 | [] | no_license | extern crate nix;
extern crate termios;
use std::os::unix::process::ExitStatusExt;
use nix::sys::signal::Signal;
use std::ops::BitOr;
use std::process::{Command, Stdio};
use std::fs::File;
use std::io::{Error, Read, Write};
use std::os::unix::prelude::*;
use std::process::exit;
use nix::poll::{poll, EventFlags, PollFd... | true |
373b458444f541f320fb1e48faca9fd98d7f4b6f | Rust | ykafia/SyracuseRust | /src/base_types.rs | UTF-8 | 5,678 | 3.28125 | 3 | [] | no_license | use std::fmt;
use std::ops::{Add, AddAssign, Sub};
pub struct Value {
pub x: u64,
pub y: u64,
}
impl fmt::Display for Value {
// This trait requires `fmt` with this exact signature.
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}-{}", self.x, self.y)
}
}
#[derive(Clon... | true |
a6d4f619208e6c1c2b8d6227fccb037f1143871f | Rust | zezic/nona | /src/color.rs | UTF-8 | 2,258 | 3.390625 | 3 | [
"MIT"
] | permissive | use clamped::Clamp;
use std::ops::Rem;
#[derive(Debug, Copy, Clone, Default)]
pub struct Color {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}
impl Color {
pub fn rgba(r: f32, g: f32, b: f32, a: f32) -> Color {
Color { r, g, b, a }
}
pub fn rgb(r: f32, g: f32, b: f32) -> Color... | true |
3ddb17a39f8a426bc96fe755e68f5ee2c7a7e3ff | Rust | rome/tools | /xtask/coverage/src/compare.rs | UTF-8 | 2,834 | 2.609375 | 3 | [
"MIT"
] | permissive | use std::collections::HashMap;
use std::fs::File;
use std::io::Read;
use std::path::{Path, PathBuf};
use xtask::project_root;
use crate::results::emit_compare;
use crate::util::decode_maybe_utf16_string;
use crate::TestResults;
// this is the filename of the results coming from `main` branch
const BASE_RESULT_FILE: &... | true |
b82270d93b926745d4b57800e6bc9719077511e6 | Rust | JoseFilipeFerreira/carage | /carage/src/img/api.rs | UTF-8 | 2,899 | 2.65625 | 3 | [] | no_license | use super::{File, FileApi};
use crate::{
car::Car,
fairings::{Claims, Db},
};
use lazy_static::lazy_static;
use rocket::serde::json::Json;
use rocket::{
data::{Limits, ToByteUnit},
fs::NamedFile,
};
use std::{
fs,
io::{self, Write},
path::Path,
};
use uuid::Uuid;
lazy_static! {
pub stat... | true |
3347c4cdea2b5233c0db39cf96c5197b1b5aec61 | Rust | mattjmcnaughton/hacks | /binstaller/src/main.rs | UTF-8 | 2,493 | 2.6875 | 3 | [] | no_license | use std::error::Error;
use std::fs;
use std::io::Read;
use std::path::Path;
use flate2::read::GzDecoder;
use quicli::prelude::*;
use structopt::StructOpt;
use tar::Archive;
use tempfile::tempdir;
use xz2::read::XzDecoder;
#[derive(Debug, StructOpt)]
struct Cli {
remote_url: String,
destination_directory: Stri... | true |
a810d280e9ea5bd1635716c29f2ecb792f2cc655 | Rust | bobwhitelock/exercism-exercises | /rust/hamming/src/lib.rs | UTF-8 | 332 | 3.296875 | 3 | [] | no_license |
pub fn hamming_distance<'a>(strand: &'a str, other: &'a str) -> Result<u32, &'a str> {
if strand.chars().count() != other.chars().count() {
return Err("inputs of different length")
}
let distance = strand.chars().zip(other.chars())
.filter(|&(s, o)| s != o)
.count() as u32;
Ok(... | true |
ebe1f18a86d3b9adf1987232fd794451b763a5ce | Rust | alexander-zw/plusplus | /src/main.rs | UTF-8 | 1,565 | 2.984375 | 3 | [] | no_license | /// Main file that handles terminal arguments.
mod tokenizer;
mod compiler;
use std::fs::File;
use std::io::Write;
use crate::tokenizer::Tokenizer;
use crate::compiler::Compiler;
fn compile_pp_file(filename: &str) {
print_title();
println!("[ INFO ] Trying to open {}...", filename);
let tokenizer = Tokeni... | true |
05f57b07591de90f33d9972c776096c7e3a119af | Rust | ldfdev/Exercises-from-the-book-Beginning-Rust-From-Novice-To-Expert | /Chapter 9/compiler_infers_()_retun_type_for_functions_by_default.rs | UTF-8 | 249 | 2.8125 | 3 | [] | no_license |
// not specifying a return type in function's signature
// resumes to having () rturn type
fn create_a_pair() {
// returning a tuple when compiler infers () type
// yields error[E0308]: mismatched types
(1,2)
}
fn main() {
} | true |
247597d2f2b06d8eb841906b4724e433a49f4f48 | Rust | brianarpie/rusty-sorts | /src/main.rs | UTF-8 | 1,706 | 3.140625 | 3 | [] | no_license | mod sorts;
mod benchmark;
extern crate rand;
use rand::distributions::{IndependentSample, Range};
use std::i32;
fn main() {
// TODO: move the array instantiation into a separate method.
const ARRAY_LENGTH: usize = 10000;
let mut array: [i32; ARRAY_LENGTH] = [0;ARRAY_LENGTH];
let between = Range::new(0... | true |
02b17963b5f947c2843bb50d281b9827d80fe6c3 | Rust | Twinklebear/bspline | /src/lib.rs | UTF-8 | 9,247 | 3.28125 | 3 | [
"MIT"
] | permissive | //! [](http://i.imgur.com/RUEw8EW.png)
//!
//! bspline
//! ===
//! A library for computing B-spline interpolating curves on generic control points. bspline can
//! be used to evaluate B-splines of varying orders on any type that can be linearly interpolated,
//! ranging from float... | true |
56fe0f25e702739561bd71e2b87c50822ee62ade | Rust | mcheshkov/icfpc2020 | /app/parser.rs | UTF-8 | 4,456 | 2.734375 | 3 | [
"MIT"
] | permissive | use std::collections::HashMap;
use std::fs::File;
use std::io::Read;
use std::io::Write;
use std::path::Path;
use text_parser::Action;
mod text_parser;
fn is_constant(action: &Action) -> bool {
match action {
Action::Number(_) => true,
Action::Value("nil") => true,
Action::List(args) => ar... | true |
6ddc9d7686fc65421bc000d5a37277e5158cc14f | Rust | paholg/spin | /src/lib.rs | UTF-8 | 5,290 | 2.890625 | 3 | [] | no_license | //! This is a module comment!
#![feature(const_fn)]
#![feature(question_mark)]
// spin stuff:
#![cfg_attr(feature = "spin", no_std)]
#![cfg_attr(feature = "spin", feature(plugin))]
#![cfg_attr(feature = "spin", plugin(macro_zinc))]
// #![cfg_attr(feature = "spin", feature(core_float))]
#[cfg(feature = "spin")]
exter... | true |
d10c0351e945cf22e19c4fe7c9342a52381a7339 | Rust | RCasatta/rusty-paper-wallet | /src/html.rs | UTF-8 | 4,288 | 3.078125 | 3 | [
"MIT"
] | permissive | use crate::Result;
use maud::{html, PreEscaped};
use qr_code::QrCode;
use std::io::Cursor;
const CSS: &str = include_str!("html.css");
#[derive(Debug, Clone)]
pub struct WalletData {
/// Alias name of the owner of the paper wallet, shown in public part
pub alias: String,
/// Address of the paper wallet
... | true |
b8e2064747141d2d7c1f5144c98bbbdc0b3e6ad6 | Rust | jnpn/rdupes | /src/mt.rs | UTF-8 | 708 | 2.546875 | 3 | [] | no_license | use std::thread;
use walkdir::WalkDir;
use std::channels;
mod mt {
/*
*
* scan-thread -> <scan-queue> -> hash-thread -> <hash-q> -> map-thread -> <map-q> -> screen-thread
*
* - scan-p: (fn, ctime)
* - hash-p: (fn, ctime, hash)
* - map-p : (hash, [(fn, ctime)]), hash-count
*
... | true |
57ca2013802501cbb73b21e0e37a10f25e6afdb9 | Rust | run-mojo/listpack | /src/old.rs | UTF-8 | 69,880 | 2.78125 | 3 | [] | no_license | #![allow(dead_code)]
extern crate libc;
mod zigzag;
pub mod raw;
use std::mem;
use std::mem::size_of;
use zigzag::ZigZag;
pub const HDR_SIZE: i32 = 6;
pub const MIN_SIZE: i32 = 7;
// HDR + TERMINATOR
pub const EMPTY: &'static [u8] = &[];
const INTBUF_SIZE: usize = 21;
/// Used for determining how to treat the "at"... | true |
7ec9a571b508d5527b5ae5d239af9ac3f16141d6 | Rust | wyyerd-contrib/juniper | /juniper/src/integrations/uuid.rs | UTF-8 | 673 | 2.984375 | 3 | [
"BSD-2-Clause"
] | permissive | use uuid::Uuid;
use Value;
graphql_scalar!(Uuid {
description: "Uuid"
resolve(&self) -> Value {
Value::string(self.to_string())
}
from_input_value(v: &InputValue) -> Option<Uuid> {
v.as_string_value()
.and_then(|s| Uuid::parse_str(s).ok())
}
});
#[cfg(test)]
mod test {
... | true |
5daaa1a1d40d3de6c56f6ab8a8963e11c8bdffd1 | Rust | mnts26/aws-sdk-rust | /sdk/route53domains/src/output.rs | UTF-8 | 97,720 | 2.546875 | 3 | [
"Apache-2.0"
] | permissive | // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
/// <p>The ViewBilling response includes the following elements.</p>
#[non_exhaustive]
#[derive(std::clone::Clone, std::cmp::PartialEq)]
pub struct ViewBillingOutput {
/// <p>If there are more billing records than you specified for <co... | true |
1c03fd590aba17a0122bea6488e57eb82f6b1cae | Rust | rust-lang/rust | /tests/rustdoc/empty-impl-block-private.rs | UTF-8 | 831 | 2.9375 | 3 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"BSD-2-Clause",
"LicenseRef-scancode-unicode",
"MIT",
"LicenseRef-scancode-other-permissive"
] | permissive | #![feature(inherent_associated_types)]
#![allow(incomplete_features)]
#![crate_name = "foo"]
// @has 'foo/struct.Foo.html'
pub struct Foo;
// There are 3 impl blocks with public item and one that should not be displayed
// because it only contains private items.
// @count - '//*[@class="impl"]' 'impl Foo' 3
// Impl ... | true |
264f55c049f71f069b75fb6e66b54f90bc380226 | Rust | vinca-rosea/RayTracingInOneWeekend | /src/material.rs | UTF-8 | 3,215 | 2.90625 | 3 | [] | no_license | use super::*;
pub fn schlick(cosine: f64, ref_idx: f64) -> f64 {
let mut r0 = (1.0 - ref_idx) / (1.0 + ref_idx);
r0 = r0 * r0;
r0 + (1.0 - r0) * (1.0 - cosine).powi(5)
}
pub trait Material {
fn scatter(
&self,
r_in: &Ray,
rec: &HitRecord,
attenuation: &mut Vec3,
... | true |
7e1426700fc751626f5229ae5b4d7e54e1d82331 | Rust | OTL/kiss3d | /src/post_processing/sobel_edge_highlight.rs | UTF-8 | 5,781 | 2.640625 | 3 | [
"BSD-2-Clause"
] | permissive | //! A post-processing effect to highlight edges.
use gl;
use gl::types::*;
use na::Vector2;
use resource::{BufferType, AllocationType, Shader, ShaderUniform, ShaderAttribute, RenderTarget,
GPUVec};
use post_processing::post_processing_effect::PostProcessingEffect;
#[path = "../error.rs"]
mod error;
//... | true |
99db814a206d583c4584360c979bf96f75ba86fe | Rust | aylei/leetcode-rust | /src/solution/s0077_combinations.rs | UTF-8 | 1,751 | 3.625 | 4 | [
"Apache-2.0"
] | permissive | /**
* [77] Combinations
*
* Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.
*
* Example:
*
*
* Input: n = 4, k = 2
* Output:
* [
* [2,4],
* [3,4],
* [2,3],
* [1,2],
* [1,3],
* [1,4],
* ]
*
*
*/
pub struct Solution {}
// problem: https://leetcode... | true |
94fc9ea06cca3e1e99d9e39610efcc7b95f0cc05 | Rust | TheBlueHeron/The-Rust-Book | /smart_pointers/src/main.rs | UTF-8 | 4,834 | 3.65625 | 4 | [
"Unlicense"
] | permissive | use crate::List::{Cons, Nil};
use crate::MultiOwnerList::{Cns, Nl};
use std::cell::RefCell;
use std::ops::Deref;
use std::rc::Rc;
use std::rc::Weak;
fn main() {
let b = Box::new(5); // 5 is stored on the heap; the box (pointer) data is stored on the stack
// box implements only Deref trait and Drop trait and o... | true |
0e7933216094497d70292335a7e7c83c665173e8 | Rust | leudz/shipyard | /src/borrow/non_send_sync.rs | UTF-8 | 691 | 2.703125 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use core::convert::{AsMut, AsRef};
use core::ops::{Deref, DerefMut};
/// Type used to access `!Send + !Sync` storages.
#[cfg_attr(docsrs, doc(cfg(feature = "thread_local")))]
pub struct NonSendSync<T: ?Sized>(pub(crate) T);
impl<T: ?Sized> AsRef<T> for NonSendSync<T> {
fn as_ref(&self) -> &T {
&self.0
... | true |
02b1322a689a3d3a1da05e68fdaf9343bc56834a | Rust | awsdocs/aws-doc-sdk-examples | /rust_dev_preview/examples/dynamodb/src/scenario/movies/startup.rs | UTF-8 | 5,771 | 2.78125 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use super::Movie;
use crate::scenario::error::Error;
use aws_sdk_dynamodb::{
operation::create_table::builders::CreateTableFluentBuilder,
types::{
AttributeDefinition, KeySchemaElement, KeyType, ProvisionedThroughput, ScalarAttributeType,
TableStatus, WriteRequest,
},
Client,
};
use futu... | true |
9fe7bdb7b4fbdeadddc32638f7b51637d7c49a07 | Rust | Skgland/Response-Time-Analysis-for-Fixed-Priority-Servers | /rta-for-fps-lib/tests/consolidated_tests/server_tests.rs | UTF-8 | 1,232 | 2.6875 | 3 | [] | no_license | use crate::rta_lib::curve::Curve;
use crate::rta_lib::iterators::CurveIterator;
use crate::rta_lib::server::{Server, ServerKind};
use crate::rta_lib::task::Task;
use crate::rta_lib::time::TimeUnit;
use crate::rta_lib::window::Window;
#[test]
fn deferrable_server() {
// Example 6. with t = 18
let tasks = &[Tas... | true |
0becb1d001e88b1d3b97e4794135391372135ba7 | Rust | jiyilanzhou/chw | /local_rust/learn_rust/44learn_box1/src/main.rs | UTF-8 | 2,764 | 3.421875 | 3 | [] | no_license |
/* // detect[dɪˈtekt]v.检测,探测
box 适用场景:
(1)当有一个在编译时未知大小的类型,而又需要再确切大小的上下文中使用这个类型值的时候;
(举例子:在一个 list 环境下,存放数据,但是每个元素的大小在编译时又不确定)
(2)当有大量数据并希望在确保数据不被拷贝的情况下转移所有权的时候;
(3)当希望拥有一个值并只关心它的类型是否实现了特定 trait 而不是其具体类型时。
*/
use List::Cons;
use List::Nil;
/* //循环嵌套:
enum List {
Cons(i32, List), // 编译时未知... | true |
5d5af8c1378fd1d537bd13b332ea79550ab66f35 | Rust | okuvshynov/hcl | /src/data/metric_parse.rs | UTF-8 | 798 | 3.546875 | 4 | [
"MIT"
] | permissive | fn base<'a>(v: &'a str) -> &'a str {
&v[0..v.len() - 1]
}
pub fn metric_parse(s: &str) -> Result<f64, std::num::ParseFloatError> {
let s = s.trim();
let (exponent, mantissa) = match s.to_uppercase().chars().last() {
Some('K') => (1.0e3, base(s)),
Some('M') => (1.0e6, base(s)),
Some(... | true |
dfdf3480aa2100e981f5d0d954016d304df78774 | Rust | efancier-cn/embedded-gui | /src/state/mod.rs | UTF-8 | 1,081 | 2.8125 | 3 | [] | no_license | //! Visual state container.
pub mod selection;
pub trait StateGroup {
const MASK: u32;
}
pub trait State {
type Group: StateGroup;
const VALUE: u32;
}
#[macro_export]
macro_rules! state_group {
($([$group:ident: $mask:literal] = {
$($state:ident = $value:literal),+ $(,)?
})+) => {
... | true |
482ed15bad3f077e7bbdf6aeb0c2e9b5e53a411f | Rust | lineCode/lyken | /gll/src/lib.rs | UTF-8 | 11,012 | 2.53125 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | #![feature(conservative_impl_trait, decl_macro, from_ref, str_escape)]
extern crate indexing;
extern crate ordermap;
use indexing::container_traits::Trustworthy;
use indexing::{scope, Container};
use std::cmp::{Ordering, Reverse};
use std::collections::{BTreeSet, BinaryHeap, HashMap};
use std::fmt;
use std::hash::{Ha... | true |
d032eb648f31bfeb65179bbd93cf660ea8e6063e | Rust | clinuxrulz/sodium-rust-demo | /core/src/math/cos.rs | UTF-8 | 264 | 2.859375 | 3 | [] | no_license | pub trait Cos {
type Output;
fn cos(self) -> Self::Output;
}
impl Cos for f32 {
type Output = f32;
fn cos(self) -> f32 {
self.cos()
}
}
impl Cos for f64 {
type Output = f64;
fn cos(self) -> f64 {
self.cos()
}
}
| true |
4f94075eacf5889d4eeb7180c76b4cf79d662a11 | Rust | Symforian/University | /Rust/List_7/5.last_dig_huge/src/main.rs | UTF-8 | 1,549 | 3.53125 | 4 | [] | no_license | fn last_digit(lst: &[u64]) -> u64 {
fn trim_number(number: u128, base: u128) -> u128{
return if number < base { number } else { number % base + base }
}
if lst.len()==0 {return 1;}
let first = *(lst.iter().last().unwrap()) as u128;
let folded = lst.iter().clone().take(lst.len()-1).collect:... | true |
b3152fd5ddd2e0e9b76870c36b9b833ad03f6e59 | Rust | JonasBak/imglang | /tests/heap_rc.rs | UTF-8 | 3,511 | 2.96875 | 3 | [] | no_license | use imglang::*;
fn run_script(input: &'static str) -> VM {
let mut lexer = Lexer::new(&input.to_string()).unwrap();
let mut ast = parse(&mut lexer).unwrap();
TypeChecker::annotate_types(&mut ast, None).unwrap();
let chunks = Compiler::compile(&ast, None);
let mut output: Vec<u8> = vec![];
le... | true |
577dc5e9d11c8d621d9eaabae53e43a815ea25ba | Rust | AndreasOM/ggj19 | /src/fb.rs | UTF-8 | 1,858 | 3.046875 | 3 | [
"MIT",
"LicenseRef-scancode-warranty-disclaimer"
] | permissive |
#[derive(Debug)]
pub struct FB {
pub width: isize,
pub height: isize,
buffer: Vec<u32>,
}
impl FB {
pub fn new( width: isize, height: isize ) -> FB {
FB {
width: width,
height: height,
buffer: vec![0; ( width * height ) as usize],
}
}
pub fn buffer( &mut self ) -> &mut Vec<u32> {
&mut self.buffe... | true |
484907de16d9ba751a92049a4da42dcd418977a8 | Rust | statianzo/imposters | /src/ch06_datastructures/heap.rs | UTF-8 | 3,242 | 3.859375 | 4 | [
"ISC"
] | permissive | use std::iter::FromIterator;
use std::slice::Iter;
pub struct Heap<T: PartialOrd> {
elements: Vec<T>,
}
fn parent_index(index: usize) -> usize {
(index - 1) / 2
}
impl<T: PartialOrd> Heap<T> {
pub fn new() -> Self {
Heap {
elements: Vec::new(),
}
}
pub fn len(&self) -... | true |
a85a7feb2901e7a383231796bdc96f812ad6d240 | Rust | mambisi/edgekv | /src/schema.rs | UTF-8 | 6,226 | 3.140625 | 3 | [] | no_license | use anyhow::Result;
use std::io::{Read};
use crc32fast::Hasher;
pub(crate) fn crc_checksum<P : AsRef<[u8]>>(payload : P) -> u32 {
let mut hasher = Hasher::new();
hasher.update(payload.as_ref());
hasher.finalize()
}
#[derive(Debug, Clone, PartialOrd, PartialEq)]
pub(crate) struct DataEntry {
crc: u32,... | true |
e4f950a54e736c3cec5e323270039de6ddbcaa8a | Rust | njeisecke/umya-spreadsheet | /src/structs/drawing/charts/view_3d.rs | UTF-8 | 4,371 | 2.71875 | 3 | [
"MIT"
] | permissive | // c:view3D
use super::RotateX;
use super::RotateY;
use super::RightAngleAxes;
use super::Perspective;
use writer::driver::*;
use reader::driver::*;
use quick_xml::Reader;
use quick_xml::events::{Event, BytesStart};
use quick_xml::Writer;
use std::io::Cursor;
#[derive(Default, Debug)]
pub struct View3D {
rotate_x:... | true |
885c8b6f536949c96c922c6be71127ca014ac4f1 | Rust | hppRC/competitive-hpp-rs | /src/utils/math.rs | UTF-8 | 1,929 | 3.453125 | 3 | [
"MIT"
] | permissive | pub trait MathUtils {
/// ## Example:
/// ```
/// use competitive_hpp::prelude::*;
///
/// assert_eq!(16.log2_trunc(), 4);
/// assert_eq!(10.log2_trunc(), 3);
/// ```
fn log2_trunc(self) -> Self;
fn sqrt_floor(self) -> Self;
fn sqrt_ceil(self) -> Self;
}
macro_rules! impl_digit_... | true |
a2c513589c525f46d3851685d3350b7985e49083 | Rust | Hoblovski/riscv | /src/paging/recursive.rs | UTF-8 | 8,006 | 3.03125 | 3 | [
"ISC"
] | permissive | use super::frame_alloc::*;
use super::page_table::*;
use addr::*;
pub trait Mapper {
/// Creates a new mapping in the page table.
///
/// This function might need additional physical frames to create new page tables. These
/// frames are allocated from the `allocator` argument. At most three frames are... | true |
7159b6b3adb3727a2d53e42ea3e5f8360371e5c9 | Rust | mwillsey/simple-lang | /src/syntax/ast.rs | UTF-8 | 5,553 | 3.03125 | 3 | [] | no_license | use std::rc::Rc;
use im::{HashMap as Map, HashSet as Set};
pub type RcType = Rc<Type>;
pub type RcPattern = Rc<Pattern>;
pub type RcExpr = Rc<Expr>;
pub type RcDecl = Rc<Decl>;
#[derive(Debug, PartialEq)]
pub enum Type {
Int,
Float,
Tuple(Vec<RcType>),
Fn(Vec<RcType>, RcType),
Named(Name),
}
pub... | true |
15bdc7b94f27e36df0ede9bf076491c4c47660cd | Rust | triamero/advent-of-code-2018 | /src/days/day3.rs | UTF-8 | 3,853 | 3.015625 | 3 | [
"MIT"
] | permissive | use super::day;
use super::day_result::DayResult;
pub struct Day3();
impl day::Day for Day3 {
fn get_name(&self) -> String {
return String::from("day3");
}
fn compute_first(&self, input: &Vec<String>) -> DayResult {
let claims = input.iter().map(|x| Claim::new(x)).collect::<Vec... | true |
5db0f35a94a4313fd9b5ba78bada82253b718133 | Rust | mdsherry/rocket-auth-login | /src/authorization.rs | UTF-8 | 18,881 | 3.046875 | 3 | [
"Apache-2.0"
] | permissive |
use rocket::{Request, Outcome};
use rocket::response::{Redirect, Flash};
use rocket::request::{FromRequest, FromForm, FormItems, FormItem};
use rocket::http::{Cookie, Cookies};
use std::collections::HashMap;
use std::marker::Sized;
use sanitization::*;
#[derive(Debug, Clone)]
pub struct UserQuery {
pub user: Str... | true |
062d8a4222909eec58ea563a083f3006617b4737 | Rust | fivemoreminix/keycrypt-recrypted | /rust/src/main.rs | UTF-8 | 1,886 | 3.3125 | 3 | [] | no_license | use keycrypt::*;
use std::path::{Path, PathBuf};
use structopt::StructOpt;
#[derive(StructOpt)]
#[structopt(name = "keycrypt", about = "The keyboard-based encryption algorithm.")]
struct Opt {
/// Whether to "encode" or "decode"
#[structopt(short, long, default_value = "auto")]
action: String,
/// Whe... | true |
d7a579da75261a69d4d3ecf38c64352bbe98a3eb | Rust | rust-lang/rust | /tests/ui/borrowck/issue-70919-drop-in-loop.rs | UTF-8 | 502 | 3 | 3 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"BSD-2-Clause",
"LicenseRef-scancode-unicode",
"MIT",
"LicenseRef-scancode-other-permissive"
] | permissive | // Regression test for issue #70919
// Tests that we don't emit a spurious "borrow might be used" error
// when we have an explicit `drop` in a loop
// check-pass
struct WrapperWithDrop<'a>(&'a mut bool);
impl<'a> Drop for WrapperWithDrop<'a> {
fn drop(&mut self) {
}
}
fn drop_in_loop() {
let mut base = ... | true |
7f7e0ab5c6a1dbc2811ad37006fc73ad3ea7213b | Rust | Akagi201/learning-rust | /error-handling/read-file/src/main.rs | UTF-8 | 522 | 3.59375 | 4 | [
"MIT"
] | permissive | fn main() {
let path = "/tmp/dat"; // 文件路径
match read_file(path) {
// 判断方法结果
Ok(file) => {
println!("{}", file)
} // OK 代表读取到文件内容,正确打印文件内容
Err(e) => {
println!("{} {}", path, e)
} // Err 代表结果不存在,打印错误结果
}
}
fn read_file(path: &str) -> Result<St... | true |
c2718a540f2ab8025163df2db359e199d34d46b6 | Rust | spacedragon/rust-git | /src/model/tag.rs | UTF-8 | 5,052 | 2.765625 | 3 | [] | no_license | use super::object::ObjectType;
use super::id::Id;
use super::commit::Identity;
use nom::IResult;
use nom::bytes::complete::{tag, take_while, take_until, take_till};
use nom::combinator::{map_res, rest};
use nom::character::complete::{not_line_ending, line_ending};
use nom::character::is_space;
use crate::model::commit:... | true |
1eb4194e090fe7e4ea8a2e37ee7e9e0e94ef8b20 | Rust | wangjun861205/nbauth-rust | /src/request.rs | UTF-8 | 466 | 2.859375 | 3 | [] | no_license | use serde::Deserialize;
#[derive(Debug, Clone, Deserialize)]
pub struct SignUp {
pub phone: String,
pub password: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct SignIn {
pub phone: String,
pub password: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct VerifyToken(pub String);
#[de... | true |
0eb14bcede809f273baecd8bb2bf0802fb9f2bbd | Rust | lamedh-dev/aws-lambda-rust-runtime | /lambda-http/examples/hello-http-without-macros.rs | UTF-8 | 616 | 2.765625 | 3 | [
"Apache-2.0"
] | permissive | use lamedh_http::{
handler,
lambda::{Context, Error},
IntoResponse, Request, RequestExt, Response,
};
#[tokio::main]
async fn main() -> Result<(), Error> {
lamedh_runtime::run(handler(func)).await?;
Ok(())
}
async fn func(event: Request, _: Context) -> Result<impl IntoResponse, Error> {
Ok(mat... | true |
40092dfd0ab586cfae885aade1e81ed409e63515 | Rust | savnik/aoc2019 | /day02a/src/main.rs | UTF-8 | 1,426 | 3.265625 | 3 | [] | no_license | fn main() {
let mut input = [1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,6,1,19,1,5,19,23,2,6,23,27,1,27,5,31,2,9,31,35,1,5,35,39,2,6,39,43,2,6,43,47,1,5,47,51,2,9,51,55,1,5,55,59,1,10,59,63,1,63,6,67,1,9,67,71,1,71,6,75,1,75,13,79,2,79,13,83,2,9,83,87,1,87,5,91,1,9,91,95,2,10,95,99,1,5,99,103,1,103,9,107,1,13,107,111,2,111,... | true |
0e1ca2a818f6d26e9aa0efdb0dd53a1943e8fedb | Rust | jingfee/advent-of-code-rust | /src/y2020/day25.rs | UTF-8 | 1,600 | 3.15625 | 3 | [] | no_license | use crate::solver::Solver;
use std::fs::File;
use std::io::prelude::*;
use std::io::BufReader;
pub struct Problem;
impl Solver for Problem {
type Input = (usize, usize);
type Output1 = usize;
type Output2 = usize;
fn parse_input(&self, file: File) -> (usize, usize) {
let buf_reader = BufReade... | true |
ea3f3f2580043804ecab352ce6a365b53fbbca6e | Rust | smburdick/dbie | /src/bitmap_vector.rs | UTF-8 | 1,567 | 3.390625 | 3 | [] | no_license |
mod bitmap_vector {
use std::mem;
type Word = u64;
struct BitmapVector {
value: Vec<Word> // TODO could make this an array
}
impl BitmapVector {
fn clone(&self) -> Self {
return Self {
value: self.value.clone()
};
}
fn word_... | true |
dba0d270d57a89c81622ca60b8b7577a8ede0134 | Rust | dhedegaard/adventofcode2017 | /day19/src/main.rs | UTF-8 | 3,760 | 3.875 | 4 | [] | no_license | extern crate time;
use std::fs::File;
use std::io::Read;
use time::now;
type Maze = Vec<Vec<char>>;
#[derive(Debug, PartialEq)]
enum Direction {
Up,
Down,
Left,
Right,
}
fn parse(input: &str) -> Maze {
input.lines().map(|line| line.chars().collect()).collect()
}
fn traverse(maze: &Maze) -> (Str... | true |
aba024edee93dd4707d739713f1bf106f63922a6 | Rust | 0rvar/advent-of-code-2018 | /day06/src/main.rs | UTF-8 | 2,374 | 3.234375 | 3 | [] | no_license | use shared::*;
use std::collections::HashMap;
use std::collections::HashSet;
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
struct Claim {
id: isize,
distance: usize,
}
fn main() {
let input = include_str!("input.txt")
.trim()
.split("\n")
.map(|x| {
let parts = x
... | true |
fa5f7b02086301babbd7ca12c216bea8ec7d1d3a | Rust | timcryt/poker-durak | /src/comb/test.rs | UTF-8 | 12,389 | 2.90625 | 3 | [] | no_license | #[cfg(test)]
mod tests {
use crate::card::*;
use crate::comb::*;
#[test]
fn comb_test_straight_flush() {
assert_eq!(
Comb::new(
vec![
Card {
rank: CardRank::Ten,
suit: CardSuit::Hearts
... | true |
146cf21688d876533ea24703863c7a67b4865587 | Rust | ngortheone/runt | /src/config.rs | UTF-8 | 2,484 | 3.09375 | 3 | [
"MIT"
] | permissive | use std::fs::File;
use std::io::Read;
use std::path::PathBuf;
use std::process::Command;
use std::vec::Vec;
#[derive(Deserialize, Clone)]
pub struct Account {
pub account: String,
pub server: String,
pub port: Option<u16>,
pub username: String,
pub maildir: String,
pub password_command: Option<... | true |
cd5d5eb642185bbeec076f3f947a4b0004c7a7c5 | Rust | brianjimenez/rust-gso | /src/swarm.rs | UTF-8 | 2,326 | 3.03125 | 3 | [
"Apache-2.0"
] | permissive | use super::glowworm::Glowworm;
use super::glowworm::distance;
use rand::Rng;
#[derive(Debug)]
pub struct Swarm {
pub glowworms: Vec<Glowworm>,
}
impl Swarm {
pub fn new() -> Swarm {
Swarm {
glowworms: Vec::new(),
}
}
pub fn add_glowworms(&mut self, positions: &Vec<Vec<f64>>) {
for... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.