text
stringlengths
232
16.3k
domain
stringclasses
1 value
difficulty
stringclasses
3 values
meta
dict
<|fim_prefix|>// repo: kanru/memoir path: /src/main.rs extern crate docopt; extern crate rustc_serialize; pub mod config; use docopt::Docopt; <|fim_suffix|> let args: Args = Docopt::new(USAGE) .and_then(|dopt| dopt.decode()) .unwrap_or_else(|e| e.exit()); if...
code_fim
hard
{ "lang": "rust", "repo": "kanru/memoir", "path": "/src/main.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|>#[cfg_attr(rustfmt,rustfmt_skip)] const USAGE: &'static str = " Usage: memoir build memoir -h Options: -h, --help Print this help message. "; #[derive(RustcDecodable)] struct Args { cmd_build: bool, } fn main() { let args: Args = Docopt::new(USAGE) .and_th...
code_fim
medium
{ "lang": "rust", "repo": "kanru/memoir", "path": "/src/main.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> fn into_inner(mut self) -> Result<Self::V, Self> where Self::V: Sized { match Rc::try_unwrap(self.inner) { Err(rc) => { self.inner = rc; Err(self) } Ok(cell) => Ok(cell.into_inner()), } } } // `TextView` doesn't take focus, while `FocusableTextView` does pub ...
code_fim
hard
{ "lang": "rust", "repo": "MashPlant/cursive-path-selector", "path": "/src/util.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: MashPlant/cursive-path-selector path: /src/util.rs use std::{cell::*, rc::*}; use cursive::{view::*, views::*, direction::Direction}; // a wrapper of view V // it allows you to hold an mutable reference to a view after adding it to another view pub struct RcView<V> { inner: Rc<RefCell<V>> } im...
code_fim
hard
{ "lang": "rust", "repo": "MashPlant/cursive-path-selector", "path": "/src/util.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>impl<V: View> NonAutoScrollView<V> { pub fn new(v: V) -> Self { Self { inner: ScrollView::new(v) } } pub fn inner(&mut self) -> &mut V { self.inner.get_inner_mut() } } impl<V: View> ViewWrapper for NonAutoScrollView<V> { cursive::wrap_impl!(self.inner: ScrollView<V>); fn wrap_take_focus(&mut se...
code_fim
hard
{ "lang": "rust", "repo": "MashPlant/cursive-path-selector", "path": "/src/util.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let mut data = Vec::with_capacity(nx * ny * 3); for (_, _, pixel) in img.pixels() { data.push(pixel[0]); data.push(pixel[1]); data.push(pixel[2]); } data } impl Texture for ImageTexture { #[allow(unused_variables)] fn value(&self, u: f32, v: f32, p: Vec3) -...
code_fim
hard
{ "lang": "rust", "repo": "Ninjani/ray-tracing-the-next-week", "path": "/src/textures.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>impl NoiseTexture { pub fn new<R: Rng>(rng: &mut R, scale: f32) -> NoiseTexture { NoiseTexture { noise: Box::new(Perlin::new(rng)), scale, } } } impl Texture for NoiseTexture { #[allow(unused_variables)] fn value(&self, u: f32, v: f32, p: Vec3) -> V...
code_fim
hard
{ "lang": "rust", "repo": "Ninjani/ray-tracing-the-next-week", "path": "/src/textures.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: Ninjani/ray-tracing-the-next-week path: /src/textures.rs use image::{DynamicImage, GenericImage}; use crate::perlin::Perlin; use rand::Rng; use crate::vectors::Vec3; use std::rc::Rc; use std::fmt::Debug; pub trait Texture: Debug { fn value(&self, u: f32, v: f32, p: Vec3) -> Vec3; } #[deri...
code_fim
hard
{ "lang": "rust", "repo": "Ninjani/ray-tracing-the-next-week", "path": "/src/textures.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: awidegreen/vmail-rs path: /src/cmd/alias.rs use crate::db::account::Account; use crate::db::alias::Alias; use crate::db::result::Result; use crate::db::{establish_connection, DatabaseConnection}; use clap::{App, AppSettings, Arg, ArgMatches, SubCommand}; use failure::format_err; use crate::util...
code_fim
hard
{ "lang": "rust", "repo": "awidegreen/vmail-rs", "path": "/src/cmd/alias.rs", "mode": "psm", "license": "BSD-3-Clause", "source": "the-stack-v2" }
<|fim_suffix|>pub fn get_subcommand() -> App<'static, 'static> { SubCommand::with_name("alias") .about("Manage aliases for the vmail database") .setting(AppSettings::SubcommandRequiredElseHelp) .subcommand( SubCommand::with_name("show") .about("Show aliases for us...
code_fim
hard
{ "lang": "rust", "repo": "awidegreen/vmail-rs", "path": "/src/cmd/alias.rs", "mode": "spm", "license": "BSD-3-Clause", "source": "the-stack-v2" }
<|fim_prefix|>// repo: 3Hren/sonmhub path: /src/main.rs #[macro_use] extern crate clap; extern crate sonmhub; use std::error::Error; use clap::{App, Arg}; use sonmhub::{bot, config::Config, logging}; fn main() -> Result<(), Box<Error>> { <|fim_suffix|> logging::init()?; match bot::run(cfg) { 0 => Ok...
code_fim
hard
{ "lang": "rust", "repo": "3Hren/sonmhub", "path": "/src/main.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> match bot::run(cfg) { 0 => Ok(()), v => Err(format!("application exited with {} code", v).into()), } }<|fim_prefix|>// repo: 3Hren/sonmhub path: /src/main.rs #[macro_use] extern crate clap; extern crate sonmhub; use std::error::Error; use clap::{App, Arg}; use sonmhub::{bot, con...
code_fim
hard
{ "lang": "rust", "repo": "3Hren/sonmhub", "path": "/src/main.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let cfg = Config::load(path)?; logging::init()?; match bot::run(cfg) { 0 => Ok(()), v => Err(format!("application exited with {} code", v).into()), } }<|fim_prefix|>// repo: 3Hren/sonmhub path: /src/main.rs #[macro_use] extern crate clap; extern crate sonmhub; use std::...
code_fim
hard
{ "lang": "rust", "repo": "3Hren/sonmhub", "path": "/src/main.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: Demindiro/godot_rapier3d path: /rapier3d/src/indices.rs //! Based on https://github.com/fitzgen/generational-arena/blob/master/src/lib.rs but optimized for //! smaller indices (u32 for index, u16 for generation) so that it's suitable for FFI. use core::mem; pub struct Indices<T> { elements: V...
code_fim
hard
{ "lang": "rust", "repo": "Demindiro/godot_rapier3d", "path": "/rapier3d/src/indices.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> pub fn generation(&self) -> u16 { self.generation } fn split(self) -> (u32, u16) { (self.index, self.generation) } } #[cfg(test)] mod test { use super::*; #[test] fn get2_mut() { let mut inds = Indices::new(); let a = inds.add("foo"); let b = inds.add("bar"); let (a, b) = inds.get2_m...
code_fim
hard
{ "lang": "rust", "repo": "Demindiro/godot_rapier3d", "path": "/rapier3d/src/indices.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|>r) -> Error { Error { error: error.to_string() } } }<|fim_prefix|>// repo: D3fus/jellydesktop path: /src/app/error.rs pub struct Error { pub error: String }<|fim_middle|> impl Error { pub fn error(error: &st
code_fim
easy
{ "lang": "rust", "repo": "D3fus/jellydesktop", "path": "/src/app/error.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: D3fus/jellydesktop path: /src/app/error.rs pub struct Error { pub error: String } impl Error { pub fn error(error: &st<|fim_suffix|>error: error.to_string() } } }<|fim_middle|>r) -> Error { Error {
code_fim
easy
{ "lang": "rust", "repo": "D3fus/jellydesktop", "path": "/src/app/error.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>error: error.to_string() } } }<|fim_prefix|>// repo: D3fus/jellydesktop path: /src/app/error.rs pub struct Error { pub error: String } impl Error { pub fn error(error: &st<|fim_middle|>r) -> Error { Error {
code_fim
easy
{ "lang": "rust", "repo": "D3fus/jellydesktop", "path": "/src/app/error.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: matthannah/rust path: /rust-by-example/03 - Custom Types/constants.rs // Rust has two different types of constants which can be declared in any scope // including global. Both require explicit type annotation: <|fim_suffix|>fn main() { let n = 16; // Access constant in the main thread ...
code_fim
hard
{ "lang": "rust", "repo": "matthannah/rust", "path": "/rust-by-example/03 - Custom Types/constants.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> // Access constant in the main thread println!("This is {}", LANGUAGE); println!("The threshold is {}", THRESHOLD); println!("{} is {}", n, if is_big(n) { "big" } else { "small" }); // Error! Cannot modify a `const`. // THRESHOLD = 5; // FIXME ^ Comment out this line }<|fim_pr...
code_fim
medium
{ "lang": "rust", "repo": "matthannah/rust", "path": "/rust-by-example/03 - Custom Types/constants.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: longfangsong/edvertize path: /src/memory.rs use alloc_cortex_m::CortexMHeap; use cortex_m_rt::heap_start; #[global_allocator] static ALLOCATOR: CortexMHeap = CortexMHeap::empty(); <|fim_suffix|>#[alloc_error_handler] fn alloc_error(layout: core::alloc::Layout) -> ! { panic!("Alloc failed! ...
code_fim
medium
{ "lang": "rust", "repo": "longfangsong/edvertize", "path": "/src/memory.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|>#[alloc_error_handler] fn alloc_error(layout: core::alloc::Layout) -> ! { panic!("Alloc failed! layout: {:?}", layout) }<|fim_prefix|>// repo: longfangsong/edvertize path: /src/memory.rs use alloc_cortex_m::CortexMHeap; use cortex_m_rt::heap_start; #[global_allocator] static ALLOCATOR: CortexMHeap =...
code_fim
medium
{ "lang": "rust", "repo": "longfangsong/edvertize", "path": "/src/memory.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: lzskyline/DPDK_SURICATA-4_1_1 path: /suricata-4.1.4/rust/vendor/der-parser/src/macros.rs tent::Set(vec![ /// DerObject::from_int_slice(b"\x01\x00\x01"), /// DerObject::from_int_slice(b"\x01\x00\x00"), /// ])); /// assert_eq!(localparse_set(&bytes), IResult::Done(empty, expected)); /// # ...
code_fim
hard
{ "lang": "rust", "repo": "lzskyline/DPDK_SURICATA-4_1_1", "path": "/suricata-4.1.4/rust/vendor/der-parser/src/macros.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: lzskyline/DPDK_SURICATA-4_1_1 path: /suricata-4.1.4/rust/vendor/der-parser/src/macros.rs // assert_eq!(localparse_seq(&bytes), IResult::Done(empty, expected)); /// # } /// ``` #[macro_export] macro_rules! parse_der_sequence_defined( ($i:expr, $($args:tt)*) => ( map!( $i, ...
code_fim
hard
{ "lang": "rust", "repo": "lzskyline/DPDK_SURICATA-4_1_1", "path": "/suricata-4.1.4/rust/vendor/der-parser/src/macros.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|>/// Parse a set of DER elements (folding version) /// /// Unlike [`parse_der_set`](fn.parse_der_set.html), this function allows to specify the /// list of expected types in the DER sequence. /// /// Similar to [`parse_der_set_defined_m`](macro.parse_der_set_defined_m.html), but uses /// `fold` internally....
code_fim
hard
{ "lang": "rust", "repo": "lzskyline/DPDK_SURICATA-4_1_1", "path": "/suricata-4.1.4/rust/vendor/der-parser/src/macros.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> fn view(&self) -> Html { html! { <> <div class="flex-fill fs-3 fw-bold mt-3"> {"Activity"}</div> <div class="card mt-3 me-2"> <div class="card-body"> <div class="container"> ...
code_fim
hard
{ "lang": "rust", "repo": "brotheryeska/domain_try", "path": "/src/pages/activity.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: brotheryeska/domain_try path: /src/pages/activity.rs use yew::prelude::*; pub struct Activity {} pub enum Msg {} impl Component for Activity { type Message = Msg; type Properties = (); fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self { Activity {} } ...
code_fim
hard
{ "lang": "rust", "repo": "brotheryeska/domain_try", "path": "/src/pages/activity.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: nrf-rs/nrf52832-pac path: /src/uart0/pselrts.rs #[doc = "Reader of register PSELRTS"] pub type R = crate::R<u32, super::PSELRTS>; #[doc = "Writer for register PSELRTS"] pub type W = crate::W<u32, super::PSELRTS>; #[doc = "Register PSELRTS `reset()`'s with value 0xffff_ffff"] impl crate::ResetVal...
code_fim
hard
{ "lang": "rust", "repo": "nrf-rs/nrf52832-pac", "path": "/src/uart0/pselrts.rs", "mode": "psm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|> variant as _ } } #[doc = "Reader of field `PSELRTS`"] pub type PSELRTS_R = crate::R<u32, PSELRTS_A>; impl PSELRTS_R { #[doc = r"Get enumerated values variant"] #[inline(always)] pub fn variant(&self) -> crate::Variant<u32, PSELRTS_A> { use crate::Variant::*; match s...
code_fim
hard
{ "lang": "rust", "repo": "nrf-rs/nrf52832-pac", "path": "/src/uart0/pselrts.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_prefix|>// repo: toulouse-blockchains/jormungandr path: /jcli/src/jcli_app/utils/debug_flag.rs use structopt::StructOpt; #[derive(StructOpt)] pub struct DebugFlag { /// print additional debug inform<|fim_suffix|> match self.debug { true => Some(std::io::stderr()), false => None, ...
code_fim
hard
{ "lang": "rust", "repo": "toulouse-blockchains/jormungandr", "path": "/jcli/src/jcli_app/utils/debug_flag.rs", "mode": "psm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|> match self.debug { true => Some(std::io::stderr()), false => None, } } }<|fim_prefix|>// repo: toulouse-blockchains/jormungandr path: /jcli/src/jcli_app/utils/debug_flag.rs use structopt::StructOpt; #[derive(StructOpt)] pub struct DebugFlag { /// print additional...
code_fim
medium
{ "lang": "rust", "repo": "toulouse-blockchains/jormungandr", "path": "/jcli/src/jcli_app/utils/debug_flag.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|> debug: bool, } impl DebugFlag { pub fn debug_writer(&self) -> Option<impl std::io::Write> { match self.debug { true => Some(std::io::stderr()), false => None, } } }<|fim_prefix|>// repo: toulouse-blockchains/jormungandr path: /jcli/src/jcli_app/utils/d...
code_fim
medium
{ "lang": "rust", "repo": "toulouse-blockchains/jormungandr", "path": "/jcli/src/jcli_app/utils/debug_flag.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|> void main() { gl_Position = vec4(position, 0.0, 1.0); v_tex_coords = tex_coords; } "; let fragment = " #version 140 uniform sampler2D tex; varying vec2 v_tex_coords; void main() { ...
code_fim
hard
{ "lang": "rust", "repo": "12Tall/chip8-rs", "path": "/src/graphics.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> pub fn draw_screen(&mut self, content: Vec<Vec<Color>>) { let texture = Texture::new(&self.display, content).expect("Couldn't create empty texture!"); let vertex_buffer = glium::VertexBuffer::new(&self.display, &FRAMEBUFFER_VERTICES) .expect("Coudln't create vertex buffer!...
code_fim
hard
{ "lang": "rust", "repo": "12Tall/chip8-rs", "path": "/src/graphics.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: 12Tall/chip8-rs path: /src/graphics.rs use glium::glutin; use glium::Surface; #[derive(Copy, Clone)] pub struct Vertex { position: [f32; 2], tex_coords: [f32; 2], } implement_vertex!(Vertex, position, tex_coords); // const FRAMEBUFFER_WIDTH: u32 = 64; // const FRAMEBUFFER_HEIGHT: u32...
code_fim
hard
{ "lang": "rust", "repo": "12Tall/chip8-rs", "path": "/src/graphics.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> // the file contains 3 lines let mut parser = Parser::new("test/commands.txt"); assert_eq!(parser.advance(), true); // @1000 assert!(matches!(parser.command_type(), CommandType::A)); assert_eq!(parser.symbol(), Some("1000")); assert_eq!(parser.advan...
code_fim
hard
{ "lang": "rust", "repo": "mayoko/hack_assembler", "path": "/src/Parser.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: mayoko/hack_assembler path: /src/Parser.rs use std::fs::File; use std::io::{BufRead, BufReader, Lines}; mod OneLineParser; use OneLineParser::{CommandType, command_type, comp, dest, jump, symbol}; struct Parser { line_iter: Lines<BufReader<File>>, current_line: String } impl Parser { ...
code_fim
hard
{ "lang": "rust", "repo": "mayoko/hack_assembler", "path": "/src/Parser.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: salsa-rs/salsa path: /components/salsa-2022/src/cycle.rs use crate::debug::DebugWithDb; use crate::{key::DatabaseKeyIndex, Database}; use std::{panic::AssertUnwindSafe, sync::Arc}; /// Captures the participants of a cycle that occurred when executing a query. /// /// This type is meant to be us...
code_fim
hard
{ "lang": "rust", "repo": "salsa-rs/salsa", "path": "/components/salsa-2022/src/cycle.rs", "mode": "psm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|> /// Iterate over the [`DatabaseKeyIndex`] for each query participating /// in the cycle. The start point of this iteration within the cycle /// is arbitrary but deterministic, but the ordering is otherwise determined /// by the execution. pub fn participant_keys(&self) -> impl Iterator...
code_fim
hard
{ "lang": "rust", "repo": "salsa-rs/salsa", "path": "/components/salsa-2022/src/cycle.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_prefix|>// repo: Lapz/tox-rewrite path: /semant/src/resolver/function/expression.rs use crate::{ hir::{Expr, ExprId, FunctionAstMap, NameId}, resolver::data::ResolverDataCollector, util, HirDatabase, }; impl<'a, DB> ResolverDataCollector<&'a DB> where DB: HirDatabase, { // pub(crate) fn reso...
code_fim
hard
{ "lang": "rust", "repo": "Lapz/tox-rewrite", "path": "/semant/src/resolver/function/expression.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> Expr::Unary { expr, .. } => self.resolve_expression(fn_name, expr, ast_map)?, Expr::Return(expr) => { if let Some(expr) = expr { self.resolve_expression(fn_name, expr, ast_map)?; } } Expr::Match { expr, arm...
code_fim
hard
{ "lang": "rust", "repo": "Lapz/tox-rewrite", "path": "/semant/src/resolver/function/expression.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: ruggeri/fourier2 path: /src/lib/util/fns.rs use byteorder::{LittleEndian, WriteBytesExt}; use std::f64; use std::fs::File; use std::i16; use std::io::BufWriter; pub fn sin_val_for_freq_at_time(freq: f64, t: f64) -> f64 { let radians = 2.0 * f64::consts::PI * t * freq; radians.sin() } <...
code_fim
hard
{ "lang": "rust", "repo": "ruggeri/fourier2", "path": "/src/lib/util/fns.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> for val in vals { writer .write_i16::<LittleEndian>(f64_to_i16(val * 2_f64)) .unwrap(); writer .write_i16::<LittleEndian>(f64_to_i16(val * 2_f64)) .unwrap(); } }<|fim_prefix|>// repo: ruggeri/fourier2 path: /src/lib/util/fns.rs use b...
code_fim
hard
{ "lang": "rust", "repo": "ruggeri/fourier2", "path": "/src/lib/util/fns.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>pub fn f64_to_i16(val: f64) -> i16 { (val * f64::from(i16::MAX)) as i16 } pub fn amplitude(coeffs: (f64, f64)) -> f64 { (coeffs.0.powf(2.0_f64) + coeffs.1.powf(2.0_f64)).sqrt() } pub fn play_to_file<Iter>(fname: &str, vals: Iter) where Iter: Iterator<Item = f64>, { let mut writer = BufWr...
code_fim
medium
{ "lang": "rust", "repo": "ruggeri/fourier2", "path": "/src/lib/util/fns.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: bevyengine/bevy path: /benches/benches/bevy_ecs/iteration/iter_simple_system.rs use bevy_ecs::prelude::*; use glam::*; #[derive(Component, Copy, Clone)] struct Transform(Mat4); #[derive(Component, Copy, Clone)] struct Position(Vec3); <|fim_suffix|>impl Benchmark { pub fn new() -> Self { ...
code_fim
medium
{ "lang": "rust", "repo": "bevyengine/bevy", "path": "/benches/benches/bevy_ecs/iteration/iter_simple_system.rs", "mode": "psm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|>#[derive(Component, Copy, Clone)] struct Velocity(Vec3); pub struct Benchmark(World, Box<dyn System<In = (), Out = ()>>); impl Benchmark { pub fn new() -> Self { let mut world = World::new(); // TODO: batch this for _ in 0..10_000 { world.spawn(( ...
code_fim
medium
{ "lang": "rust", "repo": "bevyengine/bevy", "path": "/benches/benches/bevy_ecs/iteration/iter_simple_system.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|>impl Benchmark { pub fn new() -> Self { let mut world = World::new(); // TODO: batch this for _ in 0..10_000 { world.spawn(( Transform(Mat4::from_scale(Vec3::ONE)), Position(Vec3::X), Rotation(Vec3::X), ...
code_fim
medium
{ "lang": "rust", "repo": "bevyengine/bevy", "path": "/benches/benches/bevy_ecs/iteration/iter_simple_system.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_prefix|>// repo: damascene/slp-htlc path: /src/util.rs use bitcoin_cash::*; use bitcoin_cash_slp::TokenId; use anyhow::Result; use crate::ecs_client::ECSClient; pub fn get_utxo_token_amount(client: &ECSClient, txid: &str, vout: u32) -> Result<(TokenId, u64)> { let tx_hex = client.gettransaction(txid)?; ...
code_fim
hard
{ "lang": "rust", "repo": "damascene/slp-htlc", "path": "/src/util.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>!("Insufficient funds (not enough 'gas' in BCH)"); } let next_utxo = utxos.remove(0); let utxo_sk = client.getprivatekeys(&next_utxo.address.cash_addr())?; let utxo_pk = ecc.derive_pubkey(&utxo_sk)?; let gas_ref = tx_builder.add_input( UnsignedTxInput { ...
code_fim
hard
{ "lang": "rust", "repo": "damascene/slp-htlc", "path": "/src/util.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: SimonMaracine/rusty_json path: /src/lib.rs #![allow(unused)] mod data_structure; mod tokenizer; mod parser; use std::fs::read_to_string; use std::error::Error; use data_structure::{JsonObject, JsonArray, ArrayType, ArrayTypeRef}; use tokenizer::{tokenize, ParseError}; pub fn load<'object>(fi...
code_fim
hard
{ "lang": "rust", "repo": "SimonMaracine/rusty_json", "path": "/src/lib.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let mut my_array = JsonArray::new(); my_array.add_int(12); my_array.add_bool(true); my_array.add_string(String::from("Simon")); base.insert_float("my_float", 18.95); base.insert_array("my_array", my_array); // Get the array, mutate it and put it ba...
code_fim
hard
{ "lang": "rust", "repo": "SimonMaracine/rusty_json", "path": "/src/lib.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: Infinity-OS/infinity path: /libs/hole_list_allocator/src/lib.rs #![feature(allocator)] #![allocator] #![no_std] #![feature(const_fn)] use spin::Mutex; use linked_list_allocator::Heap; extern crate spin; extern crate linked_list_allocator; pub const HEAP_START: usize = 0o_000_001_000_000_000...
code_fim
hard
{ "lang": "rust", "repo": "Infinity-OS/infinity", "path": "/libs/hole_list_allocator/src/lib.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|>#[no_mangle] pub extern fn __rust_usable_size(size: usize, _align: usize) -> usize { size } #[no_mangle] pub extern fn __rust_reallocate_inplace(_ptr: *mut u8, size: usize, _new_size: usize, _align: usize) -> usize { size } #[no_mangle] pub extern fn __rus...
code_fim
medium
{ "lang": "rust", "repo": "Infinity-OS/infinity", "path": "/libs/hole_list_allocator/src/lib.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|>#[no_mangle] pub extern fn __rust_allocate(size: usize, align: usize) -> *mut u8 { HEAP.lock().allocate_first_fit(size, align).expect("out of memory") } #[no_mangle] pub extern fn __rust_deallocate(ptr: *mut u8, size: usize, align: usize) { unsafe { HEAP.lock().deallocate(ptr, size, align) }; } ...
code_fim
medium
{ "lang": "rust", "repo": "Infinity-OS/infinity", "path": "/libs/hole_list_allocator/src/lib.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> let mode = Mode::from_str("normal").unwrap(); assert_eq!(Mode::Normal, mode); assert_eq!(String::from("-- normal --"), mode.to_string()); let mode = Mode::from_str("visual").unwrap(); assert_eq!(Mode::Visual, mode); assert_eq!(String::from("-- visual --"), mode.to_string()); let mode = Mode:...
code_fim
medium
{ "lang": "rust", "repo": "seeseemelk/gpg-tui", "path": "/src/app/mode.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: seeseemelk/gpg-tui path: /src/app/mode.rs use std::fmt::{Display, Formatter, Result as FmtResult}; use std::str::FromStr; /// Application mode. #[derive(Clone, Copy, Debug, PartialEq)] pub enum Mode { /// Normal mode. Normal, /// Visual mode. /// (Disables the mouse capture) Visual, /// C...
code_fim
hard
{ "lang": "rust", "repo": "seeseemelk/gpg-tui", "path": "/src/app/mode.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> write!(f, "-- {} --", format!("{:?}", self).to_lowercase()) } } impl FromStr for Mode { type Err = (); fn from_str(s: &str) -> Result<Self, Self::Err> { match s.to_lowercase().as_str() { "normal" | "n" => Ok(Self::Normal), "visual" | "v" => Ok(Self::Visual), "copy" | "c" => Ok(Self::Copy)...
code_fim
medium
{ "lang": "rust", "repo": "seeseemelk/gpg-tui", "path": "/src/app/mode.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: 1Crazymoney/wasmtime path: /cranelift/codegen/src/isa/aarch64/inst/regs.rs //! AArch64 ISA definitions: registers. use crate::isa::aarch64::inst::OperandSize; use crate::isa::aarch64::inst::ScalarSize; use crate::isa::aarch64::inst::VectorSize; use crate::settings; use regalloc::{ PrettyPr...
code_fim
hard
{ "lang": "rust", "repo": "1Crazymoney/wasmtime", "path": "/cranelift/codegen/src/isa/aarch64/inst/regs.rs", "mode": "psm", "license": "LLVM-exception", "source": "the-stack-v2" }
<|fim_suffix|> // Add the X registers. N.B.: the order here must match the order implied // by XREG_INDICES, ZERO_REG_INDEX, and SP_REG_INDEX above. let x_reg_base = 32u8; // in contiguous real-register index space let mut x_reg_count = 0; let uses_pinned_reg = flags.enable_pinned_reg(); for i...
code_fim
hard
{ "lang": "rust", "repo": "1Crazymoney/wasmtime", "path": "/cranelift/codegen/src/isa/aarch64/inst/regs.rs", "mode": "spm", "license": "LLVM-exception", "source": "the-stack-v2" }
<|fim_prefix|>// repo: Madoc/euler-rust path: /src/problems/p006.rs // Sum square difference // // The sum of the squares of the first ten natural numbers is, // // 1^2 + 2^2 + ... + 10^2 = 385 // // The square of the sum of the first ten natural numbers is, // // (1 + 2 + ... 10)^2 = 55^2 = 3025 // // Hence the diffe...
code_fim
medium
{ "lang": "rust", "repo": "Madoc/euler-rust", "path": "/src/problems/p006.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>fn diff_of_sums(max: u64) -> u64 { let mut sum_of_squares = 0; let mut square_of_sum = 0; for i in 1..=max { sum_of_squares += i * i; square_of_sum += i; } square_of_sum *= square_of_sum; square_of_sum - sum_of_squares }<|fim_prefix|>// repo: Madoc/euler-rust path: /src/problems/p006....
code_fim
medium
{ "lang": "rust", "repo": "Madoc/euler-rust", "path": "/src/problems/p006.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> assert_eq!(diff_of_sums(10), 2640) } pub fn solve() -> u64 { diff_of_sums(100) } fn diff_of_sums(max: u64) -> u64 { let mut sum_of_squares = 0; let mut square_of_sum = 0; for i in 1..=max { sum_of_squares += i * i; square_of_sum += i; } square_of_sum *= square_of_sum; square_of_s...
code_fim
medium
{ "lang": "rust", "repo": "Madoc/euler-rust", "path": "/src/problems/p006.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> pub fn cheat(&mut self, value: i32) { let addr = self.target_u32.keys().clone().collect::<Vec<_>>(); if addr.len() == 1 { self.process.virt_mem.virt_write(Address::from(*addr[0]), &value).unwrap(); self.target_u32.clear(); } else { println!("...
code_fim
hard
{ "lang": "rust", "repo": "morimolymoly/simple-counter-hacker", "path": "/src/engine/stacksearch.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: morimolymoly/simple-counter-hacker path: /src/engine/stacksearch.rs use std::collections::HashMap; use memflow::*; use memflow_win32::*; struct Target<T> { address: Address, value: T, } pub struct StackSearch<T: VirtualMemory> { stack_base: Address, stack_limit: Address, p...
code_fim
hard
{ "lang": "rust", "repo": "morimolymoly/simple-counter-hacker", "path": "/src/engine/stacksearch.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: mjanjic01/rust-practice path: /rust-playground/src/types.rs #![allow(dead_code)] use std::mem; const MEANING_OF_LIFE:u8 = 42; // no fixed address static mut Z:i32 = 123; // static mut - memory unsafe (use unsafe block) fn operators() { // arithmetic let mut a = 2 + 3 * 4; println!("a ...
code_fim
hard
{ "lang": "rust", "repo": "mjanjic01/rust-practice", "path": "/rust-playground/src/types.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> // isize - pointer sized let z:isize = 123; let size_of_z = mem::size_of_val(&z); println!("z = {}, takes up {} bytes, {}-bit OS", z, size_of_z, size_of_z * 8); // characters let d:char = 'x'; println!("d = {}, size = {} bytes", d, mem::size_of_val(&d)); // double precision f64, f32 le...
code_fim
hard
{ "lang": "rust", "repo": "mjanjic01/rust-practice", "path": "/rust-playground/src/types.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: junior-dev-for-life/tinyrenderer-rs path: /src/main.rs mod obj_reader; mod render; mod line; use render::{ render_to_file, Pixel }; use line::{ dda_algorithm, line_bresenham }; const WIDTH: u32 = 500; const HEIGHT: u32 = 500; fn main() { <|fim_suffix|> let line = line_bresenham(x0,...
code_fim
hard
{ "lang": "rust", "repo": "junior-dev-for-life/tinyrenderer-rs", "path": "/src/main.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let line = line_bresenham(x0, y0, x1, y1); for pixel in line.iter() { points.push(pixel.clone()); } } } render_to_file(points, WIDTH, HEIGHT, "output_bresenham.png"); }<|fim_prefix|>// repo: junior-dev-for-life/tinyrenderer-rs path: /sr...
code_fim
hard
{ "lang": "rust", "repo": "junior-dev-for-life/tinyrenderer-rs", "path": "/src/main.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>// returns 2 bit colour fn get_tile_colour(tilerow: (u8, u8), tx: u8) -> u8 { let (byte1, byte2) = tilerow; let offset = (7 - std::cmp::min(7, tx)); let bit = 0b1 << offset; ((byte1 & bit) >> offset) | (((byte2 & bit) >> offset) << 1) } fn apply_palette(colour: u8, pal: u8) -> u8 { ...
code_fim
hard
{ "lang": "rust", "repo": "adamncasey/rust-gameboy", "path": "/gameboy/src/gpu.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> debug.sprites += sprites_drawn; } #[derive(Debug, Copy, Clone)] struct Sprite { y: i16, x: i16, tile: u8, priority: bool, yflip: bool, xflip: bool, palette: u8, } const SPRITE_MEM_START: u16 = 0xFE00; const SPRITE_MEM_SIZE: u16 = 4; fn load_sprite(mem: &Memory, num: u16,...
code_fim
hard
{ "lang": "rust", "repo": "adamncasey/rust-gameboy", "path": "/gameboy/src/gpu.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: adamncasey/rust-gameboy path: /gameboy/src/gpu.rs use crate::interrupt; use crate::memory::Memory; pub const GB_HSIZE: usize = 160; pub const GB_VSIZE: usize = 144; const LCD_ON_BIT: u8 = 1 << 7; const WINDOW_TILEMAP_BIT: u8 = 1 << 6; const WINDOW_DISP_BIT: u8 = 1 << 5; const TILEDATA_BIT: u8 ...
code_fim
hard
{ "lang": "rust", "repo": "adamncasey/rust-gameboy", "path": "/gameboy/src/gpu.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: thales17/rust-bouncing-cube path: /src/main.rs extern crate rand; extern crate sdl2; use rand::Rng; use sdl2::event::Event; use sdl2::keyboard::Keycode; use sdl2::pixels::Color; use sdl2::rect::Rect; use sdl2::render::WindowCanvas; use specs::world::Entity; use specs::{ Builder, Component, ...
code_fim
hard
{ "lang": "rust", "repo": "thales17/rust-bouncing-cube", "path": "/src/main.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let mut render = Render { canvas: window.into_canvas().build().map_err(|e| e.to_string())?, }; let mut physics = Physics { width: 800, height: 600, entities: Vec::new(), }; let entity_count = 200; for _ in 0..entity_count { let size = rand...
code_fim
hard
{ "lang": "rust", "repo": "thales17/rust-bouncing-cube", "path": "/src/main.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: danielschemmel/ralik path: /ralik/src/value/serializer/sequences.rs use my_serde::ser; use super::SerializerError; use crate::types::TypeKind; use crate::{Context, TypeHandle, Value}; enum ElementTypes { Repeating(TypeHandle), Consuming(Vec<TypeHandle>), } pub(super) struct SerializeSequen...
code_fim
hard
{ "lang": "rust", "repo": "danielschemmel/ralik", "path": "/ralik/src/value/serializer/sequences.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> match self.element_types { ElementTypes::Consuming(element_type_stack) => { if !element_type_stack.is_empty() { return Err(SerializerError::TooFewValues { r#type: self.expected_type, count: element_type_stack.len(), }); } } _ => (), } match self.expected_type....
code_fim
hard
{ "lang": "rust", "repo": "danielschemmel/ralik", "path": "/ralik/src/value/serializer/sequences.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> match self.expected_type.kind() { TypeKind::Tuple => { let value = Value::new_tuple(self.context, self.result)?; if value.has_type(&self.expected_type) { Ok(value) } else { Err(SerializerError::TypeMismatch { expected: self.expected_type, actual: value.get_type().clo...
code_fim
hard
{ "lang": "rust", "repo": "danielschemmel/ralik", "path": "/ralik/src/value/serializer/sequences.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: narumatt/sqlitefs path: /tests/sqlite.rs use sqlite_fs::db_module::{sqlite, DbModule}; mod helpers; #[test] fn sqlite_create_db() { <|fim_suffix|>#[test] fn sqlite_create_db_file() { let mut dbf = helpers::DBWithTempFile::new(); match dbf.db.init() { Ok(_) => assert!(true), ...
code_fim
medium
{ "lang": "rust", "repo": "narumatt/sqlitefs", "path": "/tests/sqlite.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|>#[test] fn sqlite_init_db() { let mut db = match sqlite::Sqlite::new_in_memory() { Ok(n) => n, Err(_) => { assert!(false, "failed to create db in memory"); return; } }; match db.init() { Ok(_) => assert!(true), Err(_) => assert!(f...
code_fim
hard
{ "lang": "rust", "repo": "narumatt/sqlitefs", "path": "/tests/sqlite.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: zCloneHero/midi-to-fnf path: /src/util.rs use std::io::stdin; pub fn ticks_to_steps(ticks: u32, ticks_per_beat: u16) -> f64 { let beats = ticks as f64 / ticks_per_beat as f64; beats * 4. } <|fim_suffix|>/// get line input pub fn prompt(prompt: &str, default: Option<&str>) -> String { ...
code_fim
medium
{ "lang": "rust", "repo": "zCloneHero/midi-to-fnf", "path": "/src/util.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>pub fn init_panic_hook() { std::panic::set_hook(Box::new(|info| { let message = if let Some(message) = info.message() { message.to_string() } else if let Some(payload) = info.payload().downcast_ref::<&str>() { payload.to_string() } else { "ca...
code_fim
hard
{ "lang": "rust", "repo": "zCloneHero/midi-to-fnf", "path": "/src/util.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> fn get_color(&self) -> &'static str { "darkgreen" } fn get_edit_default(&self) -> Option<&'static str> { Some("0.0") } fn get_multi_output(&self) -> bool { true } } pub fn add_blocks(logic: &mut crate::Logic) { logic.add_block(Box::new(FloatAdd {})); ...
code_fim
hard
{ "lang": "rust", "repo": "Roba1993/Business-Model-Executor", "path": "/src/blocks/float.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: Roba1993/Business-Model-Executor path: /src/blocks/float.rs use bme_macro::ExecutionBlockHelper; pub type Float = f64; impl crate::types::ExecutionType for Float { fn get_name(&self) -> &'static str { "Float" } fn from_json(&self, json: serde_json::Value) -> Box<crate::typ...
code_fim
hard
{ "lang": "rust", "repo": "Roba1993/Business-Model-Executor", "path": "/src/blocks/float.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: NNemec/azul path: /azul-core/src/macros.rs #![allow(unused_macros)] /// Implements functions for `CallbackInfo` and `Info`, /// to prevent duplicating the functions #[macro_export] macro_rules! impl_task_api {() => ( /// Insert a timer into the list of active timers. /// Replaces the e...
code_fim
hard
{ "lang": "rust", "repo": "NNemec/azul", "path": "/azul-core/src/macros.rs", "mode": "psm", "license": "MPL-2.0", "source": "the-stack-v2" }
<|fim_suffix|> // For a type without a lifetime ($enum:ident, {$($variant:pat => $fmt_string:expr),+$(,)* }) => { impl ::core::fmt::Display for $enum { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { use self::$enum::*; match &self { ...
code_fim
hard
{ "lang": "rust", "repo": "NNemec/azul", "path": "/azul-core/src/macros.rs", "mode": "spm", "license": "MPL-2.0", "source": "the-stack-v2" }
<|fim_prefix|>// repo: f3r10/talent-plan-kvs path: /src/error.rs use std::result; use std::fmt; use sled; pub enum KvStoreError{ SerdeIo(serde_json::Error), Io(std::io::Error), KeyNotFound, ServerResponseErr(String), SledError(sled::Error), StringUtf8Error(std::string::FromUtf8Error), Engi...
code_fim
hard
{ "lang": "rust", "repo": "f3r10/talent-plan-kvs", "path": "/src/error.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>} impl From<std::string::FromUtf8Error> for KvStoreError { fn from(err: std::string::FromUtf8Error) -> Self { KvStoreError::StringUtf8Error(err) } } impl fmt::Debug for KvStoreError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match &*self { KvSto...
code_fim
medium
{ "lang": "rust", "repo": "f3r10/talent-plan-kvs", "path": "/src/error.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: AngusGMorrison/trpl path: /8_common_collections/employees/src/main.rs mod cli; mod employees; fn main() { let mut db = employees::EmployeeDB::new(); <|fim_suffix|> let cmd = cli::get_command(); if cmd == "list" { db.list(); } else if cmd == "quit" { ...
code_fim
hard
{ "lang": "rust", "repo": "AngusGMorrison/trpl", "path": "/8_common_collections/employees/src/main.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let cmd = cli::get_command(); if cmd == "list" { db.list(); } else if cmd == "quit" { std::process::exit(0); } else if cmd.to_lowercase().starts_with("add") { let (name, dept) = match employees::parse_employee_data(&cmd) { ...
code_fim
hard
{ "lang": "rust", "repo": "AngusGMorrison/trpl", "path": "/8_common_collections/employees/src/main.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: nmoresco/aoc2020 path: /src/day6.rs use std::collections::HashSet; const LETTERS: [char; 26] = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']; <|fim_suffix|>pub fn solve_basement() { let data: usize = i...
code_fim
hard
{ "lang": "rust", "repo": "nmoresco/aoc2020", "path": "/src/day6.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> println!("{}", data); } pub fn solve_basement() { let data: usize = include_str!("../resources/6-1.txt") .split("\n\n") .map(|group| group.split('\n').collect()) .map(|group: Vec<&str>| { LETTERS .iter() .filter(|&ch| group.iter(...
code_fim
hard
{ "lang": "rust", "repo": "nmoresco/aoc2020", "path": "/src/day6.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> #[test] fn multi_dealing_from_short_deck_returns_only_remaining_cards() { let mut deck = Deck::new(); deck.multi_deal(50); let dealt_cards = deck.multi_deal(10).unwrap(); assert_eq!(dealt_cards.len(), 2); } #[test] fn shuffling_does_not_remove_cards_fro...
code_fim
hard
{ "lang": "rust", "repo": "mus0u/go-fish-rs", "path": "/src/deck.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: mus0u/go-fish-rs path: /src/deck.rs use rand::{Rng, thread_rng}; use card::*; use card::Rank::*; use card::Suit::*; pub struct Deck { cards: Vec<Card>, } impl Deck { pub fn new() -> Deck { let suits = [Diamonds, Clubs, Hearts, Spades]; let ranks = [Two, Three, Four, Fiv...
code_fim
hard
{ "lang": "rust", "repo": "mus0u/go-fish-rs", "path": "/src/deck.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let mut deck = Deck::new(); deck.multi_deal(50); let dealt_cards = deck.multi_deal(10).unwrap(); assert_eq!(dealt_cards.len(), 2); } #[test] fn shuffling_does_not_remove_cards_from_deck() { let mut deck = Deck::new(); deck.shuffle(); ass...
code_fim
hard
{ "lang": "rust", "repo": "mus0u/go-fish-rs", "path": "/src/deck.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: ncihnegn/reetcode path: /src/palindrome.rs pub fn is_palindrome(s: &str) -> bool { let mut chars = s.to_lowercase().chars().collect::<Vec<_>>(); chars.retain(|&x| x.is_alphanumeric()); let mut iter = chars.iter(); let mut rev_iter = chars.iter().rev(); while let Some(c) ...
code_fim
medium
{ "lang": "rust", "repo": "ncihnegn/reetcode", "path": "/src/palindrome.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> assert_eq!(is_palindrome("A man, a plan, a canal: Panama"), true); assert_eq!(is_palindrome("race a car"), false); } }<|fim_prefix|>// repo: ncihnegn/reetcode path: /src/palindrome.rs pub fn is_palindrome(s: &str) -> bool { let mut chars = s.to_lowercase().chars().collect::<Ve...
code_fim
medium
{ "lang": "rust", "repo": "ncihnegn/reetcode", "path": "/src/palindrome.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>#[no_mangle] pub unsafe extern "C" fn ruststringrange_new_utf8( buffer: *const u8, buffer_len: usize, ) -> *mut c_void { Box::into_raw(Box::new(RustStringRange::from_buffer_utf8( buffer, buffer_len, ))) as *mut c_void } #[no_mangle] pub unsafe extern "C" fn ruststringrange_free(p:...
code_fim
hard
{ "lang": "rust", "repo": "saschanaz/ime-rs", "path": "/rust/ruststringrange/src/lib.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: saschanaz/ime-rs path: /rust/ruststringrange/src/lib.rs #![allow(clippy::missing_safety_doc)] #![allow(clippy::len_without_is_empty)] #![allow(clippy::should_implement_trait)] use core::ffi::c_void; use std::cmp::Ordering; use std::rc::Rc; // Don't bind the struct itself, instead just expose f...
code_fim
hard
{ "lang": "rust", "repo": "saschanaz/ime-rs", "path": "/rust/ruststringrange/src/lib.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let alef = 'ا'; let alef_final = LETTERS[alef][FINAL as usize]; let hamza = 'ء'; let hamza_isolated = LETTERS[hamza][ISOLATED as usize]; let beh = beh.to_string(); let beh_isolated = beh_isolated.to_string(); let beh_initial = beh_initial.to_string(); let beh_final = beh_...
code_fim
hard
{ "lang": "rust", "repo": "sigmaSd/arabic-reshaper-rs", "path": "/src/tests/test_002_reshaping.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: sigmaSd/arabic-reshaper-rs path: /src/tests/test_002_reshaping.rs use crate::arabic_reshape; use crate::letters::LETTERS; use crate::letters::{FINAL, INITIAL, ISOLATED, MEDIAL, ZWJ}; use crate::ArabicReshaper; #[test] fn reshape_test() { let cases = [ ("السلام عليكم", "ﺍﻟﺴﻼﻡ ﻋﻠﻴﻜﻢ")...
code_fim
hard
{ "lang": "rust", "repo": "sigmaSd/arabic-reshaper-rs", "path": "/src/tests/test_002_reshaping.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> let mut reshaper = ArabicReshaper::new(); *reshaper.configuration.get_mut("delete_harakat").unwrap() = false; *reshaper.configuration.get_mut("support_ligatures").unwrap() = false; let cases = [ ("السَلَاْمٌ عَلَيْكُمْ", "ﺍﻟﺴَﻠَﺎْﻡٌ ﻋَﻠَﻴْﻜُﻢْ"), ( "اللغة العربي...
code_fim
hard
{ "lang": "rust", "repo": "sigmaSd/arabic-reshaper-rs", "path": "/src/tests/test_002_reshaping.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }