text
stringlengths
232
16.3k
domain
stringclasses
1 value
difficulty
stringclasses
3 values
meta
dict
<|fim_prefix|>// repo: whichxjy/aoc-2020 path: /day-11/src/main.rs #[derive(Debug, Clone, PartialEq)] enum SeatKind { Floor, Empty, Occupied, } #[derive(Debug, Clone)] struct Layout { row_num: usize, col_num: usize, seat_map: Vec<Vec<SeatKind>>, } fn parse_layout(lines: &[&str]) -> Layout { ...
code_fim
hard
{ "lang": "rust", "repo": "whichxjy/aoc-2020", "path": "/day-11/src/main.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>#[js_function(1)] fn query(ctx: CallContext) -> napi::Result<JsObject> { let ext = ctx.get::<JsExternal>(0)?; let qe = ctx.env.get_value_external::<QueryEngine>(&ext)?; let qe = qe.clone(); ctx .env .execute_tokio_future(async move { Ok(qe.query().await) }, |env, v| { env.create_stri...
code_fim
hard
{ "lang": "rust", "repo": "napi-rs/napi-rs", "path": "/bench/src/query.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: napi-rs/napi-rs path: /bench/src/query.rs use napi::{CallContext, JsExternal, JsObject, JsString}; #[derive(Clone)] pub struct QueryEngine { pub datamodel: String, } unsafe impl Sync for QueryEngine {} impl QueryEngine { pub async fn query(&self) -> String { let data = serde_json::jso...
code_fim
medium
{ "lang": "rust", "repo": "napi-rs/napi-rs", "path": "/bench/src/query.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> Json(json!({ "message": "New nodes have been added", "total_nodes": 3, })) } #[post("/transaction/new", format = "application/json", data = "<transaction>")] fn transactions(transaction: Json<Transaction>) -> Json<Value> { Json(json!({ "message": "new transaction creat...
code_fim
hard
{ "lang": "rust", "repo": "zhongwei/rustnote", "path": "/rocket_note/src/main.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: zhongwei/rustnote path: /rocket_note/src/main.rs #![feature(plugin)] #![plugin(rocket_codegen)] extern crate rocket; extern crate serde; extern crate serde_json; #[macro_use] extern crate serde_derive; #[macro_use] extern crate rocket_contrib; use rocket_contrib::{Json, Value}; <|fim_suffix|...
code_fim
hard
{ "lang": "rust", "repo": "zhongwei/rustnote", "path": "/rocket_note/src/main.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> rocket::ignite() .mount("/", routes![hello, mine, chain, nodes_resolve, nodes_register, transactions, ] ) .launch(); }<|fim_prefix|>// repo: zhongwei/rustnote path: /rock...
code_fim
hard
{ "lang": "rust", "repo": "zhongwei/rustnote", "path": "/rocket_note/src/main.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: prk3/super-average-tetris path: /src/generator.rs use rand::seq::SliceRandom; use crate::block::*; pub struct BlockGenerator { options: [u8; 7], colors: [u8; 6], next_option: u8, next_color: u8, } pub struct BlockGeneratorResult { pub block: Block, pub block_color: u8,...
code_fim
hard
{ "lang": "rust", "repo": "prk3/super-average-tetris", "path": "/src/generator.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> match option { 0 => Block::new(BlockType::I), 1 => Block::new(BlockType::L), 2 => Block::new(BlockType::J), 3 => Block::new(BlockType::S), 4 => Block::new(BlockType::Z), 5 => Block::new(BlockType::T), _ => Block::n...
code_fim
hard
{ "lang": "rust", "repo": "prk3/super-average-tetris", "path": "/src/generator.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: thepowersgang/rust_os path: /Helpers/make_elf_stub/src/main.rs // // // use ::elf_utilities::header; fn main() { use ::elf_utilities::header::{Machine,OSABI}; let args: Vec<_> = ::std::env::args().collect(); let args = { let mut opts = ::getopts::Options::new(); opts.reqopt("o", "output"...
code_fim
hard
{ "lang": "rust", "repo": "thepowersgang/rust_os", "path": "/Helpers/make_elf_stub/src/main.rs", "mode": "psm", "license": "BSD-2-Clause", "source": "the-stack-v2" }
<|fim_suffix|> let mut hdr = Ehdr32::default(); hdr.set_file_version(header::Version::Current); hdr.set_object_version(header::Version::Current); hdr.set_class(header::Class::Bit32); hdr.set_data(header::Data::LSB2); hdr.set_machine(machine); // RISCV hdr.set_elf_type(header::Type::Dyn); hdr.set_...
code_fim
hard
{ "lang": "rust", "repo": "thepowersgang/rust_os", "path": "/Helpers/make_elf_stub/src/main.rs", "mode": "spm", "license": "BSD-2-Clause", "source": "the-stack-v2" }
<|fim_prefix|>// repo: Kerollmops/linen path: /core/src/extensions.rs use std::str::SplitWhitespace; #[derive(Debug, Clone)] pub struct Extensions { <|fim_suffix|>tensions, /// represented by an `str` that doesn't contains space. pub fn iter(&self) -> SplitWhitespace { self.inner.split_whitespace() ...
code_fim
medium
{ "lang": "rust", "repo": "Kerollmops/linen", "path": "/core/src/extensions.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|>tensions, /// represented by an `str` that doesn't contains space. pub fn iter(&self) -> SplitWhitespace { self.inner.split_whitespace() } }<|fim_prefix|>// repo: Kerollmops/linen path: /core/src/extensions.rs use std::str::SplitWhitespace; #[derive(Debug, Clone)] pub struct Extensio...
code_fim
medium
{ "lang": "rust", "repo": "Kerollmops/linen", "path": "/core/src/extensions.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: krhoda/comrade path: /src/work_queue.rs // FOR CUSTOM ERRs // use std::error::Error; // use std::fmt; use std::sync::{Arc, Mutex, RwLock}; #[derive(Debug)] struct WorkQ<T>(Vec<T>, bool); #[derive(Debug)] struct WorkMachine<T> { work_q: Mutex<WorkQ<T>>, sender_q: RwLock<u64>, } impl<T>...
code_fim
hard
{ "lang": "rust", "repo": "krhoda/comrade", "path": "/src/work_queue.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> // TODO: RETURN ERR pub fn steal(&mut self) -> Option<T> { // If the sender_q is contested, PLEASE GIVE UP match self.0.sender_q.try_read() { Ok(num) => { // if the sender_q is greater than 0 PLEASE GIVE UP, // let the sender do it's thin...
code_fim
hard
{ "lang": "rust", "repo": "krhoda/comrade", "path": "/src/work_queue.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let regs = ptrace::getregs(pid).unwrap(); let retval = match regs.rax as i64 { v if v < 0 => v + 1, v => v }; println!(" = {}", retval); } fn main() { let mut child = prepare_traced_child(std::env::args().skip(1)); let child = child.spawn().expect("failure in child pr...
code_fim
hard
{ "lang": "rust", "repo": "vkobel/supertrace", "path": "/src/main.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: vkobel/supertrace path: /src/main.rs use nix::sys::{ptrace, signal, wait}; use nix::sys::wait::WaitStatus; use std::process::Command; use core::ffi::c_void; mod x64_openflags; mod alterable_command; use alterable_command::alterable_command::AlterableCommand; fn prepare_traced_child<I>(mut args...
code_fim
hard
{ "lang": "rust", "repo": "vkobel/supertrace", "path": "/src/main.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let mut ret = vec![]; let mut offset: usize = 0; loop { let mem = ptrace::read(pid, (address + offset as u64) as *mut c_void).unwrap(); ret.write_i64::<LittleEndian>(mem).unwrap(); // break and truncate on string termination (null, 0) if let Some(nul) = ret.it...
code_fim
hard
{ "lang": "rust", "repo": "vkobel/supertrace", "path": "/src/main.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> self.id == m.id && self.url == m.url && self.runtime == m.runtime } } impl PartialEq<TestMovie> for Movie { fn eq(&self, tm: &TestMovie) -> bool { tm == self } } impl PartialEq<Genre> for TestGenre { fn eq(&self, g: &Genre) -> bool { self.id == g.id && self.name =...
code_fim
hard
{ "lang": "rust", "repo": "roignpar/thetvdb", "path": "/tests/data/mod.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_prefix|>// repo: roignpar/thetvdb path: /tests/data/mod.rs use chrono::NaiveDate; use lazy_static::lazy_static; use thetvdb::{language::*, response::*}; #[derive(Debug)] pub struct TestSeries { pub id: SeriesID, pub series_name: String, pub first_aired: NaiveDate, pub network: String, pub s...
code_fim
hard
{ "lang": "rust", "repo": "roignpar/thetvdb", "path": "/tests/data/mod.rs", "mode": "psm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_prefix|>// repo: rust-lang/rust path: /tests/rustdoc-ui/proc_macro_bug.rs // regression test for failing to pass `--crate-type proc-macro` to rustdoc // when documenting a proc macro crate https://github.com/rust-lang/rust/pull/107291 <|fim_suffix|>use proc_macro::TokenStream; #[proc_macro_derive(DeriveA)] //~...
code_fim
easy
{ "lang": "rust", "repo": "rust-lang/rust", "path": "/tests/rustdoc-ui/proc_macro_bug.rs", "mode": "psm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|>#[proc_macro_derive(DeriveA)] //~^ ERROR the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type pub fn a_derive(input: TokenStream) -> TokenStream { input }<|fim_prefix|>// repo: rust-lang/rust path: /tests/rustdoc-ui/proc_macro_bug.rs // regression test for fa...
code_fim
easy
{ "lang": "rust", "repo": "rust-lang/rust", "path": "/tests/rustdoc-ui/proc_macro_bug.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_prefix|>// repo: frigus02/wasmcloud-playground path: /api/src/lib.rs use serde::{Deserialize, Serialize}; use todo_interface as todo; use wapc_guest as guest; use wasmcloud_actor_core as actor; use wasmcloud_actor_http_server as http; use guest::prelude::*; <|fim_suffix|>fn handle_request(req: http::Request) -...
code_fim
hard
{ "lang": "rust", "repo": "frigus02/wasmcloud-playground", "path": "/api/src/lib.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> match (req.method(), req.path_segments().as_slice()) { (http::Method::Get, [""]) => { let todos = todo::host(TODO_ACTOR).list(true)?; Ok(http::Response::json(todos, 200, "OK")) } (http::Method::Post, [""]) => { let new_todo: NewTodoRequest = ...
code_fim
medium
{ "lang": "rust", "repo": "frigus02/wasmcloud-playground", "path": "/api/src/lib.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: Overmuse/datastore path: /server/src/handlers/dividends.rs use crate::db::DbPool; use crate::error::Error; use chrono::NaiveDate; use core::convert::TryInto; use datastore_core::Dividend; use iex::client::Client; use iex::dividends::GetDividends; use iex::Range; use tokio_postgres::types::ToSql;...
code_fim
hard
{ "lang": "rust", "repo": "Overmuse/datastore", "path": "/server/src/handlers/dividends.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>pub async fn backfill_dividends(ticker: String, db: DbPool) -> Result<impl warp::Reply, Rejection> { tokio::spawn(async move { let query = GetDividends { symbol: &ticker, range: Range::FiveYears, }; let client = Client::from_env().unwrap(); let c...
code_fim
hard
{ "lang": "rust", "repo": "Overmuse/datastore", "path": "/server/src/handlers/dividends.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let command: Command = serde_json::from_str(&line)?; match command { Command::Set { key: _, value } => Ok(Some(value)), Command::Remove { key: _ } => Err(Error::from(KeyNotFound)), _ => panic!(), } } fn set(&mut self, key: String, value...
code_fim
hard
{ "lang": "rust", "repo": "lromeo/rust_kvs", "path": "/src/engines/kvs.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> fn remove(&mut self, key: String) -> Result<()> { let c = Command::Remove { key: key.clone() }; self.log(c)?; match self.index.remove(&key) { None => Err(Error::from(KeyNotFound)), Some(_value) => Ok(()), }?; self.compaction() } } ...
code_fim
hard
{ "lang": "rust", "repo": "lromeo/rust_kvs", "path": "/src/engines/kvs.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: lromeo/rust_kvs path: /src/engines/kvs.rs use std::collections::HashMap; use std::fs; use std::fs::{File, OpenOptions}; use std::io::{BufRead, BufReader, Seek, SeekFrom, Write}; use std::path::PathBuf; use failure::Error; use super::KvsEngine; use crate::{Command, KeyNotFound, Result}; pub st...
code_fim
hard
{ "lang": "rust", "repo": "lromeo/rust_kvs", "path": "/src/engines/kvs.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> for row in rows.into_iter() { table.add_row(row); } table.print(writer).context("printing table to writer")?; return Ok(()); } #[cfg(test)] mod test { use super::*; use { fidl_fuchsia_developer_ffx::{ FileSystemRepositorySpec, PmRepositorySpec, Reposi...
code_fim
hard
{ "lang": "rust", "repo": "gnoliyil/fuchsia", "path": "/src/developer/ffx/plugins/repository/list/src/lib.rs", "mode": "spm", "license": "BSD-2-Clause", "source": "the-stack-v2" }
<|fim_prefix|>// repo: gnoliyil/fuchsia path: /src/developer/ffx/plugins/repository/list/src/lib.rs // Copyright 2021 The Fuchsia Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. use { anyhow::{Context as _, Result}, ffx_core...
code_fim
hard
{ "lang": "rust", "repo": "gnoliyil/fuchsia", "path": "/src/developer/ffx/plugins/repository/list/src/lib.rs", "mode": "psm", "license": "BSD-2-Clause", "source": "the-stack-v2" }
<|fim_suffix|>pub fn register(req: HttpRequest) -> &'static str{ println!("welcome to register"); "welcome to register" }<|fim_prefix|>// repo: ksiper/jupite_logic path: /src/account/basic.rs use actix_web::HttpRequest; <|fim_middle|> pub fn index(req: HttpRequest) -> &'static str { println!("REQ: {:?}", ...
code_fim
medium
{ "lang": "rust", "repo": "ksiper/jupite_logic", "path": "/src/account/basic.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: ksiper/jupite_logic path: /src/account/basic.rs use actix_web::HttpRequest; <|fim_suffix|>pub fn register(req: HttpRequest) -> &'static str{ println!("welcome to register"); "welcome to register" }<|fim_middle|> pub fn index(req: HttpRequest) -> &'static str { println!("REQ: {:?}", ...
code_fim
medium
{ "lang": "rust", "repo": "ksiper/jupite_logic", "path": "/src/account/basic.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: RusPiRo/ruspiro-i2c path: /src/interface.rs /*********************************************************************************************************************** * Copyright (c) 2019 by the authors * * Author: André Borrmann * License: Apache License 2.0 *********************************...
code_fim
hard
{ "lang": "rust", "repo": "RusPiRo/ruspiro-i2c", "path": "/src/interface.rs", "mode": "psm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|>define_mmio_register!( // status register I2C_REG_S<ReadWrite<u32>@(I2C_BASE + 0x04)> { CLK_TIMEOUT OFFSET(9) [ SET = 1, CLEAR = 0 ], // 1 Slave has held the SCL signal longer than allowed high ACK_ERROR OFFSET(8) [ SET = 1, ...
code_fim
hard
{ "lang": "rust", "repo": "RusPiRo/ruspiro-i2c", "path": "/src/interface.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_prefix|>// repo: 38/plumber-rs path: /src/rust_servlet.rs // Copyright (C) 2018, Hao Hou // //!The hepler function used by the Rust servlet. //! //!All the function defines in this file should only be used by calling `export_bootstrap` macro. use std::os::raw::{c_char, c_void}; use std::ffi::CStr; use std::ptr...
code_fim
hard
{ "lang": "rust", "repo": "38/plumber-rs", "path": "/src/rust_servlet.rs", "mode": "psm", "license": "BSD-2-Clause", "source": "the-stack-v2" }
<|fim_suffix|>unsafe fn unpack_servlet_object<'a, BT:Bootstrap>(obj_ptr : *mut c_void) -> &'a mut ServletObject<BT> { unpack(obj_ptr) } unsafe fn dispose_servlet_object<BT:Bootstrap>(obj_ptr : *mut c_void) { dispose::<ServletObject<BT>>(obj_ptr); } unsafe fn unpack_async_handle<'a>(handle_ptr : *mut c_void) ...
code_fim
hard
{ "lang": "rust", "repo": "38/plumber-rs", "path": "/src/rust_servlet.rs", "mode": "spm", "license": "BSD-2-Clause", "source": "the-stack-v2" }
<|fim_suffix|> fn add_car(&mut self, car_type: i32) -> bool { if self.spaces[(car_type - 1) as usize] > 0 { self.spaces[(car_type - 1) as usize] -= 1; return true; } return false; } } fn main() { println!("Hello, world!"); }<|fim_prefix|>// repo: abdullahwaqar...
code_fim
medium
{ "lang": "rust", "repo": "abdullahwaqar/leetcode", "path": "/1603.Design_Parking_System/src/main.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: abdullahwaqar/leetcode path: /1603.Design_Parking_System/src/main.rs struct ParkingSystem { spaces: Vec<i32>, } /** * `&self` means the method takes an immutable reference. * If you need a mutable reference, change it to `&mut self` instead. */ impl ParkingSystem { fn new(big: i32, m...
code_fim
medium
{ "lang": "rust", "repo": "abdullahwaqar/leetcode", "path": "/1603.Design_Parking_System/src/main.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> if self.spaces[(car_type - 1) as usize] > 0 { self.spaces[(car_type - 1) as usize] -= 1; return true; } return false; } } fn main() { println!("Hello, world!"); }<|fim_prefix|>// repo: abdullahwaqar/leetcode path: /1603.Design_Parking_System/src/ma...
code_fim
medium
{ "lang": "rust", "repo": "abdullahwaqar/leetcode", "path": "/1603.Design_Parking_System/src/main.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: blubfoo/libra path: /language/compiler/bytecode_source_map/src/mapping.rs // Copyright (c) The Libra Core Contributors // SPDX-License-Identifier: Apache-2.0 use crate::marking::MarkedSourceMapping; use crate::source_map::{ModuleSourceMap, SourceName}; use failure::prelude::*; use libra_types::...
code_fim
hard
{ "lang": "rust", "repo": "blubfoo/libra", "path": "/language/compiler/bytecode_source_map/src/mapping.rs", "mode": "psm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|> let nominal_name = if struct_handle.is_nominal_resource { "resource" } else { "struct" }; let name = self.bytecode.identifier_at(struct_handle.name).to_string(); let ty_params = Self::disassemble_type_formals( &struct_source_map...
code_fim
hard
{ "lang": "rust", "repo": "blubfoo/libra", "path": "/language/compiler/bytecode_source_map/src/mapping.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|> let visibility_modifier = if function_definition.is_native() { "native " } else if function_definition.is_public() { "public " } else { "" }; let ty_params = Self::disassemble_type_formals( &function_source_map.type_p...
code_fim
hard
{ "lang": "rust", "repo": "blubfoo/libra", "path": "/language/compiler/bytecode_source_map/src/mapping.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|>fn main() -> std::io::Result<()> { better_panic::install(); let mut args = std::env::args(); if args.len() != 2 { eprintln!("usage: {} <port>", args.next().unwrap()); std::process::exit(1); } let port = args.skip(1).next().unwrap(); let mut listener = TcpListener::...
code_fim
medium
{ "lang": "rust", "repo": "Dettorer/rust-experiments", "path": "/forking_echo_server/src/main.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: Dettorer/rust-experiments path: /forking_echo_server/src/main.rs use fork::{fork, Fork}; use std::io::prelude::*; use std::net::TcpListener; const READ_SIZE: usize = 512; /// Reads incomming data from a stream writes it back to it. fn echo<T: Read + Write>(mut stream: T) where T: Read + Wr...
code_fim
hard
{ "lang": "rust", "repo": "Dettorer/rust-experiments", "path": "/forking_echo_server/src/main.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: tocklime/aoc-rs path: /aoc/src/solutions/y2021/day09.rs use std::collections::BinaryHeap; use aoc_harness::*; use utils::grid2d::Grid2d; aoc_main!(2021 day 9, generator gen, part1 [p1] => 633, part2 [p2] => 1_050_192, example part1 EG => 15, example part2 EG => 1134); const EG: &str ...
code_fim
medium
{ "lang": "rust", "repo": "tocklime/aoc-rs", "path": "/aoc/src/solutions/y2021/day09.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> Grid2d::from_str(input.trim(), |c| (c as u8) - b'0') } fn p1(grid: &Grid2d<u8>) -> usize { grid.indexed_iter() .filter(|&(p, &here)| grid.neighbours(p).all(|p| grid[p] > here)) .map(|x| *(x.1) as usize + 1) .sum() } fn p2(grid: &Grid2d<u8>) -> usize { let mut done_map =...
code_fim
medium
{ "lang": "rust", "repo": "tocklime/aoc-rs", "path": "/aoc/src/solutions/y2021/day09.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> grid.indexed_iter() .filter(|&(p, &here)| grid.neighbours(p).all(|p| grid[p] > here)) .map(|x| *(x.1) as usize + 1) .sum() } fn p2(grid: &Grid2d<u8>) -> usize { let mut done_map = Grid2d::from_elem(grid.dim(), false); let mut sizes = BinaryHeap::new(); for (p, v) in...
code_fim
medium
{ "lang": "rust", "repo": "tocklime/aoc-rs", "path": "/aoc/src/solutions/y2021/day09.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: ymgyt/kvsd path: /src/core/table/table.rs use std::path::Path; use tokio::fs; use tokio::io::{AsyncRead, AsyncSeek, AsyncSeekExt, AsyncWrite, SeekFrom}; use tokio::sync::mpsc::Receiver; use tokio::sync::oneshot; use crate::common::{debug, error, info, trace, ErrorKind, Result}; use crate::core...
code_fim
hard
{ "lang": "rust", "repo": "ymgyt/kvsd", "path": "/src/core/table/table.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> fn send_value( &self, sender: Option<oneshot::Sender<Result<Option<Value>>>>, value: Result<Option<Value>>, ) -> Result<()> { sender .expect("response already sent") .send(value) .map_err(|_| ErrorKind::Internal("send to resp chan...
code_fim
hard
{ "lang": "rust", "repo": "ymgyt/kvsd", "path": "/src/core/table/table.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> /// Convert a value expressed in ticks back to an unticked value. /// /// # Errors /// Return `Err` if the number of ticks per unit does not divide some power of 10. /// /// # Panics /// Panic in case of overflow. pub fn unticked(self, ticked: TickUnit) -> Result<String, C...
code_fim
hard
{ "lang": "rust", "repo": "cambricorp/trade-rs", "path": "/src/tick/mod.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: cambricorp/trade-rs path: /src/tick/mod.rs //! A module defining types to work with discrete prices and quantities. //! //! On electronic exchanges, prices and sizes do not take continuous real values, //! but rather take their values on a discrete grid whose step is known as a *tick*. //! In ot...
code_fim
hard
{ "lang": "rust", "repo": "cambricorp/trade-rs", "path": "/src/tick/mod.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> num /= 10; used += 1; if num == 0 { break; } } used }; let mut out = [b'0'; 21]; let _ = write(fract, &mut out[..], 0); out[pad] = b'.'; let used = ...
code_fim
hard
{ "lang": "rust", "repo": "cambricorp/trade-rs", "path": "/src/tick/mod.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: blchelle/board-games path: /client/src/components/stats.rs /* Stats component for client */ use serde::{Deserialize, Serialize}; use yew::services::fetch::{FetchService, FetchTask, Request, Response}; use yew::{ format::{Json, Nothing}, prelude::*, }; // Stats page struct pub struct Stats {...
code_fim
hard
{ "lang": "rust", "repo": "blchelle/board-games", "path": "/client/src/components/stats.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> let ls = web_sys::window().unwrap().local_storage().unwrap().unwrap(); let username = match ls.get_item("user_logged_in") { Ok(a) => match a { Some(b) => b, None => "".to_string(), }, Err(_) => "".to_string(), }; Self { link: link, username: us...
code_fim
hard
{ "lang": "rust", "repo": "blchelle/board-games", "path": "/client/src/components/stats.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> fn update(&mut self, msg: Self::Message) -> ShouldRender { if self.init { let user = self.username.to_string(); self.get_stats(user); self.init = false; } match msg { Msg::ReceiveResponse(response) => { // Parse response match response { Ok(r...
code_fim
hard
{ "lang": "rust", "repo": "blchelle/board-games", "path": "/client/src/components/stats.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|>#[rocket::get("/")] pub fn graphiql() -> content::Html<String> { juniper_rocket::playground_source("/") }<|fim_prefix|>// repo: BlinfoldKing/talos path: /src/handler/graphql.rs use rocket::{response::content, State}; use crate::database::DbConn; use crate::domain::user::User; use crate::graphql::{GQ...
code_fim
hard
{ "lang": "rust", "repo": "BlinfoldKing/talos", "path": "/src/handler/graphql.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: BlinfoldKing/talos path: /src/handler/graphql.rs use rocket::{response::content, State}; use crate::database::DbConn; use crate::domain::user::User; use crate::graphql::{GQLContext, Schema}; <|fim_suffix|>#[rocket::get("/")] pub fn graphiql() -> content::Html<String> { juniper_rocket::play...
code_fim
hard
{ "lang": "rust", "repo": "BlinfoldKing/talos", "path": "/src/handler/graphql.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> pub fn elapsed(&self) -> Duration { self.start.elapsed() } pub fn is_done(&self) -> bool { self.start.elapsed() > self.duration } }<|fim_prefix|>// repo: zacharied/qs-learn-box path: /src/util.rs use std::time::{Duration, Instant}; use super::consts::system::*; pub stru...
code_fim
hard
{ "lang": "rust", "repo": "zacharied/qs-learn-box", "path": "/src/util.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: zacharied/qs-learn-box path: /src/util.rs use std::time::{Duration, Instant}; use super::consts::system::*; pub struct FpsGraph { history: [f64; FPS_GRAPH_SAMPLE_COUNT], i: usize, } impl FpsGraph { pub fn new() -> Self { FpsGraph { history: [0.; FPS_GRAPH_SAMPL...
code_fim
medium
{ "lang": "rust", "repo": "zacharied/qs-learn-box", "path": "/src/util.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|>impl Countdown { pub fn new(duration: Duration) -> Self { Self { start: Instant::now(), duration } } pub fn elapsed(&self) -> Duration { self.start.elapsed() } pub fn is_done(&self) -> bool { self.start.elapsed() > self.duration...
code_fim
hard
{ "lang": "rust", "repo": "zacharied/qs-learn-box", "path": "/src/util.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> self.advance_byte(); let high = self.position; let symbol = Symbol::intern(&source[..high - low]); Token::String(symbol) } fn scan_operator(&mut self) -> Token { match self.advance_byte() { Some(b'(') => Token::OpenDelim(Delim::Paren), ...
code_fim
hard
{ "lang": "rust", "repo": "rpjohnst/dejavu", "path": "/gml/src/front/lexer.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: rpjohnst/dejavu path: /gml/src/front/lexer.rs use crate::symbol::Symbol; use crate::front::Span; use crate::front::token::{Token, BinOp, Delim}; pub struct Lexer<'s> { source: &'s [u8], position: usize, } impl<'s> Lexer<'s> { pub fn new(source: &'s [u8], position: usize) -> Lexer<'...
code_fim
hard
{ "lang": "rust", "repo": "rpjohnst/dejavu", "path": "/gml/src/front/lexer.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: jf-marino/cinder path: /src/ledger/transaction.rs use std::sync::Arc; use super::AVL; #[derive(Debug)] pub struct LedgerTransaction<V> { root: Option<Arc<AVL<String, V>>> } impl<V> LedgerTransaction<V> { pub fn new(tree: Option<Arc<AVL<String, V>>>) -> LedgerTransaction<V> { L...
code_fim
hard
{ "lang": "rust", "repo": "jf-marino/cinder", "path": "/src/ledger/transaction.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> pub fn get(&self, key: &str) -> Option<Arc<V>> { if let Some(ref tree) = self.root { return tree.get(&String::from(key)); } None } pub fn delete(&mut self, key: &str) { self.root = match self.root { Some(ref tree) => Some(Arc::new(tree.d...
code_fim
hard
{ "lang": "rust", "repo": "jf-marino/cinder", "path": "/src/ledger/transaction.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: erictapen/nettle-rs path: /src/hash/sha3_384.rs \xe4\xc8\x65\x18\xab\x0a\x06\x26\x73\x20\xee\x9e\xc9\x5e\x50\x38\x5b\x7a\x25\x27\xdd\xaa\x1b\xd0\xea\xd2\x62\xc5\x61\x22\xd4\xf4\xeb\x08\xb0\xae\x22\xb3\xee\x7e\x6f\x44\xdd\x18"[..]); ctx.update(b"\x6f\xd7\x28\x88\xa0\x21\xf3\x6e\x55\x09\x...
code_fim
hard
{ "lang": "rust", "repo": "erictapen/nettle-rs", "path": "/src/hash/sha3_384.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> ctx.update(b"\x94\x98\x74\x98\xb1\xca\x87\xa6\xf3\xfa\x4b\x99\x9d\xb7\x26\x11\x5c\x45\x5d\x0e\xc2\x40\x29\xb2\xf5\x81\x0e\x49\xa9\x46\x68\x86\x4b\x8c\x47\x0f\x7f\xc0\x7c\x3d\xcd\x97\xf4\x1c\x97\x3b\x45\xba\x4f\xa7\x87\x9e\xe7\x54\x65\x96\x88\x15\x73\xb6\x86\x3f\xc3\x9d\x94\x0e\xb3\xfa\x34\x44\x08\...
code_fim
hard
{ "lang": "rust", "repo": "erictapen/nettle-rs", "path": "/src/hash/sha3_384.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: erictapen/nettle-rs path: /src/hash/sha3_384.rs ctx.update(b"\xa8\xcb\x78\xe1\x48\x5c\xbb\x7a\x94\x74\xc1\xc1\xf8\xe0\xf3\x07\xcd\xa5\x13\x9a\x7e\x94\x7d\xf5\xea\x20\xac\x33\x0a\x6d\xff\xca\xd4\xa9\xbd\x75\x5f\x9f\x58\x72\x47\x89\xee\xee\x53\x26\x15\xbe\x55\x0d\xd8\x4f\x52\x41\xfd\xe0\xe3\...
code_fim
hard
{ "lang": "rust", "repo": "erictapen/nettle-rs", "path": "/src/hash/sha3_384.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let mut valid: i64 = 0; for record in input_raw.split("\n\n") { let mut parsed = parse(record); parsed.sort(); if let Some(idx) = parsed.iter().position(|x| *x == "cid") { parsed.remove(idx); } if parsed == required { valid += 1; ...
code_fim
medium
{ "lang": "rust", "repo": "joshkunz/advent-of-code", "path": "/2020/04/src/bin/p1.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: joshkunz/advent-of-code path: /2020/04/src/bin/p1.rs use std::{env, fs}; fn parse(s: &str) -> Vec<&str> { let mut result: Vec<&str> = Vec::new(); for item in s.split_whitespace() { let parts: Vec<&str> = item.split(":").collect(); assert!(parts.len() == 2); resul...
code_fim
medium
{ "lang": "rust", "repo": "joshkunz/advent-of-code", "path": "/2020/04/src/bin/p1.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: Shirataki2/competitive_submissions path: /abc163/src/bin/b.rs #![allow(unused_imports)] use proconio::{input, fastout}; use std::cmp::*; <|fim_suffix|> input!(n: i64, m: usize, a: [i64; m]); let ans = n - a.iter().sum::<i64>(); println!("{}", if ans < 0 { -1 } else { ans }); }<|fim_m...
code_fim
easy
{ "lang": "rust", "repo": "Shirataki2/competitive_submissions", "path": "/abc163/src/bin/b.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> input!(n: i64, m: usize, a: [i64; m]); let ans = n - a.iter().sum::<i64>(); println!("{}", if ans < 0 { -1 } else { ans }); }<|fim_prefix|>// repo: Shirataki2/competitive_submissions path: /abc163/src/bin/b.rs #![allow(unused_imports)] use proconio::{input, fastout}; use std::cmp::*; <|fim_m...
code_fim
easy
{ "lang": "rust", "repo": "Shirataki2/competitive_submissions", "path": "/abc163/src/bin/b.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> if let Some(x) = read_line() { let vv: Vec<&str> = x.split(' ').collect::<Vec<&str>>(); let v = vv.iter().map(|x| x.trim().parse::<u32>().unwrap()).collect::<Vec<u32>>(); println!("{}", read_tree(&v.as_slice()).1); } }<|fim_prefix|>// repo: nikofil/advent-rust path: /src/b...
code_fim
hard
{ "lang": "rust", "repo": "nikofil/advent-rust", "path": "/src/bin/day8_2.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: nikofil/advent-rust path: /src/bin/day8_2.rs extern crate advent_lib; use advent_lib::read_line; fn read_tree(v: &[u32]) -> (&[u32], u32) { <|fim_suffix|>fn main() { if let Some(x) = read_line() { let vv: Vec<&str> = x.split(' ').collect::<Vec<&str>>(); let v = vv.iter().map...
code_fim
hard
{ "lang": "rust", "repo": "nikofil/advent-rust", "path": "/src/bin/day8_2.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: str4d/rage path: /age/benches/parser.rs use age::{x25519, Decryptor, Encryptor, Recipient}; use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; #[cfg(unix)] use pprof::criterion::{Output, PProfProfiler}; <|fim_suffix|> group.finish(); } #[cfg(unix)] criter...
code_fim
hard
{ "lang": "rust", "repo": "str4d/rage", "path": "/age/benches/parser.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|>#[cfg(unix)] criterion_group!( name = benches; config = Criterion::default() .with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))); targets = bench ); #[cfg(not(unix))] criterion_group!(benches, bench); criterion_main!(benches);<|fim_prefix|>// repo: str4d/rage path: /age/...
code_fim
medium
{ "lang": "rust", "repo": "str4d/rage", "path": "/age/benches/parser.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: weirane/aoc-2020 path: /src/bin/12.rs #[derive(Debug, Clone, PartialEq)] struct State { x: f64, y: f64, alpha: f64, } impl State { fn new(x: f64, y: f64, alpha: f64) -> Self { Self { x, y, alpha } } fn manhattan(&self) -> f64 { <|fim_suffix|>fn part1(insts: &[(c...
code_fim
hard
{ "lang": "rust", "repo": "weirane/aoc-2020", "path": "/src/bin/12.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>fn main() { let insts: Vec<_> = aoc_2020::stdin_lines() .filter_map(|s| { s.ok().and_then(|s| { let dir = s.chars().next()?; let amount: u32 = (&s[1..]).parse().ok()?; Some((dir, amount as f64)) }) }) .coll...
code_fim
hard
{ "lang": "rust", "repo": "weirane/aoc-2020", "path": "/src/bin/12.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> /// vote encryption key is invalid /// either because is not valid bech32, or because of the underlying bytes InvalidVoteEncryptionKey, /// wallet out of funds NotEnoughFunds, /// invalid fragment InvalidFragment, /// invalid transaction validity date InvalidTransact...
code_fim
hard
{ "lang": "rust", "repo": "input-output-hk/chain-wallet-libs", "path": "/bindings/wallet-core/src/error.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> /// set some details to the `Result` object if the `Result` is of /// error kind /// /// If the `Result` means success, then nothing is returned. /// /// # Example /// /// ``` /// # use wallet_core::{Result, Error}; /// # use thiserror::Error; /// # #[derive(Err...
code_fim
hard
{ "lang": "rust", "repo": "input-output-hk/chain-wallet-libs", "path": "/bindings/wallet-core/src/error.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: input-output-hk/chain-wallet-libs path: /bindings/wallet-core/src/error.rs use std::{ error, fmt::{self, Display}, result, }; /// result returned by a call, this allows to check if an error /// occurred while executing the function. /// /// if an error occurred it is then possible t...
code_fim
hard
{ "lang": "rust", "repo": "input-output-hk/chain-wallet-libs", "path": "/bindings/wallet-core/src/error.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: chuck-flowers/semverify path: /src/lib.rs #![warn(clippy::all)] #![warn(clippy::pedantic)] <|fim_suffix|>pub use self::consts::*; pub use self::enums::*; pub use self::functions::*; pub use self::macros::*; pub use self::modules::*; pub use self::structs::*; pub use self::traits::*;<|fim_middle...
code_fim
medium
{ "lang": "rust", "repo": "chuck-flowers/semverify", "path": "/src/lib.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|>pub use self::consts::*; pub use self::enums::*; pub use self::functions::*; pub use self::macros::*; pub use self::modules::*; pub use self::structs::*; pub use self::traits::*;<|fim_prefix|>// repo: chuck-flowers/semverify path: /src/lib.rs #![warn(clippy::all)] #![warn(clippy::pedantic)] <|fim_middle...
code_fim
medium
{ "lang": "rust", "repo": "chuck-flowers/semverify", "path": "/src/lib.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> verify!(self, root.access("not_existing") => "(Err(MissingStartComponent), Assist { valid: 0, pending: 0, pending_special: 0, next_options: Avail(0, []) })"); // Check for a basic read query verify!(self, root.access("basic.u_16") => "(Ok(NodeTree { info: Leaf(\"50158\"), meta: S...
code_fim
hard
{ "lang": "rust", "repo": "imp/interact", "path": "/interact/tests/integ.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|>#[test] fn main() { let mut context = Context { count: 0, check: true, }; context.main(); if context.count > 0 { { println!(); println!("Expected test manifest:"); println!(); let mut context = Context { ...
code_fim
hard
{ "lang": "rust", "repo": "imp/interact", "path": "/interact/tests/integ.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_prefix|>// repo: imp/interact path: /interact/tests/integ.rs extern crate interact; use pretty_assertions::assert_eq; mod common; use common::{Basic, Complex, LocalRcLoop, Rand}; struct Context { count: usize, check: bool, } macro_rules! verify { ($self:expr, $e:expr => $result:tt) => { le...
code_fim
hard
{ "lang": "rust", "repo": "imp/interact", "path": "/interact/tests/integ.rs", "mode": "psm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|> //------------ SMTP Server -------------------------------------------------- fn add_smtp_server(l: &mut Loop) { let config = smtp::server::Config::new(create_ssl_context(), Vec::from(&b"localhost.local"[..]), Vec:...
code_fim
hard
{ "lang": "rust", "repo": "partim/cloudship", "path": "/src/main.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: partim/cloudship path: /src/main.rs extern crate cloudship; extern crate env_logger; extern crate netmachines; extern crate openssl; extern crate rotor; use openssl::{ssl, x509}; use netmachines::sockets::openssl::StartTlsListener; use cloudship::smtp; //------------ main ---------------------...
code_fim
hard
{ "lang": "rust", "repo": "partim/cloudship", "path": "/src/main.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>on<String>, #[serde(rename = "taskId", skip_serializing_if = "Option::is_none")] pub task_id: Option<i32>, #[serde(rename = "user", skip_serializing_if = "Option::is_none")] pub user: Option<String>, } impl BuildLocator { pub fn new() -> BuildLocator { BuildLocator { ...
code_fim
hard
{ "lang": "rust", "repo": "ExternalReality/cider-rust", "path": "/teamcity_apis/src/models/build_locator.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: ExternalReality/cider-rust path: /teamcity_apis/src/models/build_locator.rs /* * TeamCity REST API * * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) * * The version of the OpenAPI document: 2018.1 * * Generated by: https://open...
code_fim
hard
{ "lang": "rust", "repo": "ExternalReality/cider-rust", "path": "/teamcity_apis/src/models/build_locator.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: ChristianGracia/rust path: /syntax/options/src/main.rs fn main() { use std::collections::HashMap; let mut random_var = HashMap::new(); random_var.insert(3, "cat"); random_var.insert(5, "dog"); // r is an option - either there is something or there is not let r = rand...
code_fim
medium
{ "lang": "rust", "repo": "ChristianGracia/rust", "path": "/syntax/options/src/main.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> match c { Some(n) => println!("Valid Result: {}", n), None => println!("invalid"), } } //from https://doc.rust-lang.org/std/option/ // Type Option represents an optional value: every Option is either Some and contains a value, or None, and does not. Option types are very common ...
code_fim
hard
{ "lang": "rust", "repo": "ChristianGracia/rust", "path": "/syntax/options/src/main.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>//from https://doc.rust-lang.org/std/option/ // Type Option represents an optional value: every Option is either Some and contains a value, or None, and does not. Option types are very common in Rust code, as they have a number of uses: // Initial values // Return values for functions that are not defin...
code_fim
medium
{ "lang": "rust", "repo": "ChristianGracia/rust", "path": "/syntax/options/src/main.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> for &(bytes, hex) in cases.iter() { let seed = RngSeed(bytes); let serialized = serde_json::to_value(&seed).unwrap(); assert_eq!(serialized, json!(hex)); let deserialized: RngSeed = serde_json::from_value(serialized).unwrap(); assert_eq!(...
code_fim
hard
{ "lang": "rust", "repo": "FlyingDutchmanGames/lib_table_top", "path": "/src/common/rand.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: FlyingDutchmanGames/lib_table_top path: /src/common/rand.rs use rand::prelude::*; use rand_chacha::ChaCha20Rng; use serde::{Deserialize, Serialize}; #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)] pub struct RngSeed(#[serde(with = "hex")] pub [u8; 32]...
code_fim
hard
{ "lang": "rust", "repo": "FlyingDutchmanGames/lib_table_top", "path": "/src/common/rand.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: tailhook/stator path: /src/inner/start.rs use std::thread; use std::env; use std::sync::{Arc, Mutex,}; use std::sync::mpsc::sync_channel; use std::sync::atomic::AtomicUsize; use std::collections::{HashMap, VecDeque}; <|fim_suffix|>impl Manager { pub fn start() -> Manager { if env::v...
code_fim
medium
{ "lang": "rust", "repo": "tailhook/stator", "path": "/src/inner/start.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|>impl Manager { pub fn start() -> Manager { if env::var("RUST_LOG").is_err() { env::set_var("RUST_LOG", "warn"); } env_logger::init().expect("init rust logging"); let (tx, rx) = sync_channel(1); let thread = thread::spawn(|| { let creator ...
code_fim
medium
{ "lang": "rust", "repo": "tailhook/stator", "path": "/src/inner/start.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: alexander-akhmetov/mos path: /src/memory/simple_frame_allocator.rs use crate::memory::{Frame, FrameAllocator}; use multiboot2::{MemoryArea, MemoryAreaIter}; pub struct SimpleFrameAllocator { next_free_frame: Frame, current_area: Option<&'static MemoryArea>, areas: MemoryAreaIter, ...
code_fim
hard
{ "lang": "rust", "repo": "alexander-akhmetov/mos", "path": "/src/memory/simple_frame_allocator.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> fn switch_to_next_memory_area(&mut self) { system_log_debug!("[FrameAllocator] switching to the next area..."); self.current_area = self .areas .clone() .filter(|area| { let address = area.base_addr + area.length - 1; ...
code_fim
hard
{ "lang": "rust", "repo": "alexander-akhmetov/mos", "path": "/src/memory/simple_frame_allocator.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>#[test] fn part2() { let ans = (402328..=864247).filter(|&n| is_valid_2(n)).count(); assert_eq!(ans, 288); } fn is_valid(n: u32) -> bool { let mut ds = math::digits(n); let mut prev = match ds.next() { Some(d) => d, None => return false, }; let mut has_duplicate = ...
code_fim
medium
{ "lang": "rust", "repo": "ryanpbrewster/advent-of-code-2019", "path": "/days/day04/day04.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: ryanpbrewster/advent-of-code-2019 path: /days/day04/day04.rs extern crate math; #[test] fn part1_smoke() { assert!(is_valid(111111)); assert!(!is_valid(223450)); assert!(!is_valid(123789)); assert!(!is_valid(555550)); assert!(is_valid(555559)); assert!(!is_valid(0)); } ...
code_fim
medium
{ "lang": "rust", "repo": "ryanpbrewster/advent-of-code-2019", "path": "/days/day04/day04.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }