text
stringlengths
232
16.3k
domain
stringclasses
1 value
difficulty
stringclasses
3 values
meta
dict
<|fim_suffix|> if irq & (1 << 57) != 0 { print!("{}", uart::getc_im() as char); uart::clear_rx(); } else if basic_irq & 1 != 0 { RpiTimer::get().clear_irq(); //Flip the OK LED if lit { Gpio.ok_on(false); lit = false; } else { ...
code_fim
hard
{ "lang": "rust", "repo": "wildarch/strontium", "path": "/src/interrupts.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|>array_init!{32, init, init, init, init, init, init, init, init, init, init, init, init, init, init, init, init, init, init, init, init, init, init, init, init, init, init, init, init, init, init, init, init,} #[cfg(test)] mod tests { use super::InitWith; #[test] fn expected() { let v...
code_fim
hard
{ "lang": "rust", "repo": "QuietMisdreavus/init-with-rs", "path": "/src/lib.rs", "mode": "spm", "license": "Unlicense", "source": "the-stack-v2" }
<|fim_prefix|>// repo: QuietMisdreavus/init-with-rs path: /src/lib.rs //! A helper trait to initialize a data structure with custom code. //! //! This crate is meant to aid in initializing fixed arrays using something other than a `Default` //! implementation. For example, if you wanted to create an array of Vecs, you...
code_fim
hard
{ "lang": "rust", "repo": "QuietMisdreavus/init-with-rs", "path": "/src/lib.rs", "mode": "psm", "license": "Unlicense", "source": "the-stack-v2" }
<|fim_suffix|> where F: FnMut() -> T, Self: Sized { [] } fn init_with_indices<F>(_: F) -> Self where F: FnMut(usize) -> T, Self: Sized { [] } } }; } mac...
code_fim
hard
{ "lang": "rust", "repo": "QuietMisdreavus/init-with-rs", "path": "/src/lib.rs", "mode": "spm", "license": "Unlicense", "source": "the-stack-v2" }
<|fim_suffix|> Self { head: None } } fn append(&self, data: T) -> Self { let new_node = Rc::new(Node { next: self.head.clone(), prev: RefCell::new(None), data, }); match self.head.clone() { Some(node) => { let mut pr...
code_fim
medium
{ "lang": "rust", "repo": "eliasyaoyc/masting-rust", "path": "/src/linked_list.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: eliasyaoyc/masting-rust path: /src/linked_list.rs use std::rc::{Rc, Weak}; use std::cell::RefCell; #[derive(Debug)] struct LinkedList<T> { head: Option<Rc<Node<T>>> } #[derive(Debug)] struct Node<T> { next: Option<Rc<Node<T>>>, prev: RefCell<Option<Weak<Node<T>>>>, data: T, } ...
code_fim
medium
{ "lang": "rust", "repo": "eliasyaoyc/masting-rust", "path": "/src/linked_list.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let mut rl: Editor<DIYHinter> = Editor::new(); rl.set_helper(Some(h)); loop { let input = rl.readline("> ")?; println!("input: {}", input); } }<|fim_prefix|>// repo: lightclient/rustyline path: /examples/diy_hints.rs use std::collections::HashSet; use rustyline::Editor; ...
code_fim
hard
{ "lang": "rust", "repo": "lightclient/rustyline", "path": "/examples/diy_hints.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> println!("This is a DIY hint hack of rustyline"); let h = DIYHinter { hints: diy_hints() }; let mut rl: Editor<DIYHinter> = Editor::new(); rl.set_helper(Some(h)); loop { let input = rl.readline("> ")?; println!("input: {}", input); } }<|fim_prefix|>// repo: lightc...
code_fim
hard
{ "lang": "rust", "repo": "lightclient/rustyline", "path": "/examples/diy_hints.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: lightclient/rustyline path: /examples/diy_hints.rs use std::collections::HashSet; use rustyline::Editor; use rustyline::{hint::Hinter, Context}; use rustyline_derive::{Completer, Helper, Highlighter, Validator}; #[derive(Completer, Helper, Validator, Highlighter)] struct DIYHinter { // It'...
code_fim
medium
{ "lang": "rust", "repo": "lightclient/rustyline", "path": "/examples/diy_hints.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: palantir/conjure-verification path: /verification-http-server/src/lib.rs // (c) Copyright 2018 Palantir Technologies Inc. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obta...
code_fim
hard
{ "lang": "rust", "repo": "palantir/conjure-verification", "path": "/verification-http-server/src/lib.rs", "mode": "psm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|>pub fn register_resource<T>(builder: &mut router::Builder, resource: &Arc<T>) where T: DynamicResource, { let mut binder = Binder::new(resource.clone(), builder, ""); binder.register_externally(DynamicResource::register); } /// Just like `Resource` but allowing the route registration access t...
code_fim
hard
{ "lang": "rust", "repo": "palantir/conjure-verification", "path": "/verification-http-server/src/lib.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|> where F: Fn(&T, &mut Request) -> Result<R> + 'static + Sync + Send, R: 'static + IntoResponse, { assert_ne!(method, Method::OPTIONS); self.route(method, route, "", f); self.route(Method::OPTIONS, route, "", |_, req| Self::options(req)); } /// To sup...
code_fim
hard
{ "lang": "rust", "repo": "palantir/conjure-verification", "path": "/verification-http-server/src/lib.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|>impl<'kvs> Visitor<'kvs> for KVAccumulator { fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error> { self.0.push_str(&format!(" {}={}", key, value)); Ok(()) } } impl Log for UdpLogger { fn enabled(&self, metadata: &Metadata<'_>) -> bool { &m...
code_fim
hard
{ "lang": "rust", "repo": "BruceBrown/udp-logger-rs", "path": "/src/lib.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> /// Provide a level specific destination address. /// /// This sets the destination address, for log messages matching the level. /// /// # Examples /// /// Log to UDP port "127.0.0.1:4040" all Info log messages. Trace and Debug messages /// will send to the default destina...
code_fim
hard
{ "lang": "rust", "repo": "BruceBrown/udp-logger-rs", "path": "/src/lib.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: BruceBrown/udp-logger-rs path: /src/lib.rs ( log!(kvs: $kvs, $crate::Level::Trace, $($arg)+); ); ($($arg:tt)+) => ( log!($crate::Level::Trace, $($arg)+); ) } /// Logs a message at the debug level. #[macro_export(local_inner_macros)] macro_rules! debug { (target:...
code_fim
hard
{ "lang": "rust", "repo": "BruceBrown/udp-logger-rs", "path": "/src/lib.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> let mut sleeve_boundary = vec![]; if !diagonals.is_empty() { let (u1, v1) = diagonals[0]; let (u2, v2) = *diagonals.last().unwrap(); sleeve_boundary = vec![ (start, poly.points[u1]), (start, pol...
code_fim
hard
{ "lang": "rust", "repo": "equation314/simple-polygon", "path": "/core/src/shortest/stepping.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: equation314/simple-polygon path: /core/src/shortest/stepping.rs use serde::Serialize; use std::collections::VecDeque; use crate::geo::{Point, Polygon}; use crate::tri::{Algorithm, Triangulation}; #[derive(Serialize, Debug)] pub struct ShortestPathStep { pub cusp: Point, pub current: Po...
code_fim
hard
{ "lang": "rust", "repo": "equation314/simple-polygon", "path": "/core/src/shortest/stepping.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> //two taps, then another key keyboard.pc(KeyCode::X, &[&[]]); keyboard.rc(KeyCode::X, &[&[]]); keyboard.pc(KeyCode::X, &[&[]]); keyboard.rc(KeyCode::X, &[&[]]); assert!(record.read().other_key_taps == 1); assert!(record.read().timeout_taps == 0); ...
code_fim
hard
{ "lang": "rust", "repo": "TyberiusPrime/KeyToKey", "path": "/src/handlers/tapdance.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> keyboard.rc(KeyCode::X, &[&[]]); assert!(record.read().other_key_taps == 0); assert!(record.read().timeout_taps == 0); keyboard.pc(KeyCode::Z, &[&[KeyCode::A], &[KeyCode::Z]]); assert!(record.read().other_key_taps == 1); assert!(record.read().timeout_taps =...
code_fim
hard
{ "lang": "rust", "repo": "TyberiusPrime/KeyToKey", "path": "/src/handlers/tapdance.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: TyberiusPrime/KeyToKey path: /src/handlers/tapdance.rs use crate::handlers::{ProcessKeys, HandlerResult}; use crate::key_codes::AcceptsKeycode; use crate::key_stream::{iter_unhandled_mut, Event, EventStatus}; use crate::USBKeyOut; use no_std_compat::prelude::v1::*; pub enum TapDanceEnd { Ti...
code_fim
hard
{ "lang": "rust", "repo": "TyberiusPrime/KeyToKey", "path": "/src/handlers/tapdance.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: Devolutions/IronRDP path: /crates/ironrdp-session/src/utils.rs #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[repr(u8)] pub enum Cod<|fim_suffix|>me(Self::RemoteFx) } else { None } } }<|fim_middle|>ecId { RemoteFx = 0x3, } impl CodecId { pub const fn from...
code_fim
medium
{ "lang": "rust", "repo": "Devolutions/IronRDP", "path": "/crates/ironrdp-session/src/utils.rs", "mode": "psm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|>me(Self::RemoteFx) } else { None } } }<|fim_prefix|>// repo: Devolutions/IronRDP path: /crates/ironrdp-session/src/utils.rs #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[repr(u8)] pub enum CodecId { RemoteFx = 0x3, } impl CodecId { pub const fn from_u8(<|fim_midd...
code_fim
medium
{ "lang": "rust", "repo": "Devolutions/IronRDP", "path": "/crates/ironrdp-session/src/utils.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|>_val(&mut conn, sess_key, "account"); if let Some(account_id) = o_account_id { let entries: Vec<EntryInfo> = db::get_entries(&mut conn, account_id.parse().unwrap()).unwrap(); let resp_html = tmpl::main::tmpl_main("Main", &entries).into_string(); let ct = "text/html"...
code_fim
hard
{ "lang": "rust", "repo": "mpietrzak/cashlog", "path": "/src/page/main.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: mpietrzak/cashlog path: /src/page/main.rs use actix_web::HttpMessage; use crate::common; use crate::db; use crate::model::EntryInfo; use crate::tmpl; pub async fn handle_main( req: actix_web::HttpRequest, pool: actix_web::web::Data<common::DatabasePool>, ) -> impl actix_web::Responder ...
code_fim
hard
{ "lang": "rust", "repo": "mpietrzak/cashlog", "path": "/src/page/main.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: comit-network/waves path: /bobtimus/src/fixed_rate.rs use crate::{LatestRate, LiquidUsdt, Rate, RateSubscription}; use std::{convert::TryFrom, time::Duration}; use tokio::{ sync::watch::{self, Receiver}, time::sleep, }; #[derive(Clone)] pub struct Service(Receiver<Rate>); impl Service ...
code_fim
hard
{ "lang": "rust", "repo": "comit-network/waves", "path": "/bobtimus/src/fixed_rate.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> pub fn subscribe(&self) -> RateSubscription { RateSubscription::from(self.0.clone()) } } impl Default for Service { fn default() -> Self { Self::new() } } impl LatestRate for Service { fn latest_rate(&mut self) -> Rate { fixed_rate() } } fn fixed_rate() -...
code_fim
hard
{ "lang": "rust", "repo": "comit-network/waves", "path": "/bobtimus/src/fixed_rate.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: frondeus/CommonDataLayer path: /crates/command-service/src/input/service/grpc.rs use log::trace; use rpc::command_service::{command_service_server::CommandService, Empty, InsertMessage}; use tonic::{Request, Response, Status}; use utils::message_types::BorrowedInsertMessage; use uuid::Uuid; us...
code_fim
medium
{ "lang": "rust", "repo": "frondeus/CommonDataLayer", "path": "/crates/command-service/src/input/service/grpc.rs", "mode": "psm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|> router .handle_message(generic_message) .await .map_err(Error::CommunicationError)?; Ok(()) } fn build_message(message: &'_ InsertMessage) -> Result<BorrowedInsertMessage<'_>, Error> { let json = &message.data; let event = Borr...
code_fim
hard
{ "lang": "rust", "repo": "frondeus/CommonDataLayer", "path": "/crates/command-service/src/input/service/grpc.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|> let event = BorrowedInsertMessage { object_id: message .object_id .parse::<Uuid>() .map_err(Error::not_valid_object_id)?, schema_id: message .schema_id .parse::<Uuid>() .map_err(...
code_fim
hard
{ "lang": "rust", "repo": "frondeus/CommonDataLayer", "path": "/crates/command-service/src/input/service/grpc.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|> fn get_file_content(&self, name: &str) -> Result<Vec<u8>, Error>; fn peek_file_content(&self, name: &str, len: usize) -> Result<Vec<u8>, Error>; fn store_file(&mut self, file_name: &str, data: &[u8]) -> Result<(), Error>; }<|fim_prefix|>// repo: krampenschiesser/idnadrev2server path: /repo...
code_fim
medium
{ "lang": "rust", "repo": "krampenschiesser/idnadrev2server", "path": "/repository/src/files/mod.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: krampenschiesser/idnadrev2server path: /repository/src/files/mod.rs use failure::Error; pub type StoredFileName = String; pub trait FileSource { fn list_repositories(&self) -> Result<Vec<StoredFileName>, Error>; <|fim_suffix|> fn peek_file_content(&self, name: &str, len: usize) -> Res...
code_fim
medium
{ "lang": "rust", "repo": "krampenschiesser/idnadrev2server", "path": "/repository/src/files/mod.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> fn peek_file_content(&self, name: &str, len: usize) -> Result<Vec<u8>, Error>; fn store_file(&mut self, file_name: &str, data: &[u8]) -> Result<(), Error>; }<|fim_prefix|>// repo: krampenschiesser/idnadrev2server path: /repository/src/files/mod.rs use failure::Error; pub type StoredFileName = ...
code_fim
medium
{ "lang": "rust", "repo": "krampenschiesser/idnadrev2server", "path": "/repository/src/files/mod.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> writer.write_all(DELIMITER)?; write_ids(writer, record.ids())?; writer.write_all(DELIMITER)?; write!(writer, "{}", record.reference_bases())?; writer.write_all(DELIMITER)?; if record.alternate_bases().is_empty() { writer.write_all(MISSING)?; } else { write!(w...
code_fim
hard
{ "lang": "rust", "repo": "zaeleus/noodles", "path": "/noodles-vcf/src/writer/record.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> Ok(()) } #[cfg(test)] mod tests { use super::*; use crate::record::Position; #[test] fn test_write_record() -> Result<(), Box<dyn std::error::Error>> { let record = Record::builder() .set_chromosome("sq0".parse()?) .set_position(Position::from(1)) ...
code_fim
hard
{ "lang": "rust", "repo": "zaeleus/noodles", "path": "/noodles-vcf/src/writer/record.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: zaeleus/noodles path: /noodles-vcf/src/writer/record.rs mod chromosome; mod filters; mod genotypes; mod ids; mod info; mod quality_score; use std::io::{self, Write}; use self::{ chromosome::write_chromosome, filters::write_filters, genotypes::write_genotypes, ids::write_ids, info::writ...
code_fim
hard
{ "lang": "rust", "repo": "zaeleus/noodles", "path": "/noodles-vcf/src/writer/record.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|>n + 2^(0の個数) - 1 + 1 + 2^(1の個数-1) - 1となる. 前の値も同様に求められる. */ fn main() {}<|fim_prefix|>// repo: sh0623k/coding_interview path: /src/bin/ch05p04.rs /* 3つのステップに分ける. 最下位ビットから連続する0以外の最も右の0を反転→反転したビットの右の1の個数を数えてクリア→右から1の個数分<|fim_middle|>1を埋める. 下のように,算術的にも解くことができる. 反転→クリアするときは,最下位ビットから連続する0をすべて1にするため,2^(0の...
code_fim
medium
{ "lang": "rust", "repo": "sh0623k/coding_interview", "path": "/src/bin/ch05p04.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: sh0623k/coding_interview path: /src/bin/ch05p04.rs /* 3つのステップに分ける. 最下位ビットから連続する0以外の最も右の0を反転→反転したビットの右の1の個数を数えてクリア→右から1の個数分<|fim_suffix|>n + 2^(0の個数) - 1 + 1 + 2^(1の個数-1) - 1となる. 前の値も同様に求められる. */ fn main() {}<|fim_middle|>1を埋める. 下のように,算術的にも解くことができる. 反転→クリアするときは,最下位ビットから連続する0をすべて1にするため,2^(0の...
code_fim
medium
{ "lang": "rust", "repo": "sh0623k/coding_interview", "path": "/src/bin/ch05p04.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: Zalasus/fltk-rs path: /examples/rgb.rs use fltk::*; fn main() { let app = app::App::default(); let mut wind = window::Window::new(100, 100, 400, 300, "Hello from rust"); let mut frame = frame::Frame::new(0, 0, 400, 300, ""); let v: Vec<u32> = (0..128 * 128) .map(|i| { ...
code_fim
medium
{ "lang": "rust", "repo": "Zalasus/fltk-rs", "path": "/examples/rgb.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|>^ y }) .collect(); let v: Vec<u8> = v.into_iter().map(|i| i as u8).collect(); let mut image = image::RgbImage::new(&v, 128, 128, 1).unwrap(); image.scale(200, 200, true, true); frame.set_image(Some(image)); wind.make_resizable(true); wind.end(); wind.show(); ...
code_fim
medium
{ "lang": "rust", "repo": "Zalasus/fltk-rs", "path": "/examples/rgb.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: cohyou/wasmiq path: /src/parser/typeuse_parser.rs use crate::{ TypeIdx, FuncType, }; // use crate::instr::*; use super::*; impl<R> Parser<R> where R: Read + Seek { pub(super) fn parse_typeuse(&mut self, params: &mut Vec<ValType>, results: &mut Vec<ValType>) -> Result<TypeIdx, Parse...
code_fim
hard
{ "lang": "rust", "repo": "cohyou/wasmiq", "path": "/src/parser/typeuse_parser.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> Ok(res) } pub(super) fn parse_param(&mut self) -> Result<ValType, ParseError> { self.match_keyword(Keyword::Param)?; // param id let len = self.contexts.len(); if let tk!(TokenKind::Id(s)) = &self.lookahead { if len > 1 { ...
code_fim
hard
{ "lang": "rust", "repo": "cohyou/wasmiq", "path": "/src/parser/typeuse_parser.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> let data = "{}"; let data: Example = serde_json::from_str(data).unwrap(); assert_eq!(7, data.data1); assert_eq!(false, data.data2); assert_eq!("Hello", data.data3); }<|fim_prefix|>// repo: boringcactus/serde-piecewise-default path: /tests/named_fields.rs use serde_piecewise_default::*...
code_fim
hard
{ "lang": "rust", "repo": "boringcactus/serde-piecewise-default", "path": "/tests/named_fields.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: boringcactus/serde-piecewise-default path: /tests/named_fields.rs use serde_piecewise_default::*; use serde::Deserialize; extern crate serde_json; #[derive(DeserializePiecewiseDefault)] struct Example { data1: u8, data2: bool, data3: String, } <|fim_suffix|>#[test] fn full() { ...
code_fim
medium
{ "lang": "rust", "repo": "boringcactus/serde-piecewise-default", "path": "/tests/named_fields.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: mesalock-linux/crates-io path: /vendor/rocket_codegen/src/lib.rs ormValue, attributes(form))] pub fn derive_from_form_value(input: TokenStream) -> TokenStream { emit!(derive::from_form_value::derive_from_form_value(input)) } /// Derive for the [`FromForm`] trait. /// /// The [`FromForm`] de...
code_fim
hard
{ "lang": "rust", "repo": "mesalock-linux/crates-io", "path": "/vendor/rocket_codegen/src/lib.rs", "mode": "psm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|>/// Derive for the [`FromFormValue`] trait. /// /// The [`FromFormValue`] derive can be applied to enums with nullary /// (zero-length) fields: /// /// ```rust /// # #[macro_use] extern crate rocket; /// # /// #[derive(FromFormValue)] /// enum MyValue { /// First, /// Second, /// Third, /// } ...
code_fim
hard
{ "lang": "rust", "repo": "mesalock-linux/crates-io", "path": "/vendor/rocket_codegen/src/lib.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_prefix|>// repo: alessandrostranieri/cs_algorithms_rust path: /src/binary_search.rs pub mod search { pub fn binary_search<T: PartialOrd>(nums: &Vec<T>, target: T) -> Option<usize> { if nums.is_empty() { return None; } let mut start = 0usize; let mut end = nums.len...
code_fim
hard
{ "lang": "rust", "repo": "alessandrostranieri/cs_algorithms_rust", "path": "/src/binary_search.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> #[test] fn test_unsuccessful_start() { assert_eq!(binary_search(&vec![1, 42, 69, 100], 0), None); } #[test] fn test_unsuccessful_end() { assert_eq!(binary_search(&vec![1, 42, 69, 100], 101), None); } }<|fim_prefix|>// repo: alessandrostranieri/cs_algorithms_rust p...
code_fim
hard
{ "lang": "rust", "repo": "alessandrostranieri/cs_algorithms_rust", "path": "/src/binary_search.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> for mv in moves.iter() { results.push(intmove_to_uci_ascii(*mv)); } assert!(!results.contains(&String::from("f6g8"))); assert!(results.contains(&String::from("g8f6"))); } }<|fim_prefix|>// repo: wjzz/chess-in-rust path: /tests/test_intmove.rs use rust_chess...
code_fim
hard
{ "lang": "rust", "repo": "wjzz/chess-in-rust", "path": "/tests/test_intmove.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: wjzz/chess-in-rust path: /tests/test_intmove.rs use rust_chess::Position; use rust_chess::*; #[cfg(test)] mod test_moves { use super::*; #[test] fn test_conv() { let fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"; let mut pos = Position::from_fen(...
code_fim
hard
{ "lang": "rust", "repo": "wjzz/chess-in-rust", "path": "/tests/test_intmove.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: manuel-woelker/topd path: /src/sensors/disk.rs use time::{PreciseTime}; use std::io; use std::io::prelude::*; use std::fs::File; use std::collections::HashMap; pub struct DiskSensor { last_measurement_time: PreciseTime , last_measurement: HashMap<String, u64>, } <|fim_suffix|> let file = F...
code_fim
hard
{ "lang": "rust", "repo": "manuel-woelker/topd", "path": "/src/sensors/disk.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let file = File::open("/proc/diskstats").unwrap(); let mut reader = io::BufReader::new(file); let mut result = HashMap::new(); loop { let mut line = String::new(); if let Ok(_) = reader.read_line(&mut line) { if line.len() == 0 { break; } let current_measurement: Vec<&str> =...
code_fim
hard
{ "lang": "rust", "repo": "manuel-woelker/topd", "path": "/src/sensors/disk.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: cjschneider2/novluno path: /core_compat/src/entity/map.rs use crate::entity::event::Event; use crate::entity::map_tile::MapTile; #[derive(Debug)] pub struct Map { pub size_x: u32, pub size_y: u32, pub id_count: u8, pub id_list: Vec<u8>, pub name: String, pub ...
code_fim
hard
{ "lang": "rust", "repo": "cjschneider2/novluno", "path": "/core_compat/src/entity/map.rs", "mode": "psm", "license": "Unlicense", "source": "the-stack-v2" }
<|fim_suffix|> pub fn size_y(&self) -> u32 { self.size_y } pub fn tiles(&self) -> &[MapTile] { &self.tiles } pub fn tile_count(&self) -> usize { self.tiles.len() } pub fn get_tile(&self, index: usize) -> Option<&MapTile> { self.tiles.get(index) ...
code_fim
hard
{ "lang": "rust", "repo": "cjschneider2/novluno", "path": "/core_compat/src/entity/map.rs", "mode": "spm", "license": "Unlicense", "source": "the-stack-v2" }
<|fim_suffix|> // Prints the memory address println!("{ref}'s address {ref:p}", ref=&42); // Print does not accept variables in place of the format string // This fails to compile: // let some_string = "Some string"; // println!(some_string); println!("======= END EXAMPLES ======="); }<...
code_fim
medium
{ "lang": "rust", "repo": "lmansur/rust", "path": "/string_formatting/str_formatting.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: lmansur/rust path: /string_formatting/str_formatting.rs fn main() { println!("======= BEGIN EXAMPLES ======="); // Standard printing println!("Hello, world!"); // Printing with parameters println!("{}, {}", "Hello", "world!"); // Printing with named parameters. The orde...
code_fim
hard
{ "lang": "rust", "repo": "lmansur/rust", "path": "/string_formatting/str_formatting.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> // Print does not accept variables in place of the format string // This fails to compile: // let some_string = "Some string"; // println!(some_string); println!("======= END EXAMPLES ======="); }<|fim_prefix|>// repo: lmansur/rust path: /string_formatting/str_formatting.rs fn ma...
code_fim
hard
{ "lang": "rust", "repo": "lmansur/rust", "path": "/string_formatting/str_formatting.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>fn last_digit(n: i64) -> u8 { (n % 10).abs() as u8 } fn half_round(buf: &mut [u8]) { let mut total = buf.iter().map(|it| *it as i64).sum::<i64>(); for digit in buf.iter_mut() { let d = *digit; *digit = last_digit(total); total -= d as i64 } } #[test] fn test_examp...
code_fim
hard
{ "lang": "rust", "repo": "matklad/aoc2019", "path": "/src/bin/day16.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>#[test] fn test_examples() { assert_eq!(solve("80871224585914546619083218645595"), "24176176"); assert_eq!(solve("19617804207202209144916044189917"), "73745418"); assert_eq!(solve("69317163492948606335995924319873"), "52432133"); assert_eq!(solve2("03036732577212944063491565474664"), "844...
code_fim
hard
{ "lang": "rust", "repo": "matklad/aoc2019", "path": "/src/bin/day16.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: matklad/aoc2019 path: /src/bin/day16.rs use std::{iter::repeat, mem::swap}; use aoc::{read_stdin_to_string, Result}; fn main() -> Result<()> { let input = read_stdin_to_string()?; let input = input.trim(); eprintln!("{}", solve2(input)); Ok(()) } fn to_digits(input: &str) -> V...
code_fim
hard
{ "lang": "rust", "repo": "matklad/aoc2019", "path": "/src/bin/day16.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let mut ans = 0i64; // 查找0符合的位置 let chars: Vec<char> = s.chars().collect(); for (i, &c) in chars.iter().enumerate() { if i == 0 { if c == 'I' { // 符合要求 ans += Self::l903_f(&s[1..], C, rem); ...
code_fim
hard
{ "lang": "rust", "repo": "qinxiaoguang/rs-lc", "path": "/src/solution/l903.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: qinxiaoguang/rs-lc path: /src/solution/l903.rs use super::Solution; impl Solution { pub fn num_perms_di_sequence(s: String) -> i32 { // 先放0, 0左侧及右侧,都可以随便分配及排列 // 所以优先找0适合的位置,0左侧有待分配的i个数,右侧有待分配的j个数,f(i)表示i个数的排列个数 // 那么res = C(i+j, i)*f(i) * f(j), C是组合数 // 0的位置...
code_fim
hard
{ "lang": "rust", "repo": "qinxiaoguang/rs-lc", "path": "/src/solution/l903.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let MOD = 1000000007; if rem.contains_key(s) { return *rem.get(s).unwrap(); } let mut l = s.len(); if l == 0 || l == 1 { return 1; } let mut ans = 0i64; // 查找0符合的位置 let chars: Vec<char> = s.chars().collect(); ...
code_fim
hard
{ "lang": "rust", "repo": "qinxiaoguang/rs-lc", "path": "/src/solution/l903.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|>= pos as i32 > max / 2; ring.insert(pos + 1, x1); ring.insert(pos + 2, x2); ring.insert(pos + 3, x3); // ring.rotate_left(pos + 1); // ring.push_front(x3); // ring.push_front(x2); // ring.push_front(x1); // ring.rotate_right(pos + 1); ...
code_fim
hard
{ "lang": "rust", "repo": "nanabear0/aoc2020", "path": "/day23/src/main.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: nanabear0/aoc2020 path: /day23/src/main.rs use std::{collections::VecDeque, time::SystemTime}; use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator}; fn main() { // let max = 9; let max = 1_000_000; let mut ring = "394618527" .chars() ...
code_fim
hard
{ "lang": "rust", "repo": "nanabear0/aoc2020", "path": "/day23/src/main.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: algermissen/tokio-process-pipes path: /src/main.rs extern crate tokio_io; extern crate tokio_process; extern crate futures; extern crate tokio_core; use tokio_core::reactor::Core; use tokio_core::reactor::Handle; use tokio_process::CommandExt; use tokio_io::io::lines; use futures::Stream; use s...
code_fim
hard
{ "lang": "rust", "repo": "algermissen/tokio-process-pipes", "path": "/src/main.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> // Make sure the child process survives the call to the 'child' variable destructor // If we did not call this, child process would be killed if cmd_stdout(..) returns. child.forget(); Box::new(stream) } fn main() { let mut core = Core::new().unwrap(); let handle = core.handle()...
code_fim
hard
{ "lang": "rust", "repo": "algermissen/tokio-process-pipes", "path": "/src/main.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|>pub struct Actor<K: Kernel> { pub id: K::Token, task: Task<K>, inbox: Receiver<Event<K>>, inbox_buf: Vec<Event<K>>, } impl<K: Kernel> Actor<K> { pub fn create(task: Task<K>) -> (Sender<Event<K>>, Self) { let (sender, receiver) = mpsc::channel(); let actor = Actor { ...
code_fim
medium
{ "lang": "rust", "repo": "HyeonuPark/Flock", "path": "/src/actor.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: HyeonuPark/Flock path: /src/actor.rs use std::sync::mpsc::{self, Sender, Receiver}; use kernel::Kernel; use event::{Event, EventId, Request}; pub type Task<K> = Box<(FnMut(&[Event<K>]) -> Option<Request<K>>) + Send>; pub struct Actor<K: Kernel> { pub id: K::Token, task: Task<K>, i...
code_fim
medium
{ "lang": "rust", "repo": "HyeonuPark/Flock", "path": "/src/actor.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: matter-labs/zksync path: /core/bin/zksync_witness_generator/src/scaler.rs //! Module with utilities for prover scaler service. // Workspace deps use crate::database_interface::DatabaseInterface; /// Scaler oracle provides information for prover scaler /// service about required amount of prover...
code_fim
hard
{ "lang": "rust", "repo": "matter-labs/zksync", "path": "/core/bin/zksync_witness_generator/src/scaler.rs", "mode": "psm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|> let mut storage = self.db.acquire_connection().await?; let pending_jobs = self.db.pending_jobs_count(&mut storage).await?; let provers_required = std::cmp::max(pending_jobs, self.idle_provers); Ok(provers_required) } }<|fim_prefix|>// repo: matter-labs/zksync path: /c...
code_fim
hard
{ "lang": "rust", "repo": "matter-labs/zksync", "path": "/core/bin/zksync_witness_generator/src/scaler.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_prefix|>// repo: redox-os/calc path: /src/parse.rs use crate::error::CalcError; use crate::token::*; use crate::value::{Value, IR}; use decimal::d128; use rand::Rng; const RECURSION_LIMIT: usize = 10; /// Represents an environment for evaluating a mathematical expression pub trait Environment { /// Look up...
code_fim
hard
{ "lang": "rust", "repo": "redox-os/calc", "path": "/src/parse.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> use super::*; #[test] fn unary_minus() { let expr = [ Token::Minus, Token::Number(Value::dec(1)), Token::Plus, Token::Number(Value::dec(1)), ]; let expected = Value::dec(0); let mut env = DefaultEnvironment::new()...
code_fim
hard
{ "lang": "rust", "repo": "redox-os/calc", "path": "/src/parse.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> // println!("deleted /test -> {:?}", delete); println!("press enter to close client"); io::stdin().read_line(&mut tmp).unwrap(); // The client can be shared between tasks let zk2 = zk.clone(); thread::spawn(move || { zk2.close(); // And operations return error af...
code_fim
hard
{ "lang": "rust", "repo": "tempbottle/rust-zookeeper", "path": "/examples/zookeeper_example.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: tempbottle/rust-zookeeper path: /examples/zookeeper_example.rs #![feature(duration)] extern crate zookeeper; #[macro_use] extern crate log; extern crate log4rs; use std::time::Duration; use std::thread; use std::io; use zookeeper::{Acl, CreateMode, Watcher, WatchedEvent, ZooKeeper}; use zookeep...
code_fim
hard
{ "lang": "rust", "repo": "tempbottle/rust-zookeeper", "path": "/examples/zookeeper_example.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> println!("press enter to close client"); io::stdin().read_line(&mut tmp).unwrap(); // The client can be shared between tasks let zk2 = zk.clone(); thread::spawn(move || { zk2.close(); // And operations return error after closed match zk.exists("/test", false) ...
code_fim
hard
{ "lang": "rust", "repo": "tempbottle/rust-zookeeper", "path": "/examples/zookeeper_example.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> if options.should_format { // TODO: This doesn't work with 'cross' let res = Command::new("rustfmt").arg(output_path.as_str()).output()?; if !res.status.success() { std::io::stdout().write_all(&res.stdout).unwrap(); std::io::stder...
code_fim
hard
{ "lang": "rust", "repo": "dennisss/dacha", "path": "/pkg/protobuf/compiler/src/build.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|> let mut output_path = output_dir.join(relative_path); output_path.set_extension("rs"); std::fs::create_dir_all(output_path.parent().unwrap())?; let output = Compiler::compile(&desc, &input_path, current_package_name, &options)?; std::fs::write(&output_path, output...
code_fim
hard
{ "lang": "rust", "repo": "dennisss/dacha", "path": "/pkg/protobuf/compiler/src/build.rs", "mode": "spm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_prefix|>// repo: dennisss/dacha path: /pkg/protobuf/compiler/src/build.rs use std::io::Write; use std::process::Command; use common::errors::*; use file::{LocalPath, LocalPathBuf}; use crate::compiler::{Compiler, CompilerOptions}; use crate::syntax::parse_proto; // TODO: Most of this code is identical across ...
code_fim
hard
{ "lang": "rust", "repo": "dennisss/dacha", "path": "/pkg/protobuf/compiler/src/build.rs", "mode": "psm", "license": "Apache-2.0", "source": "the-stack-v2" }
<|fim_suffix|> let computer = thread::spawn(move || { for noun in 0..100 { for verb in 0..100 { let mut mem = memory.clone(); mem[1] = noun; mem[2] = verb; let mut i = 0; while i < mem.len() { let ...
code_fim
hard
{ "lang": "rust", "repo": "EliTheCreator/AdventOfCode", "path": "/2019/day02/src/main.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: EliTheCreator/AdventOfCode path: /2019/day02/src/main.rs use std::fs; use std::thread; fn task1() { let file = fs::read_to_string("input").expect("Unable to read the file"); let mut memory: Vec<usize> = file .split_terminator(",") .filter_map(|x| x.parse::<usize>().ok())...
code_fim
hard
{ "lang": "rust", "repo": "EliTheCreator/AdventOfCode", "path": "/2019/day02/src/main.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: ankurdelight/osrank-rs path: /src/importers/gephi_json.rs extern crate num_traits; extern crate oscoin_graph_api; extern crate serde; extern crate serde_json; use crate::types::network::{ArtifactType, DependencyType, Network}; use crate::types::Weight; use num_traits::Zero; use oscoin_graph_api...
code_fim
medium
{ "lang": "rust", "repo": "ankurdelight/osrank-rs", "path": "/src/importers/gephi_json.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> for (ix, edge) in edges.iter().enumerate() { //FIXME(adn) This should take into account normalisation and //redistribution of the weights etc. let depends_on = DependencyType::Depend(Weight::new(1, 1)); network.add_edge( ix, &edge.s.to_string(), ...
code_fim
hard
{ "lang": "rust", "repo": "ankurdelight/osrank-rs", "path": "/src/importers/gephi_json.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> fn part2(input: &Vec<BagRule>) -> usize { let target = String::from("shiny gold"); let trees = build_trees(input); let filtered: Vec<Bag> = trees.into_iter().filter(|b| b.color == target).collect(); let tree = filtered.get(0).expect("Bag should be present"); ...
code_fim
hard
{ "lang": "rust", "repo": "bmitchelmore/aoc2020", "path": "/src/day7/mod.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> fn part1(input: &Vec<BagRule>) -> usize { let target = String::from("shiny gold"); let trees = build_trees(input); let filtered: Vec<Bag> = trees.into_iter().filter(|b| b.contains(&target)).collect(); filtered.len() } fn part2(input: &Vec<BagRule>) -> us...
code_fim
hard
{ "lang": "rust", "repo": "bmitchelmore/aoc2020", "path": "/src/day7/mod.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: bmitchelmore/aoc2020 path: /src/day7/mod.rs use std::fs::File; use std::collections::HashMap; use std::io::{BufRead, BufReader}; use regex::Regex; use super::Day; #[derive(Debug)] pub struct BagRule { color: String, contains: Vec<(u32,String)> } #[derive(Debug)] pub struct...
code_fim
hard
{ "lang": "rust", "repo": "bmitchelmore/aoc2020", "path": "/src/day7/mod.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_prefix|>// repo: jbiason/random path: /ms/txtclient/src/main.rs use tokio::io::AsyncReadExt; use tokio::net::TcpStream; use shared::Message; <|fim_suffix|> let mut stream = TcpStream::connect("127.0.0.1:4435") .await .expect("Failed to connect to server"); loop { let mut buffer =...
code_fim
medium
{ "lang": "rust", "repo": "jbiason/random", "path": "/ms/txtclient/src/main.rs", "mode": "psm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> let mut stream = TcpStream::connect("127.0.0.1:4435") .await .expect("Failed to connect to server"); loop { let mut buffer = [0; 1024]; let bytes = stream.read(&mut buffer).await.expect("Failed to read data"); let decoded: Message = bincode::dese...
code_fim
medium
{ "lang": "rust", "repo": "jbiason/random", "path": "/ms/txtclient/src/main.rs", "mode": "spm", "license": "unknown", "source": "the-stack-v2" }
<|fim_suffix|> data.eci = ds.take_bits(8); if (data.eci & 0xc0) == 0x80 { if ds.bits_remaining() < 8 { return QuircDecodeError::QuircErrorDataUnderflow; } data.eci = (data.eci << 8) | ds.take_bits(8); } else if (data.eci & 0xe0) == 0xc0 { if ds.bits_remaining() <...
code_fim
hard
{ "lang": "rust", "repo": "nabijaczleweli/quirc-rs-impl", "path": "/src/util/decode/decoder.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: nabijaczleweli/quirc-rs-impl path: /src/util/decode/decoder.rs //! Decoder algorithm pub use self::super::super::super::constants::{QUIRC_DATA_TYPE_NUMERIC, QUIRC_DATA_TYPE_ALPHA, QUIRC_DATA_TYPE_KANJI, QUIRC_DATA_TYPE_BYTE, QUIRC_MAX_PAYLOAD}; use self::super::super::super::ops::version_db::{...
code_fim
hard
{ "lang": "rust", "repo": "nabijaczleweli/quirc-rs-impl", "path": "/src/util/decode/decoder.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> QuircDecodeError::QuircSuccess } pub fn alpha_tuple(data: &mut QuircData, ds: &mut Datastream, bits: usize, digits: usize) -> bool { if ds.bits_remaining() < bits { return true; } let mut tuple = ds.take_bits(bits); for i in 0..digits { static ALPHA_MAP: &[u8] = b"01...
code_fim
hard
{ "lang": "rust", "repo": "nabijaczleweli/quirc-rs-impl", "path": "/src/util/decode/decoder.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: mechtronium/wasm_membrane path: /host/rust/wasm_membrane_host/src/membrane.rs use std::sync::{Arc, RwLock, Weak}; use crate::error::Error; use wasmer::{Module, Instance, WasmPtr, Array, WasmerEnv, imports, Function, RuntimeError}; pub static VERSION: i32 = 1; pub struct WasmMembrane { pu...
code_fim
hard
{ "lang": "rust", "repo": "mechtronium/wasm_membrane", "path": "/host/rust/wasm_membrane_host/src/membrane.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> { host.write().unwrap().membrane = Option::Some(Arc::downgrade(&membrane)); } return Ok(membrane); } } pub struct BufferLock { id: i32, membrane: Arc<WasmMembrane> } impl BufferLock { pub fn new( id: i32, membrane: Arc<WasmMembrane> )->Self { ...
code_fim
hard
{ "lang": "rust", "repo": "mechtronium/wasm_membrane", "path": "/host/rust/wasm_membrane_host/src/membrane.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> fn get_buffer_ptr( &self, buffer_id: i32 )->Result<WasmPtr<u8,Array>,Error> { Ok(self.instance.exports.get_native_function::<i32, WasmPtr<u8, Array>>("membrane_guest_get_buffer_ptr").unwrap().call(buffer_id)?) } pub fn read_buffer(&self, buffer_id: i32 ) ->Result<Vec<u8>,Error> ...
code_fim
hard
{ "lang": "rust", "repo": "mechtronium/wasm_membrane", "path": "/host/rust/wasm_membrane_host/src/membrane.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> self.stream.send(Accepted(connection.clone())); } fn received(&mut self, _connection: &mut TcpConnection, data: Vec<u8>) { self.stream.send(Received(data)); } fn closed(&mut self, connection: &mut TcpConnection) { self.stream.send(Closed(connection.clone())); ...
code_fim
hard
{ "lang": "rust", "repo": "samsung-ads-grave-yard/mini-rs", "path": "/examples/chat_server.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> fn received(&mut self, _connection: &mut TcpConnection, data: Vec<u8>) { self.stream.send(Received(data)); } fn closed(&mut self, connection: &mut TcpConnection) { self.stream.send(Closed(connection.clone())); } } fn main() { let mut event_loop = Loop::new().expect("e...
code_fim
hard
{ "lang": "rust", "repo": "samsung-ads-grave-yard/mini-rs", "path": "/examples/chat_server.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: samsung-ads-grave-yard/mini-rs path: /examples/chat_server.rs extern crate mini; use std::os::unix::io::AsRawFd; use std::net; use mini::aio::handler::{ Handler, Loop, Stream, }; use mini::aio::net::{ TcpConnection, TcpConnectionNotify, TcpListenNotify, }; use mini::aio...
code_fim
hard
{ "lang": "rust", "repo": "samsung-ads-grave-yard/mini-rs", "path": "/examples/chat_server.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_prefix|>// repo: braeutigamj/rumq path: /rumq-client/src/state_persistence.rs use crate::MqttState; use std::iter::FromIterator; use rumq_core::*; use serde::{Serialize, Deserialize}; use std::collections::VecDeque; use tokio::fs; use async_trait::async_trait; // State persistence interface #[async_trait] pub...
code_fim
hard
{ "lang": "rust", "repo": "braeutigamj/rumq", "path": "/rumq-client/src/state_persistence.rs", "mode": "psm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|>#[derive(Serialize, Deserialize)] struct PublishData { dup: bool, qos: QoSData, retain: bool, topic_name: String, pkid: Option<PacketIdentifierData>, payload: Vec<u8>, } #[derive(Serialize, Deserialize)] struct StateData { last_pkid: PacketIdentifierData, outgoing_pub: Vec...
code_fim
hard
{ "lang": "rust", "repo": "braeutigamj/rumq", "path": "/rumq-client/src/state_persistence.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|> loop { // Run through 25 colours (0 to 250 into the colour wheel). for i in 0..25 { let drop = wheel(i * 10); // Pulse the colour along the LED chain excluding the final LED. for led in 0..11 { for j in 0....
code_fim
hard
{ "lang": "rust", "repo": "pace-noge/peautkb", "path": "/firmware/examples/adam_led.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }
<|fim_suffix|>// Colour wheel from https://github.com/smart-leds-rs/smart-leds-samples fn wheel(mut wheel_pos: u8) -> RGB8 { wheel_pos = 255 - wheel_pos; if wheel_pos < 85 { return (255 - wheel_pos * 3, 0, wheel_pos * 3).into(); } if wheel_pos < 170 { wheel_pos -= 85; return (0, ...
code_fim
hard
{ "lang": "rust", "repo": "pace-noge/peautkb", "path": "/firmware/examples/adam_led.rs", "mode": "spm", "license": "MIT", "source": "the-stack-v2" }