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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
789481137a9b9edcd42b1b61292fcdf5d94991c5 | Rust | pacman82/rtiow | /src/camera.rs | UTF-8 | 2,579 | 3.15625 | 3 | [] | no_license | use crate::{
ray::Ray,
vec3::{cross, Point, Vec3},
};
use rand::Rng;
pub struct Camera {
origin: Point,
lower_left_corner: Point,
horizontal: Vec3,
vertical: Vec3,
lens_radius: f64,
u: Vec3,
v: Vec3,
exposure_time: f64,
}
impl Camera {
pub fn new(
vertical_field_of_... | true |
c014415aaabf3c8a1b98de867af4b265338a5987 | Rust | torkeldanielsson/pe | /pe_21/src/main.rs | UTF-8 | 485 | 3.40625 | 3 | [] | no_license | fn sum_of_proper_divisors(d: i64) -> i64 {
let mut res: i64 = 0;
let mut t: i64 = 0;
while t < d / 2 {
t += 1;
if d % t == 0 {
res += t;
}
}
return res;
}
fn main() {
let mut res = 0;
for i in 1..10000 {
let a = sum_of_proper_divisors(i);
... | true |
92ba6ea0169fb1e5684d5d106e565c62cfe418b5 | Rust | LordAro/dcpu16 | /src/dcpu.rs | UTF-8 | 25,680 | 2.765625 | 3 | [
"MIT"
] | permissive | #![allow(dead_code)]
use std::path::Path;
use std::fs::File;
use std::io::Read;
use std::io::Result;
use std::any::Any;
use std::cell::RefCell;
use std::rc::Rc;
use instructions::*;
// Note: this can't be changed willy-nilly, since the PC is naturally wrapped around, so it will
// not wrap around correctly if this i... | true |
3ee007d7500391df60d759912c99cedb7f0126a9 | Rust | Limegrass/luffy | /luffy_gitea/src/structs.rs | UTF-8 | 9,026 | 2.609375 | 3 | [
"MIT"
] | permissive | use serde::{Deserialize, Serialize};
// use chrono::DateTime if I'm doing more than just forwarding
type DateTimeType = String; // "2017-03-13T13:52:11-04:00"
#[derive(Debug, PartialEq, Deserialize, Serialize)]
pub struct GitUser {
pub name: String,
pub email: String,
pub username: String,
}
#[derive(Deb... | true |
82a71fc7c8b16d74847eccb8b05fdeda190fa43d | Rust | ResidentMario/rust-learn | /enums/src/main.rs | UTF-8 | 1,549 | 4.03125 | 4 | [] | no_license | enum Whiteness {
Whiteish,
Alabama
}
// When you attach fields to a enum like this you have to declare those
// field with values when you use them. Remember: an enum is just a fancy struct.
// This is kind of sort of just a struct with another struct field in it that you
// can run a match over.
enum Race {
... | true |
3543370474007b9ea61a4c092fbbbdf5cdcd809a | Rust | starsheriff/rsql | /src/tokenizer.rs | UTF-8 | 3,245 | 3.796875 | 4 | [
"MIT"
] | permissive | use std::iter::Peekable;
use std::str::Chars;
#[derive(Debug, PartialEq)]
pub enum Token {
Word(Word),
Select,
Equal,
Gt,
Lt,
LBrace,
RBrace,
}
#[derive(Debug, PartialEq)]
pub struct Word {}
#[derive(Debug)]
pub enum Command {
Quit,
Help,
}
#[derive(Debug)]
pub enum Error {
U... | true |
12ed0875693e0ff2a03ed5bb71ca15fd61419604 | Rust | DrunkFlamingo/kailua | /kailua_langsvr/src/message.rs | UTF-8 | 1,412 | 2.5625 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use std::error::Error;
// general notifications
define_msg! { pub CannotReadConfig:
"ko" => "프로젝트에서 `kailua.json`이나 `.vscode/kailua.json`을 읽을 수 없습니다. \
이번 세션에서 타입 체크가 비활성화됩니다.",
_ => "Cannot read `kailua.json` or `.vscode/kailua.json` in the project; \
type checking is disabled fo... | true |
6f4b89e61d35ce594dbb53412d1740f95be3f993 | Rust | AlisCode/ld44 | /src/resources/mouse.rs | UTF-8 | 532 | 2.953125 | 3 | [
"MIT"
] | permissive | use quicksilver::geom::Vector;
use quicksilver::input::{ButtonState, Mouse, MouseButton};
#[derive(Default)]
pub struct MouseWrapper {
pub mouse: Option<Mouse>,
}
impl MouseWrapper {
pub fn get_button(&self, btn: MouseButton) -> ButtonState {
if let Some(m) = &self.mouse {
m[btn]
}... | true |
3e22e6cb37bf5bb1c9366d5b902983fc97c71f96 | Rust | rust-lang/rust | /tests/ui/typeck/do-not-suggest-adding-missing-zero-to-floating-point-number.rs | UTF-8 | 756 | 3 | 3 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"BSD-2-Clause",
"LicenseRef-scancode-unicode",
"MIT",
"LicenseRef-scancode-other-permissive"
] | permissive | macro_rules! num { () => { 1 } }
fn main() {
let x = 1i32;
x.e10; //~ERROR `i32` is a primitive type and therefore doesn't have fields
let y = 1;
y.e10; //~ERROR `{integer}` is a primitive type and therefore doesn't have fields
2u32.e10; //~ERROR `u32` is a primitive type and therefore doesn't ha... | true |
e434edee7d79a5e3af1c6fb9a859cdf14b6922bb | Rust | dfrankland/mk20d7 | /src/uart1/c1/mod.rs | UTF-8 | 26,257 | 2.796875 | 3 | [
"MIT"
] | permissive | #[doc = r" Value read from the register"]
pub struct R {
bits: u8,
}
#[doc = r" Value to write to the register"]
pub struct W {
bits: u8,
}
impl super::C1 {
#[doc = r" Modifies the contents of the register"]
#[inline]
pub fn modify<F>(&self, f: F)
where
for<'w> F: FnOnce(&R, &'w mut W) -... | true |
df5e230a2af8ac60780a393d0b10ac5d937b36e1 | Rust | drew-y/rustracer | /src/geometry/translation.rs | UTF-8 | 5,624 | 2.921875 | 3 | [] | no_license | use super::super::tracer::*;
use std::f32::{consts::PI, MAX as F32MAX};
#[derive(Clone)]
pub struct FlipNormals {
hitable: BoxHitable,
}
impl Hitable for FlipNormals {
fn hit(&self, r: &Ray, t_min: f32, t_max: f32) -> Option<HitRecord> {
let rec = self.hitable.hit(r, t_min, t_max)?;
Some(HitRe... | true |
ef0d8b26f9c894c914454f4b2f111850da9f7440 | Rust | PurpleBooth/kata-tennis | /src/lib.rs | UTF-8 | 7,383 | 3.25 | 3 | [] | no_license | use std::collections::HashMap;
use std::fmt::Error;
use std::fmt::Formatter;
const PLAYER_1_ID: bool = false;
const PLAYER_2_ID: bool = true;
#[derive(PartialEq, Eq, Debug, Hash, Copy, Clone)]
struct Score(u8);
impl Score {
fn new(score: u8) -> Result<Score, String> {
score_to_call(score)
.ma... | true |
019bcaacbd9f5a8933ce74dafc433e41586ca04d | Rust | jjyr/godwoken | /crates/rpc-client/src/error.rs | UTF-8 | 4,161 | 2.796875 | 3 | [
"MIT"
] | permissive | /// Get JSONRPC error code from errors returned by RPC methods.
pub fn get_jsonrpc_error_code(e: &anyhow::Error) -> Option<i64> {
let e: &jsonrpc_core::types::error::Error = e.downcast_ref()?;
Some(e.code.code())
}
// Copied from CKB.
pub enum CkbRpcError {
/// (-1): CKB internal errors are considered to n... | true |
224469f6defb2175a4fc1846f114916f9caff14f | Rust | GSam/rust-refactor | /tests/lib.rs | UTF-8 | 35,087 | 2.71875 | 3 | [] | no_license |
extern crate refactor;
use std::fs::File;
use std::io::Read;
use refactor::{AnalysisData, Response};
fn read_to_string(filename: &str) -> String {
let mut file = match File::open(filename) {
Err(why) => panic!("couldn't open file {} {}", filename, why),
Ok(file) => file,
};
let mut outpu... | true |
f7dc75117ad383e4bdfbdd74ba76d930982bfc2a | Rust | ChangeCaps/orchard | /src/assets.rs | UTF-8 | 1,477 | 2.890625 | 3 | [] | no_license | use ike::prelude::*;
pub struct Assets {
pub font: Font,
pub cursor: Texture,
pub base_tile: Texture,
pub farm_tile: Texture,
pub wheat_seed: Texture,
pub wheat_item: Texture,
pub wheat_0: Texture,
pub wheat_1: Texture,
pub wheat_2: Texture,
pub wheat_3: Texture,
pub pole: ... | true |
37f199edeb7d06df5a7a5b877335e71e8d7131d7 | Rust | flyq/datastruct-algorithm | /leetcode/p1170/src/main.rs | UTF-8 | 2,081 | 3.28125 | 3 | [
"MIT"
] | permissive | fn main() {
println!("Hello, world!");
let a = vec!["aabbbabaa".to_string()];
let b = vec!["b".to_string(),"aaaba".to_string(),"aaaabba".to_string(),"aa".to_string(),"aabaabab".to_string(),"aabbaaabbb".to_string(),"ababb".to_string(),"bbb".to_string(),"aabbbabb".to_string(),"aab".to_string(),"bbaaababba".t... | true |
5132d4a9e444a60767e1e778334d06c3a96c104d | Rust | spriest487/uncle-pascal | /pas_syn/src/ast/ctor.rs | UTF-8 | 3,750 | 2.890625 | 3 | [] | no_license | use crate::{ast::Expression, parse::prelude::*};
#[derive(Eq, PartialEq, Clone, Hash, Debug)]
pub struct ObjectCtorMember<A: Annotation> {
pub ident: Ident,
pub value: Expression<A>,
pub span: Span,
}
impl<A: Annotation> fmt::Display for ObjectCtorMember<A> {
fn fmt(&self, f: &mut fmt::Formatter) -> f... | true |
6fb9079d4625d510837f78feee50addef86cb9e7 | Rust | holaymzhang/aarch64 | /kernel/memory/src/list.rs | UTF-8 | 3,252 | 3.109375 | 3 | [] | no_license | use core::default::Default;
use core::marker::PhantomData;
use core::option::Option;
use crate::page::Page;
use intrusive::IntrusiveList;
#[derive(Debug)]
pub struct PageList<'a> {
list: IntrusiveList<Page>,
_marker: PhantomData<&'a Page>,
}
impl<'a> PageList<'a> {
pub fn new() -> PageList<'a> {
l... | true |
f7b193f61f3ca8eb442e2e1b7c924b7e9dd89aa5 | Rust | 2892931976/mirdb | /mirdb-server/src/slice.rs | UTF-8 | 5,513 | 2.703125 | 3 | [] | no_license | use std::borrow::Borrow;
use std::cmp::Ordering;
use std::convert::From;
use std::fmt;
use std::hash;
use std::io::Cursor;
use std::ops::Index;
use std::ops::Range;
use std::ops::RangeFull;
use std::ops::RangeTo;
use std::slice::SliceIndex;
use bytes::buf;
use bytes::Bytes;
use bytes::BytesMut;
use serde::de::{self, V... | true |
4709a049cc105f62cb7de3f0702ddfbf745e4f8d | Rust | SaahilClaypool/aoc_2018 | /day_15/src/main.rs | UTF-8 | 19,929 | 3.203125 | 3 | [] | no_license | use std::cell::RefCell;
use std::collections::HashMap;
use std::str::FromStr;
use std::string::ToString;
// 195888
fn main() {
// let elf = &game.units[0];
// let new_pos = elf.do_move(&game); // need to split up unit structure from game structure
let input = include_str!("input.txt");
part_b(input);
}... | true |
064191738bee08fd95ea96ef12d750be25fa08fa | Rust | xunilrj/sandbox | /sources/rust/relm/runtime/src/executor.rs | UTF-8 | 2,631 | 2.71875 | 3 | [
"Apache-2.0"
] | permissive | use std::boxed::*;
use std::future::*;
use std::pin::*;
use std::task::*;
pub struct Executor {
next: usize,
handles: [Option<Pin<Box<dyn std::future::Future<Output = ()>>>>; 100],
}
pub static mut VTABLE: RawWakerVTable = std::task::RawWakerVTable::new(
Executor::clone,
Executor::wake,
Executor::... | true |
a425b3a9e2e587e93c69f1e3b044741fca11ead4 | Rust | tz-rs/tz-rs | /rpc/src/responses/chains/blocks/block_ids_in_chain.rs | UTF-8 | 4,160 | 3.140625 | 3 | [
"MIT"
] | permissive | use crate::errors::ParseError;
use crate::responses::{json_array, Response};
use crate::types::Unistring;
use serde::{Deserialize, Serialize};
use serde_json::json;
use std::fmt;
#[derive(Serialize, Deserialize)]
pub struct BlocksInChainResponse {
pub block_ids: json_array::JsonArray<Unistring>,
}
impl fmt::Displ... | true |
935d1eec5666fc39644bb02e357df1594f05f3e9 | Rust | xgillard/ddo | /ddo/src/abstraction/mdd.rs | UTF-8 | 5,817 | 2.59375 | 3 | [
"MIT"
] | permissive | // Copyright 2020 Xavier Gillard
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, di... | true |
f97ccabaee393768ca2b5a70bc0898b01b4f7c9c | Rust | pcsm/simulacrum | /simulacrum/examples/manual.rs | UTF-8 | 3,225 | 3.375 | 3 | [
"MIT"
] | permissive | // This example demonstrates everything that can be done with Simulacrum at the
// at the lowest level API.
extern crate simulacrum;
use simulacrum::*;
trait CoolTrait {
// Shared self
fn foo(&self);
// Mutable self
fn bar(&mut self);
// One parameter and returning a value
fn goop(&mut self... | true |
e8fb8e59acb178331c71a3a3c31afbe800812f08 | Rust | dalcde/x11rb | /src/rust_connection/stream.rs | UTF-8 | 8,440 | 2.890625 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use std::io::{IoSlice, Result};
use std::net::{Ipv4Addr, SocketAddr, TcpStream};
#[cfg(unix)]
use std::os::unix::io::{AsRawFd, RawFd};
#[cfg(unix)]
use std::os::unix::net::UnixStream;
use super::fd_read_write::{ReadFD, WriteFD};
use super::xauth::Family;
use crate::utils::RawFdContainer;
/// A wrapper around a `TcpSt... | true |
c9f24ac6590278aa68b4b9e5a000805c2a8c1b72 | Rust | cusiman7/AdventOfCode2020 | /src/bin/day3.rs | UTF-8 | 867 | 2.90625 | 3 | [] | no_license |
fn check_slope(ski_map : &Vec<Vec<char>>, dx : usize, dy : usize) -> u32 {
let mut x = 0;
let mut y = 0;
let mut tree_count = 0;
while y < ski_map.len() {
if ski_map[y][x] == '#' {
tree_count += 1;
}
x = (x + dx) % (ski_map[0].len());
y += dy;
}
retur... | true |
8d9a8f5653848e1ba2d115e8c61d08c365827504 | Rust | willfrew/virtual-rc-controller | /hid-server/src/ws_device.rs | UTF-8 | 3,705 | 2.59375 | 3 | [] | no_license | use std::{io, thread, time, fs};
use uhid_virt::{Bus, CreateParams, UHIDDevice, };
use usbd_hid::descriptor::SerializedDescriptor;
use actix::{Actor, StreamHandler};
use actix_web_actors::ws;
use serde::Deserialize;
use serde_json;
use crate::reports::{RCControllerInputReport};
#[derive(Deserialize)]
struct Coord {
... | true |
e29b1d2c3b6b970ce248b79b2b0e62bcef8eec64 | Rust | semrov/JsonParser | /src/test_lex.rs | UTF-8 | 8,482 | 3.21875 | 3 | [] | no_license | use lex::{Lex,Token,TokenType};
// assert_eq!(lexer.next(),Token{span: &json[], token_type: } );
#[test]
fn test_simple()
{
let json = r#"-3.12e-10 [-4559,12.66,"string",[]] true false null {}"#;
let mut lexer = Lex::new(json);
assert_eq!(lexer.next(),Token{span: &json[0..9], token_type: TokenType::Numbe... | true |
b2d7380e1146f9ca8886f4313e890ac3ebc3479b | Rust | johnny-human/nlp-euclidean | /src/lib.rs | UTF-8 | 2,569 | 3.796875 | 4 | [
"MIT"
] | permissive | use std::env;
struct Count<T: Iterator> {
iter: T,
next: Option<T::Item>
}
impl<T: Iterator> From<T> for Count<T> {
fn from (iter: T) -> Count<T> {
Count {
iter: iter, next: None
}
}
}
impl<T:Iterator> Iterator for Count<T> where T::Item: PartialEq {
type Item = (T::It... | true |
27176da7556d0a7615d686003aa2797e630a5d89 | Rust | jarkkom/adventofcode-2020 | /src/15/part2.rs | UTF-8 | 4,184 | 3.953125 | 4 | [] | no_license | use std::collections::HashMap;
#[derive(Debug)]
struct MemoryGame {
turn: i64,
starting_numbers: Vec<i64>,
last_seen: HashMap<i64, i64>,
previous: i64,
}
impl MemoryGame {
fn new(starting_numbers: Vec<i64>) -> Self {
Self {
turn: 0,
starting_numbers,
las... | true |
1f63b1ac655b76b5d82fdd78bc94b74986966370 | Rust | fireice-uk/rus_errors | /src/main.rs | UTF-8 | 3,001 | 3.234375 | 3 | [] | no_license | use std::fmt;
use std::error::Error;
#[derive(Debug)] // Needed for fmt not to complain
struct ErrorNumberIsOne {
c : &'static str,
}
impl ErrorNumberIsOne {
fn new() -> ErrorNumberIsOne {
ErrorNumberIsOne {
c : "You passed one to fun_needs_zero"
}
}
}
impl fmt::Display for Err... | true |
4eb5c67657b9133fc1bc760710e8070200ef51b4 | Rust | pombredanne/whackadep | /depdive/src/ghcomment.rs | UTF-8 | 7,613 | 3.75 | 4 | [
"Apache-2.0"
] | permissive | //! This module abstracts github comment generation
//! by using markdown, html, and emojis
#[derive(PartialEq)]
#[allow(dead_code)]
pub enum TextStyle {
Plain,
Bold,
Italic,
Code,
}
#[non_exhaustive]
pub enum Emoji {
WhiteCheckMark,
RedCross,
Warning,
}
pub struct GitHubCommentGenerator ... | true |
6601e67d3b89ffa8f5c64c62eee781e014fb34bc | Rust | Playing-with-Rust/simple-card-draft | /src/main.rs | UTF-8 | 789 | 3.03125 | 3 | [] | no_license | mod card;
mod pack;
mod random;
mod helpers;
use card::Card;
use helpers::ask_input;
use pack::Pack;
fn main() {
manual_flow()
}
fn manual_flow() {
let mut picked_cards: Vec<Card> = vec!();
let mut pack1 = Pack::new();
pack1.open();
picked_cards.push(pick_from_pack(pack1).unwrap());
... | true |
86eac495f42aef429dded6ea7e822ad863fd671e | Rust | BitcoinCredit/E-Bills | /build.rs | UTF-8 | 3,019 | 2.71875 | 3 | [
"MIT"
] | permissive | use std::{
env, fs,
path::{Path, PathBuf},
};
const IDENTITY_FOLDER_PATH: &str = "identity";
const BILLS_FOLDER_PATH: &str = "bills";
const CONTACT_MAP_FOLDER_PATH: &str = "contacts";
const CSS_FOLDER_PATH: &str = "css";
const IMAGE_FOLDER_PATH: &str = "image";
const TEMPLATES_FOLDER_PATH: &str = "templates";
... | true |
42d32d9029a5682e92de0e2d3c9965faa943f4b3 | Rust | vni/programming | /rust-in-action/ch10/src/bin/listing10_1.rs | UTF-8 | 290 | 3.5 | 4 | [] | no_license | fn add(a: i32, b: i32) -> i32 {
a + b
}
fn main() {
let lambda_add = |a, b| a + b;
let lambda_add_2 = |a, b| a + b;
println!("add(4, 5): {}", add(4, 5));
println!("lambda_add(4, 5): {}", lambda_add(4, 5));
println!("lambda_add_2(4, 5): {}", lambda_add_2(4, 5));
}
| true |
6ef2fd8ccb92d084508ac674bd6a7882d6d75c02 | Rust | GuilloteauQ/tex-rs | /src/math_mode.rs | UTF-8 | 588 | 2.890625 | 3 | [] | no_license | use latex_file::LatexFile;
/// Math mode
use std::io::BufWriter;
use std::io::Write;
use writable::*;
#[derive(Clone)]
pub struct MathContent {
content: String,
}
impl MathContent {
pub fn new(content: String) -> Self {
MathContent { content }
}
}
impl Writable for MathContent {
fn write_late... | true |
8ac22336b041ffc3af73251d7a7732fa61f6c4de | Rust | lperlaki/const-layout-rs | /src/lib.rs | UTF-8 | 1,993 | 3.078125 | 3 | [] | no_license | #![feature(const_generics)]
use core::mem::{align_of, size_of};
#[doc(hidden)]
pub enum Size<const SIZE: usize> {}
#[doc(hidden)]
pub enum Align<const ALIGN: usize> {}
#[doc(hidden)]
pub unsafe trait CL {
type Size;
type Align;
}
#[doc(hidden)]
unsafe impl<T> CL for T {
type Size = Size<{ size_of::<T>(... | true |
4dbb1aa055070e02c21641f422477cbe465c9ffd | Rust | Stef-a-d/raytracing | /src/texture.rs | UTF-8 | 1,053 | 3.328125 | 3 | [] | no_license | use crate::vec3::{Point3, Color, Vec3};
use std::rc::Rc;
pub trait Texture {
fn value(&self, u:f64, v: f64, p: &Point3) -> Color;
}
pub struct SolidColor {
color_value: Color,
}
impl SolidColor {
pub fn new(c: Color) -> SolidColor {
SolidColor {
color_value: c,
}
}
}
impl... | true |
e13e813df771ba2a574964d7a8b6b77585bfad08 | Rust | sigp/lighthouse | /beacon_node/beacon_chain/src/observed_block_producers.rs | UTF-8 | 17,419 | 2.96875 | 3 | [
"Apache-2.0"
] | permissive | //! Provides the `ObservedBlockProducers` struct which allows for rejecting gossip blocks from
//! validators that have already produced a block.
use std::collections::hash_map::Entry;
use std::collections::{HashMap, HashSet};
use std::marker::PhantomData;
use types::{BeaconBlockRef, Epoch, EthSpec, Hash256, Slot, Uns... | true |
1455cb1831e476eae513ac5fc018e264df54e1be | Rust | optozorax/olymp | /templates/src/to_include/z_function.rs | UTF-8 | 940 | 2.984375 | 3 | [] | no_license | fn z_function<T: PartialEq>(input: &[T]) -> Vec<usize> {
let mut z = vec![0; input.len()];
let mut l = 0usize;
let mut r = 0usize;
for i in 1..input.len() {
let prototype_z = z[i - l];
let zi = &mut z[i];
if let Some(dist_to_end) = (r + 1).checked_sub(i) {
*zi = min(p... | true |
474a0612b87464b64999185040b47962828b9e46 | Rust | jobdeng/rucene | /src/core/util/variant_value.rs | UTF-8 | 14,190 | 2.765625 | 3 | [
"Apache-2.0"
] | permissive | // Copyright 2019 Zhizhesihai (Beijing) Technology Limited.
//
// 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 a... | true |
602077669378cff53251beebf3556febeef04832 | Rust | hiimtaylorjones/programming-kata | /karate/rust/src/lib.rs | UTF-8 | 3,031 | 3.671875 | 4 | [] | no_license | use std::thread;
pub fn chop(int: i32, array: &mut [i32]) -> i32{
let mut count = 0;
for x in array.iter() {
if x == &int {
return count;
}
count += 1;
}
return -1;
}
pub fn binary_chop(int: i32, array: &mut [i32]) -> i32 {
let half = array.len() / 2;
let fu... | true |
0c7c424bedb2b8d2e2c80c0ce33298e1c81be09f | Rust | IThawk/rust-project | /rust-master/src/test/ui/consts/const-binops.rs | UTF-8 | 2,396 | 2.9375 | 3 | [
"MIT",
"LicenseRef-scancode-other-permissive",
"Apache-2.0",
"BSD-3-Clause",
"BSD-2-Clause",
"NCSA"
] | permissive | // run-pass
macro_rules! assert_approx_eq {
($a:expr, $b:expr) => ({
let (a, b) = (&$a, &$b);
assert!((*a - *b).abs() < 1.0e-6,
"{} is not approximately equal to {}", *a, *b);
})
}
static A: isize = -4 + 3;
static A2: usize = 3 + 3;
static B: f64 = 3.0 + 2.7;
static C: isize =... | true |
9d30573c3c0489c42491cfe80a0b6dbba7306a3b | Rust | mehcode/config-rs | /examples/static_env.rs | UTF-8 | 630 | 2.9375 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use config::Config;
lazy_static::lazy_static! {
#[derive(Debug)]
pub static ref CONFIG: Config = Config::builder()
.add_source(config::Environment::with_prefix("APP_NAME").separator("_"))
.build()
.unwrap();
}
/// Get a configuration value from the static configuration object
pub fn ge... | true |
0473e1a309f82a3691be1fec0a7c3b115f3337e7 | Rust | ThermalSpan/rust-util | /src/num_util/mod.rs | UTF-8 | 1,086 | 3.546875 | 4 | [] | no_license |
use std::ops::Rem;
use std::fmt;
use std::error::Error;
#[derive(Debug)]
struct FactorError {
description: String,
}
impl fmt::Display for FactorError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description)
}
}
impl Error for FactorError {
fn description(&s... | true |
f8a8a0f00ec3a00d154ea117daf373059e86d449 | Rust | fabianschuiki/moore | /src/vhdl/hir/expr.rs | UTF-8 | 6,733 | 2.734375 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | // Copyright (c) 2016-2021 Fabian Schuiki
#![deny(missing_docs)]
use num::{BigInt, BigRational, ToPrimitive};
use crate::common::errors::*;
use crate::common::SessionContext;
use crate::hir::prelude::*;
use crate::konst2::{Const2, FloatingConst, IntegerConst};
pub use crate::syntax::ast::Dir;
use crate::ty2::{Unive... | true |
a1debb1259142744d8d653f19172fc88f141f1d4 | Rust | maxsnew/cargo-dot | /src/main.rs | UTF-8 | 4,725 | 2.703125 | 3 | [] | no_license | extern crate cargo;
extern crate docopt;
extern crate dot;
extern crate rustc_serialize;
use cargo::core::{Resolve, SourceId, PackageId};
use docopt::Docopt;
use std::borrow::{Cow};
use std::convert::Into;
use std::env;
use std::io;
use std::io::Write;
use std::fs::File;
use std::path::{Path, PathBuf};
static USAGE: ... | true |
4ae0715152794c3feee2031d226a81f2b4caeb7c | Rust | rickwebiii/RustHexEditor | /src/hex_edit/binary_file.rs | UTF-8 | 1,176 | 3.3125 | 3 | [] | no_license | use std::fs::File;
use std::io;
use std::io::prelude::*;
pub struct BinaryFile {
_data: Vec<u8>,
}
#[derive(Debug)]
pub enum BinaryFileErrorCode {
CouldNotOpenFile { reason: io::Error },
CouldNotReadFile { reason: io::Error }
}
impl BinaryFile {
pub fn open(file_path: &String) -> Result<BinaryFile, B... | true |
a0158f6928506a9684b539aa1cc8b509ebd9072f | Rust | White-Green/partial_const | /src/stable.rs | UTF-8 | 4,741 | 3.703125 | 4 | [
"MIT"
] | permissive | /// A trait for handling constant and non-constant values in a common way
///
/// # Example
/// ```
/// # #[cfg(feature = "usize")] #[rustversion::since(1.51)] fn test() {
/// fn twice<T: partial_const::MayBeConst<usize>>(i: T) -> usize {
/// i.value() * 2
/// }
///
/// assert_eq!(twice(1usize), 2usize);
/// assert... | true |
19816651355e6d33a10592e62e56d38e6ff891a5 | Rust | johannlilly/the-rust-programming-language_v2 | /projects/hello_world/main.rs | UTF-8 | 107 | 2.578125 | 3 | [] | no_license | fn main() {
println!("Hello, world!"); // println! is a Rust macro. println without the ! is a function
} | true |
8a05bbeed9086377d26854898647af09b921e9ec | Rust | Neo-Ciber94/mattro-rs | /src/name_value.rs | UTF-8 | 7,283 | 3.59375 | 4 | [
"MIT"
] | permissive | use crate::{lit_to_string, display_lit};
use syn::{Lit};
use std::str::FromStr;
use std::fmt::{Display, Formatter, Write};
use std::hash::{Hash, Hasher};
/// Represents an attribute name-value: `name="value"`.
#[derive(Debug, Clone)]
pub struct NameValue {
pub name: String,
pub value: Value,
}
impl Display fo... | true |
4118fce1e550827e43bf6cce7015b94b98ee2f37 | Rust | joseluis/bitarray | /src/serde_impl.rs | UTF-8 | 2,144 | 2.96875 | 3 | [
"MIT"
] | permissive | use crate::BitArray;
use core::fmt;
use serde::{
de::{Error, Expected, SeqAccess, Visitor},
Deserialize, Deserializer, Serialize, Serializer,
};
impl<const B: usize> Serialize for BitArray<B> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
s... | true |
947720be15e9ba3b2a9e0a8f3b416c5ddcace6ea | Rust | SuperiorJT/twilight | /http/src/request/application/command/create_guild_command/message.rs | UTF-8 | 2,360 | 3.109375 | 3 | [
"ISC"
] | permissive | use super::super::CommandBorrowed;
use crate::{
client::Client,
error::Error,
request::{Request, RequestBuilder},
response::ResponseFuture,
routing::Route,
};
use twilight_model::{
application::command::{Command, CommandType},
id::{ApplicationId, GuildId},
};
/// Create a message command in... | true |
44e74265af7d91f6016f958b5aa81ab2fa61a35c | Rust | llgoer/quickjs-rs | /src/bindings.rs | UTF-8 | 22,353 | 2.515625 | 3 | [
"MIT"
] | permissive | use std::{
ffi::CString,
os::raw::{c_int, c_void},
sync::Mutex,
};
use libquickjs_sys as q;
use crate::{callback::Callback, ContextError, ExecutionError, JsValue, ValueError};
// JS_TAG_* constants from quickjs.
// For some reason bindgen does not pick them up.
const TAG_STRING: i64 = -7;
const TAG_OBJEC... | true |
c19314e3fb7f34bc4c3830ba7aa43a75e044c10f | Rust | kmeisthax/retrogram | /src/arch/sm83/types.rs | UTF-8 | 6,544 | 2.921875 | 3 | [] | no_license | //! Types used in modeling the SM83
use crate::arch::sm83::{dataflow, disassemble, prereq, trace};
use crate::arch::{ArchName, Architecture};
use crate::memory::{Memory, Pointer};
use crate::{analysis, ast, memory, reg};
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
use std::{fmt, result, str};
... | true |
aa69981a2790e35a1f80e08ba6a53115b3787785 | Rust | jingfee/advent-of-code-rust | /src/y2020/day19.rs | UTF-8 | 6,415 | 3.125 | 3 | [] | no_license | use crate::solver::Solver;
use itertools::Itertools;
use pcre2::bytes::Regex;
use std::io::prelude::*;
use std::io::BufReader;
use std::{collections::HashMap, fs::File};
pub struct Problem;
impl Solver for Problem {
type Input = (HashMap<usize, String>, Vec<String>);
type Output1 = usize;
type Output2 = u... | true |
9392d671f4ec3a8026a996a78282a9a90d41b2e3 | Rust | melted/aoc2016 | /day19/src/main.rs | UTF-8 | 1,103 | 3.296875 | 3 | [] | no_license | fn get_elves(n : usize) -> Vec<usize> {
let mut out = Vec::with_capacity(n);
for i in 1..n + 1 {
out.push(i)
}
out
}
fn play_game(n : usize, part1 : bool) -> usize {
let mut elves = get_elves(n);
let mut count = n;
let mut index = 0;
loop {
let mut target = if part1 { 1... | true |
a1cd5d9ff345b2f3f4df7d86c6f71bd19b31a620 | Rust | jacob-pro/arm-kernel | /hilevel/src/io/PL011.rs | UTF-8 | 2,714 | 2.703125 | 3 | [] | no_license | #![allow(non_snake_case)]
use crate::bindings;
use crate::bindings::{PL011_t, PL011_putc, PL011_getc};
use core::fmt::{Write, Error};
use core::result::Result;
use crate::io::descriptor::{FileDescriptor, FileDescriptorBase, IOResult, FileError};
use alloc::collections::VecDeque;
const KEYBOARD_BUFFER: usize = 4096;
... | true |
ec617854da558698464ed35538f83e52871a4eb5 | Rust | AgeManning/discv5-cli | /src/server/bootstrap.rs | UTF-8 | 2,281 | 2.984375 | 3 | [
"MIT"
] | permissive | use std::{fs::File, io::BufReader, str::FromStr};
use discv5::{Discv5, Enr};
use serde::{Deserialize, Serialize};
/// The top level bootstrap object.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Ord, PartialOrd, Hash)]
pub struct BootstrapStore {
/// The list of bootstrap nodes.
pub data: Vec... | true |
0733da369ef91bfbf642813824ac66a3da1ee141 | Rust | kazu69/Scripts_Notes | /rust/basic_study/vendor_machine.rs | UTF-8 | 1,998 | 3.859375 | 4 | [] | no_license | #[derive(Debug)]
struct Drink{
name: String,
price_in_yen: u32
}
impl Drink {
fn new(name: &str, price_in_yen: u32) -> Drink {
Drink {
name: name.to_string(),
price_in_yen: price_in_yen
}
}
}
#[derive(Debug)]
struct VendingMachine {
drinks: Vec<Drink>,
cash_balance: u64
}
impl Vendin... | true |
6c254e43e42683cdc84c513d2ad400f86370ff07 | Rust | cpralea/xlang | /xlc/src/ast/token.rs | UTF-8 | 685 | 3.125 | 3 | [
"MIT"
] | permissive | use common;
pub struct Token {
pub kind: TokenKind,
pub value: String,
pub location: common::Location,
}
impl Token {
pub fn new(kind: TokenKind, value: String, location: common::Location) -> Token {
Token {
kind: kind,
value: value,
location: location,
... | true |
4a3af3cee9ca284a7a769ce908ebafb207ca1908 | Rust | 38/grass-demo | /grass-macros/src/ql/operator.rs | UTF-8 | 4,123 | 2.8125 | 3 | [] | no_license | use super::CodeGeneratorContext;
use quote::quote;
use std::fmt::{Debug, Formatter, Result as FmtResult};
use syn::{
parenthesized,
parse::{Parse, ParseStream},
punctuated::Punctuated,
visit_mut::VisitMut,
Expr, Ident, LitInt, Result, Token,
};
pub(crate) enum Operator {
Where(Expr),
Map(Ex... | true |
c3dcef3bead0ae82838e5f60c7751c033f73a457 | Rust | nphyx/scrapsrl | /src/resource/asset/entity_template.rs | UTF-8 | 3,408 | 2.890625 | 3 | [] | no_license | use serde::{Deserialize, Serialize};
use specs::World;
use crate::component::*;
#[derive(Clone, Serialize, Deserialize)]
pub struct EntityTemplate {
brain: Option<AIBrain>,
character: Option<Character>,
colors: Option<Colors>,
description: Option<Description>,
icon: Option<IconRef>,
notificati... | true |
4c9180da8b09a715c573d713610451c2ae0203f7 | Rust | Azure/iotedge | /edgelet/edgelet-http-mgmt/src/module/restart_or_start_or_stop.rs | UTF-8 | 3,558 | 2.953125 | 3 | [
"MIT"
] | permissive | // Copyright (c) Microsoft. All rights reserved.
pub(crate) struct Route<M>
where
M: edgelet_core::ModuleRuntime + Send + Sync,
{
runtime: std::sync::Arc<tokio::sync::Mutex<M>>,
module: String,
action: Action,
}
#[cfg_attr(test, derive(Debug, PartialEq))]
enum Action {
Restart,
Start,
Stop... | true |
432a00a7a68e171a1e2b61713bbc005bf188421d | Rust | niguangye/os_626 | /src/main.rs | UTF-8 | 2,556 | 2.578125 | 3 | [] | no_license | #![no_std] // 禁用标准库链接
#![no_main] // 告诉Rust编译器我们不使用预定义的入口点
#![feature(custom_test_frameworks)]
#![test_runner(os_626::test_runner)]
#![reexport_test_harness_main = "test_main"]
extern crate alloc;
use alloc::{boxed::Box, vec, vec::Vec, rc::Rc};
use core::panic::PanicInfo;
use os_626::println;
use bootloader::{ BootIn... | true |
d342e57cf1c942cf658f72636734c0aeb95b4b47 | Rust | asnimansari/razorpay-rs | /src/utils.rs | UTF-8 | 1,070 | 2.796875 | 3 | [] | no_license | use ring::hmac::{self};
use data_encoding::HEXLOWER;
pub fn verify_webhook_signature(data: &str, signature: &str, secret: &str) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
let key = hmac::Key::new(hmac::HMAC_SHA256, secret.as_bytes());
let expected_signature = hmac::sign(&key, data.as_b... | true |
a3fff8caeba225dd63fc57d20b132118c0828a98 | Rust | konradsz/adventofcode2018 | /day20/map.rs | UTF-8 | 2,198 | 3.453125 | 3 | [] | no_license | use std::collections::HashMap;
use std::cmp;
use std::fs;
#[derive(Clone, PartialEq, Eq, Hash)]
struct Coordinate {
x: i32,
y: i32
}
fn main() {
let content = fs::read_to_string("input").unwrap();
let input = content.trim().trim_start_matches('^').trim_end_matches('$');
let mut current_position = ... | true |
d7128e5eb69adaec0e4547337fd7391779991cf3 | Rust | PSeitz/tantivy | /src/aggregation/agg_result.rs | UTF-8 | 9,447 | 2.984375 | 3 | [
"MIT"
] | permissive | //! Contains the final aggregation tree.
//! This tree can be converted via the `into()` method from `IntermediateAggregationResults`.
//! This conversion computes the final result. For example: The intermediate result contains
//! intermediate average results, which is the sum and the number of values. The actual aver... | true |
619d3a10748d65fd8414e040727e3ca00e863b2e | Rust | wuerges/iccad2020_rust | /src/nandgraph.rs | UTF-8 | 703 | 3.25 | 3 | [] | no_license |
#[derive(Debug)]
pub struct Graph {
adj : Vec<Vec<(bool, usize)>>
}
impl Graph {
pub fn add_edge(&mut self, u: usize, v:usize, p:bool) {
self.adj[u].push((p, v));
}
pub fn new_with_n(n :usize) -> Self {
Graph { adj : vec![Vec::new(); n] }
}
pub fn new() -> Self {
Graph ... | true |
d63ed431330a491f154cc0b2ee2c1f6cdce5b44f | Rust | caibirdme/leetcode_rust | /src/prob_538.rs | UTF-8 | 2,089 | 3.515625 | 4 | [
"MIT"
] | permissive | // Definition for a binary tree node.
#[derive(Debug, PartialEq, Eq)]
pub struct TreeNode {
pub val: i32,
pub left: Option<Rc<RefCell<TreeNode>>>,
pub right: Option<Rc<RefCell<TreeNode>>>,
}
impl TreeNode {
#[inline]
pub fn new(val: i32) -> Self {
TreeNode {
val,
left: None,
... | true |
d20137fc57345f0571921f89ec9a2b844d377990 | Rust | Elena-Qiu/InferSim | /src/config.rs | UTF-8 | 601 | 2.625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT",
"Apache-2.0"
] | permissive | use std::fs;
use std::path::{Path, PathBuf};
use serde::Deserialize;
use crate::utils::app_config::AppConfig;
use crate::utils::prelude::*;
#[derive(Deserialize)]
pub(crate) struct OutputDir(PathBuf);
impl OutputDir {
pub fn file(&self, name: impl AsRef<Path>) -> Result<PathBuf> {
fs::create_dir_all(&se... | true |
d9dc94c21926f337ef5921209d9322e0bdc3411e | Rust | hamaluik/project-obsidian-mill | /src/systems/hueshift.rs | UTF-8 | 519 | 2.8125 | 3 | [
"Apache-2.0"
] | permissive |
use specs::{Read, WriteStorage, System};
pub struct HueShift;
impl<'a> System<'a> for HueShift {
type SystemData = (Read<'a, crate::DeltaTime>, WriteStorage<'a, crate::components::Colour>);
fn run(&mut self, data: Self::SystemData) {
let (dt, mut colour) = data;
let dt = dt.0;
use s... | true |
9b66aa4a0facbc93d92f5573f56c91f74152cd35 | Rust | tock/tock | /kernel/src/process_checker.rs | UTF-8 | 7,103 | 2.796875 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | // Licensed under the Apache License, Version 2.0 or the MIT License.
// SPDX-License-Identifier: Apache-2.0 OR MIT
// Copyright Tock Contributors 2022.
//! Traits and types for application credentials checkers, used to
//! decide whether an application can be loaded. See
//| the [AppID TRD](../../doc/reference/trd-ap... | true |
ff06ff848568a1af790c718dc96de4948375c5ec | Rust | EFanZh/LeetCode | /src/problem_0488_zuma_game/bfs.rs | UTF-8 | 6,098 | 2.84375 | 3 | [] | no_license | pub struct Solution;
// ------------------------------------------------------ snip ------------------------------------------------------ //
use std::collections::{HashSet, VecDeque};
use std::hash::{Hash, Hasher};
#[derive(Clone, Copy, Eq)]
struct State {
buffer: [u8; 21],
sizes: u8,
}
impl State {
fn... | true |
e7e02c03abf44c2dcc5d927c520c909f8ef7b0b8 | Rust | songyzh/leetcode-rust | /src/solution/s0371_sum_of_two_integers.rs | UTF-8 | 1,311 | 3.609375 | 4 | [
"Apache-2.0"
] | permissive | /**
* [371] Sum of Two Integers
*
* Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.
*
* <div>
* Example 1:
*
*
* Input: a = <span id="example-input-1-1">1</span>, b = <span id="example-input-1-2">2</span>
* Output: <span id="example-output-1">3</span>
*
*
* <... | true |
d4036570d6bc0b6941185855ada8eff6cc51e347 | Rust | wilsonzlin/fast-spsc-queue | /src/lib.rs | UTF-8 | 3,971 | 2.96875 | 3 | [] | no_license | use std::{mem, ptr};
struct SpscQueue<V: Send + Sync> {
buffer: *mut V,
capacity: usize,
capacity_mask: usize,
// We implement it at the queue level as it's a common requirement and so that V doesn't have to
// be a heavier enum with an end message variant.
ended: bool,
read_next: usize,
... | true |
09668341478d891c799d8639ce0b47f3e9bca48d | Rust | aiifabbf/leetcode-memo | /876.rust/src/main.rs | UTF-8 | 1,365 | 3.484375 | 3 | [] | no_license | /*
.. default-role:: math
返回链表最中间的那个节点。如果链表是偶数长度的,返回中间靠右的那个节点。
先遍历一遍链表,得到链表的长度,假设长度是 `n` 吧。无论是奇数还是偶数长度,都是第 `\lfloor n / 2 \rfloor` 个节点。
*/
struct Solution;
// Definition for singly-linked list.
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct ListNode {
pub val: i32,
pub next: Option<Box<ListNode>>,
}
imp... | true |
19d3a3c4ec3d13fb2ae367eb258af3c57241d5e4 | Rust | CGQAQ/postcss-rs | /crates/recursive-parser/src/parser.rs | UTF-8 | 7,713 | 3.390625 | 3 | [
"MIT"
] | permissive | use std::iter::Peekable;
use tokenizer::{Token, TokenType, Tokenizer};
use crate::Lexer;
pub struct Root<'a> {
children: Vec<RuleOrAtRuleOrDecl<'a>>,
start: usize,
end: usize,
}
enum RuleOrAtRuleOrDecl<'a> {
Rule(Rule<'a>),
AtRule(AtRule<'a>),
Declaration(Declaration<'a>),
}
// enum AtRuleOrDeclaration<'... | true |
26beb2de3783c0d34646eed6a9f349f2f636caed | Rust | elprl/sensehat-rs | /src/lps25h.rs | UTF-8 | 2,542 | 2.875 | 3 | [
"MIT",
"CC-BY-4.0",
"Apache-2.0"
] | permissive | //! * Driver for the LPS25H Pressure sensor
//! See <http://www.st.com/en/mems-and-sensors/lps25h.html>
use byteorder::{ByteOrder, LittleEndian};
use i2cdev::core::I2CDevice;
pub const REG_RES_CONF: u8 = 0x10;
pub const REG_CTRL_REG_1: u8 = 0x20;
pub const REG_CTRL_REG_2: u8 = 0x21;
pub const REG_STATUS_REG: u8 = 0x2... | true |
92f4434d9eceb69bbb55e66432084d70554080ce | Rust | eistaa/AdventOfCode2020 | /src/day16.rs | UTF-8 | 3,807 | 3 | 3 | [] | no_license | use itertools::Itertools;
use regex::Regex;
use std::collections::HashSet;
use std::fs;
use std::path::Path;
use std::str::FromStr;
#[derive(Debug)]
struct Rule {
pub name: String,
pub ranges: Vec<(i32, i32)>,
}
impl Rule {
fn in_any_range(&self, value: &i32) -> bool {
for (start, end) in &self.ra... | true |
f16b1fd0e1c9a1664ba998714c327ed9619b524a | Rust | serpent-charmer/RIAN | /src/ian.rs | UTF-8 | 9,332 | 3.328125 | 3 | [
"MIT"
] | permissive | pub struct Interval {
left: f64,
right: f64,
}
impl<'a, 'b> std::ops::Add<&'b Interval> for &'a Interval {
type Output = Interval;
fn add(self, addend: &'b Interval) -> Interval {
return Interval {
left: self.left + addend.left,
right: - (-self.right - addend.right)
}
}
}
impl<'a> std::... | true |
853d4494736048582e7f2e866af6273afb937e17 | Rust | sharkbound/rust-projects | /dndgui_egui/mainapp/src/topmenu/mod.rs | UTF-8 | 3,024 | 2.578125 | 3 | [
"MIT"
] | permissive | use eframe::egui;
use eframe::egui::{Context};
use dndlib::{AbilityScores, Character, DndCampaign, Note, Race};
use crate::{file_dialog_handler, MainApp};
pub(crate) fn show_top_menu(ctx: &Context, app: &mut MainApp) {
egui::TopBottomPanel::top("primary_topbar").show(ctx, |ui| {
ui.horizontal(|ui| {
... | true |
ededb553463361ac8ba001309fb278ae2edbd0ca | Rust | fission-codes/basquiat | /src/cfg_parser.rs | UTF-8 | 2,260 | 3.453125 | 3 | [
"Apache-2.0"
] | permissive | use std::{fs::File, path::Path, io::{BufReader, BufRead}};
use std::ops::Mul;
use regex::Regex;
#[derive(Copy, Clone)]
pub struct Config{
pub dimensions: Resize,
// pub operations: Option<Vec<Operation>>
}
pub struct Parser{
re: Regex
}
#[derive(Copy, Clone)]
pub enum Resize{
Width(i32),
Height(i... | true |
b8ab02db8626eebb541e95a0e93742b041eb6fc1 | Rust | RoryABrittain/Advent-of-code-2020 | /src/ten.rs | UTF-8 | 1,533 | 3.296875 | 3 | [] | no_license | use std::fs;
pub fn run() {
let raw_data = fs::read_to_string("ten_data.txt")
.expect("Can't find file");
let lines: Vec<&str> = raw_data.split("\r\n").collect();
let mut numbers: Vec<i64> = lines.iter().map(|x| x.parse::<i64>().unwrap()).collect();
numbers.push(0); // p... | true |
42246cf3b76998c6973999ed6e5d971b3e7f937e | Rust | illicitonion/cargo-raze | /examples/vendored/non_cratesio_library/cargo/vendor/futures-util-0.2.0/src/future/with_executor.rs | UTF-8 | 876 | 2.875 | 3 | [
"Apache-2.0"
] | permissive | use futures_core::{Future, Poll};
use futures_core::task;
use futures_core::executor::Executor;
/// Future for the `with_executor` combinator, assigning an executor
/// to be used when spawning other futures.
///
/// This is created by the `Future::with_executor` method.
#[derive(Debug)]
#[must_use = "futures do nothi... | true |
deac41da5dd9366a41ae32e023721c9b05fafe57 | Rust | alexander-akhmetov/mos | /src/memory/allocator.rs | UTF-8 | 1,607 | 2.75 | 3 | [] | no_license | use core::alloc::GlobalAlloc;
use core::alloc::Layout;
const PREALLOCATED_HEAP_SIZE: usize = 32 * 1024 * 1024; // 32Mb
#[repr(C)]
struct PreAllocatedMemory {
heap: [u8; PREALLOCATED_HEAP_SIZE],
index: usize,
}
impl PreAllocatedMemory {
const fn new() -> PreAllocatedMemory {
PreAllocatedMemory {
... | true |
b958d805ad7df6dcc305684f4b5e29ad13722253 | Rust | nolik/CodeSignal | /src/task/box_blur.rs | UTF-8 | 2,055 | 3.28125 | 3 | [] | no_license | pub fn boxBlur(image: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
let mut result: Vec<Vec<i32>> = Vec::new();
for row in 2..image.len() {
let mut vec: Vec<i32> = Vec::new();
for item in 2..image[row].len() {
let box_value = box_value(row, item, &image);
vec.push(box_value);
... | true |
ff238418db05697fdd31b0c1c1cf83e26254658b | Rust | barreiro/euler | /src/main/rust/euler/solver106.rs | UTF-8 | 1,877 | 3.453125 | 3 | [
"MIT"
] | permissive | // COPYRIGHT (C) 2022 barreiro. All Rights Reserved.
// Rust solvers for Project Euler problems
use algorithm::cast::to_i64;
use algorithm::combinatorics::choose;
use Solver;
/// Let `S(A)` represent the sum of elements in set `A` of size `n`. We shall call it a special sum set if for any two non-empty disjoint subse... | true |
e8f4c43e08b7325814f4a7452d68c5b9ba6dc6e8 | Rust | woodgear/tpm | /src/main.rs | UTF-8 | 28,510 | 2.5625 | 3 | [] | no_license | #![allow(clippy::needless_return)]
use failure;
use serde::{Deserialize, Serialize};
use serde_json;
use std::cmp::{Ord, Ordering};
use std::collections::HashMap;
use std::collections::VecDeque;
use std::fmt::Debug;
use std::path::{Path, PathBuf};
use std::pin::Pin;
use std::ptr::NonNull;
use structopt::StructOpt;
mod ... | true |
73926957ab5e08658057677b3da36321b40482c5 | Rust | chromium/chromium | /third_party/rust/rstest_macros/v0_17/crate/src/lib.rs | UTF-8 | 31,130 | 3.03125 | 3 | [
"Apache-2.0",
"MIT",
"BSD-3-Clause",
"GPL-1.0-or-later",
"LGPL-2.0-or-later"
] | permissive | #![cfg_attr(use_proc_macro_diagnostic, feature(proc_macro_diagnostic))]
extern crate proc_macro;
// Test utility module
#[cfg(test)]
pub(crate) mod test;
#[cfg(test)]
use rstest_reuse;
#[macro_use]
mod error;
mod parse;
mod refident;
mod render;
mod resolver;
mod utils;
use syn::{parse_macro_input, ItemFn};
use cra... | true |
9dd437a0d6cf61cec25f67615edae9b2d58d612d | Rust | mongodb-rust/decimal128 | /src/lib.rs | UTF-8 | 21,682 | 3.4375 | 3 | [
"Apache-2.0"
] | permissive | //! Decimal 128 bits are broken down like so:
//! [1bits] [ 14bits ] [ 113 bits ]
//! sign exponent significand
//! field
use bitvec::{bitvec, BigEndian, BitVec};
use byteorder::*;
use std::cmp::Ordering;
use std::fmt;
use std::io::Cursor;
use std::str::FromStr;
#[derive(Clone, P... | true |
fc56557cfa5aaeb5a3af2834772a8aa37bf44d77 | Rust | ms705/timely-dataflow | /src/construction/builder.rs | UTF-8 | 7,234 | 3.046875 | 3 | [
"MIT"
] | permissive | use std::rc::Rc;
use std::cell::RefCell;
use progress::timestamp::RootTimestamp;
use progress::{Timestamp, Scope, Subgraph};
use progress::nested::{Source, Target};
use progress::nested::product::Product;
use progress::nested::scope_wrapper::ScopeWrapper;
use communication::{Communicator, Data, Pullable};
use communic... | true |
70a1f55cd76a341dc8daf2719e97d37a4025ded8 | Rust | zeeshanakram3/advent-of-code | /aoc04/src/main.rs | UTF-8 | 7,188 | 3.078125 | 3 | [
"Unlicense",
"MIT"
] | permissive | #[macro_use]
extern crate lazy_static;
extern crate regex;
use std::collections::HashMap;
use std::error::Error;
use std::io::{self, Read, Write};
use std::ops::Range;
use std::result;
use std::slice;
use std::str::FromStr;
use regex::Regex;
macro_rules! err {
($($tt:tt)*) => { Err(Box::<Error>::from(format!($($... | true |
652c68b638a9e3ae8356771dc1af65fcea0f5843 | Rust | alexvilanovab/blendit | /src/main.rs | UTF-8 | 2,787 | 2.921875 | 3 | [
"MIT"
] | permissive | extern crate image;
extern crate imageproc;
extern crate indicatif;
extern crate rusttype;
mod cli;
fn main() {
let args = cli::get_arguments();
let img_path = std::path::Path::new(args.value_of("image").unwrap());
let img = match image::open(img_path) {
Ok(img) => img.to_rgb8(),
Err(e) =... | true |
ab8653a0b77a1860eba451f5b139802583d24781 | Rust | njsh4261/benchmarksgame | /bencher/programs/floydwarshall/floydwarshall.rs | UTF-8 | 879 | 3.078125 | 3 | [
"MIT",
"BSD-2-Clause",
"BSD-3-Clause"
] | permissive | use std::io;
fn floydwarshall(graph: &mut Vec<Vec<i32>>, vertex_num: usize) {
for k in 0..vertex_num {
for i in 0..vertex_num {
for j in 0..vertex_num {
if graph[i][j] > graph[i][k] + graph[k][j] {
graph[i][j] = graph[i][k] + graph[k][j];
}
... | true |
20f5631b3cdaf2c261968641b44dedde5ee2a135 | Rust | CodeChain-io/remote-trait-object | /remote-trait-object/src/service/id.rs | UTF-8 | 3,499 | 3.109375 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use super::MethodId;
use linkme::distributed_slice;
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
pub const ID_ORDERING: std::sync::atomic::Ordering = std::sync::atomic::Ordering::SeqCst;
pub type MethodIdAtomic = std::sync::atomic::AtomicU32;
// linkme crate smartly collects all the ... | true |
27454423e88ade09deadf335e03e5c4b32d1f464 | Rust | iicurtis/mcp9808-rs | /src/reg_temp.rs | UTF-8 | 1,500 | 2.875 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use reg::Register;
use reg_temp_generic::ReadableTempRegister;
const REGISTER_PTR: u8 = 0b0101;
const REGISTER_SIZE: u8 = 2;
const BIT_ALERT_CRITICAL: usize = 15;
const BIT_ALERT_UPPER: usize = 14;
const BIT_ALERT_LOWER: usize = 13;
pub trait Temperature: ReadableTempRegister {
fn is_alert_critical(&self) -> boo... | true |
a620aff5cfb1b398b347d6151719c1bb1123eb44 | Rust | lecorref/linear_regression | /src/predict.rs | UTF-8 | 1,025 | 3.3125 | 3 | [] | no_license | use std::io;
use std::io::Read;
use std::fs::File;
fn read_file(mut file: std::fs::File, mileage: f64) -> (){
let mut input = String::new();
file.read_to_string(&mut input).expect("Cannot read file");
let vec = input.split(" ").collect::<Vec<&str>>();
let theta0: f64 = vec[0].trim().parse().expect("Th... | true |
667a25ff9c4660d99e508c67e7e7c6bfb31f4702 | Rust | grufkork/scpmapper | /src/main.rs | UTF-8 | 14,923 | 2.875 | 3 | [] | no_license | use inputbot::{self};
use std::{cmp::max, collections::HashMap, io::{Write, stdout}, thread::sleep};
use std::time::Duration;
use std::fs::read_to_string;
#[derive(Copy, Clone, PartialEq, Eq)]
enum Direction{
Up,
Right,
Down,
Left
}
#[derive(Copy, Clone)]
enum Zone{
Entrance,
Heavy,
Light... | true |
81db8081f1039d6f7513b713b4246b5ead6edba6 | Rust | alexpana/enigma | /src/tags_old.rs | UTF-8 | 5,270 | 2.9375 | 3 | [] | no_license | use std::collections::HashMap;
use std::fs::File;
use std::io::BufRead;
use std::io::BufReader;
use std::path::Path;
use std::time::Instant;
#[derive(Debug, PartialOrd, PartialEq)]
pub enum TagKind {
MacroDefinitions,
EnumValue,
FunctionDefinition,
Enum,
HeaderInclude,
LocalVariable,
ClassM... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.