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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
38806be6444d4ec42e556ce0c4a255bd1c3ff16d | Rust | bkolad/mini-async-http | /src/io/reactor.rs | UTF-8 | 5,051 | 2.5625 | 3 | [
"MIT"
] | permissive | use log::error;
use slab::Slab;
use std::sync::Arc;
use std::task::Waker;
use crate::data::AtomicTake;
use crate::data::{global_injector, Receiver, Sender};
const DEFAULT_SLAB_SIZE: usize = 16384;
const DEFAULT_EVENTS_SIZE: usize = 16384;
pub(crate) struct Reactor {
poll: mio::Poll,
events: mio::Events,
... | true |
8eab6b0ec73d5d7ece9056f50e9c6f2861ebc3b5 | Rust | badboy/flip-rs | /build.rs | UTF-8 | 3,348 | 2.609375 | 3 | [
"MIT"
] | permissive | extern crate phf_codegen;
use std::env;
use std::fs::File;
use std::io::{ BufWriter, Write };
use std::path::Path;
fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let path = Path::new(&out_dir).join("flip_char.rs");
let mut file = BufWriter::new(File::create(&path).unwrap());
write!(&mut file... | true |
15c1a8be73e98295a7176cca4fdad28bee7ead1c | Rust | vivlim/vivcms | /src/storage/crud/boards.rs | UTF-8 | 1,031 | 2.578125 | 3 | [] | no_license |
use diesel::prelude::*;
use crate::storage::db::models::NewBoard;
use crate::storage::db::models;
use crate::storage::db::schema;
// TODO for boards
// add board ordering
// get last post in board
// get # threads and messages in board?
pub fn create_board(conn: &SqliteConnection, title: String, details: String) ->... | true |
2846ec21a1f2da25af023723d8f5df8fae20885d | Rust | SKyletoft/containers | /vector/src/test_zst.rs | UTF-8 | 3,411 | 3.34375 | 3 | [] | no_license | use crate::*;
#[derive(Copy, Clone, Debug, PartialEq)]
struct ZST;
#[test]
fn add_one() {
let mut vec = Vector::new();
vec.push(1);
assert_eq!(vec.get(0), Some(&1));
}
#[test]
fn insert() {
let mut vec = Vector::new();
vec.push(ZST);
vec.push(ZST);
vec.push(ZST);
vec.push(ZST);
vec.insert(2, ZST);
assert_e... | true |
94280238d14f68c4bcf3e69e2c8fc8e23745ec11 | Rust | cham7irxc5zb/understanding-memory-models | /src/util.rs | UTF-8 | 942 | 3.359375 | 3 | [] | no_license | pub trait VecPushFastExt<T> {
fn push_fast(&mut self, value: T);
fn extend_from_slice_fast(&mut self, v: &[T])
where
T: Clone;
}
impl<T> VecPushFastExt<T> for Vec<T> {
#[inline(always)]
fn push_fast(&mut self, v: T) {
let n = self.len();
if n >= self.capacity() {
... | true |
089c286d6bff9e5f26f7080fbc3333ce77886404 | Rust | gdetal/rust-packet | /src/udp/mod.rs | UTF-8 | 2,232 | 2.671875 | 3 | [
"WTFPL"
] | permissive | // DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
// Version 2, December 2004
//
// Copyleft (ↄ) meh. <meh@schizofreni.co> | http://meh.schizofreni.co
//
// Everyone is permitted to copy and distribute verbatim or modified
// copies of this license document, and changing it is allowed as long... | true |
c5dbfe77443bfc16525acc199310d90f02c83762 | Rust | 01intelligence/hulk | /src/utils/units.rs | UTF-8 | 475 | 2.65625 | 3 | [
"Apache-2.0"
] | permissive | use super::Duration;
pub const KIB: usize = 1 << (1 * 10);
pub const MIB: usize = 1 << (2 * 10);
pub const MINUTE: u64 = 60;
pub const HOUR: u64 = MINUTE * 60;
pub const fn milliseconds(n: u64) -> Duration {
Duration::from_millis(n)
}
pub const fn seconds(n: u64) -> Duration {
Duration::from_secs(n)
}
pub ... | true |
c805f19c588b483e9f4ab6a1c7f47e8162a11fbb | Rust | Bombfuse/emerald | /emerald/examples/sprites.rs | UTF-8 | 2,915 | 2.828125 | 3 | [
"MIT"
] | permissive | use emerald::{rendering::components::Sprite, *};
pub fn main() {
let mut settings = GameSettings::default();
settings.render_settings.resolution = (320, 180);
emerald::start(
Box::new(SpritesExample {
world: World::new(),
}),
settings,
)
}
pub struct SpritesExample ... | true |
9a42c8e08ff63d2607a03175495be8ef69e93f9b | Rust | jasoncabot-ms/rust-web-helloworld | /src/main.rs | UTF-8 | 653 | 2.8125 | 3 | [
"MIT"
] | permissive | use actix_web::{web, App, HttpRequest, HttpServer, Responder};
use std::env;
fn greet(req: HttpRequest) -> impl Responder {
let name = req.match_info().get("name").unwrap_or("World");
format!("Hello {}!", &name)
}
fn main() {
let key = "PORT";
let env_value;
match env::var(key) {
Ok(val) =... | true |
055b0d762b0e71a6fa8824f43674db28de121baf | Rust | jiangyangmu/LearnRust | /HelloOwnership/HelloOwnership.rs | UTF-8 | 1,383 | 3.53125 | 4 | [] | no_license | fn fun_move(s : String) -> String {
s
}
fn fun_ref(s : &String) -> &String {
s
}
fn fun_refmut(s : &mut String) -> &String {
s.push_str(" World");
s
}
fn main() {
// Move by default
let movesrc1 = String::from("Hello");
let movesrc2 = String::from("Hello");
let varmove = movesrc1;
let varclone = varmove.clo... | true |
7390047cfa0ffce211c2bbe2bf34b4bda4a04e88 | Rust | lucas-miranda/Raccoon-Rust | /src/rendering/backend/hal/error/hal_graphics_pipeline_error.rs | UTF-8 | 1,550 | 2.6875 | 3 | [
"MIT"
] | permissive | use std::{
error::{
Error
},
fmt::{
self,
Display,
Formatter
}
};
use gfx_hal::{
device,
pso
};
use crate::{
rendering::{
ShaderStage
}
};
#[derive(Debug)]
pub enum HalGraphicsPipelineError {
ShaderModuleCreationFailed {
stage: Shade... | true |
48258a4500e7e22b343c74db320e0da4a25de165 | Rust | F3kilo/vk_raii | /examples/init.rs | UTF-8 | 841 | 2.765625 | 3 | [] | no_license | use log::LevelFilter;
use std::error::Error;
use std::fmt;
use vk_raii::instance;
fn main() {
env_logger::builder()
.filter_level(LevelFilter::max())
.init();
let init_result = init();
init_result.expect("Vulkan can't be initialized")
}
fn init() -> Result<(), InitError> {
let entry = ... | true |
b0c322c4a4a09866f04fbed2cad245feaadd9f18 | Rust | redstrike/paddlers-browser-game | /paddlers-game-master/src/game_master/town_defence.rs | UTF-8 | 6,345 | 3 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! This module deals with visitor groups (attacks) leaving towns again and calculating the outcome of the visit.
//!
//! A fight report is generated as soon as all visitors have left or have been satisfied.
//! Usually, the satisfaction of each visitor is only computed when time is up for an attack to be finished.
//!... | true |
8a219349f258e526378ac1c20cb18c7812d6a5d1 | Rust | dropbox/dropbox-sdk-rust | /src/generated/secondary_emails.rs | UTF-8 | 3,981 | 2.71875 | 3 | [
"Apache-2.0"
] | permissive | // DO NOT EDIT
// This file was @generated by Stone
#![allow(
clippy::too_many_arguments,
clippy::large_enum_variant,
clippy::doc_markdown,
)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive] // structs may have more fields added in the future.
pub struct SecondaryEmail {
/// Secondary email a... | true |
41473ddc26fe9beea67b7fa81a19bcb676626ef7 | Rust | rust-rosetta/rust-rosetta | /tasks/soundex/src/lib.rs | UTF-8 | 2,351 | 3.375 | 3 | [
"Unlicense"
] | permissive | use std::collections::HashMap;
pub fn soundex(word: &str) -> String {
let dropped_vowels = ['a', 'e', 'i', 'o', 'u', 'y'];
let mut consonants_value = HashMap::new();
let letter_groups = vec![
vec!['b', 'f', 'p', 'v'],
vec!['c', 'g', 'j', 'k', 'q', 's', 'x', 'z'],
vec!['d', 't'],
... | true |
a79e8436445df7b1b37fba787e14ac11721beed2 | Rust | augusto-mantilla/rust-exercises | /changes/src/main.rs | UTF-8 | 503 | 2.84375 | 3 | [] | no_license | /*
## error types
### Instructions
Make this code compile
*/
fn main() {
let ref mut a = String::from("Hello");
let len = a.len();
let b = &a;
add_excitement(a);
println!("The len of {} is {}", a, len);
println!("The length of {} is {}", b, b.len());
}
fn add_excitement(s: &mut String) {
s.push_str("!");
... | true |
c2141bb06219fc8bd7b705de6231f0e0c23d49a6 | Rust | savage13/geotherm | /src/erf.rs | UTF-8 | 30,402 | 3.1875 | 3 | [
"MIT"
] | permissive |
/// Error Function Trait
///
/// Implementation based on [Netlib Specfun 2.5](http://www.netlib.org/specfun/)
///
/// Translated from Fortran March 2019
///
/// ## References
/// - Cody, W. (1990), Performance evaluation of programs for the error
/// and complementary error functions, ACM Transactions on Mathema... | true |
35470a3a33e0b0333e751c5c8bb27d9a5916cae4 | Rust | gnames/gnverify-rs | /src/format.rs | UTF-8 | 931 | 3.171875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use super::GNVerifyError;
use strum_macros::Display;
/// Indicates desired format for the output;
#[derive(Debug, Display, Clone)]
pub enum Format {
/// Outputs verification results in CSV format.
CSV,
/// Outputs verification results in as a compact JSON format.
Compact,
/// Outputs verification r... | true |
17077a9c307f92fd223461e79e6be70582aec23e | Rust | feadoor/rustdoku | /src/generator/patterns.rs | UTF-8 | 7,171 | 3.203125 | 3 | [] | no_license | //! Processes to generate Sudoku puzzles with a specific pattern of clues.
use itertools::Itertools;
use std::collections::HashSet;
use rand::prelude::*;
use generator::brute_force::BruteForceSolver;
use generator::canonicalization::minlex;
use grid::{Grid, GridSize};
/// A convenience type to represent a ... | true |
6eed7c91c340f8478eabb383a3595146c32909fb | Rust | ronweikamp/aoc2020 | /src/day9.rs | UTF-8 | 1,857 | 3.046875 | 3 | [] | no_license | use crate::utils::read;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_day9_part1_example() {
assert_eq!(day9_part1("data/day9/example", 5), 127);
}
#[test]
fn test_day9_part1() {
assert_eq!(day9_part1("data/day9/input", 25), 105950735);
}
#[test]
fn t... | true |
7f66cbf780061f2c6336e5e4838df0325ca6d268 | Rust | SeSodesa/rustla | /src/parser/tests/test_converters.rs | UTF-8 | 1,947 | 2.78125 | 3 | [
"MIT"
] | permissive | /*!
A submodule for testing converter functions.
Copyright © 2020 Santtu Söderholm
*/
use super::*;
use crate::parser::converters;
#[cfg(test)]
#[test]
fn upper_roman_to_usize_01() {
let iii = "III";
let iv = "IV";
let mmmmcmxcix = "MMMMCMXCIX";
let over_max = "MMMMCMXCX";
let iii_as_u32 = match... | true |
415d047c1064cee4cf48bfce951c47de53672982 | Rust | dmit/time | /tests/integration/compile-fail/invalid_time.rs | UTF-8 | 593 | 2.890625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | use time::macros::time;
fn main() {
let _ = time!(24:00); //~ERROR invalid component: hour was 24
let _ = time!(0:60); //~ERROR invalid component: minute was 60
let _ = time!(0:00:60); //~ERROR invalid component: second was 60
let _ = time!(x); //~ERROR unexpected token: x
let _ = time!(0:00:00 x);... | true |
1789b66a907ba02055f642606d9a59276eefd558 | Rust | aosp-riscv/toolchain_rustc | /vendor/dissimilar/tests/test.rs | UTF-8 | 696 | 2.671875 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"BSD-3-Clause",
"BSD-2-Clause",
"LicenseRef-scancode-other-permissive",
"NCSA"
] | permissive | // Upstream diff-match-patch's test suite is imported as unit tests in
// src/tests.rs, as they test APIs which are private in the Rust implementation.
//
// This directory is for Rust-specific integration tests and regression tests.
use dissimilar::{diff, Chunk};
#[test]
fn test_unicode() {
// Unicode snowman an... | true |
4ddc2d85754bee8bbcb4401c0ba3868726ab98bf | Rust | malkoG/RustPython | /compiler/src/error.rs | UTF-8 | 3,046 | 3.125 | 3 | [
"MIT"
] | permissive | use rustpython_parser::error::{LexicalErrorType, ParseError, ParseErrorType};
use rustpython_parser::location::Location;
use rustpython_parser::token::Tok;
use std::error::Error;
use std::fmt;
#[derive(Debug)]
pub struct CompileError {
pub error: CompileErrorType,
pub location: Location,
}
impl From<ParseErr... | true |
0ea67629f4c3bdbd0f3ecc717e6152416a5a1bfe | Rust | xunilrj/sandbox | /sources/rust/codescanner/scanner-cli/src/console_reporter.rs | UTF-8 | 871 | 2.515625 | 3 | [
"Apache-2.0"
] | permissive | use scan::{reporter::ScanReporter, ScanError, ScanResult};
pub struct ConsoleScanReporter {}
impl ConsoleScanReporter {
pub fn new() -> Self {
Self {}
}
}
impl ScanReporter for ConsoleScanReporter {
fn report(
&mut self,
result: &std::result::Result<ScanResult, ScanError>,
) -... | true |
76cef3d087d6394b462e632c7be93b5f378836da | Rust | shadowDragonCloud/rosario | /src/utils.rs | UTF-8 | 950 | 2.625 | 3 | [
"Apache-2.0"
] | permissive | use anyhow::{anyhow, Context};
use ego_tree::NodeRef;
use scraper::element_ref::ElementRef;
use scraper::node::Node;
use scraper::Selector;
use std::iter::Iterator;
pub(crate) fn parse_book_id(book_page_url: &str) -> String {
let url_segments = book_page_url
.rsplit('/')
.filter(|s| !s.is_empty())
... | true |
7feea905f8a10ca0c3f9336bafb02100e1f65955 | Rust | Agile-Llama/Rust-Stuff | /FirstTextSearch/src/main.rs | UTF-8 | 1,350 | 3.84375 | 4 | [] | no_license | use std::fs::File;
use std::io::prelude::*;
fn main() {
let mut file = File::open("output.txt")
.expect("Can't Open File!"); //need this for if something fails.
let mut contents = String::new(); //create a new String object which holds the read in text
file.read_to_string(&mut contents)
... | true |
bedd5df07243540e6b70935b9f30fee4965280d7 | Rust | stackcats/leetcode | /algorithms/medium/number_of_islands.rs | UTF-8 | 690 | 2.9375 | 3 | [
"MIT"
] | permissive | fn dfs(grid: &mut Vec<Vec<char>>, i: usize, j: usize) {
grid[i][j] = '0';
for (dx, dy) in [(-1, 0), (0, 1), (1, 0), (0, -1)] {
let ni = (i as i32 + dx) as usize;
let nj = (j as i32 + dy) as usize;
if ni < grid.len() && nj < grid[0].len() && grid[ni][nj] == '1' {
dfs(grid, ni,... | true |
c83e14d9a9ccf7712e5d3952527f2a290af189e0 | Rust | SNES-Dev/SNES-Dev | /w65-abi-extra/src/fp16.rs | UTF-8 | 3,591 | 2.921875 | 3 | [
"MIT",
"GPL-3.0-only",
"LGPL-3.0-or-later",
"LGPL-3.0-only"
] | permissive | #[allow(non_camel_case_types)]
#[repr(transparent)]
// TODO: There really should be a repr(float) in rust, but until then, floats and ints have the same abi
#[derive(Copy, Clone, Hash, Default)]
///
/// A type that acts like a 16-bit floating-point type. This has the same layout and ABI as the `_Float16` C type
/// And... | true |
c13c80bacdac3304abad064086d1abdcf3382ae4 | Rust | lucdew/rusoto-example | /src/credentials.rs | UTF-8 | 3,399 | 2.609375 | 3 | [] | no_license | use crate::client::HttpClient;
use crate::config;
use anyhow::Context;
use anyhow::Result;
use dialoguer::Input;
use rusoto_core::region::Region;
use rusoto_credential::StaticProvider;
use rusoto_sts::{AssumeRoleRequest, GetSessionTokenRequest, Sts, StsClient};
use std::sync::Arc;
use chrono::prelude::*;
#[derive(De... | true |
62cd063b1d6c1b329394f9769ee47d458595d387 | Rust | yskszk63/ssssh | /src/msg/request_success.rs | UTF-8 | 636 | 2.765625 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use derive_new::new;
use super::*;
#[derive(Debug, new)]
pub(crate) struct RequestSuccess {
additional_data: Bytes,
}
impl MsgItem for RequestSuccess {
const ID: u8 = 81;
}
impl Pack for RequestSuccess {
fn pack<P: Put>(&self, buf: &mut P) {
buf.put(&self.additional_data);
}
}
impl Unpack f... | true |
e4a5bcd77e7c465d9b1ba75b9c584e2f0d7809eb | Rust | sith98/rust-tictactoe | /src/player.rs | UTF-8 | 1,234 | 3.3125 | 3 | [] | no_license | mod human_player;
mod minimax_player;
mod random_player;
use super::board::{Board, Index, Piece};
use rand::Rng;
use std::fmt::Display;
pub use human_player::HumanPlayer;
pub use minimax_player::MinimaxPlayer;
pub use random_player::RandomPlayer;
pub trait Player: Display {
fn play(&self, board: &Board, piece: P... | true |
30bbe0d59acf328deaacd3e47be4cd6cbb7cf675 | Rust | andoriyu/fd | /src/exec/mod.rs | UTF-8 | 6,672 | 2.953125 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | // Copyright (c) 2017 fd developers
// 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. All files in the project carrying such
// notice may not be copied, modifi... | true |
4899b81df65aee086edf9afc2aa1e220361098aa | Rust | lineCode/barnes-hut-rs | /src/quadtree/tree.rs | UTF-8 | 7,550 | 3.34375 | 3 | [
"MIT"
] | permissive | //! Quadtree that keeps track of centers of mass.
use super::BoundingBox2D;
use crate::vector::{Scalar, Vector3D};
const EPSILON: Scalar = 1e-4;
/// Computes the l2 norm of a 2d vector represented by x1, y1, x2, y2
fn l2(x1: Scalar, y1: Scalar, x2: Scalar, y2: Scalar) -> Scalar {
let dx: Scalar = x2 - x1;
let... | true |
4e453063a14d81f46b48b9622d8afd684b7553ea | Rust | wulymammoth/rust-dsa | /src/data_structures/queue.rs | UTF-8 | 756 | 3.6875 | 4 | [] | no_license | use std::collections::LinkedList;
pub struct Queue {
data: LinkedList<i32>,
}
#[allow(dead_code)]
impl Queue {
fn new() -> Self {
Queue {
data: LinkedList::new(),
}
}
fn enqueue(&mut self, item: i32) {
&self.data.push_back(item);
}
fn dequeue(&mut self) ->... | true |
74e57de67400c3f5e796e36d17ca2f581374b733 | Rust | baszalmstra/rosty | /crates/rosty/tests/parameters.rs | UTF-8 | 1,693 | 3.15625 | 3 | [
"MIT"
] | permissive | pub mod util;
#[test]
fn test_parameter_api() {
util::run_with_node(async {
let parameters = rosty::param_names()
.await
.expect("No parameters could be retrieved from the ROS master");
assert!(
parameters.len() > 0,
"No parameters were found on the R... | true |
5b9fc000e4fd6670a020b2e18358441fee9901e4 | Rust | rust-console/gba | /src/mmio.rs | UTF-8 | 19,168 | 2.609375 | 3 | [] | permissive | #![cfg_attr(rustfmt, rustfmt::skip)]
//! Contains all the MMIO address definitions for the GBA's components.
//!
//! This module contains *only* the MMIO addresses. The data type definitions
//! for each MMIO control value are stored in the appropriate other modules such
//! as [`video`](crate::video), [`interrupts`](... | true |
b4dfed860b56ffb47e5a7ff1f11ab4f4bd6f7e02 | Rust | yeslogic/fathom | /fathom/src/surface/distillation.rs | UTF-8 | 32,691 | 2.84375 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! Bidirectional distillation of the core language into the surface language.
use scoped_arena::Scope;
use crate::alloc::SliceVec;
use crate::core;
use crate::core::{Const, Plicity, UIntStyle};
use crate::env::{self, EnvLen, Index, Level, UniqueEnv};
use crate::source::Span;
use crate::surface::elaboration::MetaSour... | true |
6290951c81e529e7204043ba7c2364cc6ee0c688 | Rust | feifeiq/example.rs | /src/prim.rs | UTF-8 | 428 | 3.203125 | 3 | [] | no_license | #![feature(lang_items)]
fn main() {
let x=1234567u32;
let mut primes:Vec<u32>=Vec::new();
let f1=|x:u32|{
let mut ret=false;
let mut y=(x as f32).sqrt().floor() as u32;
while x>=2&&y>1&&!ret{
ret |= x % y==0;
y-=1;
}
!ret
};
for x in 1..1_000_000{
if f1(x) {print!("{:?},", x);};
}
println!... | true |
c79a6a0b22dbec174d3faa6a2684f44dd8edd271 | Rust | leshow/retry_fn | /src/lib.rs | UTF-8 | 7,064 | 3.3125 | 3 | [
"MIT"
] | permissive | #![doc(html_root_url = "https://docs.rs/retry_fn/0.2.0")]
//! # retry
//!
//! Function for executing retry either as a closure with a std-based sleep
//! (`thread::sleep`) or using either of the most popular async runtimes. See
//! `tokio` or `async-std` module for futures-aware versions.
//!
//! ## Sync Example
//!
//... | true |
c49149ef6b24e27344d4fd281fb6b55062eb2721 | Rust | zmilan/puck | /puck_codegen/src/sm.rs | UTF-8 | 1,447 | 2.90625 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use proc_macro2::TokenStream;
use quote::quote;
use crate::handler::Handler;
use crate::handler::Segment;
/// Generate code to call the relevant route, if it matches the path in question.
pub fn route_matcher(handler: &Handler) -> TokenStream {
let path: String = handler.at.clone();
let segments = path
... | true |
14a41d82fb92612e74f59aaa4f1003b0e31f68ba | Rust | kittydepa/guessing_game | /src/main.rs | UTF-8 | 1,937 | 4.1875 | 4 | [] | no_license | use std::io; // Use the io library from standard. Allows you to accept user input
use std::cmp::Ordering; // for Less, Greater, Equal
use rand::Rng; // We bring the Rng trait from the rand crate into this scope
fn main() { // Entry point to the program
println!("Guess the number!");
let secret_number = rand:... | true |
4db8af5e8e83c03c9b2edabe0f0ee34fb67ebe66 | Rust | p2mate/aoc2020 | /day2/src/main.rs | UTF-8 | 2,411 | 3.21875 | 3 | [
"Apache-2.0"
] | permissive | #[derive(Debug, Clone)]
struct PasswordPolicy {
min: usize,
max: usize,
letter: char,
password: String,
}
use std::io;
fn check_one(input: &[PasswordPolicy]) -> usize {
input
.iter()
.filter(|x| {
let count = x.password.match_indices(x.letter).count();
count... | true |
09593e5cbc91d4c97769194f487c42a40a21cba7 | Rust | Devolutions/gfwx-rs | /src/errors.rs | UTF-8 | 2,082 | 2.921875 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use std::{error::Error, fmt, io};
#[derive(Debug)]
pub enum CompressError {
IOErr(io::Error),
Overflow,
Malformed,
}
#[derive(Debug)]
pub enum DecompressError {
IOErr(io::Error),
Unsupported,
Underflow,
Malformed,
TypeMismatch,
}
impl From<io::Error> for CompressError {
fn from(er... | true |
f2e5fdb66176ca11dc6d0770f2e8384d1458f5eb | Rust | czyczk/LeetCode | /rust/lc-766/src/main.rs | UTF-8 | 399 | 2.75 | 3 | [] | no_license | mod solution;
use solution::Solution;
fn main() {
let matrix1 = vec![
vec![1, 2, 3, 4],
vec![5, 1, 2, 3],
vec![9, 5, 1, 2],
];
let matrix2 = vec![
vec![1, 2],
vec![2, 2],
];
// Expecting true
println!("{}", Solution::is_toeplitz_matrix(matrix1));
/... | true |
d168d728a0398f454cb33590625e8449bf33431c | Rust | sria91-rlox/lox-rs-4 | /src/lox_err.rs | UTF-8 | 1,143 | 3.75 | 4 | [] | no_license | use std::fmt;
#[derive(Debug)]
pub struct LoxErr {
line: usize,
message: String,
}
impl LoxErr {
pub fn new(line: usize, message: String) -> LoxErr {
LoxErr {
line: line,
message: message,
}
}
pub fn display_message(&self) -> String {
format!("[Line... | true |
d79b3a396825bb3cfadc1ca8ae57b6fa951f827c | Rust | brygga-dev/workdir2 | /tools/frontend/src/ast.rs | UTF-8 | 3,616 | 3.25 | 3 | [
"MIT"
] | permissive | #[derive(Debug, PartialEq)]
pub enum Node {
// Html tag
Tag(Tag),
Text(String),
// (Name, Vec<(PropKey, Option<PropValue>))
Component {
name: String,
props: Vec<(String, Option<String>)>,
children: Vec<Node>,
},
// Inline script
Script {
script: String,
... | true |
74ef49bcbe25c5f9ccf0c81922e8262bcefcb487 | Rust | nus-cs4215/sourceror | /lib-backend-wasm/src/gc/cheney/wasmtest.rs | UTF-8 | 9,561 | 2.5625 | 3 | [] | no_license | use super::*;
use wasm_test_harness::*;
pub fn wasmtest<C: TestContext>(c: &mut C) {
c.add_test("no roots", |code_builder, wasm_module, error_func, t| {
/*
In this test we will create a Cheney with the initial size (1MiB usuable size),
and add 32768 copies of 28-byte structs (which will exa... | true |
5c79921593393f76a16f530bf080a8a2bbd506ad | Rust | Frederik-Baetens/axum | /examples/validator/src/main.rs | UTF-8 | 2,680 | 3.046875 | 3 | [] | permissive | //! Run with
//!
//! ```not_rust
//! cargo run -p example-validator
//!
//! curl '127.0.0.1:3000?name='
//! -> Input validation error: [name: Can not be empty]
//!
//! curl '127.0.0.1:3000?name=LT'
//! -> <h1>Hello, LT!</h1>
//! ```
use async_trait::async_trait;
use axum::{
body::{Bytes, Full},
extract::{Form,... | true |
8d8eb89fcc5d149782c12d3907b0260d6948eb1d | Rust | Orangeices/pyduckling | /build.rs | UTF-8 | 1,297 | 2.546875 | 3 | [
"MIT"
] | permissive | use std::path::Path;
use std::process::Command;
use std::{env, str};
fn command_ok(cmd: &mut Command) -> bool {
cmd.status().ok().map_or(false, |s| s.success())
}
fn command_output(cmd: &mut Command) -> String {
str::from_utf8(&cmd.output().unwrap().stdout)
.unwrap()
.trim()
.to_string... | true |
91edbd9ff6cdb77268aa16c191bdac939952fe6f | Rust | blakesmith/arrow2 | /src/compute/comparison/simd/mod.rs | UTF-8 | 2,718 | 3.125 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | use crate::types::NativeType;
/// [`NativeType`] that supports a representation of 8 lanes
pub trait Simd8: NativeType {
/// The 8 lane representation of `Self`
type Simd: Simd8Lanes<Self>;
}
/// Trait declaring an 8-lane multi-data.
pub trait Simd8Lanes<T>: Copy {
/// loads a complete chunk
fn from_c... | true |
4c609b9308e3d737af729f082824376550f94195 | Rust | jamespharaoh/countdown | /src/lib.rs | UTF-8 | 11,084 | 3.234375 | 3 | [] | no_license | use std::cmp::Reverse;
use std::fmt;
use std::rc::Rc;
pub fn solve (numbers: & [u64], target: u64) -> Vec <Expression> {
let expressions = numbers.iter ().map (
|& number| Expression::constant (number),
).collect::<Vec <_>> ();
let solutions = combine (& expressions).iter ().skip_while (
|expr| expr.value () ... | true |
85dce3c9e500101ef520b83513587795afe8135c | Rust | SpaceEraser/liquidfun-rust | /src/box2d/dynamics/joints/weld_joint.rs | UTF-8 | 4,705 | 2.5625 | 3 | [
"MIT"
] | permissive | use libc::c_void;
use std::ptr;
use super::super::super::dynamics::world::{B2World, World};
use super::super::super::common::math::*;
use super::super::super::common::settings::*;
use super::super::super::dynamics::body::{B2Body, Body};
use super::{JointType, JointDef, Joint, B2Joint, b2Joint_GetNext};
/// Revolute j... | true |
e0e4884a5194d991cbc4d1442d37725723e7907b | Rust | kaidiren/learn-rust | /leetcode/todo/14/longest-common-prefix/src/main.rs | UTF-8 | 245 | 3.046875 | 3 | [] | no_license | struct Solution;
impl Solution {
pub fn longest_common_prefix(strs: Vec<String>) -> String {}
}
fn main() {
println!(
"{}",
Solution::longest_common_prefix(vec![String::from("flower"), String::from("flight")])
);
}
| true |
f4e5d8b7cabd7734ce1040d55bae51936b33d065 | Rust | nham/reinforcement_learning | /tictactoe.rs | UTF-8 | 5,737 | 3.375 | 3 | [] | no_license | use std::hashmap::HashMap;
use game::Game;
use player::{Player, RandomPlayer, RLPlayer, PX, PO};
mod game {
use std::fmt::{Show, Formatter};
use std::fmt;
#[deriving(Eq)]
pub enum Cell {
Nil,
X,
O,
}
impl Show for Cell {
fn fmt(&self, f: &mut Formatter) -> fmt... | true |
348e04df45a8aff1cfc7c889c0d907f99f274506 | Rust | IThawk/rust-project | /rust-master/src/test/ui/associated-const/associated-const-type-parameter-arms.rs | UTF-8 | 518 | 2.71875 | 3 | [
"MIT",
"LicenseRef-scancode-other-permissive",
"Apache-2.0",
"BSD-3-Clause",
"BSD-2-Clause",
"NCSA"
] | permissive | pub enum EFoo { A, B, C, D }
pub trait Foo {
const X: EFoo;
}
struct Abc;
impl Foo for Abc {
const X: EFoo = EFoo::B;
}
struct Def;
impl Foo for Def {
const X: EFoo = EFoo::D;
}
pub fn test<A: Foo, B: Foo>(arg: EFoo) {
match arg {
A::X => println!("A::X"),
//~^ error: associated con... | true |
20cbe524cfa3b63e8d06f67e803754f578c71849 | Rust | livingthought/Cursive | /src/utils/lines/spans/row.rs | UTF-8 | 576 | 3.09375 | 3 | [
"MIT"
] | permissive | use super::Segment;
use utils::span::{Span, SpannedString};
/// A list of segments representing a row of text
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Row {
/// List of segments
pub segments: Vec<Segment>,
/// Total width for this row
pub width: usize,
}
impl Row {
/// Resolve the row ind... | true |
ebd7033d925d70b5ff04ad584ceb461886bdf741 | Rust | owen8877/leetcode-rs | /src/problem_2.rs | UTF-8 | 1,842 | 3.59375 | 4 | [] | no_license | #[derive(PartialEq, Eq, Clone, Debug)]
struct ListNode {
pub val: i32,
pub next: Option<Box<ListNode>>
}
impl ListNode {
#[inline]
fn new(val: i32) -> Self {
ListNode {
next: None,
val
}
}
}
fn add_two_numbers(l1: Option<Box<ListNode>>, l2: Option<Box<ListNo... | true |
d4b4ed79305e3bddb8d8564b65afd3d524c181b9 | Rust | ecclarke42/from-regex | /src/tests.rs | UTF-8 | 4,052 | 3.328125 | 3 | [] | no_license | use super::*;
use crate as from_regex;
#[derive(Debug, Clone, PartialEq, Eq, FromRegex)]
#[from_regex(pattern = "abc(?P<named>def)")]
struct MyStruct {
named: String,
}
lazy_static! {
static ref MY_STRUCT: MyStruct = MyStruct {
named: String::from("def")
};
}
#[derive(Debug, Clone, PartialEq, Eq,... | true |
b00c82bce29b5872525ca18b87de07568a6a019f | Rust | mikroncoin/mikron_node | /load-tester/src/rpc.rs | UTF-8 | 2,937 | 2.734375 | 3 | [
"BSD-2-Clause"
] | permissive | use std::fmt;
use futures::{Future, Stream};
use futures::future;
use tokio_core::reactor::Handle;
use hyper::{self, Request, Uri};
use hyper::client::{Connect, HttpConnector};
use hyper::header::{ContentLength, ContentType};
use serde::{Deserialize, Serialize};
use serde_json::{self, Value};
#[derive(Debug)]
pub... | true |
43aa474ad94237d710816d8d2949b8e8cb79073b | Rust | LPGhatguy/two-stroke | /src/vertex.rs | UTF-8 | 327 | 2.78125 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | gfx_vertex_struct! {
Vertex {
position: [f32; 3] = "a_Pos",
color: [f32; 3] = "a_Color",
}
}
impl Vertex {
pub fn new(x: f32, y: f32, z: f32) -> Vertex {
Vertex { position: [x, y, z], color: [1.0, 1.0, 1.0] }
}
pub fn from_position(position: [f32; 3]) -> Vertex {
Vertex { position, color: [1.0, 1.0, 1.0]... | true |
a464b9fc3ed8ab53e5f3a864b5e4908942d3c9b6 | Rust | pcein/trust-rust | /code/product-types/tuples/a3.rs | UTF-8 | 130 | 3.46875 | 3 | [] | no_license |
fn main() {
let p = (1,2,3.0);
// de-structuring let
let (x, y, z) = p;
println!("{}, {}, {}", x, y, z);
}
| true |
06ca514b5cc3a91591c8767457acedb5eab39b14 | Rust | camden-smallwood-zz/blam-rs | /src/math/vector2d.rs | UTF-8 | 372 | 3.015625 | 3 | [] | no_license | #[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
pub struct Vector2d<T> {
pub i: T,
pub j: T
}
impl<T> Vector2d<T> {
pub fn new(i: T, j: T) -> Vector2d<T> {
Vector2d { i, j }
}
}
impl<T: Default> Default for Vector2d<T> {
fn default() -> Self {
Self::n... | true |
c3fd8f3459fe5d295b61554b4c948c22c741d686 | Rust | chdsbd/eve | /src/slack.rs | UTF-8 | 750 | 2.875 | 3 | [] | no_license | use serde_json::{json, Value};
#[derive(Debug)]
pub enum SlackError {
HttpError(reqwest::Error),
}
impl std::convert::From<reqwest::Error> for SlackError {
fn from(e: reqwest::Error) -> Self {
Self::HttpError(e)
}
}
/// https://slack.com/api/chat.postMessage
pub fn chat_post_message(token: &str, ... | true |
2e5a058a250d116d0641a20c25c0835633856484 | Rust | ferm10n/dansible-rust | /capi/src/metadata.rs | UTF-8 | 2,027 | 2.671875 | 3 | [
"MIT"
] | permissive | use eventual::Async;
use std::sync::Arc;
use std::ffi::CStr;
use std::cell::UnsafeCell;
use librespot::metadata::{MetadataTrait, MetadataRef};
use cstring_cache::CStringCache;
use session::SpSession;
pub struct UnsafeSyncCell<T> {
cell: UnsafeCell<T>
}
impl <T> UnsafeSyncCell<T> {
fn new(value: T) -> Unsaf... | true |
64b2c3c85eb8aeb2e5c289a90417b4368df887ad | Rust | althonos/uniprot.rs | /src/uniparc/mod.rs | UTF-8 | 4,812 | 3.0625 | 3 | [
"MIT"
] | permissive | //! Data types for the UniParc database.
use std::io::BufRead;
mod model;
#[doc(inline)]
pub use self::model::*;
/// The sequential parser type for UniParc entries.
pub type SequentialParser<B> = super::parser::SequentialParser<B, UniParc>;
#[cfg(feature = "threading")]
/// The threaded parser type for UniParc ent... | true |
abb1a6728feec9adb9783bacc95e355f9ceef0d8 | Rust | reformat0r/nae | /examples/gfx_textured_cube.rs | UTF-8 | 4,376 | 2.734375 | 3 | [] | no_license | use nae::prelude::*;
use nalgebra_glm as glm;
struct State {
texture: Texture,
pipeline: Pipeline,
vertex_buffer: VertexBuffer,
clear: ClearOptions,
vertices: [f32; 180],
rx: f32,
ry: f32,
tex_location: Uniform,
mvp_location: Uniform,
mvp: glm::Mat4,
}
#[nae::main]
fn main() {
... | true |
befcf84b94e171bf526f0fd3d90698766de0915e | Rust | cirho/powerline-rust | /src/modules/time.rs | UTF-8 | 792 | 2.625 | 3 | [
"MIT"
] | permissive | use std::marker::PhantomData;
use chrono;
use super::Module;
use crate::{Color, Powerline, Style};
pub struct Time<S: TimeScheme> {
time_format: &'static str,
scheme: PhantomData<S>,
}
pub trait TimeScheme {
const TIME_BG: Color;
const TIME_FG: Color;
}
impl<S: TimeScheme> Time<S> {
pub fn new(... | true |
237fd6f2e6b6da27b1daa74db3dac0c6739df3cd | Rust | 8BitMate/reflect | /tests/test_subtypes.rs | UTF-8 | 4,436 | 2.859375 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use quote::quote;
use reflect::*;
library! {
use subtypes {
type Subtypes;
type SameLifetime<'a, T>;
impl Subtypes {
fn sub1<'a, 'b, 'c, T, U>(&'a T, &'b U) -> &'c U where 'a: 'b;
fn sub2<'c, 'b: 'c, 'd, U, V>(&'b U, &'c V) -> &'d V;
fn sub3<'c, 'd, V, W... | true |
b81f2c57ffdd3e48fa2fbe6f908efa5507e241c8 | Rust | ezhang887/extract-cli | /src/utils.rs | UTF-8 | 1,661 | 2.828125 | 3 | [
"MIT"
] | permissive | extern crate clap;
use clap::{App, Arg};
use std::path::Path;
use std::process::Command;
use crate::commands;
use crate::errors;
pub fn parse_args() -> String {
let matches = App::new("extract")
.version("0.1.0")
.author("Eric Zhang <ezhang887@gmail.com>")
.arg(
Arg::with_name... | true |
a37d36b8bd353ebc4137aff3d3359aa23c1cc169 | Rust | Tockra/ma_random_data_generator | /src/main.rs | UTF-8 | 7,958 | 3.140625 | 3 | [
"BSD-2-Clause"
] | permissive | extern crate rand_distr;
use std::io::Write;
use std::fs::{File, create_dir_all};
use std::io::BufWriter;
use rand_distr::{Normal, Distribution, Uniform};
use std::time::Instant;
use std::cmp::Ord;
use std::io::Read;
use std::collections::BTreeSet;
use uint::{u40,u48};
use uint::Typable;
fn main() {
let args: ... | true |
784d5eade3f8cf3c4a8b59501c1471797125b476 | Rust | arynh/cs419-ray-tracer | /src/hittable/mesh.rs | UTF-8 | 4,558 | 3.21875 | 3 | [
"MIT"
] | permissive | use crate::hit_record::HitRecord;
use crate::hittable::aabb::AABB;
use crate::hittable::bvh::BVH;
use crate::hittable::triangle::Triangle;
use crate::hittable::Hittable;
use crate::material::MaterialType;
use crate::ray::Ray;
use glm::Vec3;
pub struct Mesh {
triangles: BVH,
}
impl Hittable for Mesh {
/// If a... | true |
d04da5ade407e93422bb637a6ffee2de9192ed96 | Rust | slmccart/advent-of-code | /2015/05_doesnt_he_have_intern-elves_for_this/src/main.rs | UTF-8 | 4,997 | 3.703125 | 4 | [] | no_license | use std::fs;
use pcre::Pcre;
fn main() {
let strings = read_input("input.txt");
let strings: Vec<&str> = strings.split('\n').collect();
let mut nice_strings = 0;
let mut nice_strings_new_rules = 0;
for string in strings {
if is_nice_string(string) { nice_strings += 1 }
if is_nice_s... | true |
1af5e5cc1ca18feb7919421a3eb5611e6e0305cb | Rust | russelltg/srt-rs | /srt-protocol/src/packet/modular_num.rs | UTF-8 | 6,400 | 3.421875 | 3 | [
"Apache-2.0"
] | permissive | /// Defines a macro to define a modular number that uses a predefined number of bits
use std::fmt::{self, Display, Formatter};
#[derive(Debug)]
pub struct OutOfRangeError(pub &'static str);
impl Display for OutOfRangeError {
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
write!(f, "Number ou... | true |
48919709c98e03668f81f5fb8f5831668815bad9 | Rust | oxidecomputer/third-party-api-clients | /slack/src/chat.rs | UTF-8 | 7,916 | 2.96875 | 3 | [
"MIT"
] | permissive | use crate::Client;
use crate::ClientResult;
pub struct Chat {
pub client: Client,
}
impl Chat {
#[doc(hidden)]
pub fn new(client: Client) -> Self {
Chat { client }
}
/**
* This function performs a `POST` to the `/chat.delete` endpoint.
*
* Deletes a message.
*
* F... | true |
710bbb23a14ce7f22f828fdda2320e103923553c | Rust | stmtk1/100knock-rs | /src/main.rs | UTF-8 | 2,479 | 2.96875 | 3 | [] | no_license | use std::fs::{ self, File, OpenOptions };
use rand::seq::SliceRandom;
use std::io::{ Write, BufWriter };
fn main() -> Result<(), Box<dyn std::error::Error>> {
let train_news: Vec<News> = fs::read_to_string("train.txt")?.split('\n').filter_map(|s| News::new(String::from(s))).collect();
let valid_news: Vec<News>... | true |
fdcc085f416ba8e2c88e3631a07ae68ec9cc092d | Rust | ksakiyama/practice_atcoder | /abc096d/src/main.rs | UTF-8 | 621 | 3.296875 | 3 | [] | no_license | fn read() -> i32 {
let mut s = String::new();
std::io::stdin().read_line(&mut s).ok();
s.trim().parse().ok().unwrap()
}
fn isprime(p: i32) -> bool {
if p == 1 {
return false;
}
for i in 2..p {
if p % i == 0 {
return false;
}
}
return true;
}
fn main(... | true |
ff8edbcc73e7c2a7fe70abcf351264888c9bf6a5 | Rust | dreambo8563/actix-demo | /src/utils/logger.rs | UTF-8 | 1,488 | 2.640625 | 3 | [] | no_license | use crate::utils::ENV;
use slog::LevelFilter;
use slog::{o, Drain, FnValue, Level, Logger};
use std::fs::OpenOptions;
use std::sync::Mutex;
const APP_NAME: &str = "demo App";
pub struct Logging {
pub logger: Logger,
}
impl Logging {
pub fn new() -> Logger {
//! if path includes in logconfig, log to f... | true |
ff41d8ecf26a45052de319e77d5533a641195e51 | Rust | eij/rs-convert | /src/drivers/jpg.rs | UTF-8 | 1,306 | 2.734375 | 3 | [
"Unlicense"
] | permissive | extern crate image;
use std::fs::File;
use std::io::{self, Write, Seek, SeekFrom};
use std::path::PathBuf;
use self::image::{ImageOutputFormat, GenericImageView};
use crate::structs::Settings;
struct Dimension {
w: u32,
h: u32,
}
pub fn convert_to_jpg(entry: &PathBuf, destination: &PathBuf, settings: &Settings) ... | true |
68c892b93d28e98c2c8dc5d0a5658150fa66332e | Rust | suspend0/aws-sdk-rust | /sdk/mediapackagevod/src/client.rs | UTF-8 | 74,464 | 2.640625 | 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 = aws_smithy_client::erase::DynConnector,
M = aws_hyper::AwsMiddleware,
R = aws_smithy_client::retry::Standard,
> {
client: aws_smithy_client::Client<C, M, R>,
conf: crate::C... | true |
28f813fe8e3bd4b7caa38ecae0ef8500da6d942a | Rust | peter-signal/dtls | /src/cipher_suite/cipher_suite_tls_psk_with_aes_128_gcm_sha256.rs | UTF-8 | 2,698 | 2.734375 | 3 | [
"MIT"
] | permissive | use super::*;
use crate::crypto::crypto_gcm::*;
use crate::prf::*;
#[derive(Clone)]
pub struct CipherSuiteTLSPskWithAes128GcmSha256 {
gcm: Option<CryptoGcm>,
}
impl CipherSuiteTLSPskWithAes128GcmSha256 {
const PRF_MAC_LEN: usize = 0;
const PRF_KEY_LEN: usize = 16;
const PRF_IV_LEN: usize = 4;
}
impl ... | true |
3eb84941f67ef52c0dd46d6a0a3b542899624174 | Rust | holochain/holochain-anchors | /src/lib.rs | UTF-8 | 4,878 | 2.703125 | 3 | [
"MIT"
] | permissive | use hdk::{
self,
error::ZomeApiResult,
holochain_core_types::entry::Entry,
holochain_persistence_api::cas::content::{Address, AddressableContent},
};
use serde_derive::{Deserialize, Serialize};
use hdk::prelude::*;
pub mod defs;
pub use defs::*;
const ROOT_ANCHOR: &'static str = concat!("holochain_a... | true |
f966fe1555345d683fb7cf47c00ca6fbaa662f0f | Rust | chromium/chromium | /third_party/rust/static_assertions/v1/crate/src/assert_trait.rs | UTF-8 | 3,106 | 3.65625 | 4 | [
"BSD-3-Clause",
"Apache-2.0",
"MIT",
"GPL-1.0-or-later",
"LGPL-2.0-or-later"
] | permissive | /// Asserts that the trait is a child of all of the other traits.
///
/// Related:
/// - [`assert_trait_super_all!`]
///
/// # Examples
///
/// All types that implement [`Copy`] must implement [`Clone`]:
///
/// ```
/// # #[macro_use] extern crate static_assertions; fn main() {}
/// assert_trait_sub_all!(Copy: Clone);
... | true |
8f44bc8318359f3032a62664531f1a39bd53b8f3 | Rust | rustgd/gsf | /gsf_rlua/src/util.rs | UTF-8 | 7,674 | 2.765625 | 3 | [] | no_license | use std::collections::VecDeque;
use gsf::{self, ValueTy};
use rlua::{self, Value};
use super::*;
pub fn to_lua_err(err: gsf::Error) -> rlua::Error {
match err {
gsf::Error::MissingSelfArg => rlua::Error::FromLuaConversionError {
from: "missing argument",
to: "self",
me... | true |
acc87b5dc1c3d9734c8108bbbba6e057cb839160 | Rust | sharkdp/hyperfine | /tests/execution_order_tests.rs | UTF-8 | 7,242 | 3.046875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use std::{fs::File, io::Read, path::PathBuf};
use tempfile::{tempdir, TempDir};
mod common;
use common::hyperfine;
struct ExecutionOrderTest {
cmd: assert_cmd::Command,
expected_content: String,
logfile_path: PathBuf,
#[allow(dead_code)]
tempdir: TempDir,
}
impl ExecutionOrderTest {
fn new()... | true |
90dae430a95ba103ead8e85b9a683c1e0a31f5a6 | Rust | gaultier/aoc-2020 | /src/one_a.rs | UTF-8 | 588 | 3 | 3 | [] | no_license | use std::fs::File;
use std::io::Read;
use itertools::Itertools;
pub fn solve() {
let mut f = File::open("1a.txt").unwrap();
let mut content = String::new();
f.read_to_string(&mut content).unwrap();
let numbers = content
.lines()
.filter(|l| !l.trim().is_empty())
.map(|l| l.par... | true |
30fbbaf64b51e711f98e5f9cf99fa52e10562e78 | Rust | seungha-kim/base95 | /examples/print_random.rs | UTF-8 | 615 | 2.90625 | 3 | [
"MIT"
] | permissive | use base95::Base95;
use rand::prelude::*;
fn main() {
let mut v = vec![Base95::mid()];
let mut rng = thread_rng();
for _ in 0..1000 {
let pos: usize = rng.gen_range(0..=v.len());
if pos == 0 {
v.insert(pos, Base95::avg_with_zero(&v[pos]));
} else if pos == v.len() {
... | true |
51bd2053da9df57a821520c41c6b0924e209a687 | Rust | EnsicoinDevs/ensicoin-message | /src/message/inv.rs | UTF-8 | 1,498 | 2.53125 | 3 | [
"MIT"
] | permissive | use ensicoin_serializer::types::Sha256Result;
use ensicoin_serializer::{Deserialize, Serialize};
use crate::message::{Message, MessageType};
#[derive(Serialize, Deserialize)]
pub struct InvVect {
pub data_type: crate::message::ResourceType,
pub hash: Sha256Result,
}
impl std::fmt::Debug for InvVect {
fn ... | true |
3a2a2b9e4492757624f1301c0b2459f3df2fde04 | Rust | nimbol/euler | /rust/src/bin/p021.rs | UTF-8 | 2,232 | 3.90625 | 4 | [] | no_license | use std::collections::HashMap;
/// # Amicable numbers
/// Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly
/// into n).
/// If d(a) = b and d(b) = a, where a ≠ b, then a and b are an amicable pair and each of a and b are
/// called amicable numbers.
///
/// For example, t... | true |
6223b2fd58cc2567f3c9fba8e94b5ef5369ed146 | Rust | forkkit/semaphore | /general/tests/test_derive.rs | UTF-8 | 3,014 | 2.921875 | 3 | [
"MIT"
] | permissive | use semaphore_general::processor::process_value;
use semaphore_general::processor::ProcessValue;
use semaphore_general::processor::ProcessingState;
use semaphore_general::processor::Processor;
use semaphore_general::protocol::HeaderName;
use semaphore_general::types::Annotated;
use semaphore_general::types::Meta;
use s... | true |
dd7b07247b6887f14d1ad9906f3259c68ada4154 | Rust | kodek16/colang | /colang/src/ast/globals.rs | UTF-8 | 2,855 | 3.21875 | 3 | [
"MIT"
] | permissive | //! AST node definitions for global program structure. Global structure is everything starting
//! from the root `Program` node but stopping at function bodies (not including them).
use crate::ast::expressions::Expression;
use crate::ast::type_expressions::TypeExpr;
use crate::ast::Identifier;
use crate::source::Input... | true |
b8ae3105d2fda57a13a6d55ae72a82586cab24db | Rust | ftilde/rust-x86asm | /src/test/instruction_tests/instr_bts.rs | UTF-8 | 15,583 | 2.53125 | 3 | [
"MIT"
] | permissive | use instruction_def::*;
use test::run_test;
use Operand::*;
use Reg::*;
use RegScale::*;
use RegType::*;
use {BroadcastMode, Instruction, MaskReg, MergeMode, Mnemonic, OperandSize, Reg, RoundingMode};
#[test]
fn bts_1() {
run_test(
&Instruction {
mnemonic: Mnemonic::BTS,
operand1: S... | true |
b83a2a531bca85d6fa696f33acdf2db001110961 | Rust | zerokpr/AtCoderProblems | /atcoder-problems-backend/src/error.rs | UTF-8 | 528 | 2.921875 | 3 | [
"MIT"
] | permissive | use serde::export::Formatter;
/// Since http_types::Error is a wrapper of anyhow::Error, but it can not be constructed from anyhow::Error,
/// let's us http_types::Error as anyhow::Error.
pub type Result<T> = std::result::Result<T, http_types::Error>;
#[derive(Debug)]
pub(crate) enum ErrorTypes {
InvalidRequest,
... | true |
c5580b12f03a634b3f6193599c6dc25195c70472 | Rust | TimUntersberger/nogscript | /interpreter/src/expression.rs | UTF-8 | 1,673 | 3.0625 | 3 | [] | no_license | use itertools::Itertools;
use std::collections::HashMap;
use std::ops::Range;
use super::{
ast::AstNode,
formatter::Formatter,
operator::Operator,
token::{Token, TokenKind},
};
#[derive(Clone, Debug, PartialEq)]
pub enum ExpressionKind {
BinaryOp(Box<Expression>, Operator, Box<Expression>),
Po... | true |
b623871d1f4a2d34bfdf8c7972cf10382599f7d6 | Rust | jmcolella/advent-of-code-2020 | /src/day_9/solution.rs | UTF-8 | 2,220 | 3.15625 | 3 | [] | no_license | use std::fs;
fn parse_file() -> Vec<usize> {
let file = fs::read_to_string("src/day_9/input.txt").unwrap();
let mut values: Vec<usize> = Vec::new();
for l in file.lines() {
values.push(l.parse::<usize>().unwrap());
}
return values;
}
fn part_one(list: &Vec<usize>) -> usize {
let preamble = 25;
l... | true |
d6e709e0d43dc3ec1913db6b625da05a9fd1e067 | Rust | panicbit/weechat_relay_rust | /src/object/array.rs | UTF-8 | 666 | 2.734375 | 3 | [] | no_license | use std::io::Read;
use byteorder::{ReadBytesExt,BigEndian as BE};
use super::{Object,Tag,DecodableObject,read_tag};
use errors::*;
pub type Array = Vec<Object>;
impl DecodableObject for Array {
const TAG: Tag = b"arr";
fn decode_bare<R: Read + ?Sized>(r: &mut R) -> Result<Self> {
let elem_tag = read_... | true |
d1261e9126fa21e674441e790e05f17e6c917d57 | Rust | azdavis/advent-of-code | /years/y2015/src/d12.rs | UTF-8 | 744 | 3.265625 | 3 | [
"MIT"
] | permissive | use serde_json::{from_str, Value};
fn parse(s: &str) -> Value {
from_str(s.trim()).unwrap()
}
fn sum_val(v: &Value, p2: bool) -> i64 {
match v {
Value::Null | Value::Bool(_) | Value::String(_) => 0,
Value::Number(n) => n.as_i64().unwrap(),
Value::Array(vs) => vs.iter().map(|v| sum_val(v, p2)).sum(),
... | true |
bfef94116a3f68e85943de7ec6c61b1b71dca803 | Rust | MuhammadUmersiddiqui/Calculator | /src/lib.rs | UTF-8 | 2,813 | 3.453125 | 3 | [] | no_license | mod calculator{
mod basic_fuctions {
use std::io;
pub fn add() {
println!("please enter x = ");
let mut x = String::new();
io::stdin().read_line(&mut x);
let x:i32= x.trim().parse().unwrap();
println!("please enter y = ");
let... | true |
6ddddb40b9f5cabbcd64019d04909ca3915aa211 | Rust | jblebrun/wrausmt | /src/format/text/lex/error.rs | UTF-8 | 1,380 | 3.09375 | 3 | [
"MIT"
] | permissive | #[derive(Debug)]
pub enum LexError {
WithContext(Vec<String>, Box<LexError>),
IoError(std::io::Error),
Utf8Error(std::string::FromUtf8Error),
UnexpectedChar(char),
InvalidEscape(u8),
}
pub type Result<T> = std::result::Result<T, LexError>;
pub trait WithContext<T>: Sized {
fn ctx(self, ctx: &s... | true |
31c2ce96731c3918f1aa9b1c7b06b42c31f0e5fb | Rust | vitorhnn/sliding-puzzle | /src/main.rs | UTF-8 | 5,600 | 2.984375 | 3 | [
"Unlicense"
] | permissive | extern crate nalgebra as na;
use std::collections::HashSet;
use std::collections::BinaryHeap;
use std::cmp::Ordering;
use std::io;
use na::{Matrix3};
#[derive(Debug, Clone, Eq, PartialEq)]
enum Direction {
Up,
Down,
Left,
Right,
}
#[derive(Debug, Clone, Eq, PartialEq)]
struct BoardState {
board: ... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.