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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
8f3c827b9f27aeba7d5fbb37c236564fbda1beab | Rust | zentner-kyle/match-diagram | /src/tiny_map.rs | UTF-8 | 3,724 | 3.375 | 3 | [] | no_license | use std::cmp::PartialEq;
use std::fmt;
use std::mem;
use std::slice;
use std::vec;
pub struct TinyMap<K, V>
where
K: PartialEq,
{
data: Vec<(K, V)>,
}
impl<K, V> TinyMap<K, V>
where
K: PartialEq,
{
pub fn new() -> Self {
TinyMap { data: Vec::new() }
}
pub fn with_capacity(capacity: us... | true |
2d55e9fa802461da91d151addde2ea04fa7bab02 | Rust | LuoZijun/es | /crates/vm/src/error.rs | UTF-8 | 3,414 | 3.3125 | 3 | [
"MIT"
] | permissive | use std::fmt;
/*
Prop:
filename: String,
line_number: usize,
column_number: usize,
Prototype:
name: String
message: String
toString: Function
*/
#[derive(Debug, Clone)]
pub struct Error {
line_number: usize,
column_number: usize,
filename: String,
message: String,
stack: ... | true |
4a3726fa2f529db5da1acf4145afca539d355908 | Rust | Gopiandcode/rust-projects | /cond_sync/src/classroom.rs | UTF-8 | 2,722 | 3.109375 | 3 | [] | no_license | extern crate rand;
use std::sync::{Arc, Condvar, Mutex};
use std::time;
use std::thread;
use self::rand::Rng;
/*
* Classroom struct
*
*
*/
pub struct ClassroomInternal {
waiting_spaces: i16,
free_computers: u32,
}
pub struct Classroom (Arc<(Mutex<ClassroomInternal>,Condvar)>);
impl Classroom {
pu... | true |
e9c5087a1b22dd9b1d1eb157e297353f925bc92d | Rust | savish/rosalind | /src/lib.rs | UTF-8 | 4,396 | 3.5 | 4 | [] | no_license | //! # Rosalind project
//!
//! The Rosalind project is a platform for learning bioinformatics through problem solving.
//! More information about the project is available at http://rosalind.info/about/
//!
//! This repository contains solutions to some of the rosalind problems. Each propblem is available as a subcomman... | true |
1063d4fcf11541902bf88d59456df53b96981a2d | Rust | joecargill/git-diary | /src/main.rs | UTF-8 | 2,753 | 2.890625 | 3 | [
"MIT"
] | permissive | use std::env;
use std::io;
use std::io::prelude::*;
use std::fs::File;
use std::path::Path;
use chrono::{DateTime, Utc};
use git2::Repository;
use git2::{Commit, ObjectType};
use git2::{Oid, Signature};
fn main() -> Result<(), git2::Error> {
let now: DateTime<Utc> = Utc::now();
let stdin = io::stdin();
let r... | true |
cf1bae0708337363d97dce3fbe4e0854ac6d73d0 | Rust | bouzuya/rust-atcoder | /cargo-atcoder/contests/code-festival-2017-qualb/src/bin/a.rs | UTF-8 | 218 | 2.53125 | 3 | [] | no_license | use proconio::input;
use proconio::marker::Chars;
fn main() {
input! {
s: Chars,
};
let n = s.len();
let ans = s[0..n - "FESTIVAL".len()].iter().collect::<String>();
println!("{}", ans);
}
| true |
9cb61998e7e357e19fc88f8a696aa737d2df443c | Rust | TorelTwiddler/rust_checkers | /src/piece.rs | UTF-8 | 118 | 2.78125 | 3 | [] | no_license | /// A Piece on the board.
#[derive(Debug, Copy, Clone)]
pub struct Piece {
pub player: i32,
pub king: bool,
}
| true |
0dcaa0053a41752f9a7cc3eb2a99caae04f4e272 | Rust | djmittens/learn-rust | /rust-language-book/minigrep/src/main.rs | UTF-8 | 880 | 2.875 | 3 | [] | no_license | use minigrep;
use minigrep::Config;
use std::collections::HashMap;
use std::env;
use std::process;
fn main() {
// let query = &args[1];
// let filename = &args[2];
// let args: Vec<String> = env::args().collect();
let envVars: HashMap<String, String> = env::vars().collect();
let config = Config::n... | true |
3e2f381f6183c974f86e2824cce9a12c385ef591 | Rust | mike-barber/advent-of-code-2020-rust | /day16/src/main.rs | UTF-8 | 7,651 | 3.03125 | 3 | [] | no_license | use anyhow::{anyhow, Result};
use lazy_static::lazy_static;
use regex::Regex;
use std::{collections::HashSet, ops::RangeInclusive, str::FromStr};
#[derive(Debug, Clone)]
struct FieldRange(Vec<RangeInclusive<i32>>);
impl FieldRange {
fn create(ranges: Vec<RangeInclusive<i32>>) -> Self {
FieldRange(ranges)
... | true |
9af8eae2f1dd05396194fbc669d8b3dcdd27e7fd | Rust | nambrosini/adventofcode | /2015/src/day02.rs | UTF-8 | 1,339 | 3.3125 | 3 | [] | no_license | #[aoc_generator(day2)]
pub fn generator(input: &str) -> Vec<Vec<usize>> {
input
.lines()
.map(|x| {
x.split('x')
.map(|x| x.parse().unwrap())
.collect::<Vec<usize>>()
})
.map(|x| {
let mut x = x;
x.sort_unstable();
... | true |
8999f4367362389673bb6415e60baee69a5353bd | Rust | kulp/tyrga | /tyrga-lib/src/exprtree.rs | UTF-8 | 3,315 | 3.734375 | 4 | [] | no_license | use std::borrow::Cow;
use std::fmt;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Operation {
Add,
Sub,
}
impl fmt::Display for Operation {
fn fmt(&self, f : &mut fmt::Formatter) -> fmt::Result {
use Operation::*;
match self {
Add => write!(f, "+"),
Sub => write!(... | true |
6a8de372bcff2bbf1bbf81a1c1cdcf14dfb7436d | Rust | mjkoo/rtxon | /src/image.rs | UTF-8 | 3,773 | 3.09375 | 3 | [
"Apache-2.0"
] | permissive | use core::marker::PhantomData;
use std::alloc::{alloc, dealloc, Layout};
use std::io::Result;
use std::mem::size_of;
use std::path::Path;
use image::{ImageBuffer, Pixel};
use raw_cpuid::CpuId;
use scoped_threadpool::Pool;
/// Determine the size of a cache line, used to align allocations and prevent false sharing
fn c... | true |
7f0e8aceed38071bdc160c2dbd5e1663c33e4ca2 | Rust | kmeisthax/retrogram | /src/ast/instr.rs | UTF-8 | 755 | 3.328125 | 3 | [] | no_license | //! Instruction AST type
use crate::ast::{Literal, Operand};
use std::{slice, str};
#[derive(Clone, Debug)]
pub struct Instruction<L>
where
L: Literal,
{
/// The instruction being executed
opcode: String,
/// Operands for the instruction, if any
operands: Vec<Operand<L>>,
}
impl<L> Instruction<L... | true |
52d33d352b4b0ea53a2e6913b5b2a9acbd5bf1ef | Rust | nrskt/rust-serde-sample | /csv/src/pattern_1.rs | UTF-8 | 3,918 | 3 | 3 | [] | no_license | use std::marker::PhantomData;
use core::SampleValue;
use serde::{de, Deserialize, Serialize, Serializer};
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Deserialize)]
struct CsvValue<T, Target>(T, PhantomData<Target>);
impl<T, Target> Serialize for CsvValue<T, Target>
where
T: Serialize,
{
fn seriali... | true |
872aa56a336ca9717e310a993a82f806ca1921c0 | Rust | ilya-mezentsev/cloud-box | /cbox/src/controllers/handlers.rs | UTF-8 | 3,393 | 2.671875 | 3 | [] | no_license | use crate::commands::factory::{CommandFactory, RespondingCommand, SilentCommand};
use crate::controllers::presenter;
use crate::models::commands::{
CreateFile, CreateFolder, DeleteFile, DeleteFolder, GetFile, GetFolder, Rename,
};
pub fn server_options() -> rouille::Response {
presenter::make_empty_response()
... | true |
225d924b62ced2c716cb5cbe31c1cce127b6d6dd | Rust | oxidecomputer/cio | /cio-api-types/src/swag_inventory.rs | UTF-8 | 411 | 2.546875 | 3 | [
"Apache-2.0"
] | permissive | use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
/// A request to print labels.
#[derive(Debug, Clone, Default, JsonSchema, Deserialize, Serialize)]
pub struct PrintRequest {
#[serde(default, skip_serializing_if = "String::is_empty")]
pub url: String,
#[serde(default)]
pub quantity: i32,
... | true |
c95e67bc1a8e0b8decf8dfe2f1091089fe1bb753 | Rust | jeremyletang/rust-sfml | /src/audio/listener.rs | UTF-8 | 3,460 | 3.859375 | 4 | [
"Zlib"
] | permissive | //! The audio listener is the point in the scene from where all the sounds are heard.
//!
//! The audio listener defines the global properties of the audio environment,
//! it defines where and how sounds and musics are heard.
//!
//! If [`View`] is the eyes of the user, then `listener` is his ears (by the way, they ar... | true |
0f0c2001a62635bf2a00284aaee19588d789c8e4 | Rust | kyokomi/rust-sandbox | /startup/examples/variables.rs | UTF-8 | 1,587 | 3.734375 | 4 | [] | no_license | fn main() {
let spaces = " ";
let spaces = spaces.len();
println!("The value of spaces is: {}", spaces);
let guess: u32 = "42".parse().expect("Not a number!");
println!("The value of guess is: {}", guess);
// 整数型
let x = 5;
let x = x + 1;
let x = x * 2;
println!("The value of... | true |
86f6e9076554e3acab8baed0914ba1a991141ea8 | Rust | miracle2k/corporeal | /tools/to-keepassx/src/main.rs | UTF-8 | 2,240 | 2.6875 | 3 | [] | no_license | extern crate encoding;
extern crate kpdb;
extern crate chrono;
mod pwstore;
mod delphi_date;
use std::fs::File;
use std::env;
use std::io;
use std::io::Write;
use std::io::BufReader;
use std::path::Path;
use pwstore::{PWStore};
use chrono::{DateTime, Utc, TimeZone};
use kpdb::{CompositeKey, Database, Entry};
use kpd... | true |
4d0121bf09084bc566137e3df4e424e4573ff9f9 | Rust | ZcashFoundation/zebra | /zebrad/src/components/mempool/gossip.rs | UTF-8 | 4,084 | 2.890625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0",
"MIT"
] | permissive | //! A task that gossips any [`zebra_chain::transaction::UnminedTxId`] that enters the mempool to peers.
//!
//! This module is just a function [`gossip_mempool_transaction_id`] that waits for mempool
//! insertion events received in a channel and broadcasts the transactions to peers.
use std::collections::HashSet;
us... | true |
290ede35f9d93aa081760b03cd2bd25f8002b8c5 | Rust | harshanavkis/vmsh | /src/tracer/ptrace_syscall_info.rs | UTF-8 | 4,681 | 2.53125 | 3 | [
"MIT"
] | permissive | use crate::result::Result;
use nix::unistd::Pid;
use simple_error::bail;
use simple_error::try_with;
use std::mem::size_of;
use std::mem::MaybeUninit;
#[cfg(all(target_os = "linux", target_env = "gnu"))]
const PTRACE_GET_SYSCALL_INFO: u32 = 0x420e;
#[cfg(not(all(target_os = "linux", target_env = "gnu")))]
const PTRAC... | true |
16d69bc8b1290a81931b753b01bdba284a232ad0 | Rust | ZakisM/regedit_rust | /src/util.rs | UTF-8 | 334 | 2.515625 | 3 | [] | no_license | use std::ffi::OsStr;
use std::os::windows::ffi::OsStrExt;
pub trait StringExt {
fn to_lpcwstr(&self) -> Vec<u16>;
}
impl StringExt for &str {
#[inline]
fn to_lpcwstr(&self) -> Vec<u16> {
OsStr::new(self)
.encode_wide()
.chain(Some(0).into_iter())
.collect::<Vec<... | true |
788002ae10a73a0bb9dcbe7ccd25fcd817b650f0 | Rust | fits/try_samples | /rust/stock_management_model/sample2/src/main.rs | UTF-8 | 2,475 | 2.84375 | 3 | [] | no_license |
mod models;
use models::{ Stock, StockMove, Restore };
fn main() {
let item1 = "item-1".to_string();
let loc1 = "maker-A".to_string();
let loc2 = "store-B".to_string();
let loc3 = "user-C".to_string();
let stock1 = Stock::unmanaged_new(item1.clone(), loc1.clone());
let stock2 = Stock::manag... | true |
1fca7d3f9291c3a110d7350655b369e66bf5d218 | Rust | rosarp/hackerrank-rust-practice | /algorithm/30-days-of-code/running-time-and-complexity/running-time-and-complexity.rs | UTF-8 | 775 | 3.484375 | 3 | [
"MIT"
] | permissive | use std::io;
fn is_prime(x : i64) -> bool {
if x == 1 {
return false;
}
let mut flag : bool = true;
for i in 2..x {
if x % i == 0 {
flag = false;
break;
}
if i*i > x {
break;
}
}
flag
}
fn main() {
let mut n = Stri... | true |
5460b09e7a5b0af37cb48fcfa46b675eb6b14028 | Rust | katis/rust-webgl-demo | /src/game.rs | UTF-8 | 4,792 | 2.546875 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use crate::assets::{ImageId, Images};
use crate::components::{Position, Velocity};
use crate::gl::Gl;
use crate::input_system::{BunnyCount, InputEvent, InputSystem};
use crate::move_system::MoveSystem;
use crate::render_system::{DisplayEvent, RenderSystem, Sprite, Transform, WindowSize};
use anyhow::Result;
use rand::R... | true |
3072fe757423b7fb39f68294ef716978d5a873e8 | Rust | selassje/nes-rs | /src/mappers/mapper_internal.rs | UTF-8 | 5,648 | 2.84375 | 3 | [] | no_license | use serde::{Deserialize, Deserializer, Serialize};
trait BoxedArrayDeserialize<'de>: Sized {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>;
}
impl<'de, T, const N: usize> BoxedArrayDeserialize<'de> for Box<[T; N]>
where
T: Default + Copy + Deseri... | true |
c971e29fc142dff6fe6133efc828fca630d0d132 | Rust | YSawc/lio | /src/token/error.rs | UTF-8 | 507 | 2.859375 | 3 | [
"MIT"
] | permissive | use super::super::location::location::*;
use super::super::token::token::*;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum TokenErrorKind {
InvalidToken(char),
InvalidNumber(Token),
}
pub type TokenError = Annot<TokenErrorKind>;
impl TokenError {
pub fn invalid_token(c: char, loc: Loc) -> Self {
... | true |
29876d306fe9dedebcbc0f5debc303426aae949a | Rust | dmitri-mamrukov/heap-in-rust | /tests/integration_test.rs | UTF-8 | 10,957 | 3.125 | 3 | [] | no_license | #[allow(dead_code)]
mod test_util {
use heap_in_rust::Heap;
pub fn assert_peek_on_empty_heap(heap: &Heap) {
let result = heap.peek();
assert!(result.is_err());
assert_eq!("Empty heap.".to_string(), result.unwrap_err());
}
pub fn assert_ok_result(result: Result<(), String>) {
... | true |
60b5f3e17fe52034cb87aeb4b8533919ab147575 | Rust | hrektts/piece-of-code | /hackerrank/algorithms/bit_manipulation/the-great-xor/src/main.rs | UTF-8 | 375 | 2.828125 | 3 | [] | no_license | use std::io::{self, BufRead};
fn main() {
let io = io::stdin();
let mut lines = io.lock().lines().filter_map(|s| s.ok());
let q = lines.next().unwrap().trim().parse::<usize>().ok().unwrap();
for _ in 0..q {
let x = lines.next().unwrap().trim().parse::<u64>().ok().unwrap();
println!("{... | true |
68376c87bb332d2e9add5f590ca1854ded67420a | Rust | IGI-111/xit | /src/core.rs | UTF-8 | 7,244 | 2.75 | 3 | [] | no_license | #![allow(dead_code)]
use std::thread;
use std::sync::{Arc, Mutex};
use std::sync::mpsc::{self, Sender, Receiver};
use std::collections::HashMap;
use serde_json;
use std::process::{Stdio, Command, ChildStdin, ChildStdout};
use std::io::{self, BufReader, BufRead, Write};
pub type Update = serde_json::Value;
pub type Re... | true |
bb9c90848995914e487345fd9771526c43d42254 | Rust | Eduardo-Vinicius/Estudo-Linguagem-RUST | /src/Rota/CompoundLooping.rs | UTF-8 | 357 | 2.90625 | 3 | [] | no_license |
pub fn e1_Ordernar(mut num:Vec<i32>) -> Vec<i32>{
let mut i = 0;
let mut j = 0;
while i < num.len(){
while j < num.len(){
if num[j] < num[i]{
let aux = num[i];
num[i] = num[j];
num[j] = aux;
}
j += 1;
}
... | true |
3fa9327875f7ee81292ce6727c70011bb03f643a | Rust | maslabgamer/advent_of_code_2020 | /src/bin/problem_5.rs | UTF-8 | 840 | 3.203125 | 3 | [] | no_license | fn main() {
let all_passes = decode_all_passes();
println!("Problem 5 part 1 solution: {}", all_passes.iter().max().unwrap());
println!("Problem 5 part 2 solution: {}", find_missing_seat(&mut all_passes.clone()));
}
fn find_missing_seat(all_passes: &mut Vec<i32>) -> i32 {
all_passes.sort();
(all_pa... | true |
812c4a8fc063933895564e8b93481601bbb1969a | Rust | roualdes/bridgestan | /rust/examples/example.rs | UTF-8 | 1,421 | 2.65625 | 3 | [
"CC-BY-4.0",
"BSD-3-Clause"
] | permissive | use bridgestan::{open_library, BridgeStanError, Model};
use std::ffi::CString;
use std::path::Path;
fn main() {
// The path to the compiled model.
// Get for instance from python `bridgestan.compile_model`
let path = Path::new(env!["CARGO_MANIFEST_DIR"])
.parent()
.unwrap()
.join("t... | true |
e8a94827338794518677734fb246b3ee756f02c6 | Rust | anvie/markdown.rs | /src/parser/block/code_block.rs | UTF-8 | 1,970 | 3.3125 | 3 | [
"MIT"
] | permissive | use regex::Regex;
use parser::Block;
use parser::Block::CodeBlock;
pub fn parse_code_block(lines: &[&str]) -> Option<(Block, usize)>{
let CODE_BLOCK_SPACES = Regex::new(r"^ {4}").unwrap();
let CODE_BLOCK_TABS = Regex::new(r"^\t").unwrap();
let mut content = String::new();
let mut i = 0;
for line i... | true |
8035aefd7807e86f32691f4db8d6ff6aa802d927 | Rust | sm921/pattern-making | /clothes/src/pattern/base/front.rs | UTF-8 | 1,301 | 2.796875 | 3 | [] | no_license | use pmdraw::shapes::{bezier::Bezier, line::Line};
use crate::pattern::{common::dart::Dart, measurements::Cm};
#[derive(Clone)]
pub struct Front {
pub center: Line,
pub arm_hole: (Bezier, Bezier),
pub dart: Dart,
pub neck: Bezier,
pub chest_dart: Dart,
pub shoulder: Line,
pub side: Line,
... | true |
598ca3f83b96704e140d326e024d4c7bf4cda460 | Rust | tangentstorm/tangentlabs | /rust/partitions.rs | UTF-8 | 2,849 | 3.5625 | 4 | [] | no_license | /// generate the the C(n,k) possible partitions you can create
/// by splitting a set of n items into subsets of length k and n-k
use std::clone;
struct PartitionGenerator<T: clone::Clone> {
k: usize, xs: Vec<T>,
i: usize, state: PGState, // internal flow control stuff.
held: Option<T>, // held an... | true |
47451c88860c9046f5a7ccbf03c1cf8c750014ca | Rust | nicolashahn/advent-of-code | /2020/d09/src/main.rs | UTF-8 | 1,132 | 3.359375 | 3 | [] | no_license | fn p1(nums: &[usize]) -> usize {
'outer: for window in nums.windows(26) {
let last = window[25];
for x in 0..24 {
for y in x..25 {
if window[x] + window[y] == last {
continue 'outer;
}
}
}
return last;
}
... | true |
79d17cedf9f73f5a446d007a5348c28fc5da7460 | Rust | akr2002/rust | /foo/src/main.rs | UTF-8 | 544 | 4.25 | 4 | [] | no_license | pub struct Foo {
x: i32
}
impl Foo {
// Constructor
pub fn new(x: i32) -> Self {
// if param matches field name, we do not need to do Foo{x: x}
Self{x}
}
pub fn update(&mut self) {
self.update_self()
}
// private function
// cannot be accessed outside of impl b... | true |
cb678926bb691d82300c9fa0a8ba01e715b7be10 | Rust | killercup/dir-diff | /src/lib.rs | UTF-8 | 2,561 | 3.609375 | 4 | [
"Apache-2.0",
"MIT"
] | permissive | //! Determine if two directories have different contents.
//!
//! For now, only one function exists: are they different, or not? In the future,
//! more functionality to actually determine the difference may be added.
//!
//! # Examples
//!
//! ```no_run
//! extern crate dir_diff;
//!
//! assert!(dir_diff::is_differen... | true |
da5fd5ced17b9f4e513556a3c843f08f2716be75 | Rust | drdozer/transl8 | /bio/src/seq/fasta.rs | UTF-8 | 8,277 | 2.9375 | 3 | [] | no_license | use std::io;
extern crate nom;
use nom::{
IResult,
branch::{
alt,
},
bytes::complete::{
tag,
take_while,
},
character::complete::{
char,
line_ending,
space0,
space1,
},
combinator::{
map,
cut,
opt,
},
error::{
context,
},
multi::{
many0,
s... | true |
0d269a32d7761743b7437417aedde7518d75a01e | Rust | odidev/advent-of-code | /crates/core/src/year2017/day13.rs | UTF-8 | 1,823 | 2.984375 | 3 | [
"MIT"
] | permissive | use crate::Input;
pub fn solve(input: &mut Input) -> Result<usize, String> {
const MAX_DELAY: usize = 10_000_000;
let layers = input.text.lines().count();
let mut scanner_ranges = vec![0; layers];
for (line_index, line) in input.text.lines().enumerate() {
let error_message = || {
... | true |
5564bee48714b887edc679f8cbc42f01128479a8 | Rust | MaestroMikey/RustLearn | /coding_activities/src/main.rs | UTF-8 | 1,475 | 4.46875 | 4 | [] | no_license | //Topic: Functions
//
//Program Requirements:
//* Displays your first and last name
//Notes:
// * Use a function to display your first name
// * Use a function to display your last name
// Use the println! macro to display messages to the terminal.
fn main() {
firstname();
lastname();
ifelse1();
ifelse2();
}
... | true |
73847212bc088cc11e3430606ea712d42409b967 | Rust | mvanotti/fuchsia-mirror | /src/security/scrutiny/lib/framework/src/model/model.rs | UTF-8 | 7,075 | 2.671875 | 3 | [
"BSD-2-Clause"
] | permissive | // Copyright 2020 The Fuchsia Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use {
super::error::ModelError,
crate::{
model::collection::DataCollection,
store::{embedded::EmbeddedStore, memory::MemoryStore, sto... | true |
10b30aec292fba660ce346571d6f0ecb64ccb588 | Rust | ttys3/init-snapshot | /src/api/signals.rs | UTF-8 | 1,408 | 2.53125 | 3 | [
"MIT"
] | permissive | use std::convert::{Infallible, TryFrom};
use nix::sys::signal::Signal;
use tokio::sync::mpsc;
use warp::http::StatusCode;
use super::{ApiReply, ErrorMessage};
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct KillSignal {
signal: i32,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct OkReply... | true |
7baf11e06ee8ca453ec92dcfd532f6cbc69c1805 | Rust | steveklabnik/cionc | /src/parser/token_stream.rs | UTF-8 | 422 | 3.25 | 3 | [
"MIT"
] | permissive | pub use super::token::Token;
// Types like the Lexer implement this trait as they are iterators
// over Tokens. Maybe it should be substituted simply with the Iterator<Token> trait.
// However, a next_token(...) method is more explicit than just next(...) and
// it allows one to add new required methods (e.g. peek_to... | true |
7a254de375c02193d8915bf8bacfa0d0a673f9d0 | Rust | bwindels/rust-exif-parser | /src/section.rs | UTF-8 | 2,512 | 3.296875 | 3 | [] | no_license | use std::iter::Iterator;
use ::cursor::Cursor;
use ::error::ParseResult;
use ::tag::{
read_exif_tag,
RawExifTag,
EXIF_TAG_SIZE
};
pub struct SectionIterator<'a> {
cursor: Cursor<'a>,
tiff_marker: Cursor<'a>,
len: u16,
i: u16
}
impl<'a> SectionIterator<'a> {
pub fn byte_size(&self) -> usize {
2 + (... | true |
a2d587a3292e3d35a62368bf45e3eaecba244036 | Rust | danhper/diem | /storage/diemdb/src/transaction_store/mod.rs | UTF-8 | 9,165 | 2.671875 | 3 | [
"Apache-2.0"
] | permissive | // Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0
//! This file defines transaction store APIs that are related to committed signed transactions.
use crate::{
change_set::ChangeSet,
errors::DiemDbError,
schema::{transaction::TransactionSchema, transaction_by_account::Trans... | true |
98f4f994e65f0ea408b8a11f8e78e387868432aa | Rust | EliasDeMa/exercism-exercises | /rust/nth-prime/src/lib.rs | UTF-8 | 620 | 3.46875 | 3 | [] | no_license | pub fn nth(n: u32) -> Option<u32> {
let mut m = 0;
let mut i = 1;
if n < 1 { return None; }
while m < n {
i += 1;
if check_prime(i) {m += 1};
}
Some(i)
}
fn check_prime(n: u32) -> bool {
match n {
_ if n <= 1 => false,
_ if n <= 3 => true,
_ if n % 2 ... | true |
47c726990fd8cde64246723976d5bde0316b7348 | Rust | davidszotten/advent-of-code-2018 | /src/bin/day03.rs | UTF-8 | 2,750 | 3.15625 | 3 | [] | no_license | use aoc2018::{dispatch, Result};
use failure::{err_msg, Error};
use itertools::{Itertools, Product};
use lazy_static::lazy_static;
use regex::{Captures, Regex};
use std::collections::HashMap;
use std::ops::Range;
use std::str::FromStr;
#[derive(Debug, PartialEq, Clone)]
struct Claim {
id: usize,
top: usize,
... | true |
153a277647f115151cf7c65444d2a0d9568e8526 | Rust | brianp/rust-pocket | /src/auth.rs | UTF-8 | 6,131 | 3.046875 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | use crate::client::PocketClient;
use crate::errors::PocketError;
use crate::Pocket;
use crate::PocketResult;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Serialize)]
pub struct PocketOAuthRequest<'a> {
consumer_key: &'a str,
redirect_uri: &'a str,
state: Option<&'a str>,
}
#[derive(Deserial... | true |
dcb4d96d2b7441231d77d566eb66e5dfa397623d | Rust | ShaneQi/hooks | /src/telegram.rs | UTF-8 | 1,517 | 2.796875 | 3 | [] | no_license |
use tokio_core::reactor::Core;
use hyper_tls::HttpsConnector;
use hyper;
use serde_json;
use dotenv;
use hyper::client::Client;
pub fn send_message(message: String) {
let mut core = Core::new().unwrap();
let client = Client::configure()
.connector(HttpsConnector::new(4, &core.handle()).unwrap())
... | true |
55732c6cbffc9a8171f148b418c53e10f1638a4d | Rust | ajunlonglive/suruga | /src/test.rs | UTF-8 | 2,891 | 2.78125 | 3 | [
"MIT"
] | permissive | use std::io::prelude::*;
use std::io::Cursor;
use std::iter::repeat;
use tls::{TlsReader, TlsWriter};
use tls_result::TlsResult;
use cipher::{Encryptor, Decryptor};
use tls::Message::{ApplicationDataMessage, ChangeCipherSpecMessage};
use tls::RECORD_MAX_LEN;
// ROT26 is a [Caesar cipher][1] with highly optimized diff... | true |
05985c07196be1bd0d36c5370d054498631c9e10 | Rust | lmarin263/rust-lang-learning-project | /chapter-4/ownership/src/main.rs | UTF-8 | 2,952 | 4.21875 | 4 | [] | no_license | fn main() {
// No acostumbrarse a usarlos porque no siempre se va a conocer su valor
// let s = "Hello";
// De esta forma podemos almacenar un valor de texto desconocido
let s = String::from("Hello");
println!("{}, world!", s);
let mut s = String::from("Hello");
s.push_str(", world!"); // p... | true |
99dc3709d0464e24a12c3f73ed7f65c85a6e3fd5 | Rust | serbe/uri | /src/error.rs | UTF-8 | 2,910 | 3.25 | 3 | [
"MIT"
] | permissive | #[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("io error")]
IO(#[from] std::io::Error),
#[error("string from utf8 error")]
Utf8Error(#[from] std::string::FromUtf8Error),
#[error("Net address parse")]
StdParseAddr(#[from] std::net::AddrParseError),
#[error("Parse ip version 6")]
... | true |
bfbd41521168767f03e0037c1d8c47a004e547d0 | Rust | max-ym/uitaco | /src/tags.rs | UTF-8 | 15,470 | 3.140625 | 3 | [] | no_license | use crate::{ResponseValue, ViewWrap};
use std::fmt::Debug;
use htmldom_read::{Node};
use crate::events::OnClick;
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
use std::fmt::Formatter;
use std::sync::Arc;
/// The functions that allow to load images concurrently.
pub mod image_loader {
use std::sync... | true |
c0a9da1a365884e9082e8ecb93d43f2eedf1aec3 | Rust | jacobjonsson/packet | /src/cli/src/main.rs | UTF-8 | 1,051 | 2.90625 | 3 | [
"MIT"
] | permissive | use js_parser::parse;
use js_printer::Printer;
use logger::LoggerImpl;
use source::Source;
use std::fs;
use std::path::PathBuf;
use std::{env, time::Instant};
struct Arguments {
input_file: PathBuf,
out_file: Option<PathBuf>,
}
fn main() {
let now = Instant::now();
let input_file = env::args().nth(1).... | true |
4b81df2584577bb8660df60f6650cdf91bca9c74 | Rust | isgasho/sniproxy-rs | /src/main.rs | UTF-8 | 15,216 | 2.578125 | 3 | [] | no_license | // This implementation is inspired by https://github.com/dlundquist/sniproxy, but I wrote it from
// scratch based on a careful reading of the TLS 1.3 specification.
use std::net::SocketAddr;
use std::path::PathBuf;
use std::time::Duration;
use tokio::io::{self, AsyncReadExt, AsyncWriteExt, Error, ErrorKind};
use toki... | true |
e9786577e4071e695e092aa366b92a673bf4bda1 | Rust | Vlad-Shcherbina/icfpc2020-tbd | /src/img_matrix.rs | UTF-8 | 4,069 | 3.296875 | 3 | [] | no_license | use std::ops::{ Index, IndexMut };
#[derive(Debug)]
pub struct Coord {
pub x: usize,
pub y: usize,
}
#[derive(Debug, Clone)]
pub struct ImgMatrix {
pub width: usize,
pub height: usize,
data: Vec<Vec<u8>>,
}
impl Index<Coord> for ImgMatrix {
type Output = u8;
fn index(&self, coord: Coord)... | true |
d451bdfcf51502bc36e551956676a6d4043a6e11 | Rust | mathw/adventofcode | /aoc2017/day24/src/main.rs | UTF-8 | 7,654 | 3.234375 | 3 | [] | no_license | extern crate util;
use util::powerset::PowerSet;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::LinkedList;
use std::hash::Hash;
fn main() {
let input = include_str!("input.txt");
let components = parse_components(input);
// let bridge = stronges... | true |
d414abef087559ef1d84731fd75385c3237d47d7 | Rust | acolley/toggler | /src/project/mod.rs | UTF-8 | 9,654 | 2.5625 | 3 | [] | no_license | pub mod error;
use std::str::FromStr;
use chrono::{DateTime, Utc};
use diesel;
use diesel::sqlite::SqliteConnection;
use diesel::RunQueryDsl;
use serde::{Deserialize, Serialize};
use serde_json;
use uuid::Uuid;
use crate::database::models::{Event, NewEvent};
use crate::database::schema;
use crate::domain::{Aggregate... | true |
27e90955c6d04db52205f212b25c03a58ee356f5 | Rust | rcarson3/Rust_Language_Trials | /Functional_Chapter/iterators/src/main.rs | UTF-8 | 4,819 | 4.03125 | 4 | [
"MIT"
] | permissive | fn main() {
//Iterators in Rust are lazy. In other words, they
//have no effect unitl we call methods that consume
//the iterator.
//Iterators all implement a trait called Iterator defined in the
//std lib.
let v1: Vec<i32> = vec![1, 2, 3];
//Other methods defined on the Iterator trait are ... | true |
3d9decdf907e7d50aea9cbf46048b78acfbb059e | Rust | foresterre/advent-of-code-2020 | /days/day03/src/main.rs | UTF-8 | 3,559 | 3.28125 | 3 | [] | no_license | use aoc2020::{read_file, TResult};
use std::ops::Mul;
#[derive(Default, Debug)]
struct Sled {
position: Position,
arrived: bool,
}
impl Sled {
fn slide(&mut self, slope_offset: Offset) -> Position {
self.position.slide(slope_offset);
self.position
}
fn update_has_arrived(&mut self... | true |
58a97d2f773537faf948af84550df7ba701c3cba | Rust | goto-bus-stop/arms | /crates/scx/src/player.rs | UTF-8 | 1,275 | 3.09375 | 3 | [
"MIT"
] | permissive | use consts::Civilization;
use unit::Unit;
pub struct BaseResources {
pub gold: u32,
pub wood: u32,
pub food: u32,
pub stone: u32,
pub ore: u32,
}
pub struct Player {
pub name: String,
pub active: u32,
pub human: u32,
pub civilization: Civilization,
pub resources: BaseResources,... | true |
0ebc3552eb9360c9218397f3fa75c0a1a78e9964 | Rust | utilForever/BOJ | /Rust/3765 - Celebrity Jeopardy.rs | UTF-8 | 400 | 3.046875 | 3 | [
"MIT"
] | permissive | use io::Write;
use std::io;
fn main() {
let stdout = io::stdout();
let mut out = io::BufWriter::new(stdout.lock());
loop {
let mut solution = String::new();
io::stdin().read_line(&mut solution).unwrap();
solution = solution.trim().to_string();
if solution.is_empty() {
... | true |
2928d038cf0d30e442691f2c6146a894cd410d39 | Rust | cameronwp/adventofcode2019 | /day4/src/main.rs | UTF-8 | 7,394 | 3.390625 | 3 | [
"MIT"
] | permissive |
#[derive(Debug, PartialEq, PartialOrd, Clone)]
struct Num([u8; 6]);
impl Num {
fn from_i32(input: i32) -> Self {
let d0 = ((input / 100_000) % 10) as u8;
let d1 = ((input / 10_000) % 10) as u8;
let d2 = ((input / 1_000) % 10) as u8;
let d3 = ((input / 100) % 10) as u8;
let ... | true |
e7283701305008a07f8f1fb054d82c8e8938850e | Rust | crypto-election/crypto-election | /node/src/schema/repository.rs | UTF-8 | 147 | 2.625 | 3 | [] | no_license | pub trait Repository<K, V> {
fn has(&self, key: &K) -> bool;
fn get(&self, key: &K) -> Option<V>;
fn require(&self, key: &K) -> V;
}
| true |
2786ce8a33d74bd1dae2d4515db18058d3a97438 | Rust | xnti/keci-mobile-api | /src/controller/seller.rs | UTF-8 | 530 | 2.5625 | 3 | [
"MIT"
] | permissive | use actix_web::{web, HttpResponse, Responder};
use serde::Deserialize;
#[derive(Deserialize)]
pub struct GetPath {
name: String,
}
pub async fn get(app_data: web::Data<crate::AppState>, path: web::Path<GetPath>) -> impl Responder {
let result = web::block(move || app_data.service_container.seller.get(&path.name))... | true |
24364912e603ea66e009e6e043cd8ed7cdf3b80e | Rust | fabianschuiki/llhd | /src/bin/llhd-conv/liberty.rs | UTF-8 | 14,657 | 2.921875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | // Copyright (c) 2017-2021 Fabian Schuiki
//! Lexer and parser for Liberty files.
use llhd::{int_ty, ir::prelude::*, signal_ty};
use std::collections::HashMap;
/// A lexer for Liberty files.
pub struct Lexer<I> {
input: I,
peek: [Option<u8>; 2],
done: bool,
offset: usize,
line: usize,
column:... | true |
4ba0e6aed000f98ccf4dd935e0d21946efd9214c | Rust | tcard/advent2020 | /2/rust/2_1.rs | UTF-8 | 2,809 | 3.546875 | 4 | [] | no_license | // --- Day 2: Password Philosophy ---
// Your flight departs in a few days from the coastal airport; the easiest way
// down to the coast from here is via toboggan.
// The shopkeeper at the North Pole Toboggan Rental Shop is having a bad day.
// "Something's wrong with our computers; we can't log in!" You ask if you ... | true |
a1658fd0521e2a5bdef91be2f8361da37d07772b | Rust | robatipoor/rust-code-snippet | /examples/filter-map.rs | UTF-8 | 445 | 3.296875 | 3 | [
"MIT"
] | permissive | fn main() {
let strings = ["P", "122", "23", "55", "45", "34", "R"];
let result: Vec<i32> = strings
.into_iter()
.filter_map(|x| x.parse::<i32>().ok())
.collect();
println!("{:?}", result);
// same to
let result: Vec<i32> = strings
.into_iter()
.map(|x| x.par... | true |
31d0ed60e16f3cd3329db2b8687e6be2b604ebc3 | Rust | white-leaf-devs/recommendation-system | /controller/src/error.rs | UTF-8 | 1,148 | 2.5625 | 3 | [
"MIT"
] | permissive | // Copyright (c) 2020 White Leaf
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
use thiserror::Error as DError;
#[derive(Debug, Clone, DError)]
pub enum ErrorKind {
#[error("Couldn't found entity with id({0})")]
NotFoundById(String),
#[error("Couldn't found ... | true |
e98ff57f5220651174995b2ebeab8b55b5b20bef | Rust | ICGNYN/RustLearning | /勉強/challenging/1.rs | UTF-8 | 513 | 3.34375 | 3 | [] | no_license | struct TreeNode<T>{
element: T,
left: Option<Box<TreeNode<T>>>,
right: Option<Box<TreeNode<T>>>
}
fn main(){
let _a = 10;
/*let t = vec![1; 10];
let b: Box<&[u32]> = Box::new(&t);
//let a = t;
//let c = &b;
print!("{:?}",b);
//print!("{:?}",c); */
let jup_tree = Some(Box::n... | true |
f9d4ad2d0d38086008361a9facbe75cfe56bf604 | Rust | l3kn/EulerLisp | /src/builtin/string.rs | UTF-8 | 4,339 | 2.953125 | 3 | [
"MIT"
] | permissive | #![allow(clippy::needless_pass_by_value)]
use std::convert::TryInto;
use crate::builtin::*;
use crate::vm::VM;
use crate::LispError::*;
use crate::{Arity, LispResult, Value};
fn string_get(s: Value, i: Value, _vm: &VM) -> LispResult<Value> {
let string: String = s.try_into()?;
let index: usize = i.try_into()... | true |
44b591a10abee56b1ad6e9f9bd73eda1a312b383 | Rust | Hylian/min-entropy | /src/main.rs | UTF-8 | 1,705 | 3.109375 | 3 | [] | no_license | use std::env;
use std::fs::File;
use std::io::prelude::*;
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
panic!("Not enough arguments!");
}
println!("{:?}", args);
let filename = &args[1];
println!("Parsing file: {}", filename);
let mut f = File::op... | true |
82d1eb3c35b78fd7e9a2545ebb8531ba6da34d91 | Rust | sankar-boro/loony | /loony/src/web/scope.rs | UTF-8 | 45,842 | 2.625 | 3 | [
"MIT"
] | permissive | use std::{
cell::RefCell, fmt, future::Future, pin::Pin, rc::Rc, task::Context, task::Poll,
};
use crate::http::Response;
use crate::router::{IntoPattern, ResourceDef, ResourceInfo, Router};
use crate::service::boxed::{self, BoxService, BoxServiceFactory};
use crate::service::{pipeline_factory, PipelineFactory};
u... | true |
429ca9abb74987ea39c384d240dbdcaddf0fbeee | Rust | dhadka/chain-libs | /btree/src/mem_page.rs | UTF-8 | 1,774 | 3.28125 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use std::alloc;
const MEM_ALIGNMENT: usize = 8;
/// Box-like structure but with custom alignment
/// all nodes are allocated on this structure, but ideally at some point we could just use pointers into the mmap
#[derive(Debug)]
pub struct MemPage {
data: *mut u8,
layout: alloc::Layout,
}
impl Drop for MemPag... | true |
8555fff39a45f87912bd68f78a28a2f070af00de | Rust | helloooooo/prac-algo | /atcoder/src/abc045c.rs | UTF-8 | 1,627 | 3.125 | 3 | [] | no_license | fn read<T: std::str::FromStr>() -> T {
let mut s = String::new();
std::io::stdin().read_line(&mut s).ok();
s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
read::<String>()
.split_whitespace()
.map(|e| e.parse().ok().unwrap())
.collect()
}
fn rea... | true |
c3161ba13fb1cc8ea5d0c86d6bf6d8ed7ae2c4c1 | Rust | Atul9/crush | /src/lang/ast.rs | UTF-8 | 16,176 | 2.640625 | 3 | [
"MIT"
] | permissive | use crate::lang::job::Job;
use crate::lang::errors::{CrushResult, error, to_crush_error};
use crate::lang::command_invocation::CommandInvocation;
use crate::lang::argument::ArgumentDefinition;
use crate::lang::value::{ValueDefinition, Value, ValueType};
use std::ops::Deref;
use crate::lang::command::{CrushCommand, Para... | true |
7ba4193eeb0853ca7d36d9c634d09fdc54de2fc0 | Rust | xfbs/xar | /src/main.rs | UTF-8 | 6,440 | 2.703125 | 3 | [] | no_license | extern crate xar;
use clap::{App, Arg, ArgMatches, SubCommand, AppSettings};
use failure::{Error, Fail};
use std::fs::File;
use std::path::*;
use xar::Archive;
use xmltree::*;
#[derive(Fail, Debug)]
enum Errors {
#[fail(display = "Argument missing.")]
ArgMissing,
#[fail(display = "File ‘{}’ doesn't exist i... | true |
369dfa10346f9faed84856a4dedffda982bc5051 | Rust | vshotarov/advent-of-code-2020 | /day14/src/main.rs | UTF-8 | 4,776 | 3.0625 | 3 | [] | no_license | use std::io::{self, Read};
use std::collections::HashMap;
fn main() -> std::io::Result<()> {
let mut input = String::new();
io::stdin().read_to_string(&mut input)?;
solve_part1(&input)?;
solve_part2(&input)?;
Ok(())
}
fn solve_part1(input: &str) -> std::io::Result<()> {
let mut bitmask: Hash... | true |
2049b34356e4efce67524ee4fc5f7d90f0f9cb57 | Rust | mahfsy/anura-rs | /src/systems/command_system.rs | UTF-8 | 1,200 | 3.078125 | 3 | [] | no_license | use hecs::{Entity, World};
use glam::Vec2;
use crate::components::{
auto_pather::{
AutoPather, AutoPatherTarget, AutoPatherTarget::*
},
};
use std::vec::Vec;
use crate::systems::System;
pub enum Command {
SetAutoPatherTarget(Entity, AutoPatherTarget),
}
use Command::*;
impl Command {
fn exec... | true |
a58f79784fcfea33adfaf1b946328360fe5f7daf | Rust | JacobVanGeffen/shuttle | /src/runtime/failure.rs | UTF-8 | 7,035 | 3.375 | 3 | [
"Apache-2.0"
] | permissive | //! This module contains the logic for printing and persisting enough failure information when a
//! test panics to allow the failure to be replayed.
//!
//! The core idea is that we install a custom panic hook (`init_panic_hook`) that runs when a thread
//! panics. That hook tries to print information about the failin... | true |
243252d95540a80c2002d9f75ef19e610aa407d1 | Rust | 0x192/iced_aw | /examples/selection_list/src/main.rs | UTF-8 | 3,270 | 3.265625 | 3 | [
"MIT"
] | permissive | use iced::{Align, Column, Container, Element, Length, Sandbox, Settings, Space, Text};
use iced_aw::selection_list::{self, SelectionList, Style, StyleSheet};
#[derive(Clone, Copy, Debug)]
pub struct CustomStyle;
impl StyleSheet for CustomStyle {
fn style() -> Style {
Style {
width: Length::Shr... | true |
3e268b2afb4aebe4786c3de0d856fc59623e382f | Rust | rgripper/village-sim | /game_plugin/src/time_cycle.rs | UTF-8 | 3,074 | 2.9375 | 3 | [
"CC0-1.0"
] | permissive | use bevy::core::Time;
use bevy::prelude::*;
use crate::GameState;
pub struct TimeCycle {
day: u64,
time: time::Time,
speed: u32,
}
impl Default for TimeCycle {
fn default() -> Self {
Self {
day: 0,
// A new day begins at seven o’clock 😀
time: time::Time::fr... | true |
998410f6ac54c3f4f2d76b637e38a82290e1b9f4 | Rust | Lisoph/glfw_ffi | /examples/hello_world.rs | UTF-8 | 1,004 | 2.953125 | 3 | [
"MIT"
] | permissive | //! Ported from http://www.glfw.org/documentation.html
extern crate glfw_ffi;
use glfw_ffi::*;
use std::ptr;
fn main() {
unsafe {
/* Initialize the library */
if glfwInit() == 0 {
return;
}
/* Create a windowed mode window and its OpenGL context */
let window ... | true |
d4d57dafc4ccc82b5c36d8a4f18eee834a794352 | Rust | doytsujin/provok | /src/font/rasterizer/mod.rs | UTF-8 | 746 | 2.609375 | 3 | [
"MIT"
] | permissive | use crate::font::ftwrap;
use crate::utils::PixelLength;
use failure::Fallible;
pub mod freetype;
pub struct RasterizedGlyph {
pub data: Vec<u8>,
pub height: usize,
pub width: usize,
pub top: PixelLength,
pub left: PixelLength,
}
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct FontMetrics {
... | true |
858936ed5b705d1266c6081da8c9c341f0def8e9 | Rust | ksw2000/Rust-Practice | /basic/10-Ownership.rs | UTF-8 | 1,348 | 3.921875 | 4 | [] | no_license | /*
Each value in Rust has a variable that is called owner of the value.
Every data stored in Rust will have an owner associated with it.
For example, in the syntax − let age = 30, age is the owner of the value 30.
*/
fn main(){
let v = vec![1,2,3];
// vector v owns the object in heap
//only a single variable ... | true |
b696d17d318ab64b5a2c29ae509e7cead98e6ca8 | Rust | andrewnturner/ray_tracer | /src/render/elements/moving_sphere.rs | UTF-8 | 8,016 | 2.859375 | 3 | [] | no_license | use std::any::Any;
use std::fmt::Debug;
use std::rc::Rc;
use crate::geometry::bounding_box::BoundingBox;
use crate::geometry::point::Point3;
use crate::geometry::ray::Ray;
use crate::geometry::vector::Vector3;
use super::sphere::sphere_uv;
use super::super::element::Element;
use super::super::hit_record::HitRecord;
u... | true |
a1c2fb8c6b9620b05a644d195d6494c6cd618a36 | Rust | TOPbuaa/enigma-rust | /src/enigma.rs | UTF-8 | 4,036 | 2.984375 | 3 | [] | no_license | // # 子模块:1.轮盘 2.反射器 3.插线板
use crate::patch_panel::PatchPanel;
use crate::reflector::Reflector;
use crate::rotor::Rotor;
pub struct Enigma {
panel: PatchPanel,
reflector: Reflector,
rotor_slow: Rotor,
rotor_middle: Rotor,
rotor_fast: Rotor,
}
impl Enigma {
pub fn new(wheel: [(&str, char); 3]... | true |
99a254b27fbeb2472f02194b0e07fbca1f685ae7 | Rust | lucifer1004/AtCoder | /abc149/src/bin/b.rs | UTF-8 | 275 | 2.734375 | 3 | [] | no_license | use proconio::input;
fn main() {
input! {
a: usize,
b: usize,
k: usize,
}
let (ra, rb) = if k < a {
(a - k, b)
} else if k < a + b {
(0, a + b - k)
} else {
(0, 0)
};
println!("{} {}", ra, rb);
}
| true |
239c825803d691a1a2def6dedceb8cabcc8d6e51 | Rust | ryanzidago/leetcode | /valid_parentheses/src/main.rs | UTF-8 | 671 | 3.96875 | 4 | [] | no_license | fn main() {
println!("Hello, world!");
}
fn is_valid(s: String) -> bool {
let mut stack = Vec::new();
for char in s.chars() {
match char {
'{' => stack.push('}'),
'(' => stack.push(')'),
'[' => stack.push(']'),
'}' | ')' | ']' if Some(char) != stack.p... | true |
048e38d30d4fd591302172dcadca4f1077857165 | Rust | nampdn/prisma-engines | /libs/datamodel/core/tests/directives/default_negative.rs | UTF-8 | 2,108 | 2.828125 | 3 | [
"Apache-2.0"
] | permissive | use crate::common::*;
use datamodel::{ast::Span, error::DatamodelError};
#[test]
fn should_error_if_default_value_for_relation_field() {
let dml = r#"
model Model {
id Int @id
rel A @default("")
}
model A {
id Int @id
}
"#;
let errors = parse_error(dml);
error... | true |
4762dd3b80606ec5446db4dded1db0f2bc5838da | Rust | nrxus/rust_smasher | /src/master_smasher/shape/mod.rs | UTF-8 | 461 | 2.71875 | 3 | [
"MIT"
] | permissive | pub mod circle;
pub mod rectangle;
pub use self::circle::Circle;
pub use self::rectangle::Rectangle;
use glm;
pub type Line = (glm::DVec2, glm::DVec2);
pub trait Intersect<S> {
fn intersects(&self, other: &S) -> bool;
}
pub trait Shape {
fn get_center(&self) -> glm::DVec2;
fn contains(&self, point: &gl... | true |
b16852059afc5a93e2fbc02f9c496161403b36d4 | Rust | alacritty/copypasta | /src/wayland_clipboard.rs | UTF-8 | 1,918 | 2.5625 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | // Copyright 2017 Avraham Weinstock
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to i... | true |
40a285ee18b96632c53fc629ee87532db4884f08 | Rust | komonad/rustpad | /rustpad-client/src/editor_binding.rs | UTF-8 | 5,255 | 2.890625 | 3 | [
"MIT"
] | permissive | use crate::client::{Callback, RustpadClient};
use std::borrow::Cow;
use std::ops::Range;
use druid::piet::TextStorage as PietTextStorage;
use druid::Data;
use std::sync::Arc;
use parking_lot::RwLock;
use crate::code_editor::text::{TextStorage, StringCursor};
use crate::code_editor::text::editable_text::EditableText;
#... | true |
1d9bc971f1b2cfc79332145ff8248ceddbfe3a4c | Rust | rtpg/safe_lua | /src/compile/utils.rs | UTF-8 | 471 | 2.59375 | 3 | [] | no_license | use super::compile;
use compile::CodeObj;
use parse;
pub fn try_compile_block<'a>(input: &'a str) -> Result<CodeObj, String> {
// take some input and then build out the code for it
// this is mainly for REPL usage
let parse_result = parse::try_parse(input);
match parse_result {
Err(err) => retu... | true |
f4cecce321e13a6cbc2d1916d5e521d9d8dc4144 | Rust | AkiaCode/cargo-neko | /src/main.rs | UTF-8 | 922 | 2.65625 | 3 | [
"MIT"
] | permissive | use viuer::{print_from_file, Config};
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug)]
struct Neko {
pub url: String
}
fn main() {
let conf = Config {
transparent: true,
absolute_offset: false,
x: 0,
y: 0,
width: Some(80),
height: So... | true |
c15d2de28f8ab2c73badcc2610536a8e4bcdd691 | Rust | mpcsh/sara-lang | /src/bake.rs | UTF-8 | 878 | 2.765625 | 3 | [] | no_license | use std::collections::{HashMap, HashSet};
use unicase::UniCase;
use crate::ast::{Ingredient, Instruction, Recipe};
pub struct Baker<'a> {
recipe: &'a Recipe,
cookbook: HashMap<HashSet<Ingredient>, Ingredient>,
}
impl<'a> Baker<'a> {
fn step(&self, instruction: Instruction) -> String {
match instruction {
... | true |
d9c23f16d31407a783c8ae843e9b12b657915040 | Rust | ian-henderson/rust-by-example | /08-flow_of_control/for.rs | UTF-8 | 3,034 | 4.21875 | 4 | [] | no_license | // for loops
// for and range
// The for in construct can be used to iterate through an Iterator. One of
// the easiest ways to create an iterator is to use the range notation a..b.
// This yields values from a (inclusive) to b (exclusive) in steps of one.
// Let's write FizzBuzz using for instead of while.
#[allo... | true |
b02e73a4686108c3aa2b2477188f731f446fcfb5 | Rust | mosbasik/CtCI-6th-Edition-Rust | /src/ch_01_arrays_and_strings/q_02_check_permutation.rs | UTF-8 | 1,747 | 4.03125 | 4 | [] | no_license | /// sort both strings, then check if they are equal
pub mod approach_1 {
fn sort_string(s: &str) -> String {
let mut bytes = s.as_bytes().to_vec();
bytes.sort_unstable();
String::from_utf8(bytes).unwrap()
}
pub fn permutation(a: &str, b: &str) -> bool {
sort_string(a) == sor... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.