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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
9128a2bff61505df861162f46ddf1cc6a294e68c | Rust | chops76/AoC15 | /AoC15.1/src/main.rs | UTF-8 | 660 | 3.15625 | 3 | [] | no_license | use std::io;
fn main() {
let mut input = String::new();
io::stdin().read_line(&mut input)
.expect("Couldn't read input");
let mut count = 0;
let mut i1 = input.chars();
let mut been_neg = false;
let mut first_neg = 0;
let mut pos = 1;
while let Some(ch) = i1.next() {
... | true |
06b09d5c3d65e361848b65abcc2d66afd0148666 | Rust | mattheww/rmicrobit | /src/buttons/monitors/single.rs | UTF-8 | 1,851 | 3.421875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | //! High-level driver for a single button.
use crate::buttons::core::{PollButton, TransitionEvent};
/// An event from one of this module's monitors.
#[derive(Debug)]
pub enum Event {
Click,
}
/// Wrapper for a single [`PollButton`] generating click events on release.
pub struct LazyMonitor<T: PollButton> {
b... | true |
83a3965f5df1ecd861a77186a54772e88038a452 | Rust | sminez/penrose | /src/pure/geometry.rs | UTF-8 | 22,080 | 3.640625 | 4 | [
"MIT"
] | permissive | //! Geometry primitives
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::cmp::max;
/// An x,y coordinate pair
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Point {
/// An absolute x coordinate relative to... | true |
0a44af0fee7b1993d4c4cf633177362f5a6153c3 | Rust | SkyBulk/FuzzWeek2020-notes | /Day2/main.rs | UTF-8 | 4,184 | 3.03125 | 3 | [] | no_license | use std::io;
use std::path::Path;
use std::time::{Instant, Duration};
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::process::{Command, ExitStatus};
use std::collections::BTreeSet;
use std::os::unix::process::ExitStatusExt;
/// Number of iterations to run per thread before reporting stats... | true |
6d2772bc0163b70239013569b85ddac74c3c9212 | Rust | aidanhs/frametool | /src/main.rs | UTF-8 | 63,299 | 2.515625 | 3 | [] | no_license | #![recursion_limit="200"]
#![feature(plugin,range_contains,trace_macros)]
#![plugin(interpolate_idents)]
#![feature(field_init_shorthand)]
extern crate combine;
#[macro_use]
extern crate nom;
use std::borrow::Cow;
use std::cmp;
use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::str;
use parser::MIFTr... | true |
8cf11dd1c121836b5d9d87fed53484322dbc7fcf | Rust | wuwx/web_demo | /src/main.rs | UTF-8 | 2,270 | 2.546875 | 3 | [] | no_license | #![feature(link_args)]
#[link_args = "-s USE_SDL=2"]
extern {}
extern crate sdl2;
extern crate libc;
extern crate emscripten;
extern crate rand;
use sdl2::pixels::Color;
use sdl2::render::Renderer;
use sdl2::EventPump;
use sdl2::event::Event;
use sdl2::keyboard::Keycode;
use emscripten::em;
use std::mem::transmute;
... | true |
db2c162c9dcdb7ae03b29fa33cea17d0d6835def | Rust | tpearson1/rust-raytracer | /lib/ray_math/src/bvh_node.rs | UTF-8 | 3,219 | 2.90625 | 3 | [] | no_license | use std::{cmp::Ordering, ops::Range, sync::Arc};
use rand::Rng;
use crate::{Aabb, HitResult, Hittable, HittableList, Ray};
pub struct BvhNode {
left: Arc<dyn Hittable>,
right: Arc<dyn Hittable>,
bounds: Aabb,
}
impl BvhNode {
pub fn new(
rng: &mut dyn rand::RngCore,
mut list: Hittabl... | true |
07bce77d74f8350ad926ed9e8d403692732ac468 | Rust | tearitco/FactorishWasm | /src/power_network.rs | UTF-8 | 1,978 | 2.703125 | 3 | [
"MIT"
] | permissive | use super::{
structure::{StructureDynIter, StructureId},
PowerWire,
};
use std::collections::HashSet;
#[derive(Debug)]
pub(crate) struct PowerNetwork {
pub wires: Vec<PowerWire>,
pub sources: HashSet<StructureId>,
pub sinks: HashSet<StructureId>,
}
pub(crate) fn build_power_networks(
structure... | true |
618569f029de95eda5701052a399b38f57ed7c80 | Rust | klaxit/heroku_rs | /src/endpoints/misc/get.rs | UTF-8 | 6,268 | 3.0625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | //Anything related to GET requests for mixed endpoints goes here.
use super::{Ratelimit, Region, Stack};
use crate::framework::endpoint::{HerokuEndpoint, Method};
/// Region Info
///
/// Info for existing region.
///
/// [See Heroku documentation for more information about this endpoint](https://devcenter.heroku.com/... | true |
4314992b655d30a1d973e79c4d0ff0515b2ecfe8 | Rust | lanocci/algorithm-and-data-struscture-in-rust | /data_structure/complete_binary_tree_printing/src/main.rs | UTF-8 | 1,202 | 2.890625 | 3 | [] | no_license | use std::io::*;
use util::Scanner;
use complete_binary_tree::CompleteBinaryTree;
fn main() {
std::thread::Builder::new()
.stack_size(1048576)
.spawn(solve)
.unwrap()
.join()
.unwrap();
}
fn solve() {
let cin = stdin();
let cin = cin.lock();
let mut sc = Scanner:... | true |
c4ea3728fc9f9fe5ba86b9a12b17411af3af17c8 | Rust | pmespresso/rust-by-example | /multithreaded_web_server/src/main.rs | UTF-8 | 1,269 | 3.3125 | 3 | [] | no_license | use std::io::prelude::*; // get access to traits that allow reading and writing from a stream
use std::net::TcpStream;
use std::net::TcpListener;
use std::fs;
fn main() {
// the bind() function returns Result<T, E> meaning it might fail, so we unwrap to stop the program if errors happen.
let listener = TcpList... | true |
1557a64400d3d682f1e61fa10091ae2369725cdb | Rust | resamplr/knobimage | /src/main.rs | UTF-8 | 2,358 | 3.28125 | 3 | [] | no_license | extern crate image;
use std::io::Write;
use std::env;
use std::fs;
use image::{
GenericImage,
ImageBuffer
};
struct Dimension {
width: u32,
height: u32,
final_height: u32
}
fn main() {
// parse args
for argument in env::args() {
println!("{}", argument);
}
// get vector of all files in working ... | true |
f357d564cffb1ec5626a940bb5ddf7fafce5554b | Rust | Erk-/discord-bots-org.rs | /src/builder/widget.rs | UTF-8 | 6,162 | 3.203125 | 3 | [
"ISC"
] | permissive | //! Types for generating widget embed URLs.
use crate::{endpoints, Result};
use std::collections::HashMap;
use url::Url;
#[derive(Clone, Debug)]
struct Widget(u64, HashMap<&'static str, String>, bool);
impl Widget {
fn build(self) -> Result<String> {
let uri = if self.2 {
endpoints::png_widge... | true |
a2605d9c5844201d2140224bc80dd0a33d9b9102 | Rust | prataprc/gist | /rs/thread.rs | UTF-8 | 850 | 3.15625 | 3 | [
"MIT"
] | permissive | use std::sync::mpsc;
use std::thread;
use std::time::SystemTime;
fn main() {
let mut threads = vec![];
let rx = {
let (tx, rx) = mpsc::sync_channel(1000);
for _i in 0..2 {
let tx1 = mpsc::SyncSender::clone(&tx);
threads.push(thread::spawn(|| generate(tx1)));
}
... | true |
373722bb3d9082b28abdfd6c2a24ac71dd1462a1 | Rust | thomasmathew365/rust-for-ts-devs | /src/lifetime_elision.rs | UTF-8 | 514 | 3.15625 | 3 | [] | no_license | // Why didn't we need to specify lifetimes before?
// This works without specifying lifetimes, but they're still
// there... it's just that the compiler allows you to *elide*
// them because it can trivially figure them out.
pub fn substr(string: &str, offset: usize, len: usize) -> &str {
&string[offset..offset + ... | true |
44e527003a01550192fdcb599d5f40e8463722c1 | Rust | tlightsky/parser-combinator | /src/lib.rs | UTF-8 | 13,371 | 3.234375 | 3 | [] | no_license | // https://bodil.lol/parser-combinators/
// Parsing is a process of deriving structure from a stream of data.
// A parser is something which teases out that structure.
#![type_length_limit="181933244"]
#[derive(Clone, Debug, PartialEq, Eq)]
struct Element {
name: String,
attributes: Vec<(String, String)>,
... | true |
43f726bc496ae9376c3b0a48ce9bebe2d4f5851f | Rust | rabisg0/rust-clippy | /clippy_lints/src/utils/hir_utils.rs | UTF-8 | 27,198 | 2.59375 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | use crate::consts::{constant_context, constant_simple};
use crate::utils::differing_macro_contexts;
use rustc::ich::StableHashingContextProvider;
use rustc::ty::TypeckTables;
use rustc_ast::ast::Name;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_hir::{
BinOpKind, Block, BlockCheck... | true |
3c6a6a6f05fa730f7b53eeadc1730e9dddc73dcc | Rust | chrisvittal/aoc-2017 | /src/bin/day02.rs | UTF-8 | 719 | 2.96875 | 3 | [
"MIT"
] | permissive |
extern crate aoc;
use aoc::file;
fn main() {
let s = file::to_split_parsed("data/day02");
println!("1: {}", checksum(&s));
println!("2: {}", checksum2(&s));
}
fn checksum(data: &Vec<Vec<u32>>) -> u32 {
let mut tot = 0;
for v in data {
tot += v.iter().max().unwrap() - v.iter().min().unwra... | true |
d7f9f3eadb7b150d60e47a2d50a0350185175b86 | Rust | ecreeth/hhvm | /hphp/hack/test/rust/gc_ocaml_rust.rs | UTF-8 | 2,837 | 2.9375 | 3 | [
"MIT",
"PHP-3.01",
"Zend-2.0"
] | permissive | use ocaml::caml;
use std::time::{SystemTime, UNIX_EPOCH};
trait OCamlTransferableStruct {}
struct InterlanguageStruct {
id: u128,
value: u32,
}
impl InterlanguageStruct {
fn new(value: u32) -> Self {
let id = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
... | true |
e5536975ebf9695b549a5c6a873a72cc69b3ead4 | Rust | Financial-Times/scrumple | /src/manifest.rs | UTF-8 | 17,217 | 2.640625 | 3 | [
"MIT"
] | permissive | use crate::path_ext::*;
use crate::CliError;
use fnv::FnvHashMap;
use matches::matches;
use serde::de::{SeqAccess, Visitor};
use serde::{de, Deserialize, Deserializer};
use std::cell::RefCell;
use std::marker::PhantomData;
use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::{fmt, fs, io, mem};
#[derive(Debug, Pa... | true |
c823e1a872537dc5604c1f177d53bd534538fc9e | Rust | svobot/manta | /src/color.rs | UTF-8 | 2,406 | 3.21875 | 3 | [] | no_license | use crate::material::scatter;
use crate::objects::Object;
use crate::ray::Ray;
use crate::spaces::Vec3;
use std::ops::{Add, AddAssign, Mul};
#[derive(Copy, Clone)]
pub struct Color {
r: f64,
g: f64,
b: f64,
}
impl Color {
pub fn new(r: f64, g: f64, b: f64) -> Self {
Color { r, g, b }
}
... | true |
02d80260b7e8eee9e6a290e54dd5b8d0d3fbcb12 | Rust | leopepe/fib-rs | /src/iterator.rs | UTF-8 | 505 | 3.671875 | 4 | [] | no_license | struct Fibonacci {
curr: u64,
next: u64,
}
impl Fibonacci {
fn new() -> Self {
Fibonacci { curr: 1, next: 1 }
}
}
impl Iterator for Fibonacci {
type Item = u64;
fn next(&mut self) -> Option<u64> {
let new_next = self.curr + self.next;
self.curr = self.next;
self.... | true |
04c09c509988576dbd2bf087d521d932904b1fe1 | Rust | nickmass/acme2-slim | /src/jwt.rs | UTF-8 | 4,294 | 2.640625 | 3 | [
"MIT"
] | permissive | use openssl::hash::MessageDigest;
use openssl::pkey::PKey;
use openssl::sign::Signer;
use crate::{helper::b64, Account};
use serde::{Deserialize, Serialize};
use serde_json::to_string;
use crate::error::Result;
/// JwsHeader that is required for ACME2
/// kid is passed after an account is created / looked up
/// jw... | true |
36fce9dac991455e75c1691f778446c2a3ce796b | Rust | danieldeankon/hypermine | /client/src/config.rs | UTF-8 | 3,243 | 2.546875 | 3 | [
"Apache-2.0",
"Zlib",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use std::{
env, fs, io,
net::SocketAddr,
path::{Path, PathBuf},
sync::Arc,
};
use serde::Deserialize;
use tracing::{debug, error, info};
use common::{SimConfig, SimConfigRaw};
pub struct Config {
pub name: Arc<str>,
pub data_dirs: Vec<PathBuf>,
pub chunk_load_parallelism: u32,
pub ser... | true |
e86ed5cae9c3089533531e43ef48924ebed96a51 | Rust | vandenoever/rome-hdt | /src/hdt.rs | UTF-8 | 3,842 | 2.609375 | 3 | [] | no_license | use rome;
use std::ffi::CString;
use std::os::raw::{c_void, c_char};
use get_resource_string::*;
extern "C" {
fn map_indexed_hdt(file_path: *const u8) -> *mut c_void;
fn delete_hdt(hdt: *mut c_void);
fn hdt_search_all(hdt: *mut c_void) -> *mut c_void;
fn hdt_search_sp(hdt: *mut c_void, s: *const c_ch... | true |
2abc4017dc34639477dc4999c67472c7f489e9fa | Rust | Serbis/sealrs | /src/examples/actors/supervision/example.rs | UTF-8 | 1,799 | 2.78125 | 3 | [] | no_license | use crate::actors::prelude::*;
use crate::examples::actors::supervision::a_actor;
use crate::examples::actors::supervision::c_actor;
use crate::futures::future::WrappedFuture;
use std::sync::{Mutex, Arc};
use std::thread;
use std::time::Duration;
pub fn run() {
// In this example presents various supervision oper... | true |
717d8472d2fedcfd9e547b6af47a876872aaba92 | Rust | revsolid/polyminis-core | /src/actuators.rs | UTF-8 | 3,198 | 3.328125 | 3 | [] | no_license | //TODO: These sould derive Clone / Copy and others
use std::fmt;
use ::types::*;
use ::serialization::*;
#[derive(Copy, Clone, Debug)]
pub enum Action
{
NoAction,
MoveAction(MoveAction),
}
impl ToJson for Action
{
fn to_json(&self) -> Json
{
match *self
{
Action::NoAction ... | true |
684070978d420f09e80835ce7fa27b4e18cf6c59 | Rust | kiskoza/himzo-calculator | /src/order.rs | UTF-8 | 1,758 | 3.046875 | 3 | [] | no_license | use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub struct Order {
count: u32,
diameter: u32,
fancy_stitch: u32,
patch: bool,
piece: u32,
stitch: u32,
svie: bool,
}
#[wasm_bindgen]
impl Order {
pub fn new() -> Order {
Order {
count: 0,
diameter: 0,
fancy_stitch: 0,
patch: tru... | true |
d525c05d09e724bb0ff7433f12ddf14c4aeebd39 | Rust | Borrus-sudo/aero | /src/aero_kernel/src/utils/io.rs | UTF-8 | 2,612 | 2.671875 | 3 | [
"Apache-2.0"
] | permissive | //! Wrapper functions for the hardware IO using respective assembly instructions.
pub const IA32_EFER: u32 = 0xc0000080;
pub const IA32_FS_BASE: u32 = 0xC0000100;
/// System Call Target Address (R/W).
pub const IA32_STAR: u32 = 0xc0000081;
/// IA-32e Mode System Call Target Address (R/W).
pub const IA32_L... | true |
2bd145c3d4d214e0ba5bb0debe41f97d6ead97f9 | Rust | gwy15/leetcode | /src/462.最少移动次数使数组元素相等-ii.rs | UTF-8 | 676 | 2.96875 | 3 | [] | no_license | /*
* @lc app=leetcode.cn id=462 lang=rust
*
* [462] 最少移动次数使数组元素相等 II
*/
struct Solution;
// @lc code=start
impl Solution {
#[allow(unused)]
pub fn min_moves2(mut nums: Vec<i32>) -> i32 {
nums.sort();
let mid = nums[nums.len() / 2]; // 奇偶统一处理
nums.iter().fold(0, |sum, &n| sum + (n - m... | true |
a41bd7f3003f8a5e980ed1414350f298b322ff3f | Rust | isgasho/RVM1.5 | /src/memory/mapper.rs | UTF-8 | 1,611 | 2.875 | 3 | [
"MIT"
] | permissive | use core::fmt::{Debug, Formatter, Result};
use super::addr::{align_down, virt_to_phys};
use super::{AlignedPage, MemFlags, MemoryRegion, PhysAddr};
static EMPTY_PAGE: AlignedPage = AlignedPage::new();
#[derive(Clone)]
pub(super) struct Mapper {
phys_virt_offset: Option<usize>,
}
impl Mapper {
pub fn map_fn<... | true |
91730c0cc3dbe1a91ef5e405cca52e59ca4c2d00 | Rust | gauteh/ambiq-apollo3-pac | /src/ctimer/globen/mod.rs | UTF-8 | 49,322 | 2.765625 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #[doc = r" Value read from the register"]
pub struct R {
bits: u32,
}
#[doc = r" Value to write to the register"]
pub struct W {
bits: u32,
}
impl super::GLOBEN {
#[doc = r" Modifies the contents of the register"]
#[inline]
pub fn modify<F>(&self, f: F)
where
for<'w> F: FnOnce(&R, &'w mu... | true |
d8a269659ad4fc615f687a3e8f063fbf8202d4b8 | Rust | Sibuken/lapin | /src/queue.rs | UTF-8 | 701 | 3 | 3 | [
"MIT"
] | permissive | use crate::types::ShortString;
use std::borrow::Borrow;
#[derive(Clone, Debug)]
pub struct Queue {
name: ShortString,
message_count: u32,
consumer_count: u32,
}
impl Queue {
pub(crate) fn new(name: ShortString, message_count: u32, consumer_count: u32) -> Self {
Self {
name,
... | true |
4368052b21a02f022a73b8139064e0b2623b2c0c | Rust | jiayaoqijia/picoquic-rs | /src/verify_certificate.rs | UTF-8 | 1,197 | 2.6875 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | use crate::{ConnectionId, ConnectionType};
pub use openssl::{
error::ErrorStack,
stack::StackRef,
x509::{store::X509StoreRef, X509Ref, X509StoreContext, X509StoreContextRef, X509},
*,
};
/// The `VerifyCertificate` trait is used by the verify certificate handler, to verify a
/// certificate.
pub trait... | true |
709190237f8b6b2e120155ea740d3d34e3119a0b | Rust | JeffBelgum/chip-8 | /src/sound.rs | UTF-8 | 2,007 | 2.71875 | 3 | [] | no_license | use std::f64::consts::PI;
use portaudio as pa;
const CHANNELS: i32 = 2;
const NUM_MILLIS: i32 = 16;
const SAMPLE_RATE: f64 = 44_100.0;
const FRAMES_PER_BUFFER: u32 = 64;
const TABLE_SIZE: usize = 200;
type Stream = pa::Stream<pa::NonBlocking, pa::Output<f32>>;
pub struct Sound {
pa: pa::PortAudio,
stream: S... | true |
ddd56a4fe51e7a1bbe9736a43db66963e7c40c7d | Rust | youngqqcn/RustNotes | /rust-by-example/18-错误处理/3-使用问号解开option.rs | UTF-8 | 795 | 3.09375 | 3 | [] | no_license | // Author: yqq
// Date: 2022-11-19 21:01:27
// Description:
struct Person {
job: Option<Job>,
}
#[derive(Clone, Copy)]
struct Job {
phone_number: Option<PhoneNumber>,
}
#[derive(Clone, Copy)]
struct PhoneNumber {
area_code: Option<u8>,
number: u32,
}
impl Person {
fn work_phone_area_code(&self) ... | true |
9802c88033e6c751844e65429d11abcbf1e5f229 | Rust | jxnu-liguobin/cs-summary-reflection | /rust-leetcode/src/leetcode_35.rs | UTF-8 | 563 | 3.03125 | 3 | [
"Apache-2.0"
] | permissive | use crate::pre_structs::Solution;
///搜索插入位置
impl Solution {
pub fn search_insert(nums: Vec<i32>, target: i32) -> i32 {
let nums = nums;
//找到知己反回索引,没有找到则返回该元素插入后保持数组仍然有序的索引位置,主要用于有序的数组/向量
let ret = match nums.binary_search(&target) {
Ok(found_index) => found_index,
Er... | true |
cfc5ee91406cf17e9323d5cf3b589b5dd425832f | Rust | acmcarther/next_space_coop | /cargo/vendor/nalgebra-0.9.0/src/structs/algebra/rotation.rs | UTF-8 | 2,863 | 2.578125 | 3 | [
"BSD-2-Clause"
] | permissive | #![macro_use]
macro_rules! use_special_orthogonal_group_modules(
() => {
use algebra::structure::{EuclideanGroupApprox, SpecialEuclideanGroupApprox,
OrthogonalGroupApprox, SpecialOrthogonalGroupApprox,
GroupApprox, LoopApprox, MonoidApprox,... | true |
2a1abbd0b73a48f8273a4c5b76395ba6a5796de5 | Rust | f5xs-0000a/yasc_project | /src/song_player/fx.rs | UTF-8 | 7,331 | 2.84375 | 3 | [] | no_license | pub struct Fx {
unsounded_chip: FxUnsounded,
sounded_chip: FxSounded,
long: BtLong,
}
pub struct FxSounded {
note_buffer: Buffer<Resources, DeviceBtChip>,
notes: [Vec<HostBtChip>; 4],
soundbite: (), // unimplemented!()
}
pub struct FxUnsounded {
note_buffer: Buffer<Resources, DeviceBtChip>... | true |
c45fad86fcefde4a46a1afda1a2d2437d9675dbf | Rust | leonardinius/git-wayback-machine.rs | /src/history.rs | UTF-8 | 4,415 | 3.125 | 3 | [
"MIT"
] | permissive | use std::fmt;
use std::path::Path;
use std::process::Command;
use git;
#[derive(Debug, Clone)]
pub struct Entry { name: String, time: String, comment: String, commit: String, }
impl fmt::Display for Entry {
fn fmt(& self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Entry: {:?} {:?} {:?}: {:?}", s... | true |
f3de00b5ff77343759c96abe622d3d165a617ad1 | Rust | azennto/snippet | /src/math.rs | UTF-8 | 1,048 | 3.3125 | 3 | [] | no_license | use cargo_snippet::snippet;
#[snippet]
pub fn gcd(a:u64,b:u64) -> u64{
if b == 0 {
a
} else {
gcd(b,a%b)
}
}
#[snippet(include="gcd")]
pub fn lcm(a:u64,b:u64) -> u64{
a*b/gcd(a,b)
}
#[snippet]
pub fn prime_judge(n:usize) -> bool{
if n == 1 {
return false;
}
for i i... | true |
6013203dcfc2042aeff4c26756b9c3f329cf2f74 | Rust | lkadalski/leftwm | /src/bin/common/theme_setting.rs | UTF-8 | 1,120 | 2.6875 | 3 | [
"MIT"
] | permissive | use leftwm::config::ThemeSetting;
use leftwm::errors::Result;
use leftwm::models::Margins;
use std::fs;
use std::path::Path;
pub struct ThemeLoader;
impl leftwm::config::ThemeLoader for ThemeLoader {
fn load(&self, path: &Path) -> ThemeSetting {
match load_theme_file(path) {
Ok(theme) => theme... | true |
c632a03caee4b7b680ab24f4dd6fe1f8a27fed74 | Rust | BigAngryDinosaur/rs_atcoder | /src/bin/grid_one.rs | UTF-8 | 2,333 | 3.203125 | 3 | [] | no_license | use std::io;
use std::io::prelude::*;
#[derive(PartialEq)]
enum Part {
Floor,
Wall
}
type Grid = Vec<Vec<Part>>;
fn main() {
let stdin = io::stdin();
let handle = stdin.lock();
let mut lines = handle.lines().map(|l| l.unwrap());
let line1: Vec<usize> = lines.next().unwrap()
... | true |
84aee605fd15d9a0a983b9dac2a257a9a28b6151 | Rust | aleyhdar/Rust-By-Example | /rust_example_03.rs | UTF-8 | 1,018 | 4.375 | 4 | [] | no_license | fn main (){
//let variables are immutable
//Add this keyword and can mutable
let mut x = 50; /*i32*/
println!("X's value : {}",x);
x = 80;
println!("X's new value : {}",x);
//If conditions
if x < 70 {
println!("X is less than 70");
}
else if x >50 {
print... | true |
c69d28a5ad40526496fc97b00809909cc317c812 | Rust | Fonan15/vier_gewinnt | /src/main.rs | UTF-8 | 4,235 | 3.453125 | 3 | [] | no_license | use std::io;
//use std::thread;
//use std::io::stdout;
//use std::io::Write;
fn main() {
// Initialization
println!("Minimal version of 4-wins");
println!("==========================");
println!();
let mut round = 1;
let mut player = 2;
loop{
// Variable resetting and stuff
let mut again = String::new();
... | true |
3cc5362978380b7ac8159d00583a2b32b6a805ce | Rust | naokirin/logian | /src/schema/config.rs | UTF-8 | 706 | 2.65625 | 3 | [
"MIT"
] | permissive | use ::json;
pub struct Config {
pub log_label: String,
}
pub fn parse(json: &str) -> Result<Config, String> {
let parsed = json::parse(json)?;
if !parsed.is_object() {
return Err("schema.config root is not a object.".to_string());
}
let obj = parsed.as_object().unwrap();
let log_labe... | true |
7ad3294db8a8c34776c8748e99f2e6dae6ce3239 | Rust | yacoob/aoc-2018 | /src/bin/13.rs | UTF-8 | 7,960 | 3.515625 | 4 | [
"BSD-3-Clause"
] | permissive | use self::Direction::*;
use aoc::*;
use std::collections::hash_map::{Entry, HashMap};
const TRACKS_SIZE: usize = 150;
const TURNS: [Direction; 4] = [Up, Right, Down, Left];
#[derive(Clone, Copy, Debug, PartialEq)]
enum Direction {
Up,
Right,
Down,
Left,
}
#[derive(Clone, Debug)]
struct Cart {
id:... | true |
7f93433bcc1d3b12836bc046acd0d4bf67304055 | Rust | BenoitZugmeyer/RustyAdventOfCode | /2016/src/bin/day06.rs | UTF-8 | 1,020 | 2.84375 | 3 | [] | no_license | use std::collections::HashMap;
use std::io::stdin;
use std::io::Read;
fn main() {
let columns = stdin()
.bytes()
.filter_map(|b| b.ok())
.map(|b| b as char)
.fold((0, Vec::new()), |(mut column_index, mut columns), ch| {
if ch == '\n' {
column_index = 0;
... | true |
9432354545be51670852563e1c8c6a4d70278ea3 | Rust | fuchsch1234/lpc178x_7x | /src/usb/i2c_sts.rs | UTF-8 | 15,957 | 2.640625 | 3 | [
"BSD-3-Clause"
] | permissive | #[doc = "Reader of register I2C_STS"]
pub type R = crate::R<u32, super::I2C_STS>;
#[doc = "Transaction Done Interrupt. This flag is set if a transaction completes successfully. It is cleared by writing a one to bit 0 of the status register. It is unaffected by slave transactions.\n\nValue on reset: 0"]
#[derive(Clone, ... | true |
fadf283e354644ef2e5ffbbbf53832bb76b9e134 | Rust | rcore-os/arceos | /modules/axfs/src/fs/fatfs.rs | UTF-8 | 9,209 | 2.5625 | 3 | [
"Apache-2.0",
"AGPL-3.0-only",
"LicenseRef-scancode-mulanpubl-2.0",
"AGPL-3.0-or-later",
"GPL-3.0-only",
"MulanPSL-2.0",
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-mulanpsl-2.0-en"
] | permissive | use alloc::sync::Arc;
use core::cell::UnsafeCell;
use axfs_vfs::{VfsDirEntry, VfsError, VfsNodePerm, VfsResult};
use axfs_vfs::{VfsNodeAttr, VfsNodeOps, VfsNodeRef, VfsNodeType, VfsOps};
use axsync::Mutex;
use fatfs::{Dir, File, LossyOemCpConverter, NullTimeProvider, Read, Seek, SeekFrom, Write};
use crate::dev::Disk... | true |
3e1b60de3f1ae125f57611a99bd74a0015283ac5 | Rust | pacheco/rust-vecset | /examples/bench.rs | UTF-8 | 2,102 | 2.96875 | 3 | [] | no_license | use std::collections::HashSet;
use std::collections::BTreeSet;
extern crate fnv;
extern crate vecset;
use vecset::*;
#[macro_use]
extern crate timeit;
extern crate rand;
fn main() {
for n in vec![1,2,4,8,16,64,128,512,1024].into_iter() {
let items: Vec<usize> = (0..n).map(|_| rand::random()).collect();
... | true |
a164df524a8b087a03541139c48c39fecd902070 | Rust | jimblandy/harfbuzz_rs | /src/rusttype.rs | UTF-8 | 4,954 | 2.734375 | 3 | [
"MIT"
] | permissive | //! This module allows you to use rusttype to provide the font operations that harfbuzz needs.
extern crate rusttype;
use common::Tag;
use self::rusttype::{Codepoint, GlyphId, Scale};
use self::rusttype::Font as RTFont;
use font;
use face;
use font::{Font, FontFuncs, Glyph as GlyphIndex, GlyphExtents, Position};
us... | true |
b9f93c2c714678c71f3e099d1d31856779d903ec | Rust | ChrisGreenaway/accounts-solution | /src/account.rs | UTF-8 | 3,297 | 3.09375 | 3 | [] | no_license | use crate::transaction::{Transaction, TransactionType};
use rust_decimal::prelude::Zero;
use rust_decimal::Decimal;
use serde::Serialize;
use std::collections::HashMap;
#[derive(Debug, Serialize, Eq, PartialEq)]
pub struct ClientAccount {
pub client: u16,
pub available: Decimal,
pub held: Decimal,
pub ... | true |
11a65de8058504037369c2c78e02829fec96ee16 | Rust | greym0uth/life-of-a-monster | /src/states/gameplay.rs | UTF-8 | 2,231 | 2.5625 | 3 | [] | no_license | use amethyst::{
assets::{Handle},
core::{
math::{Vector3},
transform::Transform,
},
prelude::*,
renderer::{Camera, SpriteRender, SpriteSheet, Transparent},
tiles::{FlatEncoder, TileMap},
};
use crate::resources::{Hero, Dungeon, DungeonRenderTile};
pub struct GameplayState {
... | true |
b24fc99d5267ae79fba872ed35afbfb280ea4962 | Rust | CyberFlameGO/aoc | /src/y2020p5.rs | UTF-8 | 3,004 | 3.4375 | 3 | [] | no_license | use crate::futil::read_lines;
use anyhow::anyhow;
use std::path::PathBuf;
use std::str::Chars;
struct Seat {
row: usize,
col: usize,
}
enum SplitResult {
Range(usize, usize),
One(usize),
}
enum Direction {
Higher,
Lower,
}
fn split(lower: usize, higher: usize, d: Direction) -> SplitResult {... | true |
45cdf065ab7c89854bf4180f85640b35d6da77ec | Rust | jgilchrist/advent-of-code | /rust/src/y2015/src/d05.rs | UTF-8 | 1,536 | 2.828125 | 3 | [] | no_license | use prelude::*;
pub struct Day05;
impl AocSolution for Day05 {
type Input = Vec<String>;
fn process_input(input: &str) -> Self::Input {
inputs::lines(input)
}
const PART1_SOLUTION: Solution = solution(255);
fn part1(input: &Self::Input) -> impl Into<Solution> {
fn is_nice(line: &s... | true |
6e5195eebc522a88cf01e0dd5276cfb293f74de4 | Rust | isgasho/Lystem | /src/scripting.rs | UTF-8 | 3,768 | 3.421875 | 3 | [] | no_license | use std::str::FromStr;
// This trait is implemented for types that have to interact with the config files
// Scripts for now only use floating point numbers
// from_num() cannot return Self because then
// we wouldn't be able to make ScriptVariable into a trait object
pub trait ScriptVariable {
fn from_num(&mut se... | true |
5641cc9a45d6dd31fcada1c60b59fd5da5288fd7 | Rust | magiclen/rust-short-crypt | /tests/tests.rs | UTF-8 | 2,548 | 3 | 3 | [
"MIT"
] | permissive | use short_crypt::ShortCrypt;
#[test]
fn test_encrypt() {
let sc = ShortCrypt::new("magickey");
assert_eq!((8, [216, 78, 214, 199, 157, 190, 78, 250].to_vec()), sc.encrypt("articles"));
}
#[test]
fn test_decrypt() {
let sc = ShortCrypt::new("magickey");
assert_eq!(
b"articles".to_vec(),
... | true |
cb6423044e4673ee026669cc3989663dbe78afc3 | Rust | marioortizmanero/rspotify-bench | /rspotify-0.10.0-patched/examples/blocking/current_user_top_artists.rs | UTF-8 | 1,574 | 2.625 | 3 | [
"MIT"
] | permissive | extern crate rspotify;
use rspotify::blocking::client::Spotify;
use rspotify::blocking::oauth2::{SpotifyClientCredentials, SpotifyOAuth};
use rspotify::blocking::util::get_token;
use rspotify::senum::TimeRange;
fn main() {
// Set client_id and client_secret in .env file or
// export CLIENT_ID="your client_id"... | true |
ce7e606fb44f9d8cdf7d22a26281cf009a9d82b6 | Rust | mark-i-m/os1 | /kernel/memory/vm/structs.rs | UTF-8 | 4,784 | 2.859375 | 3 | [
"MIT"
] | permissive | //! A module containing useful structs to abstract paging structures
use core::intrinsics::transmute;
use core::ops::{Index, IndexMut};
use interrupts::no_interrupts;
use process::CURRENT_PROCESS;
use super::super::physmem::Frame;
use super::VMM_ON;
/// A single entry in a page directory or table
/// ```
/// 31 ... | true |
eaaefdf181e7a5a706c9198cd1f1f121fc0ae788 | Rust | pierreyoda/rustboycolor | /src/joypad.rs | UTF-8 | 6,754 | 3.34375 | 3 | [
"MIT"
] | permissive | use self::JoypadKey::*;
use crate::irq::{Interrupt, IrqHandler};
use crate::memory::Memory;
pub const JOYPAD_ADDRESS: u16 = 0xFF00;
pub const JOYPAD_KEYS: [&str; 8] = ["Up", "Down", "Left", "Right", "Select", "Start", "A", "B"];
pub const JOYPAD_SELECT_DIRECTIONAL: u8 = 1 << 4;
pub const JOYPAD_SELECT_BUTTON: u8 = 1 <... | true |
778ebae8fdf9f3f56116817bd19258c9e346418c | Rust | chvp/zauth | /src/errors.rs | UTF-8 | 5,668 | 2.609375 | 3 | [
"MIT"
] | permissive | use rocket::http::Status;
use rocket::response::{self, Responder, Response};
use rocket::Request;
use thiserror::Error;
use diesel::result::Error::NotFound;
use lettre::Message;
use std::io::Cursor;
use std::sync::mpsc::{SendError, TrySendError};
use validator::ValidationErrors;
#[derive(Error, Debug)]
pub enum Zauth... | true |
496b58f49078c88faab20b797b1629a959d169cc | Rust | bouzuya/rust-atcoder | /atcoder-problems-virtual-contests/6962eea9-3a7e-4c37-b77f-748705500d91/src/bin/d.rs | UTF-8 | 980 | 2.6875 | 3 | [] | no_license | use proconio::input;
fn main() {
input! {
n: usize,
a: [usize; n],
}
let mut x = vec![0; n];
for i in (0..n).rev() {
let mut r = 0;
for j in (i + i + 2 - 1..n).step_by(i + 1) {
r += x[j];
r %= 2;
}
if a[i] != r {
x[i] ... | true |
93db963ebc623eaceb23d5a26fb03c57c387ff8d | Rust | garvitgoel/circom | /type_analysis/src/decorators/type_reduction.rs | UTF-8 | 5,969 | 3.015625 | 3 | [] | no_license | use program_structure::ast::*;
use program_structure::environment::CircomEnvironment;
use program_structure::function_data::FunctionData;
use program_structure::template_data::TemplateData;
type Environment = CircomEnvironment<(), (), ()>;
pub fn reduce_function(function_data: &mut FunctionData) {
let mut environ... | true |
78599216b0375f820d73e66347267601bcdc5b59 | Rust | RoaringBitmap/roaring-rs | /src/treemap/ops.rs | UTF-8 | 16,498 | 3.546875 | 4 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | use std::collections::btree_map::Entry;
use std::mem;
use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Sub, SubAssign};
use crate::RoaringTreemap;
impl RoaringTreemap {
/// Computes the len of the union with the specified other treemap without creating a new
/// treemap.
///
... | true |
01e25ecbc819b3aa4332377de4cf36eeb0f50396 | Rust | mdup/multizip | /src/lib.rs | UTF-8 | 13,998 | 3.53125 | 4 | [
"MIT"
] | permissive | use std::iter::Zip;
/*
* zip2
*/
#[derive(Clone)]
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
pub struct Zip2<A, B> {
subzip: Zip<A, B>
}
impl<A, B> Iterator for Zip2<A, B> where
A: Iterator,
B: Iterator
{
type Item = (A::Item, B::Item);
#[inline]
fn next(&mut self) -> ... | true |
4f0134bd9a4a6d25bba1c65e7ba932eeb2d8d5fa | Rust | volyx/advent2020-rust | /src/advent1/mod.rs | UTF-8 | 861 | 3.015625 | 3 | [] | no_license | use std::fs::File;
use std::io::{prelude::*, BufReader};
use std::collections::{HashMap};
pub fn solution() {
let file = File::open("advent1.txt").unwrap();
let reader = BufReader::new(file);
let mut two_sums: HashMap<i32, i32> = HashMap::new();
let mut answer: i32 = -1;
let mut arr = vec![];
... | true |
1465259284ee936e3b208eb39527d5b9d66fed48 | Rust | apache/incubator-teaclave-sgx-sdk | /samplecode/wasmi/app/src/wasm_def.rs | UTF-8 | 8,046 | 3.15625 | 3 | [
"BSD-3-Clause",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | use std::{fmt, error};
use nan_preserving_float::{F32, F64};
#[derive(Debug, Serialize, Deserialize)]
pub struct Trap {
kind: TrapKind,
}
impl Trap {
/// Create new trap.
pub fn new(kind: TrapKind) -> Trap {
Trap { kind }
}
/// Returns kind of this trap.
pub fn kind(&self) -> &TrapKin... | true |
845e7b69b8c02aa225a87cf70a3941160a334337 | Rust | kraemahz/regia | /src/note.rs | UTF-8 | 1,763 | 3.203125 | 3 | [] | no_license | use std::cmp::Ordering;
use chrono::{DateTime, Utc};
use colored::*;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct Note {
pub(crate) id: Uuid,
pub(crate) created: DateTime<Utc>,
pub(crate) content: String,
}
impl PartialOrd for ... | true |
b5dfe2241d4477a5fcd8b17c8812c7863c6eca9e | Rust | jeschkies/async-mesos-rs | /src/decoder.rs | UTF-8 | 6,180 | 3.203125 | 3 | [
"Apache-2.0"
] | permissive | use bytes::{Bytes, BytesMut};
use failure;
use std::str;
pub trait Decoder {
type Item;
fn decode(&mut self, buf: &mut BytesMut) -> Result<Option<Self::Item>, failure::Error>;
}
#[derive(Debug, PartialEq)]
pub enum RecordIoDecoderState {
TrimWhitespaces,
ReadLength,
ReadRecord { len: u64 },
}
///... | true |
4dff98ca07e9f613c0136b1975c8bc298ce9ca79 | Rust | lucab/libsystemd-rs | /src/sysusers/mod.rs | UTF-8 | 13,467 | 2.875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | //! Helpers for working with `sysusers.d` configuration files.
//!
//! For the complete documentation see
//! <https://www.freedesktop.org/software/systemd/man/sysusers.d.html>.
//!
//! ## Example
//!
//! ```rust
//! # fn doctest_parse() -> Result<(), libsystemd::errors::SdError> {
//! use libsystemd::sysusers;
//!
//!... | true |
5a78b55e1bd061dc6222d7d0ca2715c89cb0d236 | Rust | efyang/rlisp | /src/stdlisp.rs | UTF-8 | 8,075 | 3.046875 | 3 | [] | no_license | #![allow(dead_code)]
use data::*;
use std::sync::Arc;
use eval::Eval;
use std::ops::{AddAssign, DivAssign, MulAssign, SubAssign, RemAssign};
macro_rules! generate_base_fn {
($fnname:expr, $name:ident) => {
($fnname, Function {procedure: Arc::new(LispFn::Builtin(BuiltinFn::new($fnname, $name)))})
}
}
m... | true |
c68c10ac5fa89d3d370ccf5ed4ea06d78a7c83f7 | Rust | sminez/penrose | /src/core/bindings.rs | UTF-8 | 11,178 | 2.9375 | 3 | [
"MIT"
] | permissive | //! Setting up and responding to user defined key/mouse bindings
use crate::{
core::{State, Xid},
pure::geometry::Point,
x::XConn,
Error, Result,
};
#[cfg(feature = "keysyms")]
use penrose_keysyms::XKeySym;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, co... | true |
24681107da270c4d90912b7aaa78426446fdd926 | Rust | DomtronVox/JRPG_Game | /src/assets/sprite_sheet.rs | UTF-8 | 3,136 | 3.328125 | 3 | [] | no_license | use std::collections::HashMap;
use coffee::graphics::{Point, Rectangle, Image, Batch, Sprite};
//size of a single sprite in the Sprite Sheet
struct SpriteSize { pub width: u16, pub height: u16}
//location of a single sprite
pub type SpritePos = ( u16, u16 );
//Sprite locations ordered in a way to create an animatio... | true |
7bbe676e77261ddb7675aeae2c301eddd1d4eb98 | Rust | Psychedelic/candid | /rust/candid/src/types/subtype.rs | UTF-8 | 5,093 | 2.78125 | 3 | [
"LLVM-exception",
"Apache-2.0"
] | permissive | use super::internal::{find_type, Field, Label, Type};
use crate::parser::typing::TypeEnv;
use crate::{Error, Result};
use anyhow::Context;
use std::collections::{HashMap, HashSet};
pub type Gamma = HashSet<(Type, Type)>;
/// Check if t1 <: t2
pub fn subtype(
gamma: &mut Gamma,
env1: &TypeEnv,
t1: &Type,
... | true |
958ff8d6544fbce6914274564e805c53628f4716 | Rust | dinAlt/yatt | /yatt_orm/src/lib.rs | UTF-8 | 8,158 | 2.671875 | 3 | [] | no_license | pub mod errors;
pub mod sqlite;
pub mod statement;
use chrono::prelude::*;
use chrono::{DateTime, Utc};
use core::convert::TryFrom;
use std::convert::TryInto;
use uuid::Uuid;
pub use errors::*;
pub use yatt_orm_derive::*;
use statement::*;
pub trait Storage {
fn save(&self, item: &impl StoreObject) -> DBResult<us... | true |
c10376783c2b09a0a1a4cf2fe1c48b799a534992 | Rust | laopo001/leetcode-rust | /src/group_anagrams/mod.rs | UTF-8 | 891 | 3.0625 | 3 | [] | no_license | struct Solution;
use std::collections::hash_map::DefaultHasher;
use std::collections::HashMap;
use std::hash::{Hash, Hasher};
fn format(s: String, res_map: &mut HashMap<u64, Vec<String>>) {
let mut temp_s = s.clone();
let vec = unsafe { temp_s.as_mut_vec() };
vec.sort_by(|a, b| a.partial_cmp(&b).unwrap());... | true |
5e5deef5c1c48e5060c5f7c5a7d5d1568942465c | Rust | visioncortex/polypartition | /webapp/src/polypartition/vertex.rs | UTF-8 | 720 | 2.671875 | 3 | [] | no_license | use visioncortex::PointF64;
#[derive(Clone, Debug, Default)]
pub struct PartitionVertex {
pub info: PartitionVertexInfo,
// Indices of the corresponding vertex node in the Vec
pub previous: usize,
pub next: usize,
}
#[derive(Clone, Debug, Default, PartialEq)]
pub struct PartitionVertexInfo {
pub i... | true |
1fd61c9d8af772cc17fb8e978f14c827b62b898b | Rust | tock/libtock-rs | /runner/src/main.rs | UTF-8 | 1,658 | 2.90625 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | mod elf2tab;
mod output_processor;
mod qemu;
mod tockloader;
use clap::{Parser, ValueEnum};
use std::env::{var, VarError};
use std::path::PathBuf;
/// Converts ELF binaries into Tock Binary Format binaries and runs them on a
/// Tock system.
#[derive(Debug, Parser)]
pub struct Cli {
/// Where to deploy the proces... | true |
d48330b63d3263de477850a61b2f1ef4053fa0e7 | Rust | efwxx/demonlistvn | /src/model/user/get.rs | UTF-8 | 2,363 | 2.78125 | 3 | [
"MIT"
] | permissive | use crate::{error::PointercrateError, model::user::User, permissions::Permissions, Result};
use sqlx::{Error, PgConnection};
macro_rules! construct_from_row {
($row:expr) => {
User {
id: $row.member_id,
name: $row.name,
permissions: Permissions::from_bits_truncate($row.p... | true |
92b7bd2acd0a6542fdd34ffe234c46449e44894b | Rust | quilt/lighthouse | /shard_node/shard_store/src/block_at_slot.rs | UTF-8 | 1,717 | 2.65625 | 3 | [
"Apache-2.0"
] | permissive | use super::*;
use ssz::{Decode, DecodeError};
fn get_block_bytes<T: Store>(store: &T, root: Hash256) -> Result<Option<Vec<u8>>, Error> {
store.get_bytes(ShardBlock::db_column().into(), &root[..])
}
fn read_slot_from_block_bytes(bytes: &[u8]) -> Result<ShardSlot, DecodeError> {
let end = std::cmp::min(ShardSlo... | true |
ccd2f42396859389eefd19a9386d0cea0a28df8f | Rust | JRMurr/adventOfCode2019 | /rust/src/day5/mod.rs | UTF-8 | 5,941 | 3.015625 | 3 | [] | no_license | type LangVal = isize;
pub fn main(contents: String) {
let prog: Vec<LangVal> = contents
.split(",")
.map(|x| x.trim().parse().unwrap())
.collect();
let out_buf = run_with_inital_vals(&prog, &mut vec![5 as LangVal]);
println!("out_buf: {:?}", out_buf);
// let (noun, verb) = find_d... | true |
2ca9159bfdbcbcc1430fbf51c90e919f94f935be | Rust | polonaiz/rustlang_str_test | /src/str.rs | UTF-8 | 4,421 | 3.015625 | 3 | [
"Apache-2.0"
] | permissive |
#[test]
fn test_quote() {
let haystack = "aaa,bbb,'ccc,ddd',eee";
let mut flag_qouted = false;
haystack
.split(|c| match c {
'\'' => {
flag_qouted = !flag_qouted;
false
}
',' if flag_qouted => false,
',' if !flag_qouted => true,
_ => false,
})
.for_each(|s: &str| {
let p = s.as_ptr()... | true |
f0b07bb2d683fac7a0d2b0aa70ab5478d0d90aa3 | Rust | Harzu/data_struct_rs | /hash_table.rs | UTF-8 | 2,449 | 3.671875 | 4 | [] | no_license | use hash_table::*;
mod hash_table {
use std::fmt::Debug;
use std::hash::Hasher;
use std::collections::LinkedList;
use std::collections::hash_map::DefaultHasher;
#[derive(Debug, Clone)]
struct Node<T> {
key: String,
value: T
}
#[derive(Debug)]
pub struct HashTable<T> {
values: Vec<Linked... | true |
3389137fc84c573bb807730bacc8570638fb92e0 | Rust | rust-lang/rust | /src/tools/clippy/tests/ui/cast_enum_constructor.rs | UTF-8 | 492 | 3.109375 | 3 | [
"Apache-2.0",
"MIT",
"LLVM-exception",
"NCSA",
"BSD-2-Clause",
"LicenseRef-scancode-unicode",
"LicenseRef-scancode-other-permissive"
] | permissive | #![warn(clippy::cast_enum_constructor)]
#![allow(clippy::fn_to_numeric_cast)]
fn main() {
enum Foo {
Y(u32),
}
enum Bar {
X,
}
let _ = Foo::Y as usize;
//~^ ERROR: cast of an enum tuple constructor to an integer
//~| NOTE: `-D clippy::cast-enum-constructor` implied by `-D ... | true |
f90b037e2bfaa2b88babf64b506117d658425798 | Rust | wdhg/game-boy | /src/cpu/instr/mod.rs | UTF-8 | 14,328 | 2.734375 | 3 | [
"MIT"
] | permissive | mod alu;
pub mod instr;
mod load;
mod misc;
pub mod operand;
use instr::Instr;
#[allow(dead_code)]
pub const PREFIX: u8 = 0xcb;
#[allow(dead_code)]
pub fn decode_unprefixed(opcode: u8) -> Instr {
let maybe_instr = misc::decode_unprefixed(opcode)
.or_else(|| load::decode_unprefixed(opcode))
.or_el... | true |
e2ead51718c4a1a758109bc6ba830cbd8997db61 | Rust | GreenPix/behaviour-tree | /src/parser/lexer.rs | UTF-8 | 5,881 | 3.34375 | 3 | [] | no_license | use std::str::Chars;
#[derive(Debug)]
pub enum Token {
Ident(String),
QuotedString(String),
Integer(i64),
Root,
Subtree,
Selector,
Sequence,
Priority,
Inverter,
LeftBracket,
RightBracket,
Comma,
Colon,
LeftParenthesis,
RightParenthesis,
LeftArray,
Rig... | true |
4cd5161ac92f06cc4b016dcebd84941f28e16fe3 | Rust | stkfd/poe-superfilter | /src/scope/mod.rs | UTF-8 | 4,609 | 2.984375 | 3 | [
"MIT"
] | permissive | use ast::mixin::PreparedMixin;
use std::collections::BTreeMap;
use std::cell::RefCell;
use std::rc::Rc;
use ast::transform::{TransformResult, RenderContext};
use std::io::Write;
use std::cmp::{Ordering, PartialEq};
use std::convert::{TryFrom, TryInto};
use std::fmt::Debug;
use errors::{Result, ErrorKind, Error};
mod i... | true |
e84e20884faca41615e3096359e90cc969b4b025 | Rust | adventofcode/2015solutions | /day11/p1a.rs | UTF-8 | 1,797 | 2.984375 | 3 | [] | no_license | #![feature(io)]
use std::io::{self, Read};
fn has_run(pass: &Vec<u8>) -> bool {
let mut run_length = 1;
let mut prev_val = pass[0];
for i in pass.iter().skip(1) {
if *i == prev_val + 1 {
run_length += 1;
} else {
run_length = 1;
}
if run_length >= ... | true |
5a1dcdb52b7d65ceb45384575f6c73ea21cd3a9f | Rust | pdietl/j2ds | /src/clock.rs | UTF-8 | 6,162 | 3.765625 | 4 | [
"MIT"
] | permissive | /// An increasing counter that ticks up until a particular count is
/// reached, which then resets itself
///
/// Example:
///
/// ```rust
/// use j2ds::*;
///
/// fn periodically_called_function(clock: &mut Clock) {
/// // Do some stuff...
///
/// if clock.tick() {
/// // Do something special...
/// ... | true |
98110cf4f3f0bca844c16f4b7decb88a3bc2c077 | Rust | danielwippermann/async-resol-vbus.rs | /src/device_discovery.rs | UTF-8 | 7,362 | 3.015625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0",
"MIT"
] | permissive | use std::{
collections::HashSet,
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
time::Duration,
};
use async_std::net::UdpSocket;
use crate::{device_information::DeviceInformation, error::Result};
/// Allows discovery of VBus-over-TCP devices in a local network.
///
/// All VBus-over-TCP devices listen for U... | true |
49aa08cd47c0d7aacbb4081212ca4bdf9ffaff8d | Rust | daniel5151/iotedge | /containrs/oci-digest/src/validator.rs | UTF-8 | 5,304 | 3.28125 | 3 | [
"MIT"
] | permissive | use std::fmt;
use std::str::FromStr;
use sha2::digest::DynDigest;
use crate::digest::Digest;
use crate::error::*;
pub struct Validator {
expect_digest: Vec<u8>,
digest: Box<dyn DynDigest>,
}
impl Validator {
/// Returns a new Validator.
/// If the digest algorithm is not recognized, returns None ins... | true |
ce933049f9f70249d91886e107b85f40d30ae7a4 | Rust | cnguoyj/MyParser | /src/parser/mod.rs | UTF-8 | 1,920 | 2.59375 | 3 | [] | no_license | pub mod recursive_descent;
pub mod type_analyzer;
pub mod syntax_node;
pub mod llvm_ir_generater;
mod symbol_manager;
mod symbol_checker;
use id_tree::NodeId;
use self::syntax_node::SyntaxTree;
#[derive(Debug)]
pub enum ParseError {
SyntaxError,
SemanticError,
MultiDefineError,
UndefinedSymbol,
}
#[d... | true |
a5fa0ed3b46f1d4d2e951c4235164d98f4169e50 | Rust | mutejs/rich-text | /src/op.rs | UTF-8 | 1,027 | 3.359375 | 3 | [] | no_license | use Iterator;
#[derive(Default,Clone)]
struct Op {
delete: Option<usize>,
insert: Option<String>,
retain: Option<usize>
}
impl Op {
fn new (retain:Option<usize>, insert:Option<String>, delete:Option<usize>) -> Self {
Op {
retain,
insert,
delete
}
}
fn delete (len:usize) -> Self ... | true |
365a460eb14b4d8daa685fc2c174f60999744a15 | Rust | archetect/archetect | /archetect-core/src/vendor/read_input/test_generators.rs | UTF-8 | 1,893 | 3.359375 | 3 | [
"MIT"
] | permissive | use std::{
cmp::PartialOrd,
ops::{
Bound::{Excluded, Included, Unbounded},
Range, RangeBounds, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive,
},
rc::Rc,
};
/// This trait is used to describe constraints with different types.
pub trait InsideFunc<T> {
/// Returns co... | true |
254ce77062f9c2a12cf72165c2e3827321e0e034 | Rust | rust-finland/presentations | /2019-01-31-wasm-rust-host/app/src/lib.rs | UTF-8 | 1,641 | 3.296875 | 3 | [] | no_license | // By default Wasm module has its own memory. We can specify that instead of using own memory
// host should provide a memory buffer.
// #![feature(wasm_import_memory)]
// #![wasm_import_memory]
mod small;
// This section defines methods that will be provided by host.
extern "C" {
// Host provides this function
... | true |
6640a571906912f04718acf099b0fb47ea35ac7f | Rust | aopicier/cryptopals-rust | /challenges/src/set1/challenge06.rs | UTF-8 | 2,779 | 3.046875 | 3 | [
"MIT"
] | permissive | use serialize::from_base64_file;
use std::path::Path;
use xor::XOR;
use super::challenge03::{break_single_byte_xor, compute_score};
use crate::errors::*;
fn hamming_distance(u: &[u8], v: &[u8]) -> Result<u32> {
if u.len() != v.len() {
return Err("inputs need to have the same length".into());
}
Ok... | true |
9134bf0de4945fd39b4fbfa3f56773757971cb1f | Rust | spacemeshos/svm | /crates/host/program/src/import.rs | UTF-8 | 2,860 | 3.015625 | 3 | [
"LicenseRef-scancode-free-unknown",
"MIT"
] | permissive | use indexmap::IndexMap;
use parity_wasm::elements::{External, ImportCountType, Module};
use crate::{FuncIndex, ProgramError};
/// Stores a mapping between a function index to its corresponding `(module_name, import_name)`
#[derive(Debug, Clone, Default)]
pub struct Imports {
inner: IndexMap<FuncIndex, (String, St... | true |
d8f4f774f7aa33bdc5f96110a70e8c239218dd15 | Rust | jackwickham/rust-webserver | /src/http/request/mod.rs | UTF-8 | 16,175 | 3.359375 | 3 | [] | no_license | //! [RFC 7230](https://tools.ietf.org/html/rfc723) compliant HTTP 1.1 request parser
mod util;
use std::io::prelude::*;
use std::net::TcpStream;
use std::collections::HashMap;
use std::sync::Arc;
use self::util::*;
pub use self::util::ParseError;
use self::util::TokenType::{TChar, Invalid};
/// A container for the ... | true |
7a2f0b6e7da4b8fed0515bb3c5cf3ce007b9a9ad | Rust | Luminoth/engine-rs | /core/src/math/quaternion.rs | UTF-8 | 206 | 2.796875 | 3 | [
"Apache-2.0"
] | permissive | use serde::{Deserialize, Serialize};
#[derive(Default, Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
pub struct Quaternion {
x: f32,
y: f32,
z: f32,
w: f32,
}
impl Quaternion {}
| true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.