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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
854b6036c204dee8d5f3332a724fce20d7d75b8c | Rust | gon1332/rusty-vm | /src/vm/instruction/mod.rs | UTF-8 | 1,990 | 3.203125 | 3 | [
"MIT"
] | permissive | use vm::defs::{Register, Opcode};
#[derive(Debug)]
#[derive(Copy, Clone)]
pub struct Instruction {
opcode: Opcode,
register_a: Option<Register>,
register_b: Option<Register>,
operand: Option<i32>,
}
#[allow(unused)]
impl Instruction {
pub fn get_opcode(&self) -> Opcode {
self.opcode
}
... | true |
ebb7ac7c2830c78032bbae46d9d0f46a8ac8ad95 | Rust | Buzzec/kapto_web | /src/game/ruleset/color.rs | UTF-8 | 1,835 | 3.640625 | 4 | [] | no_license | use std::convert::TryFrom;
use std::num::ParseIntError;
use std::str::FromStr;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize, )]
pub struct Color{
/// represented as `rgba(r, g, b, a)`
color: String,
}
impl Color{
pub fn new(r: u8, g: u8, b: u8, a:... | true |
3bc65ca60f7315cb46c2d64da2468ace4ae38dfa | Rust | mdowell12/advent-of-code-2020 | /solutions_fer/day8/src/main.rs | UTF-8 | 4,019 | 3.5625 | 4 | [] | no_license | use std::collections::HashSet;
use std::convert::TryFrom;
use std::io::{self, BufRead};
struct Runtime<'a> {
instructions: &'a Vec<Instruction>,
pub accumulator: isize,
ins_index: usize,
}
#[derive(std::cmp::PartialEq, Copy, Clone)]
enum InsType {
Acc,
Jmp,
Nop,
}
#[derive(Copy, Clone)]
struc... | true |
3d11c0125beea6f37855d7883ab9d89dd9c2b0cd | Rust | voetsjoeba/aoc2019 | /src/day11.rs | UTF-8 | 4,372 | 2.8125 | 3 | [] | no_license | // vim: set ai et ts=4 sts=4 sw=4:
use crate::util;
use std::collections::HashMap;
use crate::intcode::{CPU};
#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)]
enum Facing {
Up,
Down,
Left,
Right,
}
#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)]
struct Pos {
pub x: i32,
pub y: i32,
}
impl ... | true |
ad30fcc556ff9db5d3d588aed7fc037057b63b8e | Rust | RustyYato/memory-model | /memory-model/src/recycle.rs | UTF-8 | 2,233 | 3.078125 | 3 | [] | no_license | use std::{cmp::Ordering, collections::BinaryHeap, hash::Hash};
use sync_wrapper::SyncWrapper;
pub trait Recycle: Default {
type Size: Ord + Hash;
fn empty(self) -> Self;
fn size(&self) -> Self::Size;
}
pub struct Recycler<T> {
heap: SyncWrapper<BinaryHeap<Empty<T>>>,
}
use std::fmt;
impl<T> fmt::De... | true |
5cbf55e59f9dafddade0edbe80919a31e5899777 | Rust | ivardb/AdventOfCode2020 | /src/days/day9/part2.rs | UTF-8 | 1,130 | 3.125 | 3 | [] | no_license | use crate::days::day9::{parse_input, default_input};
pub fn run() {
println!("{}", xmas_str(default_input()).unwrap())
}
pub fn xmas_str(input : &str) -> Result<i64, ()> {
let nums = parse_input(input);
let target = super::part1::xmas(nums.clone());
xmas(nums, target.unwrap())
}
pub fn xmas(nums : Ve... | true |
60d0cd2245b852cf10c794db3cd6b75048e0b875 | Rust | koengit/trainspotting | /rolling/src/railway/infrastructure.rs | UTF-8 | 7,097 | 2.515625 | 3 | [] | no_license | use smallvec::SmallVec;
use eventsim::*;
use eventsim::observable::Observable;
use input::staticinfrastructure::*;
use output::history::InfrastructureLogEvent;
pub type TrainId = usize;
pub type InfLogger = Box<Fn(InfrastructureLogEvent)>;
use std::f64::INFINITY;
use railway::{Sim, Proc};
// pub trait Logger {
// ... | true |
6984b9ef496e21f4237809806c0802fe8cac2b70 | Rust | namanwahi/advent-of-code | /day10/src/main.rs | UTF-8 | 1,245 | 3.03125 | 3 | [
"Apache-2.0"
] | permissive | use std::fs::File;
use std::str;
use std::io::{self, BufRead};
use std::error::Error;
use std::cmp::max;
use std::collections::HashMap;
fn main() -> Result<(), Box<dyn Error>>{
let f = File::open("inputs.txt")?;
let reader = io::BufReader::new(f);
let mut nums: Vec<i64> = reader.lines().map(|line| line.unw... | true |
bc7422f91b1d0a01bc5516f1dfe94808d40ce219 | Rust | TianTianForever/Rust-Tutorial | /thirty-five_days_of_rust/thirty-five_days_of_rust.rs | UTF-8 | 1,131 | 3.5625 | 4 | [] | no_license | mod myerror;
use myerror::*;
use std::ops::Deref;
use std::cell::Cell;
#[derive(Debug)]
struct Rectangle{ height: Cell<f64>, width: f64 }
#[derive(Debug)]
struct Area <'a>{
rectangle: &'a Rectangle,
}
impl Deref for Rectangle {
type Target = Cell<f64>;
fn deref(&self) -> &Cell<f64> {
&self.height... | true |
cc370f9a07fb40dfb66168eeaa07a6c8e19e3e30 | Rust | isbhargav/ounce | /src/event.rs | UTF-8 | 988 | 3.125 | 3 | [] | no_license | pub enum ActionEvent {
BackSpace,
AddCharacter,
MoveRight,
MoveLeft,
MoveUp,
MoveDown,
MoveEndOfWordForward,
MoveEndOfWordBack,
MoveStartOfWordForward,
MoveStartOfWordBack,
MoveEndOfLine,
MoveStartOfLine,
DeletePreviousWord,
}
impl ActionEvent {
/* Based on provid... | true |
9cfa36c0aac7ea32aa44b37e08df060385507032 | Rust | cleancoindev/steit | /steit/src/gen/generator.rs | UTF-8 | 1,210 | 2.609375 | 3 | [] | no_license | use std::{
collections::HashMap,
fs::File,
io::{self, Write},
path::Path,
};
use super::{
gen_meta::{Enum, HasMeta, Meta, Struct},
gen_util,
writer::Writer,
};
pub trait Generator {
fn out_dir(&self) -> &str;
fn indent_size(&self) -> usize;
fn generate_struct(&self, r#struct:... | true |
e32b10390a6bc599435e02813c4b0eee53e83e78 | Rust | coriolinus/exercism-rs | /etl/src/lib.rs | UTF-8 | 273 | 2.625 | 3 | [] | no_license | use std::collections::BTreeMap;
pub fn transform(input: &BTreeMap<i32, Vec<String>>) -> BTreeMap<String, i32> {
input.iter().fold(BTreeMap::new(), |mut acc, (n, v)| {
v.iter().map(|s| acc.insert(s.to_lowercase(), *n)).collect::<Vec<_>>();
acc
})
}
| true |
a46dbc0ab627c4d866f2432b69f3c98536758fee | Rust | gelisam/ludum-dare-44 | /src/sidebar.rs | UTF-8 | 3,390 | 2.8125 | 3 | [] | no_license |
use ggez::{GameResult, Context};
use ggez::graphics::*;
use glam::f32::Vec2;
use globals::*;
use text;
pub const SIDEBAR_WIDTH: f32 = 70.0;
#[derive(Debug)]
pub struct Sidebar {
title: Text,
color: Color,
x: f32,
bounty_amount: f32,
life_amount: f32,
}
pub fn amount_to_dots(amount: f32) -> f32... | true |
90f8944a86e1bacca447810e55a255ebc0f27a23 | Rust | IThawk/rust-project | /rust-master/src/test/mir-opt/issue-62289.rs | UTF-8 | 2,458 | 2.6875 | 3 | [
"MIT",
"LicenseRef-scancode-other-permissive",
"Apache-2.0",
"BSD-3-Clause",
"BSD-2-Clause",
"NCSA"
] | permissive | // check that we don't forget to drop the Box if we early return before
// initializing it
// ignore-tidy-linelength
// ignore-emscripten compiled with panic=abort by default
#![feature(box_syntax)]
fn test() -> Option<Box<u32>> {
Some(box (None?))
}
fn main() {
test();
}
// END RUST SOURCE
// START rustc.t... | true |
64a8bcc83dd1f8859e072d1707e919373cc7b8c6 | Rust | lenoil98/basic_rs | /src/ast/token.rs | UTF-8 | 8,347 | 3.390625 | 3 | [] | no_license | use std::fmt;
use std::num;
use std::str;
use super::function::Func;
use super::keyword::Keyword;
use super::variable::{NameError, Variable};
#[derive(Debug, Clone, PartialEq)]
pub enum Token {
Natural(u64), // Natural Number 01, 12, 3339
Real(f64), // Float, 1.0, 1E10 1.2e-33
Varname(Variabl... | true |
1758bb92d4d7ada8f8ee4a4a5a0537baf8b79b09 | Rust | jbro885/rpsx | /src/psx/mod.rs | UTF-8 | 1,534 | 2.6875 | 3 | [
"MIT"
] | permissive | mod bus;
pub mod cpu;
mod cdrom;
mod controller;
mod display;
mod dma;
mod gpu;
mod interrupt;
mod joypad;
mod mdec;
mod rasteriser;
mod spu;
mod timer;
use self::bus::Bus;
use self::cpu::R3000A;
use self::interrupt::Interrupt;
pub struct System {
cpu: R3000A,
}
impl System {
pub fn new(bios_filepath: &str, ... | true |
d11bf8dcb4b7a4557a706dededd8e3dca48aa82c | Rust | dobrakmato/board3-backend | /src/server.rs | UTF-8 | 3,694 | 2.953125 | 3 | [] | no_license | use std::collections::HashMap;
use crate::messages::{PALETTE_SIZE, PALETTE_DEFAULT, Message, UserJoin, UserLeave, History, BoardConfiguration, Color, BoardFlags};
use crate::client::Client;
use crate::ser::to_bytes;
use std::num::Wrapping;
use crate::error::Error;
#[derive(Clone)]
pub struct User {
pub username: ... | true |
e53bc54558c2247119a54c933c7d4144fcfa36b4 | Rust | mbudde/gettext-po | /src/parser.rs | UTF-8 | 8,821 | 2.65625 | 3 | [] | no_license | use combine::parser;
use combine::combinator::*;
use combine::byte::*;
use combine::primitives::{Stream, ParseResult, Parser};
use ::{Message, Comment, Translation};
fn quoted_str<I>(input: I) -> ParseResult<String, I>
where I: Stream<Item=u8>
{
const ESCAPES: &'static str = "nt\"\\";
let escape = token(... | true |
b22dd371cbb2c3ecea879c21a3f9f58d29e1c142 | Rust | HaronK/aoc2019 | /common/src/color_text.rs | UTF-8 | 2,840 | 3.421875 | 3 | [
"MIT"
] | permissive | use termion;
use termion::color;
#[derive(Clone)]
pub enum Color {
Black,
Red,
Green,
Yellow,
Blue,
Magenta,
Cyan,
White,
LightBlack,
LightRed,
LightGreen,
LightYellow,
LightBlue,
LightMagenta,
LightCyan,
LightWhite,
}
pub fn color_str(color: &Color, tex... | true |
9c73ede2c275cbbfd5cc338aa5eaa918c8c7a999 | Rust | gitter-badger/rsmorphy | /src/opencorpora/kind/mood.rs | UTF-8 | 678 | 3.1875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Mood {
/// изъявительное наклонение
Indc,
/// повелительное наклонение
Impr,
}
regex!(TAG_RE, r"(?x)
(
indc
|impr
)
");
impl Mood {
pub fn try_from_str<'a, P>(s: P) -> Option<Self> where P: Into... | true |
764f25e078e273821800fd73f83dd459082c3081 | Rust | mysteriouspants/dcc2018 | /borrowck/borrowck4.rs | UTF-8 | 123 | 3 | 3 | [] | no_license | fn main() {
let s = String::from("hello");
borrow(&s);
println!("{}, world!", s);
}
fn borrow(s: &String) { }
| true |
a4cdd006ad40a95e222c3aba917d7d0851013d9f | Rust | zaksky7/Rust-project | /src/year2017/day17.rs | UTF-8 | 595 | 3.09375 | 3 | [] | no_license | pub fn part1(input: &str) -> usize {
let step: usize = input.parse().unwrap();
let mut list = vec![0];
let mut idx = 0;
for v in 1..=2017 {
idx = (idx + step) % v + 1;
list.insert(idx, v);
}
list[idx + 1]
}
pub fn part2(input: &str) -> usize {
let step: usize = input.parse()... | true |
014dcab612e1e2cdfca6977ae06eb5c1ffd7b678 | Rust | Luu-uuu/aoc2020 | /day3.rs | UTF-8 | 839 | 3.28125 | 3 | [] | no_license | use std::io::{self, BufReader};
use std::io::prelude::*;
use std::fs::File;
struct Slope {
x: usize,
y: usize,
}
fn main() -> io::Result<()> {
let f = File::open("day3.txt")?;
let f = BufReader::new(f);
let mut map: Vec::<String> = Vec::new();
for line in f.lines() {
let horizo... | true |
0b2aeb9825caacec993866c18e55cc9c206574e5 | Rust | birkenfeld/rugments | /src/formatter.rs | UTF-8 | 1,985 | 2.59375 | 3 | [] | no_license | // Copyright (c) 2006-2015 by the respective authors (see AUTHORS file).
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyrig... | true |
bbf146ed9f4576bc3a34c9164738e52c32354091 | Rust | ebenpack/rtiaw | /src/object/bvh/bvh.rs | UTF-8 | 3,812 | 3.21875 | 3 | [
"MIT"
] | permissive | use crate::aabb::AABB;
use crate::object::{HitRecord, Object, ObjectList};
use crate::ray::Ray;
use rand::Rng;
use std::sync::Arc;
pub struct BVHNode {
left: Arc<dyn Object + Send + Sync>,
right: Arc<dyn Object + Send + Sync>,
bounding_box: AABB,
}
impl BVHNode {
pub fn new(
objects: &mut Obje... | true |
269a0dbb87d163074b15e2190fd427dc14b9af1f | Rust | isgasho/tide-compress | /src/middleware.rs | UTF-8 | 4,333 | 2.875 | 3 | [
"BlueOak-1.0.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #[cfg(feature = "brotli")]
use async_compression::futures::bufread::BrotliEncoder;
#[cfg(feature = "deflate")]
use async_compression::futures::bufread::DeflateEncoder;
#[cfg(feature = "gzip")]
use async_compression::futures::bufread::GzipEncoder;
use futures_util::io::BufReader;
use tide::http::cache::{CacheControl, Ca... | true |
67586009c71795e8c0882c73c4705fd2cdfb0239 | Rust | lalrpop/lalrpop | /lalrpop/src/lr1/tls.rs | UTF-8 | 776 | 3.046875 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | //! Thread-local data specific to LR(1) processing.
use crate::grammar::repr::TerminalSet;
use std::cell::RefCell;
thread_local! {
static TERMINALS: RefCell<Option<TerminalSet>> = const { RefCell::new(None) }
}
pub struct Lr1Tls {
old_value: Option<TerminalSet>,
}
impl Lr1Tls {
pub fn install(terminals:... | true |
7bf85762cb07983b5bf3894815ca2457f7e69fea | Rust | urioTV/catboxrs | /src/lib.rs | UTF-8 | 4,129 | 2.6875 | 3 | [] | no_license | use reqwest::blocking::multipart;
const APIURL:&str = "https://catbox.moe/user/api.php";
pub fn uploadfile(userhash: String, filepath: String) -> String{
let form = multipart::Form::new()
.text("reqtype", "fileupload")
.text("userhash", userhash)
.file("fileToUpload", filepath)... | true |
75eb3ccf9f1a65a52bb7a9991a7ef1c640bcf827 | Rust | Lol3rrr/tunneload-plugin | /tunneload-plugin/src/logging.rs | UTF-8 | 1,087 | 2.828125 | 3 | [] | no_license | //! This module contains a couple of logging related parts that can be used
//! to output logs in the Tunneload instance
use log::{Level, Metadata, Record, SetLoggerError};
use crate::raw;
struct TunnloadLogger {
level: Level,
}
/// Initializes the Plugin-Logger with the given Log-Level
pub fn init(level: log::... | true |
e2f659bf01b4f76cb94b54b2ddec9af9d235373b | Rust | skeet70/rust_swig | /macroslib/src/error.rs | UTF-8 | 2,834 | 2.796875 | 3 | [
"BSD-3-Clause"
] | permissive | use std::fmt::{Display, Write};
use proc_macro2::Span;
#[derive(Debug)]
pub(crate) struct DiagnosticError {
src_id: String,
src: String,
data: Vec<syn::Error>,
}
impl DiagnosticError {
pub fn new<T: Display>(sp: Span, err: T) -> Self {
DiagnosticError {
src_id: String::new(),
... | true |
0266b8027078d6b28d255b83ae2e3c30ee35719e | Rust | a-phillips/PE-Rust | /src/bin/PE028.rs | UTF-8 | 481 | 3.125 | 3 | [] | no_license | fn main() {
//The numbers on the diagonal increase 4 at a time by 2, then 4, then 6, ...
//The upper limit is the square of the dimensions, inclusive.
let dim = 1001u;
let lim = dim*dim;
let mut curr_num = 3u;
let mut inc_by = 2u;
let mut inc_count = 0u;
let mut sum = 1u;
while curr_num <= lim {
//println!("... | true |
9276201d3195e0cd0e090579aea1d344c50a498c | Rust | morningKing/jvst | /src/cmd/classfile/cp_utf8_info.rs | UTF-8 | 523 | 2.609375 | 3 | [] | no_license | use super::clz_reader;
use super::cp_info::CpInfo;
use std::any::Any;
pub struct CpUTF8Info {
pub var: String,
}
impl CpInfo for CpUTF8Info {
fn read_inf(&mut self, data: &Vec<u8>, index: &mut u32) -> u32 {
let mut var = String::from("");
let len = clz_reader::read_u16(data, index) as u32;
... | true |
32b528c98c55bb5b6fb173e8d831261c3092766f | Rust | the-emerald/dogfish | /src/piece/attacks/knight.rs | UTF-8 | 1,194 | 2.65625 | 3 | [] | no_license | use crate::board_representation::bitboard::shift::Direction;
use crate::board_representation::bitboard::shift::Direction::{East, North, South, West};
use crate::board_representation::bitboard::BitBoard;
use crate::board_representation::square::Square;
use once_cell::sync::Lazy;
use std::convert::TryFrom;
const KNIGHT_... | true |
8029440a00ffe10a3ef98c26d477b65d1d6adb22 | Rust | MateusRodCosta/AdventOfCode-Rust | /src/bin/day02.rs | UTF-8 | 1,974 | 3.640625 | 4 | [
"MIT"
] | permissive | use std::fs;
fn main() {
let data = fs::read_to_string("input.txt").expect("Unable to read file");
let input: Vec<&str> = data.lines().collect();
println!("Part One: {}", part1(&input));
println!("Part Two: {}", part2(&input));
}
fn part1(input: &[&str]) -> i32 {
let alphabet = "abcdefghijklmnop... | true |
eb123166d593ff4285d618cbdd60997b1421d401 | Rust | Ainevsia/Leetcode-Rust | /1814. Jump Game VI/src/lib.rs | UTF-8 | 1,281 | 3.453125 | 3 | [
"BSD-2-Clause"
] | permissive | pub fn count_nice_pairs(nums: Vec<i32>) -> i32 {
// let n = nums.len();
let revs = nums
.iter()
.map(|&num| {
num
.to_string()
.chars()
.rev()
.collect::<String>()
.parse::<i32>()
.unwrap()
}).collect::<Vec<_>>()... | true |
4d67ea5300aeb7a44a04b02cde401a0903302c2a | Rust | mbiggio/gobject-example-rs | /src/nameable/mod.rs | UTF-8 | 1,764 | 2.609375 | 3 | [] | no_license | #[cfg(not(feature = "bindings"))]
pub mod imp;
#[cfg(feature = "bindings")]
mod ffi;
#[cfg(feature = "bindings")]
pub mod imp {
pub use nameable::ffi::*;
}
use glib::subclass::prelude::*;
use glib::translate::*;
use glib::IsA;
glib_wrapper! {
pub struct Nameable(Interface<imp::Nameable>);
match fn {
... | true |
d15394a2e1abbeaad1a543cc341ea87fa8d456dd | Rust | konn/groebner-rs | /src/main.rs | UTF-8 | 2,701 | 2.78125 | 3 | [] | no_license | use groebner_rs::monomial::*;
use groebner_rs::polynomial::groebner::*;
use groebner_rs::polynomial::Ordpol;
use groebner_rs::polynomial::Polynomial;
use groebner_rs::ring::*;
use num_rational::*;
use num_traits::One;
fn main() {
let x: &Ordpol<Rational, Lex2> = &Ordpol::var(lex2::X);
let y: &Ordpol<Rational, ... | true |
1d8d48418acd0411d13fe7d9970ddc70c219135a | Rust | VengeQ/categorial | /type_classes_outer_test/src/semigroup_outer.rs | UTF-8 | 1,173 | 3.53125 | 4 | [] | no_license | use categorial::Semigroup;
use std::ops::Add;
#[derive(Debug, PartialEq)]
struct Example{
value:String
}
impl Semigroup<String> for Example{
fn combine_owned(x: Self, y: Self) -> Self {
Example{value:x.value.clone().add(&y.value)}
}
fn combine(x: &Self, y: &Self) -> Self {
Example{valu... | true |
88106538be9aec4f453667bc2b805fcc026c84b2 | Rust | AstroPlant/astroplant-api | /astroplant-api/src/problem.rs | UTF-8 | 13,648 | 2.859375 | 3 | [] | no_license | //! The problems that can occur when using this API.
//! Implements RFC7807.
//!
//! TODO: ensure each status code has exactly one problem variant
use axum::headers::HeaderValue;
use axum::http::{header, StatusCode};
use axum::response::IntoResponse;
use axum::Json;
use serde::{Deserialize, Serialize};
use std::collec... | true |
7ebfce72b812604cd3f804f4fa718447cf12d038 | Rust | goodingc/ipn_sim | /ipn_sim_lib/src/message_destination.rs | UTF-8 | 1,062 | 2.984375 | 3 | [] | no_license | use crate::utils::{NodeId, Shared};
use crate::node::node::Node;
use std::rc::Rc;
use serde::{Deserialize, Serialize};
#[derive(Clone, Serialize, Deserialize)]
pub enum MessageDestination<T> {
All,
Single(T),
Multiple(Vec<T>),
}
pub trait IsIncluded<T> {
fn is_included(&self, other: T) -> bool;
}
imp... | true |
dc0cbbab2a8395681af2231bcb283bfa3d73cf38 | Rust | marschall-lab/hrfs | /src/bin/mkmin.rs | UTF-8 | 30,797 | 2.5625 | 3 | [
"MIT"
] | permissive | /* standard use */
use std::cmp::min;
use std::fs;
use std::io::{self, BufRead, Write};
use std::iter::FromIterator;
/* crate use */
use clap::Parser;
use handlegraph::handle::Handle;
use itertools::Itertools;
use petgraph::{graphmap::DiGraphMap, Incoming, Outgoing};
use rustc_hash::{FxHashMap, FxHashSet};
/* private... | true |
3d150ecdcbdd5735c275457cb68cba56c04d82b8 | Rust | triglav/advent_of_code | /2022/day02/src/main.rs | UTF-8 | 1,915 | 3.515625 | 4 | [
"MIT"
] | permissive | use std::io;
// opponent: A for Rock, B for Paper, and C for Scissors
// myself: X for Rock, Y for Paper, and Z for Scissors
// 1 for Rock, 2 for Paper, and 3 for Scissors
fn points_for_shape(myself: u8) -> u32 {
match myself {
0 => 1,
1 => 2,
2 => 3,
_ => panic!("invalid shape")... | true |
25707aeca3fb5a429dd9b7c849aff9ed64292688 | Rust | typio/snek | /src/main.rs | UTF-8 | 5,901 | 2.734375 | 3 | [] | no_license | #![allow(unused)]
use std::collections::VecDeque;
use std::process;
use ggez::conf;
use ggez::event::{self, EventHandler, KeyCode, KeyMods};
use ggez::graphics;
use ggez::timer;
use ggez::{Context, ContextBuilder, GameResult};
use nalgebra as na;
use rand;
type Point2 = na::Point2<f32>;
const SCREEN_WIDTH: f32 = 95... | true |
6aad643ad2b333ea4ad010a75476cef7b2552d72 | Rust | Kokotewa/rpatchur | /rpatchur/src/patcher/config.rs | UTF-8 | 2,573 | 2.765625 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use std::fs::File;
use std::io::BufReader;
use std::path::{Path, PathBuf};
use super::get_patcher_name;
use anyhow::{Context, Result};
use serde::Deserialize;
#[derive(Deserialize, Clone)]
pub struct PatcherConfiguration {
pub window: WindowConfiguration,
pub play: PlayConfiguration,
pub setup: SetupConfi... | true |
720f35c38611849f417141b0e33fb6099732de39 | Rust | wasm-superopt/rocinante | /src/solver/z3.rs | UTF-8 | 30,315 | 2.875 | 3 | [] | no_license | use parity_wasm::elements::{FuncBody, FunctionType, Instruction, Local, ValueType};
use std::convert::TryFrom;
use std::fmt::Debug;
use z3::{ast, ast::Ast, Context, Solver};
// NOTE(taegyunkim): Consider also putting locals in value stack, and keeping a
// stack pointer to push and pop values.
#[derive(Debug, Default)... | true |
8d074c38b5af969c1587edbd39f5932d7ec2fc36 | Rust | ninjahoahong/hello-webAssembly | /app/src/add.rs | UTF-8 | 174 | 2.9375 | 3 | [
"MIT"
] | permissive | fn main() {
println!("Hello, world!");
}
// this function can be accessed from Javascript (no_mangle)
#[no_mangle]
pub extern "C" fn add_one(x: i32) -> i32 {
x + 1
} | true |
943eedf6fe8cea53688e39eeb1e02de0c0fb3166 | Rust | halochou/exercism-rust | /etl/src/lib.rs | UTF-8 | 288 | 2.703125 | 3 | [] | no_license | use std::collections::BTreeMap;
pub fn transform(input : &BTreeMap<i32, Vec<String>>) -> BTreeMap<String, i32> {
let mut res = BTreeMap::new();
for (score, letters) in input.into_iter() {
for letter in letters {
res.insert(letter.to_lowercase().to_string(), *score);
}
}
res
} | true |
13aa9f194838101e759f628b539f3fbf75b14ecf | Rust | himanoa/blizzard-lance | /src/battle_executor.rs | UTF-8 | 1,649 | 2.65625 | 3 | [] | no_license | use std::cell::RefCell;
use std::rc::Rc;
use anyhow::anyhow;
use crate::battle::{BattleActor, BattleField};
use crate::battle_action::BattleFieldMutationImpl;
use crate::error::ApplicationError;
use crate::storategies::Strategies;
use crate::strategy::{PreemptiveStrategy, PreemptiveStrategyContext};
use crate::Result... | true |
978e14fa73147b7bb380de2c06529e0f27540644 | Rust | ahenshaw/aoc2020 | /aoc08/src/main.rs | UTF-8 | 1,604 | 3.109375 | 3 | [] | no_license | #![feature(str_split_once)]
use std::io::prelude::*;
use std::{fs, io};
use std::collections::HashSet;
type Operation = (String, i32);
type Program = Vec<Operation>;
fn main() {
let fh = fs::File::open("input.txt").expect("Missing input");
let reader = io::BufReader::new(fh);
let mut program: Program = V... | true |
04959c0b7409212d5d50e72b8212781159ae41b2 | Rust | Michael-F-Bryan/simple-net | /src/tensor.rs | UTF-8 | 6,269 | 3.578125 | 4 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use std::ops::{Add, Index, IndexMut, Mul, Sub};
/// A row-major 2D matrix of floats.
#[derive(Debug, Clone, PartialEq)]
pub struct Tensor {
data: Vec<f32>,
width: usize,
height: usize,
}
impl Tensor {
pub fn zero(width: usize, height: usize) -> Tensor {
Tensor {
data: vec![0.0; wid... | true |
4394e4649338b5cee6298595b15cc7d85eadc532 | Rust | sagiegurari/fsio | /tests/path_test.rs | UTF-8 | 2,248 | 3 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-free-unknown"
] | permissive | use fsio::path;
use fsio::path::as_path::AsPath;
use fsio::path::from_path::FromPath;
use std::path::{Path, PathBuf};
#[test]
fn as_path_str() {
let path = Path::new("./test/file.txt");
let as_path = "./test/file.txt".as_path();
assert_eq!(path, as_path);
}
#[test]
fn as_path_string() {
let path = Pa... | true |
4982d81779f9f03a7b821a78adb97df8ce1ed6ab | Rust | matz-e/mandelbrot.rs | /src/serial.rs | UTF-8 | 1,120 | 3.328125 | 3 | [
"MIT"
] | permissive | use crate::config::Domain;
fn kernel(re: f32, im: f32, count: i32) -> i32 {
let mut new_re = re;
let mut new_im = im;
for i in 0..count {
let re_sqr = new_re * new_re;
let im_sqr = new_im * new_im;
if re_sqr + im_sqr > 4.0 {
return i;
}
let tmp = new_re *... | true |
a63d0d751472c22ae0ec168596fcb119a0798272 | Rust | lizechoo/Rust-vs-Clang-CPSC311 | /Rust/simplePointer.rs | UTF-8 | 926 | 3.28125 | 3 | [] | no_license | fn main() {
//println!("Hello, world!");
#[allow(dead_code)]
let mut x :i32 = 7;
#[allow(dead_code)]
let y :i32 = 9;
let p = &x; // borrow occurs here
println!("[1] x is {}", x);
println!("[1] y is {}", y);
println!("[1] p is {:p}", p); // http://blog.zgtm.de/1 say... | true |
890f788d27b9fba4ac7c8faccffe8289cf106a8e | Rust | Huynhhung0/solana | /sdk/src/entrypoint_native.rs | UTF-8 | 5,060 | 2.796875 | 3 | [
"Apache-2.0"
] | permissive | //! @brief Solana Native program entry point
use crate::{
account::Account, account::KeyedAccount, instruction::CompiledInstruction,
instruction::InstructionError, message::Message, pubkey::Pubkey,
};
use std::{cell::RefCell, rc::Rc};
// Prototype of a native program entry point
///
/// program_id: Program ID... | true |
de29d803ebe6dd9139462e1a7b83e980ead336d5 | Rust | DarkiBoi/AoC2020 | /src/bin/aoc/day5.rs | UTF-8 | 3,302 | 2.875 | 3 | [] | no_license | use std::cmp::max;
mod util;
fn main() {
part_one();
part_two();
}
pub fn part_one() {
let lines: Vec<String> = util::get_input_lines().collect();
let mut boarding_passes_ids: Vec<i32> = Vec::new();
for line in lines {
let mut rows: Vec<i32> = vec!(0; 128);
for i in 0..rows.len... | true |
b2a721fa6b6e3c2ce9850b75d64959a933cc584a | Rust | regonn/AOJ | /ALDS1/7/C.rs | UTF-8 | 2,535 | 3.484375 | 3 | [] | no_license | use std::io::*;
use std::str::FromStr;
type NodeId = usize;
struct Node {
parent: Option<NodeId>,
left: Option<NodeId>,
right: Option<NodeId>,
}
fn read<T: FromStr>() -> T {
let stdin = stdin();
let stdin = stdin.lock();
let token: String = stdin
.bytes()
.map(|c| c.expect("fa... | true |
ffab582767f369dfaf3a4bbbdbb3a3d2b44e5d40 | Rust | Cypher1/oak | /examples/trusted_database/module/rust/src/handler.rs | UTF-8 | 5,316 | 2.578125 | 3 | [
"Apache-2.0"
] | permissive | //
// Copyright 2020 The Project Oak Authors
//
// 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 o... | true |
eba7d6a9a6a3721c7ba4729d2b0a25f2eb51bd26 | Rust | nacho-vlad/chio | /src/lib.rs | UTF-8 | 1,077 | 2.984375 | 3 | [] | no_license | mod cpu;
mod peripherals;
use cpu::Cpu;
use peripherals::{Keypad, Framebuffer};
use std::{
path::Path,
fs::File,
io::Read,
};
#[derive(Clone)]
pub struct Chip8 {
cpu: Cpu,
pub framebuffer: Framebuffer,
pub keypad: Keypad,
}
impl Chip8 {
pub fn new() -> Self {
let cpu = Cpu:... | true |
fcc1a0611cb08e5e9d537ec5c9d1170c6c87c794 | Rust | RSWilli/advent-of-code | /2022/rust/lib/src/spatial/dense.rs | UTF-8 | 7,704 | 3.03125 | 3 | [] | no_license | use std::{
fmt::{Debug, Display},
ops::{Index, IndexMut},
vec,
};
use crate::math::gcd;
use super::{
point2d::Point2D,
position::Position,
spatial_trait::{Spatial, Spatial2D},
};
pub struct SpatialDense<P: Position, T> {
// the minimum index in the grid
min: P,
// the maximum inde... | true |
5025d961f1ddd06da690a2bf5167a4e00ab32166 | Rust | timsaucer/RustDDS | /src/messages/header.rs | UTF-8 | 2,354 | 3.03125 | 3 | [
"Apache-2.0"
] | permissive | use crate::common::validity_trait::Validity;
use crate::messages::protocol_id::ProtocolId;
use crate::messages::protocol_version::ProtocolVersion;
use crate::messages::vendor_id::VendorId;
use crate::structure::guid::GuidPrefix;
use speedy::{Readable, Writable};
#[derive(Debug, Clone, Readable, Writable, PartialEq)]
p... | true |
eaee1ccac621179e979a7028aef9f52c6ad6ea18 | Rust | Lutetium-Vanadium/anilang | /crates/anilang/tests/common/mod.rs | UTF-8 | 2,139 | 2.84375 | 3 | [
"MIT"
] | permissive | use anilang::function::{native, Function};
use std::rc::Rc;
type Result = std::result::Result<anilang::Value, ()>;
fn base_scope() -> Rc<anilang::Scope> {
let scope = Rc::new(anilang::Scope::new(0, None));
scope
.declare(
"assert".into(),
anilang::Value::Function(Rc::new(Functi... | true |
2ca79bc27dcd722607849aa274a335ca6057e8c5 | Rust | wujunze/tikv | /benches/misc/util/slice_compare.rs | UTF-8 | 1,602 | 2.515625 | 3 | [
"Apache-2.0"
] | permissive | // Copyright 2019 PingCAP, Inc.
//
// 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 |
00647982d477b7f5d47afd1cdd2dc5a88f97d670 | Rust | rust-lang/stdarch | /crates/core_arch/src/x86/test.rs | UTF-8 | 4,072 | 2.53125 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-other-permissive",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! Utilities used in testing the x86 intrinsics
use crate::core_arch::x86::*;
use std::mem::transmute;
#[target_feature(enable = "sse2")]
pub unsafe fn assert_eq_m128i(a: __m128i, b: __m128i) {
assert_eq!(transmute::<_, [u64; 2]>(a), transmute::<_, [u64; 2]>(b))
}
#[target_feature(enable = "sse2")]
pub unsafe f... | true |
c778a30dd4502f3908db21033f6b9cca326e1cfe | Rust | nfrasser/lasgun | /src/core/bxdf/specular.rs | UTF-8 | 2,690 | 2.90625 | 3 | [
"MIT"
] | permissive | use crate::space::*;
use super::{util::*, fresnel::Substance, BxDFSample};
/// Describes physically plausible specular reflection with the Substance model to
/// compute fraction of light that is reflected.
#[derive(Copy, Clone)]
pub struct Reflection {
/// Reflection spectrum
r: Color,
substance: Substanc... | true |
cc9140dcf9e67d3ab2ad115f05c6fe36b98b3ca4 | Rust | Avi-D-coder/passing-arg-iter | /src/lib.rs | UTF-8 | 1,408 | 3.453125 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | #[derive(Clone)]
pub struct PassingArgument<I, T> {
iter: I,
argument: T,
}
pub trait PassingArg<I, T> {
/// Add an argument to a `Iterator::Item`
/// Default implementation requires `T: Clone`
fn passing_arg(self, arg: T) -> PassingArgument<I, T>;
}
impl<I, T> PassingArg<I, T> for I
where
I: ... | true |
9262088d2334605c94015f71c9add5d0313c2e7d | Rust | mtrx1337/crablog | /site/src/routes.rs | UTF-8 | 5,860 | 2.75 | 3 | [] | no_license | use crate::db;
use super::CONFIG_MAP;
use actix_web::{error, get, http::StatusCode, web, Error, HttpResponse};
use tera::Context;
/// tests if the post id is a valid i32 integer bigger than zero
/// assert(!(id_valid("2147483648").0))
/// assert(!(id_valid("-1").0))
/// assert(id_valid("1").0))
pub fn id_valid(post_i... | true |
5d13534757a5e793ec0516e550e946c5005079ab | Rust | RedL0tus/rust-learn | /chapter-10/10.3-validating_references_with_lifetimes/src/main.rs | UTF-8 | 2,475 | 4.21875 | 4 | [] | no_license | use std::fmt::Display;
fn main() {
borrow_checker();
// Annotating lifetime
let x = String::from("ABCD");
let y = String::from("EFGJIJ");
let longest = longest_with_an_announcement(&x, &y, String::from("Bazinga!"));
println!("{}", longest);
// Lifetime annotations in struct definitions
... | true |
9603a9f89dbb3519d7a5c19eee8a62ead79369f0 | Rust | nuta/nsh | /src/pattern.rs | UTF-8 | 11,009 | 3.4375 | 3 | [
"CC0-1.0"
] | permissive | use failure::Error;
use glob::glob;
#[derive(Debug, Fail)]
#[fail(display = "no matches")]
pub struct NoMatchesError;
type Result<I> = std::result::Result<I, Error>;
#[derive(Debug, Clone)]
pub enum LiteralOrGlob {
Literal(String),
AnyString,
AnyChar,
}
/// A word which includes patterns. We don't expan... | true |
a15dca50aeb1b6702137f097029e1e69d17ea27e | Rust | Eliah-Lakhin/rhai | /src/fn_register.rs | UTF-8 | 8,915 | 3.109375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | //! Module which defines the function registration mechanism.
#![allow(non_snake_case)]
use crate::any::{Dynamic, Variant, DynamicWriteLock};
use crate::engine::Engine;
use crate::fn_native::{CallableFunction, FnAny, FnCallArgs, SendSync};
use crate::module::Module;
use crate::parser::FnAccess;
use crate::r#unsafe::u... | true |
b982f29f0e300b8dca802b19de6016e694c1c98d | Rust | slyedoc/bevy_input_actionmap | /examples/hello_world_enum.rs | UTF-8 | 1,290 | 2.90625 | 3 | [
"MIT"
] | permissive | use bevy::prelude::*;
use bevy_input_actionmap::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(ActionPlugin::<Action>::default())
.add_startup_system(setup.system())
.add_system(run_commands.system())
.run();
}
#[derive(Hash, PartialEq, Eq, Clone)]
enum ... | true |
20d52fe8c768300643a27998b3f43cd254238d60 | Rust | TheAngusMcFire/3dxNavHidRawParser | /src/main.rs | UTF-8 | 4,661 | 2.984375 | 3 | [
"Unlicense"
] | permissive | use std::env;
use std::fs::File;
use std::io::Read;
use std::io;
use std::cmp;
extern crate colored;
use colored::*;
use termion::input::MouseTerminal;
use termion::raw::IntoRawMode;
use termion::screen::AlternateScreen;
use tui::backend::TermionBackend;
use tui::layout::{Constraint, Direction, Layout};
use tui::style... | true |
c4d0483e5c5bab2baf6adf29c42ba019967f9827 | Rust | rust-to/ferriscord | /ferriscord_derive/src/lib.rs | UTF-8 | 612 | 2.71875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | extern crate proc_macro;
use proc_macro::TokenStream;
#[proc_macro_derive(Command, attributes(test_attr))]
pub fn derive_command_fn(_item: TokenStream) -> TokenStream {
"fn command() { let meme = 21; println!(\"I purchased {} watermelons today\", meme); }"
.parse()
.unwrap()
}
#[proc_macro_derive(... | true |
f0382b0965a8cdab9bf1fcbcd46ada6768e982b9 | Rust | dimes/violetta | /src/context/screen.rs | UTF-8 | 324 | 3.078125 | 3 | [] | no_license | pub struct Screen {
pub width: u32,
pub height: u32,
}
impl Screen {
pub fn new() -> Screen {
return Screen {
width: 0,
height: 0,
};
}
pub fn set_dimensions(&mut self, width: u32, height: u32) {
self.width = width;
self.height = height;
... | true |
36827edb6e062c346634015153a9fcd76e8853b6 | Rust | RGates94/scripting-language | /src/parser.rs | UTF-8 | 9,163 | 3.171875 | 3 | [] | no_license | use crate::ast::{Expression, Function, Instruction, Operator, State, Value};
use logos::{Lexer, Logos};
#[derive(Logos, Debug, PartialEq, Copy, Clone)]
enum Token {
#[token = "fn"]
Function,
#[token = "if"]
If,
#[token = "else"]
Else,
#[token = "for"]
For,
#[token = "while"]
Whi... | true |
997d588d978a09e79edb7d00c6bf50b7f5c5fc18 | Rust | wahello/parallel-disk-usage | /tests/args_fraction.rs | UTF-8 | 1,650 | 2.734375 | 3 | [
"Apache-2.0"
] | permissive | #![cfg(feature = "cli")]
use parallel_disk_usage::args::fraction::{ConversionError::*, Fraction, FromStrError::*};
use pretty_assertions::assert_eq;
#[test]
#[allow(clippy::float_cmp)]
fn typical() {
let actual: f32 = "0.5".parse::<Fraction>().expect("create ratio").into();
assert_eq!(actual, 0.5);
}
#[test]... | true |
11fe51691074b7e1af5474f514154391bd316659 | Rust | aakshintala/rust-book-exercises | /Chapter3/fibonacci/src/main.rs | UTF-8 | 643 | 3.40625 | 3 | [
"MIT"
] | permissive | fn gen_fibonacci(minus2:i32, minus1:i32, n :i32, n_max : i32) {
print!("{} ", minus2);
if n < n_max {
gen_fibonacci(minus1, minus2+minus1, n+1, n_max);
}
}
fn main() {
println!("Hello! My only purpose is to generate the fibonacci sequence.\nHow many numbers of the sequence would you like me to generate? ");
... | true |
515ff53aaf0515c9aed7dffc3d9d461c8160140b | Rust | veeg/disir-c-frontend-rs | /src/main.rs | UTF-8 | 3,142 | 2.796875 | 3 | [] | no_license | extern crate disir_remote;
extern crate futures;
extern crate tokio_core;
extern crate tokio_tungstenite;
extern crate tungstenite;
use std::env;
use std::io::{Error, ErrorKind};
use futures::stream::Stream;
use futures::Future;
use tokio_core::net::TcpListener;
use tokio_core::reactor::Core;
use tungstenite::protoco... | true |
224b2a555348f66380613306e8d6b0374f64c559 | Rust | litex-hub/wishbone-utils | /wishbone-tool/crates/bridge/src/bridges/uart.rs | UTF-8 | 13,038 | 2.8125 | 3 | [
"Apache-2.0"
] | permissive | use std::io::prelude::*;
use std::path::{Path, PathBuf};
use std::sync::mpsc::{channel, Receiver, Sender, TryRecvError};
use std::sync::{Arc, Condvar, Mutex};
use std::thread;
use std::time::Duration;
use log::{debug, error, info};
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use serialport::prelude::*;
... | true |
2b7bc09d55da6eb0441839aad6b75d9180e1267b | Rust | symmsaur/wasmduck | /src/kernels.rs | UTF-8 | 1,950 | 3.21875 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use crate::math;
use std::f64::consts::PI;
/// Wendland quintic kernel
pub fn kernel_2d(r: f64, h: f64) -> f64 {
let q = r / h;
if q > 2.0 {
return 0.0;
}
let alpha_d = 7.0 / 4.0 / PI / h.powi(2);
return (1.0 - 0.5 * q).powi(4) * (2.0 * q + 1.0) * alpha_d;
}
/// Gradient of Wendland qui... | true |
22035fb13bc8dfcc6659b52acdcd3cbc82308151 | Rust | nacleric/simple-web-server | /simple-web-server/src/main.rs | UTF-8 | 2,613 | 3.375 | 3 | [
"MIT"
] | permissive | use std::net::TcpListener;
use std::net::TcpStream;
use std::io::prelude::*;
use std::io::{self};
use std::borrow::Cow;
fn main() {
let port = 8080;
let port_str = port.to_string();
if !check_port_availability(port) {
let stdout = io::stdout();
let _handle = stdout.lock();
// @tod... | true |
ab946e1afe8ce6ec5047aeb24f430005fb6d702a | Rust | vadorovsky/linkerd2-proxy | /lib/stack/src/either.rs | UTF-8 | 2,185 | 2.953125 | 3 | [
"Apache-2.0"
] | permissive | use futures::{future, Future, Poll};
use svc;
type Error = Box<dyn std::error::Error + Send + Sync>;
/// Describes two alternate `Layer`s, `Stacks`s or `Service`s.
#[derive(Clone, Debug)]
pub enum Either<A, B> {
A(A),
B(B),
}
impl<T, U, A, B, N> super::Layer<T, U, N> for Either<A, B>
where
A: super::Lay... | true |
d74c9908d3fa23211a670954c867318c63132b7b | Rust | eigenform/nil | /src/lift/arm/bits.rs | UTF-8 | 23,184 | 2.890625 | 3 | [] | no_license | //! Wrapper types for representing ARM instructions as bitfields.
/// ['Stc', 'LdcImm']
#[repr(transparent)]
pub struct LsCoprocBits(pub u32);
impl LsCoprocBits {
#[inline(always)]
pub fn cond(&self) -> u32 { (self.0 & 0xf0000000) >> 28 }
#[inline(always)]
pub fn p(&self) -> bool { (self.0 & 0x01000000... | true |
987b2b04eb85dfc0be6185c0f185ddd59aeba02b | Rust | codereached/advent-of-code-2018-rust | /aoc-01a/src/main.rs | UTF-8 | 518 | 3.34375 | 3 | [] | no_license | use std::io;
use std::io::prelude::*;
use std::fs::File;
fn main() {
let x = frequency(0,readfile());
println!("{}", x);
}
fn readfile() -> Vec<String>{
let file = File::open("input.txt").unwrap();;
let reader = io::BufReader::new(file);
reader.lines().map(|l| l.expect("Could not parse line")).collect()
}
... | true |
f5acadb7596d5a0e58e74b422f9182ce5f8b8d31 | Rust | Avokadoen/TDT4195_code | /src/gl_utils/scene_graph.rs | UTF-8 | 5,917 | 3.078125 | 3 | [] | no_license | extern crate nalgebra_glm as glm;
// Author: Michael H. Gimle
// TODO: Discard this and write a custom structure INSTEAD of scene graphing
use std::mem::ManuallyDrop;
use std::pin::Pin;
use super::{camera::Camera, geometric_object::GeometricInstance, geometric_object::GeometricObject};
// Used to crete an unholy a... | true |
06e95c40556c5736385a142d909706637d4953ce | Rust | Qwuke/low-level-practice | /shell-shock/src/main.rs | UTF-8 | 1,091 | 3.046875 | 3 | [] | no_license | use std::io;
use std::io::prelude::*;
use std::process::Command;
fn main() {
println!("Starting Bored Again Shell");
loop {
print!("> ");
io::stdout().flush().expect("failed to flush");
let mut user_input = String::new();
io::stdin().read_line(&mut user_input).expect("Grab user... | true |
fd37fbde29182285b19ef3b2539adc4faab75e8b | Rust | DoubleHyphen/lindel | /src/new_uints.rs | UTF-8 | 20,916 | 3.171875 | 3 | [] | no_license | //! A macro that creates a new `[usize; N]` data-type that behaves as an integer for the purposes of accepting a new `Key`.
//!
//! The `create_lineariseable_data_type` macro accepts three arguments:
//! 1. The coordinate data-type, an unsigned integer
//! 2. The amount of dimensions that the data-set must have
//! 3. ... | true |
1c8331946a7aef376c85633d7850c9af7a61661e | Rust | tianenchen/leetcode-rs | /src/leetcode/can_jump.rs | UTF-8 | 815 | 3.25 | 3 | [] | no_license | struct Solution;
impl Solution {
pub fn can_jump2(nums: Vec<i32>) -> bool {
let len = nums.len();
let mut rightmost = 0;
for i in 0..len {
if i > rightmost {
return false;
}
rightmost = std::cmp::max(rightmost, i + nums[i] as usize);
... | true |
585c4de49ca91377cd310576537e048903ba98e1 | Rust | TomasArrachea/redis-rustico | /src/protocol/lines_iterator.rs | UTF-8 | 1,317 | 3.359375 | 3 | [] | no_license | use crate::protocol::decode::decode;
use crate::protocol::type_data::TypeData;
use std::io::{BufRead, BufReader};
use std::net::TcpStream;
/// Iterador de líneas, enviadas por Redis, que el servidor lee.
pub struct LinesIterator<'a> {
input: &'a mut BufReader<TcpStream>,
}
impl<'a> LinesIterator<'a> {
/// Cre... | true |
84328a3a25fda7f21ad2aa7860a7cb54ccf5e54b | Rust | rrcobb/crafting-interpreters | /jlox-rust/src/stmt.rs | UTF-8 | 914 | 3 | 3 | [] | no_license | // in theory, would be generated by bin/generate_ast.rs
// in parallel to expr.rs
use crate::expr::Expr;
use crate::token::Token;
pub enum Stmt {
Block { stmts: Vec<Stmt> },
Expression { expr: Box<Expr> },
Print { expr: Box<Expr> },
Var { name: Token, initializer: Box<Expr> }
}
pub trait Visitor<T> {
... | true |
3fb18993c2aad1f2c65430b1fe20e952a0028915 | Rust | purdue-cap/DryadSynth | /src/meet-middle/src/enumerate/op.rs | UTF-8 | 4,041 | 2.875 | 3 | [
"MIT"
] | permissive |
use super::expr::DivideByZero;
#[inline(always)]
pub fn not(v1: u64) -> u64 { !v1 }
#[inline(always)]
pub fn neg(v1: u64) -> u64 { unsafe { (0i64.unchecked_sub(v1 as i64)) as u64 } }
#[inline(always)]
pub fn add(v1: u64, v2: u64) -> u64 { unsafe { v1.unchecked_add(v2) } }
#[inline(always)]
pub fn mul(v1: u64, v2: u64... | true |
08636834e2ae2bc3203623770d5a7b8c3b0571cd | Rust | Globidev/advent-of-code | /2018/rust/src/day25.rs | UTF-8 | 1,600 | 3.21875 | 3 | [] | no_license | const RAW_INPUT_STR: &str = include_str!("../../inputs/day25.txt");
pub fn day25() -> u32 {
let points: Vec<_> = parse_input(RAW_INPUT_STR).collect();
part1(&points)
}
pub fn part1(points: &[Point]) -> u32 {
let mut points = points.to_vec();
let mut count = 0;
while !points.is_empty() {
... | true |
3732845f5dfbf8cc824c888f2a4423691b661a1d | Rust | AnthonyK213/Rust_Practice | /quick_sort/src/main.rs | UTF-8 | 1,643 | 3.578125 | 4 | [] | no_license | fn main() {
let sort_int: Vec<u32> = vec![3, 1, 4, 1, 5, 9, 2, 6];
let sort_flt: Vec<f32> = vec![3.14, 1.0, 4.0, 1.0, 5.0, 9.0, 2.0, 6.0];
let sort_str: Vec<char> = "The five boxing wizards jump quickly".to_lowercase().chars().collect();
println!("quick_sort<int>: {:?}", quick_sort(&sort_int));
pr... | true |
997013e756dadfcc20375c96e9847120655cd995 | Rust | CyberFlameGO/srglib-rust | /src/mappings/frozen.rs | UTF-8 | 10,567 | 2.53125 | 3 | [
"MIT"
] | permissive | use std::ptr;
use std::sync::Arc;
use std::borrow::Cow;
use std::fmt::{self, Debug};
use indexmap::{map};
use lazy_static::*;
use difference::Changeset;
use owning_ref::ArcRef;
use lazycell::AtomicLazyCell;
use crate::utils::{FnvIndexMap};
use crate::prelude::*;
#[derive(Clone)]
pub struct FrozenMappings(ArcRef<Fro... | true |
aeec3a6971f41958ae4b9f45daa4e51b2cccc592 | Rust | peckpeck/AOC | /day4/src/main.rs | UTF-8 | 3,900 | 2.9375 | 3 | [] | no_license | use std;
use std::fs::File;
use std::io::prelude::*;
use std::collections::HashMap;
use nom::{ *, error::*, branch::*, character::*, character::complete::*, bytes::complete::*, sequence::*, multi::*, combinator::* };
static MANDATORY_FIELD_LIST: [&str; 7] = ["byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid"];
#[allow(d... | true |
c809e61ffd0b2b96ca225d01e01472aa31039e55 | Rust | Andy-Wilkinson/rustchem | /rustchem/src/mol/point3d.rs | UTF-8 | 854 | 3.671875 | 4 | [
"MIT"
] | permissive | #[derive(PartialEq, Debug)]
pub struct Point3d {
pub x: f64,
pub y: f64,
pub z: f64,
}
impl Point3d {
pub fn new(x: f64, y: f64, z: f64) -> Point3d {
Point3d { x, y, z }
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::test_utils::assert_f64_eq;
#[test]
fn new_from_co... | true |
52379e79537cdd95f095b494f4fb255f1d21786b | Rust | winksaville/fuchsia | /third_party/rust_crates/vendor/plist/src/serde/ser.rs | UTF-8 | 23,001 | 2.65625 | 3 | [
"MIT",
"BSD-3-Clause"
] | permissive | use serde_base::ser;
use std::fmt::Display;
use std::str::FromStr;
use {Date, Error, EventWriter, PlistEvent};
use date::serde_impls::DATE_NEWTYPE_STRUCT_NAME;
impl ser::Error for Error {
fn custom<T: Display>(msg: T) -> Self {
Error::Serde(msg.to_string())
}
}
pub struct Serializer<W: EventWriter> {... | true |
22de97ddb49f0ef0daff4ccfea0c17d1ea81305e | Rust | gunners6518/rust-software-design-202106 | /src/2章/multiThred.rs | UTF-8 | 1,861 | 3.328125 | 3 | [] | no_license | // クロージャーを利用したマルチスレッド化の例
fn main() {
// スレッド数
const N_THREADS : usize = 3;
// 処理する整数のRange
let series_range = 0..30; let add = 1;
// 1
let chunks = (0..N_THREADS)
.map(¦ii¦ series_range.clone().skip(ii).step_by(N_THREADS));
// 2
let handles : Vec<_> = chunks
.map(¦vv¦ std::thread::s... | true |
615498ef29364e6f99fe0f3b9a30744d92c9c6bb | Rust | wolfgang/srl | /src/_tests/feature/melee_combat_death_test.rs | UTF-8 | 2,090 | 3.046875 | 3 | [
"Unlicense"
] | permissive | use crate::_tests::_helpers::testable_game::TestableGame;
use crate::game::dungeon::DungeonCoords;
use crate::game::game::GameState::{PlayerDied, Running};
use crate::input::move_direction::MoveDirection::Right;
const PLAYER: DungeonCoords = (1, 0);
const ENEMY: DungeonCoords = (2, 0);
#[test]
fn enemy_is_removed_aft... | true |
da0b9dea90c8421127b52126065bc5899819c3f4 | Rust | gotham-rs/gotham | /gotham/src/router/builder/mod.rs | UTF-8 | 21,925 | 2.6875 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | //! Defines a builder API for constructing a `Router`.
mod associated;
mod draw;
mod modify;
mod single;
use std::marker::PhantomData;
use std::panic::RefUnwindSafe;
use hyper::{Body, StatusCode};
use crate::extractor::{
NoopPathExtractor, NoopQueryStringExtractor, PathExtractor, QueryStringExtractor,
};
use cr... | true |
37fa8734ccb9af09ae7ba05f59eaca57d4a2169c | Rust | Canop/broot | /src/help/help_search_modes.rs | UTF-8 | 1,943 | 2.984375 | 3 | [
"MIT"
] | permissive | use {
crate::{
app::AppContext,
pattern::*,
},
};
/// what should be shown for a search_mode in the help screen, after
/// filtering
pub struct SearchModeHelp {
pub prefix: String,
pub description: String,
pub example: String,
}
/// return the rows of the "Search Modes" table in he... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.