text
stringlengths
232
16.3k
domain
stringclasses
1 value
difficulty
stringclasses
3 values
meta
dict
<|fim_suffix|> _ => { let mut result = None; for i in self.children.iter().enumerate() { let differences: Vec<i64> = self .children .iter() .enumerate() .filter(...
code_fim
hard
{ "lang": "rust", "repo": "LinAGKar/advent-of-code-2017-rust", "path": "/day7b/src/main.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> 2 => { let child_diff = self.children[1].weight - self.children[0].weight; match difference { Some(diff) => { if child_diff == 0 { Some(self.own_weight + diff) } else...
code_fim
hard
{ "lang": "rust", "repo": "LinAGKar/advent-of-code-2017-rust", "path": "/day7b/src/main.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> Self::weighted_selection(rng, &pooled_links).token } fn weighted_selection(rng: &mut impl Rng, links: &[Link<'a>]) -> Link<'a> { let total_count: usize = links.iter().map(|l| l.count).sum(); links .iter() .cycle() .skip(rng.gen::<usize>(...
code_fim
hard
{ "lang": "rust", "repo": "museun/shaken", "path": "/brain/src/markov.rs", "mode": "spm", "license": "Unlicense", "source": "the-stack-v2" }
<|fim_prefix|>// repo: museun/shaken path: /brain/src/markov.rs use hashbrown::HashMap; use rand::prelude::*; use serde::{Deserialize, Serialize}; use std::cmp::{min, Ordering}; use std::ops::{Deref, DerefMut}; #[derive(Default, Serialize, Deserialize)] pub struct Markov<'a> { #[serde(borrow)] chain: HashMap...
code_fim
hard
{ "lang": "rust", "repo": "museun/shaken", "path": "/brain/src/markov.rs", "mode": "psm", "license": "Unlicense", "source": "the-stack-v2" }
<|fim_suffix|> if let Some(existing) = self.existing(&token) { existing.merge(&link); self.sort_unstable_by(|a, b| b.cmp(a)); // reverse } else { self.push(link); } } fn existing(&mut self, token: &Token<'a>) -> Option<&mut Link<'a>> { self.ite...
code_fim
hard
{ "lang": "rust", "repo": "museun/shaken", "path": "/brain/src/markov.rs", "mode": "spm", "license": "Unlicense", "source": "the-stack-v2" }
<|fim_suffix|> let single_asterisk: Matcher = "foo/*/bar".into(); assert!(single_asterisk.is_match("foo/4711/bar")); assert!(!single_asterisk.is_match("foo/4711/barr")); assert!(single_asterisk.is_match("foo/4711/bar?foo=true&bar=false")); assert!(!single_asterisk.is_match("foo/4711/4712/bar")); ...
code_fim
hard
{ "lang": "rust", "repo": "nickel-org/nickel.rs", "path": "/src/router/router.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: nickel-org/nickel.rs path: /src/router/router.rs use crate::middleware::{Middleware, MiddlewareResult}; use async_trait::async_trait; use crate::request::Request; use crate::response::Response; use crate::router::HttpRouter; use hyper::{Method, StatusCode}; use crate::router::{Matcher, FORMAT_P...
code_fim
hard
{ "lang": "rust", "repo": "nickel-org/nickel.rs", "path": "/src/router/router.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|>impl Flow { pub fn new(insock: TcpStream, /*ousock: TcpStream,*/ token: Token, bufsize: usize) -> Flow { Flow { inb: Conn::new(token, insock, bufsize), out: None, } } pub fn set_outbound(&mut self, outbound: TcpStream, bufsize: usize, event_loop: &mut ...
code_fim
hard
{ "lang": "rust", "repo": "darkprokoba/tnexus", "path": "/src/flow.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> pub fn set_outbound(&mut self, outbound: TcpStream, bufsize: usize, event_loop: &mut EventLoop<Nexus>) -> bool { let mut out_conn = Conn::new(Token(OUTMASK + self.inb.token.as_usize()), outbound, bufsize); out_conn.register(event_loop).ok().expect("TODO: handle registration failur...
code_fim
hard
{ "lang": "rust", "repo": "darkprokoba/tnexus", "path": "/src/flow.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: darkprokoba/tnexus path: /src/flow.rs use std::io; use mio::*; use mio::tcp::TcpStream; use bytes::buf::{Buf, RingBuf}; use multiplex::{Multiplexer, MR}; use Nexus; const OUTMASK: usize = 2147483648; //2 ** 31 pub struct Conn { // socket sock: TcpStream, // token used to registe...
code_fim
hard
{ "lang": "rust", "repo": "darkprokoba/tnexus", "path": "/src/flow.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: katharostech/pixels path: /examples/minimal-sdl2/main.rs #![deny(clippy::all)] #![forbid(unsafe_code)] #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] use beryllium::*; use pixels::{wgpu::Surface, Pixels, SurfaceTexture}; const WIDTH: u32 = 320; const HEIGHT: u32 = 240; cons...
code_fim
hard
{ "lang": "rust", "repo": "katharostech/pixels", "path": "/examples/minimal-sdl2/main.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> /// Update the `World` internal state; bounce the box around the screen. fn update(&mut self) { if self.box_x <= 0 || self.box_x + BOX_SIZE - 1 >= WIDTH as i16 { self.velocity_x *= -1; } if self.box_y <= 0 || self.box_y + BOX_SIZE - 1 >= HEIGHT as i16 { ...
code_fim
hard
{ "lang": "rust", "repo": "katharostech/pixels", "path": "/examples/minimal-sdl2/main.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: King-Coyote/ciso-rust path: /src/util.rs use std::sync::{Arc, Mutex,}; use rlua::{ FromLua, Result, Table, Value, Error as LuaError, ToLua, }; use crate::error::Error; use std::env; use std::path::{Path, PathBuf,}; pub type Shared<T> = Arc<Mutex<T>>; <|fim_suffix|>/...
code_fim
medium
{ "lang": "rust", "repo": "King-Coyote/ciso-rust", "path": "/src/util.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>pub fn get_asset_path<P: AsRef<Path>>(p: P) -> PathBuf { env::current_dir().unwrap() .join("assets") .join(p) } // pub fn unwrap_table_into_props<'lua, T, L, F>(table: &Table<'lua>, relations: &[(L, F)]) // where // L: Fn() -> Result<Rz>, // F: Fn(T) // { // }<|fi...
code_fim
hard
{ "lang": "rust", "repo": "King-Coyote/ciso-rust", "path": "/src/util.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>// pub fn unwrap_table_into_props<'lua, T, L, F>(table: &Table<'lua>, relations: &[(L, F)]) // where // L: Fn() -> Result<Rz>, // F: Fn(T) // { // }<|fim_prefix|>// repo: King-Coyote/ciso-rust path: /src/util.rs use std::sync::{Arc, Mutex,}; use rlua::{ FromLua, Result, ...
code_fim
hard
{ "lang": "rust", "repo": "King-Coyote/ciso-rust", "path": "/src/util.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: tikhono/CryptoHackPals path: /pals/set5/_33_implement_diffie_hellman/src/lib.rs #[cfg(test)] mod tests { use num::bigint::BigInt; #[allow(non_snake_case)] #[test] fn capture_the_flag() { let a = BigInt::parse_bytes(b"1122187391395429088805643595343734240130162497729319626...
code_fim
hard
{ "lang": "rust", "repo": "tikhono/CryptoHackPals", "path": "/pals/set5/_33_implement_diffie_hellman/src/lib.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>4374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca237327ffffffffffffffff", 16).unwrap(); let g = BigInt::from(2...
code_fim
hard
{ "lang": "rust", "repo": "tikhono/CryptoHackPals", "path": "/pals/set5/_33_implement_diffie_hellman/src/lib.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let _ = #[not_a_closure] 32; }<|fim_prefix|>// repo: smklein/josh_hates_closures path: /tests/not-a-closure.rs #![feature(stmt_expr_attributes)] #![feature(proc_macro_hygiene)] <|fim_middle|>use josh_hates_closures::not_a_closure; fn main() {
code_fim
easy
{ "lang": "rust", "repo": "smklein/josh_hates_closures", "path": "/tests/not-a-closure.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: smklein/josh_hates_closures path: /tests/not-a-closure.rs #![feature(stmt_expr_attributes)] #![feature(proc_macro_hygiene)] <|fim_suffix|>fn main() { let _ = #[not_a_closure] 32; }<|fim_middle|>use josh_hates_closures::not_a_closure;
code_fim
easy
{ "lang": "rust", "repo": "smklein/josh_hates_closures", "path": "/tests/not-a-closure.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|>pub fn run( network: NeuralNetwork<TenBitAS, TenBitExpFP>, architecture: NeuralArchitecture<TenBitAS, TenBitExpFP>, image: Array4<f64>, class: i64, ) { let mut server_rng = ChaChaRng::from_seed(RANDOMNESS); let mut client_rng = ChaChaRng::from_seed(RANDOMNESS); let server_addr ...
code_fim
hard
{ "lang": "rust", "repo": "mc2-project/delphi", "path": "/rust/experiments/src/inference/inference.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_prefix|>// repo: mc2-project/delphi path: /rust/experiments/src/inference/inference.rs use crate::*; use neural_network::{ndarray::Array4, tensors::Input, NeuralArchitecture}; use rand::SeedableRng; use rand_chacha::ChaChaRng; use std::cmp; const RANDOMNESS: [u8; 32] = [ 0x11, 0xe0, 0x8f, 0xbc, 0x89, 0xa7, ...
code_fim
hard
{ "lang": "rust", "repo": "mc2-project/delphi", "path": "/rust/experiments/src/inference/inference.rs", "mode": "psm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_prefix|>// repo: adrianchitescu/aoc20-rs path: /day11/src/main.rs extern crate utils; use utils::utils::*; use std::fmt; #[derive(Debug, Copy, Clone, PartialEq)] enum GridState { Empty, Occupied, Floor } #[derive(Debug)] struct Layout { grid : Vec<Vec<GridState>> } impl fmt::Display for Layout {...
code_fim
hard
{ "lang": "rust", "repo": "adrianchitescu/aoc20-rs", "path": "/day11/src/main.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> fn count_occupied(&self) -> usize { self.grid.iter().fold(0, |cnt, line| cnt + line.iter().filter(|s| **s == GridState::Occupied).count() ) } fn occupy_loop(&mut self, level:usize, tolerance: usize) -> usize { loop { // println!("{}", self); ...
code_fim
hard
{ "lang": "rust", "repo": "adrianchitescu/aoc20-rs", "path": "/day11/src/main.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> self.grid.iter().fold(0, |cnt, line| cnt + line.iter().filter(|s| **s == GridState::Occupied).count() ) } fn occupy_loop(&mut self, level:usize, tolerance: usize) -> usize { loop { // println!("{}", self); let new_layout = self.occupy(l...
code_fim
hard
{ "lang": "rust", "repo": "adrianchitescu/aoc20-rs", "path": "/day11/src/main.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: mys721tx/rust-bio-gff-csv-poc path: /src/main.rs use std::error::Error; use std::fmt::{self, Display}; use std::io; use std::process; use serde::de::{self, Visitor}; use serde::ser; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use csv::ReaderBuilder; #[derive(Debug)] pub enu...
code_fim
hard
{ "lang": "rust", "repo": "mys721tx/rust-bio-gff-csv-poc", "path": "/src/main.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let mut rdr = ReaderBuilder::new() .delimiter(b'\t') .has_headers(false) .comment(Some(b'#')) .from_reader(GFF_FILE); for result in rdr.deserialize() { let record: Record = result?; println!("{:?}", record); } Ok(()) } fn writer() -> Result<...
code_fim
hard
{ "lang": "rust", "repo": "mys721tx/rust-bio-gff-csv-poc", "path": "/src/main.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: mgill25/database path: /src/sql_engine/src/lib.rs ng) -> Self { Self { severity: Severity::Error, code: "42601".to_owned(), kind: QueryErrorKind::NotSupportedOperation(raw_sql_query), } } } impl Display for QueryError { fn fmt(&self, f...
code_fim
hard
{ "lang": "rust", "repo": "mgill25/database", "path": "/src/sql_engine/src/lib.rs", "mode": "psm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_prefix|>// repo: mgill25/database path: /src/sql_engine/src/lib.rs wrap_or(255)), _ => unimplemented!(), }; (name, sql_type) }) .collect(), )? { ...
code_fim
hard
{ "lang": "rust", "repo": "mgill25/database", "path": "/src/sql_engine/src/lib.rs", "mode": "psm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|> assert_eq!( sql_engine_with_schema .execute("insert into schema_name.table_name values (123);") .expect("no system errors"), Err(QueryError::table_does_not_exist("schema_name.table_name".to_owned())) ); ...
code_fim
hard
{ "lang": "rust", "repo": "mgill25/database", "path": "/src/sql_engine/src/lib.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_prefix|>// repo: mblonyox/adventofcode path: /2021/src/tools/grid.rs use std::{ iter::FromIterator, ops::{Index, IndexMut}, }; use super::cartesian::Point; #[allow(dead_code)] #[derive(Debug)] pub enum GridError { IndicesOutOfBounds(usize, usize), } #[derive(Debug, Default)] pub struct Grid<T> { ...
code_fim
hard
{ "lang": "rust", "repo": "mblonyox/adventofcode", "path": "/2021/src/tools/grid.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> match self.get_mut_point(&Point::new(x, y)) { Some(x) => x, None => (|| panic!("Coordinate out of bounds x: {}, y: {}", x, y))(), } } } impl<T> Index<&Point> for Grid<T> { type Output = T; fn index(&self, p: &Point) -> &Self::Output { match sel...
code_fim
hard
{ "lang": "rust", "repo": "mblonyox/adventofcode", "path": "/2021/src/tools/grid.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: AKrill91/advent-of-code path: /src/2018/day06.rs use std::collections::HashMap; #[derive(Hash, Debug)] struct Point { x: i32, y: i32, } impl PartialEq for Point { fn eq(&self, other: &Point) -> bool { self.x == other.x && self.y == other.y } } impl Eq for Point {} imp...
code_fim
hard
{ "lang": "rust", "repo": "AKrill91/advent-of-code", "path": "/src/2018/day06.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>fn parse_origins(input: &Vec<String>) -> Vec<Origin> { let mut origins = Vec::new(); let mut id_counter = 0; for line in input { let mut parts = line.split(", "); let x_str = parts.next().expect("Error getting x coord"); let y_str = parts.next().expect("Error getting ...
code_fim
hard
{ "lang": "rust", "repo": "AKrill91/advent-of-code", "path": "/src/2018/day06.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>g.replace_all(html_trim, ""); return target_html.into(); }<|fim_prefix|>// repo: TtTRz/html2VD path: /src/utils/html_filter.rs use regex::Regex; pub fn html_filter(html_source: String) -> String { let rg = Regex::new(r"[\n]+[\s]*").unwrap(); <|fim_middle|> let html_trim = html_source.trim(); ...
code_fim
medium
{ "lang": "rust", "repo": "TtTRz/html2VD", "path": "/src/utils/html_filter.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: TtTRz/html2VD path: /src/utils/html_filter.rs use regex::Regex; pub fn html_filter(html_source: String) -><|fim_suffix|> let html_trim = html_source.trim(); let target_html = rg.replace_all(html_trim, ""); return target_html.into(); }<|fim_middle|> String { let rg = Regex::new(r"[\...
code_fim
medium
{ "lang": "rust", "repo": "TtTRz/html2VD", "path": "/src/utils/html_filter.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: rune-rs/rune path: /examples/examples/custom_mul.rs //! This example showcases overloading the multiplication protocol for a //! specific type `Foo`. use rune::runtime::Protocol; use rune::{Any, ContextError, Diagnostics, Module, Vm}; use std::sync::Arc; <|fim_suffix|> let runtime = Arc::ne...
code_fim
hard
{ "lang": "rust", "repo": "rune-rs/rune", "path": "/examples/examples/custom_mul.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> println!("output: {:?}", output); Ok(()) } fn module() -> Result<Module, ContextError> { let mut m = Module::with_item(["module"]); m.ty::<Foo>()?; m.associated_function(Protocol::MUL, Foo::mul)?; Ok(m) }<|fim_prefix|>// repo: rune-rs/rune path: /examples/examples/custom_mul.rs /...
code_fim
hard
{ "lang": "rust", "repo": "rune-rs/rune", "path": "/examples/examples/custom_mul.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> loop { let adc_val = adc::read_adc(POTENTIOMETER); match adc_val { Ok(v) => println!("ADC: {}", v), Err(_) => println!("Problem reading adc file") } thread::sleep(time::Duration::from_secs(1)) } }<|fim_prefix|>// repo: bryanniwa/plant_health_...
code_fim
medium
{ "lang": "rust", "repo": "bryanniwa/plant_health_monitor", "path": "/src/lib.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: bryanniwa/plant_health_monitor path: /src/lib.rs mod adc; use std::{thread, time}; const POTENTIOMETER: &str = "/sys/bus/iio/devices/iio:device0/in_voltage0_raw"; <|fim_suffix|>fn check_potentiometer() { loop { let adc_val = adc::read_adc(POTENTIOMETER); match adc_val { ...
code_fim
easy
{ "lang": "rust", "repo": "bryanniwa/plant_health_monitor", "path": "/src/lib.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: fatalerrorcoded/stivale-rs path: /src/header/mod.rs //! stivale2 header module for letting a stivale2 compliant bootloader find the kernel //! //! Contains a stivale2 header struct and various tags allowed by stivale2 //! //! # Examples //! //! Basic header //! ```ignore //! static STACK: [u8...
code_fim
hard
{ "lang": "rust", "repo": "fatalerrorcoded/stivale-rs", "path": "/src/header/mod.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|>// Send and Sync are okay because we won't be accessing the data on runtime anyways unsafe impl Send for StivaleHeader {} unsafe impl Sync for StivaleHeader {} impl StivaleHeader { /// Create a new stivale2 header with a stack pub const fn new(stack: *const u8) -> Self { StivaleHeader { ...
code_fim
hard
{ "lang": "rust", "repo": "fatalerrorcoded/stivale-rs", "path": "/src/header/mod.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> op_info = &graph[idx]; if verbose { println!("\n\nOperator '{}' with ID: {}",op_info.name,op_info.id); } let rates = op_info.rates.get(&epoch).expect("No rates found for the given epoch."); true_processing_rate = rates.0; if verbose { println!("Aggregated t...
code_fim
hard
{ "lang": "rust", "repo": "soniclavier/ds2", "path": "/controller/src/policy/scaling.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: soniclavier/ds2 path: /controller/src/policy/scaling.rs scaling_policy(topo: &mut Topology, threshold: f64, factor: f64, verbose: bool) -> String { // Used in configuration adjustments let sources = topo.get_sources_idx(); let config_before = topo.dictionary.clone(); let mut conf...
code_fim
hard
{ "lang": "rust", "repo": "soniclavier/ds2", "path": "/controller/src/policy/scaling.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: soniclavier/ds2 path: /controller/src/policy/scaling.rs odeIndex}; use dataflow::petgraph::algo::toposort; use dataflow::topology::Topology; use dataflow::{OperatorId,OperatorInstanceId,OperatorInstances,Epoch,Rate}; /// Converts a dataflow configuration `conf` to a vector of pairs `(Operator...
code_fim
hard
{ "lang": "rust", "repo": "soniclavier/ds2", "path": "/controller/src/policy/scaling.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> It doesn't matter what you leave beyond the returned length. */ println!("{:?}", remove_element(&mut vec![3, 2, 2, 3], 3)); }<|fim_prefix|>// repo: PoorlyDefinedBehaviour/data-structures-and-algorithms path: /rust/algorithms/others/remove-element/main.rs /* * time O(n) * space O(1) **/ fn remove_e...
code_fim
hard
{ "lang": "rust", "repo": "PoorlyDefinedBehaviour/data-structures-and-algorithms", "path": "/rust/algorithms/others/remove-element/main.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> Your function should return length = 2, with the first two elements of nums being 2. It doesn't matter what you leave beyond the returned length. */ println!("{:?}", remove_element(&mut vec![3, 2, 2, 3], 3)); }<|fim_prefix|>// repo: PoorlyDefinedBehaviour/data-structures-and-algorithms path: /r...
code_fim
medium
{ "lang": "rust", "repo": "PoorlyDefinedBehaviour/data-structures-and-algorithms", "path": "/rust/algorithms/others/remove-element/main.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: PoorlyDefinedBehaviour/data-structures-and-algorithms path: /rust/algorithms/others/remove-element/main.rs /* * time O(n) * space O(1) **/ fn remove_element(numbers: &mut Vec<i32>, value: i32) -> i32 { let mut i: usize = 0; <|fim_suffix|> Do not allocate extra space for another array, you mu...
code_fim
hard
{ "lang": "rust", "repo": "PoorlyDefinedBehaviour/data-structures-and-algorithms", "path": "/rust/algorithms/others/remove-element/main.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: extrawurst/gitui path: /src/components/utils/mod.rs use chrono::{DateTime, Local, NaiveDateTime, Utc}; use unicode_width::UnicodeWidthStr; #[cfg(feature = "ghemoji")] pub mod emoji; pub mod filetree; pub mod logitems; pub mod scroll_horizontal; pub mod scroll_vertical; pub mod statustree; <|fi...
code_fim
hard
{ "lang": "rust", "repo": "extrawurst/gitui", "path": "/src/components/utils/mod.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|>#[inline] pub fn string_width_align(s: &str, width: usize) -> String { static POSTFIX: &str = ".."; let len = UnicodeWidthStr::width(s); let width_wo_postfix = width.saturating_sub(POSTFIX.len()); if (len >= width_wo_postfix && len <= width) || (len <= width_wo_postfix) { format!("{s:width$}") ...
code_fim
hard
{ "lang": "rust", "repo": "extrawurst/gitui", "path": "/src/components/utils/mod.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> &mut self, lifecycle: &WidgetLifecycle<'_>, _ctx: &Context<'_>, _data: &T, env: &Env, ) { match lifecycle { WidgetLifecycle::Initialized(textures) => { if let Self::ByName(name) = self { if let Some(id) = e...
code_fim
medium
{ "lang": "rust", "repo": "cloudhead/rgx", "path": "/src/ui/widgets/image.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: cloudhead/rgx path: /src/ui/widgets/image.rs use crate::ui::*; pub enum Image { ById(TextureId, TextureInfo), ByName(&'static str), } impl Image { pub fn texture(id: TextureId, info: TextureInfo) -> Self { Self::ById(id, info) } pub fn named(name: &'static str) -> ...
code_fim
medium
{ "lang": "rust", "repo": "cloudhead/rgx", "path": "/src/ui/widgets/image.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> fn paint(&mut self, mut canvas: Canvas<'_>, _data: &T) { if let Self::ById(id, _) = self { canvas.paint(Paint::texture(id, &canvas)); } } fn lifecycle( &mut self, lifecycle: &WidgetLifecycle<'_>, _ctx: &Context<'_>, _data: &T, ...
code_fim
hard
{ "lang": "rust", "repo": "cloudhead/rgx", "path": "/src/ui/widgets/image.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: sugyan/leetcode path: /others/june-leetcoding-challenge/week-1/3352/lib.rs pub struct Solution {} impl Solution { pub fn reconstruct_queue(people: Vec<Vec<i32>>) -> Vec<Vec<i32>> { let mut v: Vec<Vec<i32>> = people; v.sort_by(|a: &Vec<i32>, b: &Vec<i32>| match b[0].cmp(&a[0]...
code_fim
hard
{ "lang": "rust", "repo": "sugyan/leetcode", "path": "/others/june-leetcoding-challenge/week-1/3352/lib.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> assert_eq!( vec![ vec![5, 0], vec![7, 0], vec![5, 2], vec![6, 1], vec![4, 4], vec![7, 1] ], Solution::reconstruct_queue(vec![ vec![7, 0], ...
code_fim
hard
{ "lang": "rust", "repo": "sugyan/leetcode", "path": "/others/june-leetcoding-challenge/week-1/3352/lib.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: Dante-Broggi/swift-bindgen path: /swift-sys/src/ptr/relative_indirectable.rs use std::{fmt, marker::PhantomData, mem, num::NonZeroI32}; /// A nullable pointer whose pointee is either at a relative offset from itself /// or referenced at that offset. /// /// This type deliberately does not imple...
code_fim
hard
{ "lang": "rust", "repo": "Dante-Broggi/swift-bindgen", "path": "/swift-sys/src/ptr/relative_indirectable.rs", "mode": "psm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|>/// A non-null pointer whose pointee is either at a relative offset from itself /// or referenced at that offset. /// /// This type deliberately does not implement [`Copy`] in order to avoid /// accidentally dereferencing from the wrong location. #[repr(transparent)] pub struct RelativeIndirectablePointer...
code_fim
hard
{ "lang": "rust", "repo": "Dante-Broggi/swift-bindgen", "path": "/swift-sys/src/ptr/relative_indirectable.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|>impl<T> RelativeIndirectablePointerNonNull<T> { /// Creates a pointer without checking that `offset` is non-zero. /// /// # Safety /// /// `offset` must not be zero. #[inline] pub const unsafe fn new_unchecked(offset: i32) -> Self { Self::new(NonZeroI32::new_unchecked(o...
code_fim
hard
{ "lang": "rust", "repo": "Dante-Broggi/swift-bindgen", "path": "/swift-sys/src/ptr/relative_indirectable.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_prefix|>// repo: flintlang/flint-2 path: /src/ewasm/abi.rs use crate::ast::{ContractBehaviourDeclaration, FunctionDeclaration, Parameter}; use crate::ast::{ContractBehaviourMember, Type}; use json::JsonValue; pub fn generate_abi(behaviour_declarations: &[&ContractBehaviourDeclaration]) -> String { let funct...
code_fim
hard
{ "lang": "rust", "repo": "flintlang/flint-2", "path": "/src/ewasm/abi.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>fn generate_function_abi(declaration: &FunctionDeclaration) -> JsonValue { let func_name = declaration.head.identifier.token.as_str(); let func_inputs = declaration .head .parameters .iter() .map(|param| generate_parameter_abi(param)) .collect::<json::Array>...
code_fim
hard
{ "lang": "rust", "repo": "flintlang/flint-2", "path": "/src/ewasm/abi.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> if let Some(return_type) = opt_return_type { let abi_name = ""; let ether_type = generate_ether_type(return_type); json::array![json::object! { name: abi_name, type: ether_type, }] } else { json::array![] } } fn generate_ether_ty...
code_fim
hard
{ "lang": "rust", "repo": "flintlang/flint-2", "path": "/src/ewasm/abi.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let x = [4, 5, 6]; let z = second(&x); __assert(z == 5); }<|fim_prefix|>// repo: softdevteam/grass path: /tests/00_basic/05_unsize.rs fn __assert(b: bool){ 1/(b as u8);} <|fim_middle|>fn second(list: &[u32]) -> u32 { list[1] } fn main() {
code_fim
medium
{ "lang": "rust", "repo": "softdevteam/grass", "path": "/tests/00_basic/05_unsize.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: softdevteam/grass path: /tests/00_basic/05_unsize.rs fn __assert(b: bool){ 1/(b as u8);} fn second(list: &[u32]) -> u32 { list[1] } <|fim_suffix|> __assert(z == 5); }<|fim_middle|>fn main() { let x = [4, 5, 6]; let z = second(&x);
code_fim
medium
{ "lang": "rust", "repo": "softdevteam/grass", "path": "/tests/00_basic/05_unsize.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let source = &source[1..]; let mut end = 1; let mut chars = source.iter(); let mut result = String::new(); loop { end += 1; match chars.next() { Some(ch) => match *ch { '\\' => { match chars.next() { Some(ch) => match *ch...
code_fim
hard
{ "lang": "rust", "repo": "polydraw/polydraw", "path": "/src/lang/tokenizer.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> if let Some(ch) = chars.next() { if *ch == '#' { end += 1; loop { match chars.next() { Some(ch) => match *ch { '\n' => break, _ => end += 1, }, None => break, } } ...
code_fim
hard
{ "lang": "rust", "repo": "polydraw/polydraw", "path": "/src/lang/tokenizer.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: polydraw/polydraw path: /src/lang/tokenizer.rs #[derive(PartialEq, Clone, Debug)] pub enum Token { Name(String), String(String), Float(f64), NewLine, Function, Address, SpaceOffset, Assign, Add, Subtract, Multiply, Divide, Power, Not, ParenLeft, P...
code_fim
hard
{ "lang": "rust", "repo": "polydraw/polydraw", "path": "/src/lang/tokenizer.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: kryo4096/RostOS path: /rost_kernel/src/memory/mod.rs use consts::*; use process; use spin::{Mutex, MutexGuard, Once}; use x86_64::registers::control::{Cr3, Cr3Flags}; use x86_64::structures::paging::*; use x86_64::ux::u9; use x86_64::{PhysAddr, VirtAddr}; pub mod frame_allocator; mod map; use ...
code_fim
hard
{ "lang": "rust", "repo": "kryo4096/RostOS", "path": "/rost_kernel/src/memory/mod.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> p4().unmap(page); } pub fn map_range(start_addr: u64, end_addr: u64, flags: PageTableFlags) -> Result<(), MapToError> { let start_page = Page::<Size4KiB>::containing_address(VirtAddr::new(start_addr)); let end_page = Page::<Size4KiB>::containing_address(VirtAddr::new(end_addr)); //printl...
code_fim
hard
{ "lang": "rust", "repo": "kryo4096/RostOS", "path": "/rost_kernel/src/memory/mod.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: Kroisse/adventure path: /src/test/paginator.rs use std::marker::PhantomData; use std::sync::atomic::{AtomicUsize, Ordering}; use crate::{ paginator::Paginator, request::{PagedRequest, Request}, }; struct MockClient<T> { called: AtomicUsize, pred: Box<dyn Fn(&Numbers) -> bool>, ...
code_fim
hard
{ "lang": "rust", "repo": "Kroisse/adventure", "path": "/src/test/paginator.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> test_cases!(); } #[cfg(feature = "std-futures-test")] mod std_futures { use super::*; use futures_core::{Stream, TryStream}; use futures_executor::block_on; use futures_util::{future, stream::StreamExt, try_stream::TryStreamExt}; use crate::response::ResponseStdLocalFutureObj; ...
code_fim
hard
{ "lang": "rust", "repo": "Kroisse/adventure", "path": "/src/test/paginator.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> assert_eq!(block_on_next(&mut paginator), None); assert_eq!(numbers.current.load(Ordering::SeqCst), 3); assert_eq!(client.called.load(Ordering::SeqCst), 3); } #[test] fn paginator_step_with_error() { let client = MockClient::<Respons...
code_fim
hard
{ "lang": "rust", "repo": "Kroisse/adventure", "path": "/src/test/paginator.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|>#[pyfunction] fn sum_usize(a: usize, b: usize) -> PyResult<String> { return Ok(function::sum_as_string(a, b)); } // the name should be the same with rust project name, which is pyo3_learn in this project #[pymodule] fn pyo3_learn(_py: Python<'_>, m: &PyModule) -> PyResult<()> { m.add_function(wr...
code_fim
medium
{ "lang": "rust", "repo": "amyzx/pyo3_learn", "path": "/src/lib.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: amyzx/pyo3_learn path: /src/lib.rs use pyo3::prelude::*; use pyo3::wrap_pyfunction; pub mod function; <|fim_suffix|> m.add_function(wrap_pyfunction!(add_f64, m)?)?; m.add_function(wrap_pyfunction!(sum_usize, m)?)?; Ok(()) }<|fim_middle|>#[pyfunction] fn add_f64(x: f64, y: f64) -> f6...
code_fim
hard
{ "lang": "rust", "repo": "amyzx/pyo3_learn", "path": "/src/lib.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> return Ok(function::sum_as_string(a, b)); } // the name should be the same with rust project name, which is pyo3_learn in this project #[pymodule] fn pyo3_learn(_py: Python<'_>, m: &PyModule) -> PyResult<()> { m.add_function(wrap_pyfunction!(add_f64, m)?)?; m.add_function(wrap_pyfunction!(su...
code_fim
medium
{ "lang": "rust", "repo": "amyzx/pyo3_learn", "path": "/src/lib.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> Self { tile_dimensions: Vector3::new(16, 16, 1), tilesets: Vec::new(), sprite_sheets: HashMap::default(), map_render_mode: RegionMapRenderMode::default(), } } }<|fim_prefix|>// repo: jaynus/survival path: /core/src/settings.rs use crate:...
code_fim
hard
{ "lang": "rust", "repo": "jaynus/survival", "path": "/core/src/settings.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: jaynus/survival path: /core/src/settings.rs use crate::num_derive::FromPrimitive; use amethyst::{assets::Handle, core::math::Vector3, renderer::SpriteSheet}; use std::collections::HashMap; use std::path::PathBuf; #[derive( FromPrimitive, Debug, Copy, Clone, Hash, PartialEq, Eq, serde::Seria...
code_fim
medium
{ "lang": "rust", "repo": "jaynus/survival", "path": "/core/src/settings.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> RegionMapRenderMode::Normal } } #[derive(Clone, serde::Serialize, serde::Deserialize)] pub struct GraphicsSettings { pub tile_dimensions: Vector3<u32>, pub tilesets: Vec<(String, PathBuf)>, #[serde(skip)] pub sprite_sheets: HashMap<String, Handle<SpriteSheet>>, pub map_...
code_fim
hard
{ "lang": "rust", "repo": "jaynus/survival", "path": "/core/src/settings.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: IcyDefiance/p2p-game path: /src/p2p.rs use async_std::{ channel, channel::{Receiver, Sender}, }; use bevy::{prelude::*, tasks::IoTaskPool}; use bevy_rapier3d::prelude::*; use bincode::deserialize; use futures::{prelude::*, select}; use libp2p::{ development_transport, gossipsub::{ error::{...
code_fim
hard
{ "lang": "rust", "repo": "IcyDefiance/p2p-game", "path": "/src/p2p.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>async fn handle_swarm_event(event: Event, swarm: &mut Swarm<MyBehaviour>, download_send: &Sender<P2PEvent>) { match event { Event::MdnsEvent(event) => { if let MdnsEvent::Discovered(addrs) = event { for addr in addrs { println!("discovered {:?}", addr); swarm.dial_addr(addr.1).unwrap()...
code_fim
hard
{ "lang": "rust", "repo": "IcyDefiance/p2p-game", "path": "/src/p2p.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let message_authenticity = MessageAuthenticity::Signed(local_key.clone()); let mut gossipsub = Gossipsub::new(message_authenticity, GossipsubConfig::default()).unwrap(); gossipsub.subscribe(&topic).unwrap(); let identify = Identify::new(IdentifyConfig::new("ipfs/1.0.0".into(), local_key.public())...
code_fim
hard
{ "lang": "rust", "repo": "IcyDefiance/p2p-game", "path": "/src/p2p.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: stm32-rs/stm32-rs-nightlies path: /stm32mp1/src/stm32mp153/eth_mac_mmc/eth_macpcsr.rs #[doc = "Register `ETH_MACPCSR` reader"] pub type R = crate::R<ETH_MACPCSR_SPEC>; #[doc = "Register `ETH_MACPCSR` writer"] pub type W = crate::W<ETH_MACPCSR_SPEC>; #[doc = "Field `PWRDWN` reader - PWRDWN"] pub ...
code_fim
hard
{ "lang": "rust", "repo": "stm32-rs/stm32-rs-nightlies", "path": "/stm32mp1/src/stm32mp153/eth_mac_mmc/eth_macpcsr.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>TH_MACPCSR_SPEC, 31> { RWKFILTRST_W::new(self) } #[doc = "Writes raw bits to the register."] #[inline(always)] pub unsafe fn bits(&mut self, bits: u32) -> &mut Self { self.bits = bits; self } } #[doc = "The PMT Control and Status Register is present only when yo...
code_fim
hard
{ "lang": "rust", "repo": "stm32-rs/stm32-rs-nightlies", "path": "/stm32mp1/src/stm32mp153/eth_mac_mmc/eth_macpcsr.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: hdznrrd/kademlia-rs path: /src/key.rs use std::fmt::{Debug,Error,Formatter}; use crypto::digest::Digest; use crypto::sha1::Sha1; use rand; use rustc_serialize::{Decodable,Decoder,Encodable,Encoder}; use rustc_serialize::hex::FromHex; use ::KEY_LEN; #[derive(Hash,Ord,PartialOrd,Eq,PartialEq,Cop...
code_fim
hard
{ "lang": "rust", "repo": "hdznrrd/kademlia-rs", "path": "/src/key.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> for x in self.0.iter() { write!(f, "{0:02x}", x)?; } Ok(()) } } impl Decodable for Distance { fn decode<D: Decoder>(d: &mut D) -> Result<Distance, D::Error> { d.read_seq(|d, len| { if len != KEY_LEN { return Err(d.error("Wron...
code_fim
hard
{ "lang": "rust", "repo": "hdznrrd/kademlia-rs", "path": "/src/key.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>impl From<String> for Key { fn from(s: String) -> Key { let mut ret = [0; KEY_LEN]; for (i, byte) in s.from_hex().unwrap().iter().enumerate() { ret[i] = *byte; } Key(ret) } } impl Decodable for Key { fn decode<D: Decoder>(d: &mut D) -> Result<Key, D...
code_fim
hard
{ "lang": "rust", "repo": "hdznrrd/kademlia-rs", "path": "/src/key.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: fffreak9999/Launcher path: /src/chat.rs use std::thread; use std::sync::{Arc, Mutex}; use futures::unsync::mpsc::{unbounded, UnboundedSender, UnboundedReceiver}; use tokio_xmpp::{Client, Packet}; use xmpp_parsers::{Jid, Element, TryFrom}; use xmpp_parsers::message::{Body, MessageType}; use xmpp_...
code_fim
hard
{ "lang": "rust", "repo": "fffreak9999/Launcher", "path": "/src/chat.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let mut presence = Presence::new(PresenceType::None); presence.show = Some(PresenceShow::Chat); presence.statuses.insert(String::from("en"), String::from("Echoing messages.")); presence.into() } impl<R: FnMut(ChatEvent)> Chat<R> { pub fn new(receiver: R, username: String, password: String, serv...
code_fim
hard
{ "lang": "rust", "repo": "fffreak9999/Launcher", "path": "/src/chat.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>/// encodes an input to an html-encoded output pub fn encode(input: String) -> String { let mut output = String::new(); for chr in input.chars() { match chr { '0'..='9' | 'a'..='z' | 'A'..='Z' => { output.push(chr); }, _ => { output.push_str(&format!("#{};", chr a...
code_fim
hard
{ "lang": "rust", "repo": "fffreak9999/Launcher", "path": "/src/chat.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: mpmikulak/rust-lang path: /module1/src/main.rs // The keyword mod is used to import other modules mod rust1; // To import use the keyword use use std::mem; fn main() { // Any function with a "!" is a macro println!("Hello, world!"); // Lines must end with a semi-colon <|fim_suffix|> ...
code_fim
hard
{ "lang": "rust", "repo": "mpmikulak/rust-lang", "path": "/module1/src/main.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let double_number = 1.0; // Different sized available: f32, f64 println!("Double number = {}", double_number); println!("Size of double_number is {} bytes",mem::size_of_val(&double_number)); let my_string = "Hello, String!!"; println!("my_string = {}", my_string); }<|fim_prefix|>// re...
code_fim
hard
{ "lang": "rust", "repo": "mpmikulak/rust-lang", "path": "/module1/src/main.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>macro_rules! instr { ($instr:pat) => { Annot{ value: TokenKind::Keyword(Keyword::Instr($instr)), .. } } }<|fim_prefix|>// repo: cohyou/heliqs path: /src/util.rs #[macro_export] macro_rules! p { ($e:expr) => { println!(concat!(stringify!($e), ": {:?}"), {&$e}); }; } #[macro_export] macro_rules! p...
code_fim
medium
{ "lang": "rust", "repo": "cohyou/heliqs", "path": "/src/util.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: cohyou/heliqs path: /src/util.rs #[macro_export] macro_rules! p { ($e:expr) => { println!(concat!(stringify!($e), ": {:?}"), {&$e}); }; } #[macro_export] macro_rules! pp { ($i:expr, $e:expr) => { println!(concat!(stringify!($i), ": {:?}"), {&$e}); }; } macro_rules! la { ($this:...
code_fim
hard
{ "lang": "rust", "repo": "cohyou/heliqs", "path": "/src/util.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: RainmakerUA/mysrc path: /Rust/binpatcher/src/matching/pattern_match_iterator.rs use super::Pattern; pub struct PatternMatchIterator<'a> { source: &'a [u8], pattern: &'a Pattern, position: usize, } impl<'a> PatternMatchIterator<'a> { pub fn new(source: &'a [u8], pattern: &'a Pat...
code_fim
medium
{ "lang": "rust", "repo": "RainmakerUA/mysrc", "path": "/Rust/binpatcher/src/matching/pattern_match_iterator.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let pattern_len = self.pattern.len(); let mut current_pos = self.position; while current_pos + pattern_len < self.source.len() { let window = &self.source[current_pos .. current_pos + pattern_len]; if self.pattern.is_match(window).unwrap() { ...
code_fim
medium
{ "lang": "rust", "repo": "RainmakerUA/mysrc", "path": "/Rust/binpatcher/src/matching/pattern_match_iterator.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> println!("[rust] Calling cpp_bar_int"); let x = unsafe { mycpplib::cpp_bar_int() }; println!("[rust] cpp_bar_int returned {:?}", x); println!(""); println!("[rust] Calling cpp_foo"); let x = unsafe { mycpplib::cpp_foo(x) }; println!("[rust] cpp_foo returned {:?}", x); println!(...
code_fim
medium
{ "lang": "rust", "repo": "bfops/rust-cpp", "path": "/example/main.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: bfops/rust-cpp path: /example/main.rs extern crate libc; #[allow(dead_code)] mod mycpplib { include!(concat!(env!("OUT_DIR"), "/mycpplib.rs")); } <|fim_suffix|> println!("[rust] Calling cpp_bar_int"); let x = unsafe { mycpplib::cpp_bar_int() }; println!("[rust] cpp_bar_int returne...
code_fim
medium
{ "lang": "rust", "repo": "bfops/rust-cpp", "path": "/example/main.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: envis10n/libtelnet-rs path: /tests/tests.rs use bytes::Bytes; use libtelnet_rs::telnet::{op_command as cmd, op_option as opt}; use libtelnet_rs::vbytes; use libtelnet_rs::*; /// Test the parser and its general functionality. #[derive(PartialEq, Debug)] enum Event { IAC, NEGOTIATION, SUB...
code_fim
hard
{ "lang": "rust", "repo": "envis10n/libtelnet-rs", "path": "/tests/tests.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> let a: &[u8] = &[255, 102, 50, 65, 20]; let b: &[u8] = &[1, 2, 3]; let c: &[u8] = &[4, 5, 6, 7, 8, 9, 0]; let expected: Vec<u8> = vec![255, 102, 50, 65, 20, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]; let actual: Vec<u8> = [a, b, c].concat(); assert_eq!(expected, actual); } /// Test escaping IAC bytes in ...
code_fim
hard
{ "lang": "rust", "repo": "envis10n/libtelnet-rs", "path": "/tests/tests.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> let mut instance: Parser = Parser::with_capacity(10); instance.options.support_local(opt::GMCP); instance._will(opt::GMCP); let mut events = instance.receive( &[ &[cmd::IAC, cmd::SB, opt::GMCP][..], b"Otion.Data { some: json, data: in, here: ! }", ] .concat(), ); assert...
code_fim
hard
{ "lang": "rust", "repo": "envis10n/libtelnet-rs", "path": "/tests/tests.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: reidswan/adventofcode2019 path: /day2/src/lib.rs use common::int_code_machine::Machine; pub fn get_parsed_input()-> String { String::from(include_str!("input/input1")) } // part 1 -- what is the value in register 0 when register 1 = 12 and register 2 = 2 pub fn part1(src: &String) { pr...
code_fim
hard
{ "lang": "rust", "repo": "reidswan/adventofcode2019", "path": "/day2/src/lib.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>// parse the machine from `src`, set registers r1 and r2, run and return the // resulting register 0 value pub fn with_first_registers(machine_src: &str, r1: i128, r2: i128) -> i128 { let mut machine = Machine::new(machine_src, vec![]); machine.memory[1] = r1; machine.memory[2] = r2; machi...
code_fim
hard
{ "lang": "rust", "repo": "reidswan/adventofcode2019", "path": "/day2/src/lib.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }