text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_prefix|>// repo: distransient/specs-physics path: /src/joints/set.rs
use crate::{
joints::JointComponent,
nalgebra::RealField,
nphysics::{
joint::{JointConstraint, JointConstraintSet as NJointConstraintSet},
object::BodyPartHandle,
},
};
use specs::{
shred::{Fetch, FetchMut, ... | code_fim | hard | {
"lang": "rust",
"repo": "distransient/specs-physics",
"path": "/src/joints/set.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn contains(&self, handle: Entity) -> bool {
self.storage.contains(handle)
}
fn foreach(&self, mut f: impl FnMut(Entity, &dyn JointConstraint<N, Entity>)) {
for (entity, joint) in (&self.entities, &self.storage).join() {
f(entity, joint.0.as_ref())
}
}
... | code_fim | hard | {
"lang": "rust",
"repo": "distransient/specs-physics",
"path": "/src/joints/set.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> vec![ResourceId::new::<EntitiesRes>()]
}
fn writes() -> Vec<ResourceId> {
vec![
ResourceId::new::<MaskedStorage<JointComponent<N>>>(),
ResourceId::new::<JointReaderRes>(),
ResourceId::new::<JointInsertionRes>(),
ResourceId::new::<Joi... | code_fim | hard | {
"lang": "rust",
"repo": "distransient/specs-physics",
"path": "/src/joints/set.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// The upper time bound.
pub fn upper(&self) -> &Option<UnixTimestamp> {
&self.upper
}
}<|fim_prefix|>// repo: imerkle/shuttle-core path: /src/time_bounds.rs
/// Unix timestamp. Number of seconds since epoch.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct UnixTime... | code_fim | medium | {
"lang": "rust",
"repo": "imerkle/shuttle-core",
"path": "/src/time_bounds.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: imerkle/shuttle-core path: /src/time_bounds.rs
/// Unix timestamp. Number of seconds since epoch.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct UnixTimestamp(pub i64);
/// A time range for the validity of an operation.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TimeB... | code_fim | hard | {
"lang": "rust",
"repo": "imerkle/shuttle-core",
"path": "/src/time_bounds.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Ashci42/pass-gen path: /pass_gen_core/src/lib.rs
//! Password strength checker
//!
//! The checker returns one of the following strengths:
//! `VeryWeak`, `Weak`, `Medium`, `Strong`, `VeryStrong`.
//! The password is evaluated on length and the characters it contains.
<|fim_suffix|>pub use chec... | code_fim | easy | {
"lang": "rust",
"repo": "Ashci42/pass-gen",
"path": "/pass_gen_core/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub use check_pass::{check_pass, PassStrength};
pub use gen_pass::{gen_pass, gen_pass_default, PassOptions};<|fim_prefix|>// repo: Ashci42/pass-gen path: /pass_gen_core/src/lib.rs
//! Password strength checker
//!
//! The checker returns one of the following strengths:
//! `VeryWeak`, `Weak`, `Medium`, `... | code_fim | easy | {
"lang": "rust",
"repo": "Ashci42/pass-gen",
"path": "/pass_gen_core/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: baitcenter/mathbench-rs path: /benches/support/macros.rs
#[macro_export]
macro_rules! bench_func {
($b: ident, op => $func: ident, ty => $t: ty) => {{
const LEN: usize = 1 << 13;
let elems = <$t as mathbench::RandomVec>::random_vec(0, LEN);
let mut i = 0;
$b.i... | code_fim | hard | {
"lang": "rust",
"repo": "baitcenter/mathbench-rs",
"path": "/benches/support/macros.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[macro_export]
macro_rules! bench_binop {
($b: ident, op => $binop: ident, ty1 => $ty1:ty, ty2 => $ty2:ty, param => $param:tt) => {{
const LEN: usize = 1 << 7;
let elems1 = <$ty1 as mathbench::RandomVec>::random_vec(0, LEN);
let elems2 = <$ty2 as mathbench::RandomVec>::random_... | code_fim | medium | {
"lang": "rust",
"repo": "baitcenter/mathbench-rs",
"path": "/benches/support/macros.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: nola-suz/Procon path: /Atcoder/abc168/src/bin/d.rs
use proconio::*;
use std::collections::VecDeque;
fn main() {
input!{
n: usize,
m: usize,
ab: [(usize, usize); m],
}
let mut g = vec![Vec::<usize>::new(); n];
for (a, b) in ab {
g[a-1].push(b-1);... | code_fim | hard | {
"lang": "rust",
"repo": "nola-suz/Procon",
"path": "/Atcoder/abc168/src/bin/d.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> println!("Yes");
for (i, x) in ans.iter().enumerate() {
if i == 0 {
continue;
}
println!("{}", *x + 1);
}
}<|fim_prefix|>// repo: nola-suz/Procon path: /Atcoder/abc168/src/bin/d.rs
use proconio::*;
use std::collections::VecDeque;
fn main() {
input!{
... | code_fim | hard | {
"lang": "rust",
"repo": "nola-suz/Procon",
"path": "/Atcoder/abc168/src/bin/d.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut caps = CapConfig::new().unwrap();
caps.set_caps(CapType::Ambient, whitelist).unwrap();
caps.set_caps(CapType::Bounding, whitelist).unwrap();
caps.set_caps(CapType::Effective, whitelist).unwrap();
caps.set_caps(CapType::Inheritable, whitelist).unwrap();
caps.set_caps(CapType... | code_fim | medium | {
"lang": "rust",
"repo": "dgreid/run_container",
"path": "/caps/examples/drop_caps.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dgreid/run_container path: /caps/examples/drop_caps.rs
extern crate caps;
extern crate libc;
use caps::{CapConfig, CapType};
use std::ffi::CString;
use std::os::raw::c_char;
fn show_usage(arg0: &str) {
println!("Run a given program with only whitelisted capabilities.");
println!("Usag... | code_fim | medium | {
"lang": "rust",
"repo": "dgreid/run_container",
"path": "/caps/examples/drop_caps.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let pargs = &args[(div_index + 1)..];
let path = CString::new(pargs[0].clone()).unwrap();
let mut argvec: Vec<CString> = Vec::new();
for arg in pargs[..].iter() {
argvec.push(CString::new(arg.clone()).unwrap());
}
let args_p = to_exec_array(&argvec[..]);
unsafe {
... | code_fim | hard | {
"lang": "rust",
"repo": "dgreid/run_container",
"path": "/caps/examples/drop_caps.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: wITTus/cgol path: /src/game.rs
use crate::field::{Field, wrap};
use crate::rule::AutomataRule;
use crate::term::{colormap_gb, gfx_cell, gfx_cell_highres, gfx_hline, gfx_hline_highres, gfx_pos1};
pub struct Game {
field: Field<bool>,
ages: Field<u32>,
marked: Field<bool>,
rule: A... | code_fim | hard | {
"lang": "rust",
"repo": "wITTus/cgol",
"path": "/src/game.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(test)]
mod tests {
use crate::field::Field;
use crate::game::Game;
use crate::rule::AutomataRule;
#[test]
fn test_output_highres() {
{
let glider = Field::from_cells("\
......
..O...
...O..
.OOO..");
let game = Game::new(glider, AutomataRule::cgo... | code_fim | hard | {
"lang": "rust",
"repo": "wITTus/cgol",
"path": "/src/game.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> = flume::unbounded::<node::NodeRequest>();
join!(
tokio::task::spawn(grpc::start_server(cmd.host, cmd.port, tx)),
tokio::task::spawn(node::start_node(rx, None, cmd.port)),
tokio::task::spawn(web::start_web_server(cmd.web_monitor))
);... | code_fim | hard | {
"lang": "rust",
"repo": "richardanaya/hivemind",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>d.cluster_node_address).await;
let key_value = client.get_key_value(&cmd.key).await;
println!("{}", key_value);
}
cli::SubCommand::Set(cmd) => {
let mut client = grpc::create_client(cmd.cluster_node_address).await;
client
.set... | code_fim | hard | {
"lang": "rust",
"repo": "richardanaya/hivemind",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: richardanaya/hivemind path: /src/main.rs
mod cli;
mod grpc;
mod node;
mod web;
use clap::derive::Clap;
use tokio::join;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();
let opts = cli::Opts::parse();
match opts.subcmd {
cli::Su... | code_fim | hard | {
"lang": "rust",
"repo": "richardanaya/hivemind",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let chrep =
|st: WState| -> char {
match st {
WState::Conductor => ' ',
WState::EHead => 'O',
WState::ETail => 'o',
}
};
println!();
let mut r = 0;
let mut c... | code_fim | hard | {
"lang": "rust",
"repo": "cetusDownfall/exercises",
"path": "/ca_stuff/wireworld/src/wire_anim.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: cetusDownfall/exercises path: /ca_stuff/wireworld/src/wire_anim.rs
use piston_window::*;
use wire_edit::*;
use wire_grid::*;
use wire_cells::*;
use std::rc::Rc;
use std::time::{Instant, Duration};
pub trait Anim<C: WCell, G: WGrid<C>>
where Self: From<Rc<G>>
{
fn grid(&self) -> Rc<G>;
fn... | code_fim | hard | {
"lang": "rust",
"repo": "cetusDownfall/exercises",
"path": "/ca_stuff/wireworld/src/wire_anim.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: yueyuanwendy/differential-dataflow path: /src/trace/cursor/cursor_pair.rs
//! A generic cursor implementation merging pairs of different cursors.
use super::Cursor;
/// A cursor over the combined updates of two different cursors.
pub struct CursorPair<C1: Cursor, C2: Cursor<Key=C1::Key, Val=C1... | code_fim | medium | {
"lang": "rust",
"repo": "yueyuanwendy/differential-dataflow",
"path": "/src/trace/cursor/cursor_pair.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>
impl<C1: Cursor, C2: Cursor<Key=C1::Key, Val=C1::Val, Time=C1::Time>> Cursor for CursorPair<C1, C2> {
type Key = C1::Key;
type Val = C1::Val;
type Time = C1::Time;
// validation methods
fn key_valid(&self) -> bool { self.cursor1.key_valid() || self.cursor2.key_valid() }
fn val_valid(&self) -> boo... | code_fim | medium | {
"lang": "rust",
"repo": "yueyuanwendy/differential-dataflow",
"path": "/src/trace/cursor/cursor_pair.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: SolinkCorp/rust-s3 path: /aws-creds/src/lib.rs
#![allow(unused_imports)]
#![forbid(unsafe_code)]
<|fim_suffix|>mod credentials;
pub use credentials::*;<|fim_middle|>simpl::err!(AwsCredsError, {
Utf8@std::str::Utf8Error;
Reqwest@reqwest::Error;
Env@std::env::VarError;
Ini@ini::i... | code_fim | medium | {
"lang": "rust",
"repo": "SolinkCorp/rust-s3",
"path": "/aws-creds/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>mod credentials;
pub use credentials::*;<|fim_prefix|>// repo: SolinkCorp/rust-s3 path: /aws-creds/src/lib.rs
#![allow(unused_imports)]
#![forbid(unsafe_code)]
<|fim_middle|>simpl::err!(AwsCredsError, {
Utf8@std::str::Utf8Error;
Reqwest@reqwest::Error;
Env@std::env::VarError;
Ini@ini::i... | code_fim | medium | {
"lang": "rust",
"repo": "SolinkCorp/rust-s3",
"path": "/aws-creds/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: itscomputers/leema path: /src/leema/struple.rs
use leema::lstr::Lstr;
use leema::reg::{self, Ireg};
use leema::sendclone;
use leema::val::Val;
use std::fmt;
use std::iter::FromIterator;
#[derive(Clone)]
#[derive(PartialEq)]
#[derive(PartialOrd)]
#[derive(Eq)]
#[derive(Ord)]
#[derive(Hash)]
pu... | code_fim | hard | {
"lang": "rust",
"repo": "itscomputers/leema",
"path": "/src/leema/struple.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(test)]
mod tests
{
use leema::lstr::Lstr;
use leema::struple::Struple;
use leema::val::Val;
#[test]
fn test_struple_find()
{
let s = Struple(vec![
(Some(Lstr::from("taco")), Val::Int(2)),
(None, Val::Int(3)),
(Some(Lstr::from("bur... | code_fim | hard | {
"lang": "rust",
"repo": "itscomputers/leema",
"path": "/src/leema/struple.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> {
match i {
// set reg on struple
&Ireg::Reg(p) => {
if p as usize >= self.0.len() {
panic!("{:?} too big for {:?}", i, self.0);
}
&mut self.0[p as usize].1
}
&Ireg::Sub(p, ref s... | code_fim | hard | {
"lang": "rust",
"repo": "itscomputers/leema",
"path": "/src/leema/struple.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn gcd(mut x: u64, mut y: u64) -> u64 {
while y != 0 {
let z = x % y;
x = y;
y = z;
}
return x;
}
fn lcm(x: u64, y: u64) -> u64 {
x * (y / gcd(x, y))
}
impl Mul for Rho {
type Output = Rho;
fn mul(self, other: Rho) -> Rho {
Rho {
tail: ... | code_fim | hard | {
"lang": "rust",
"repo": "jld/adventofcode-2019-rs",
"path": "/day12/src/loop_temple.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jld/adventofcode-2019-rs path: /day12/src/loop_temple.rs
use crate::{Num, Vec3, Moons};
use std::cmp::max;
use std::ops::Mul;
pub(crate) const MOONS: usize = 4;
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct Facet {
ps: [Num; MOONS],
vs: [Num; MOONS],
}
impl Facet {
pub... | code_fim | hard | {
"lang": "rust",
"repo": "jld/adventofcode-2019-rs",
"path": "/day12/src/loop_temple.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: kylerky/kvmi-rs path: /observer/src/graph/construction/tests.rs
use crate::graph::entities::*;
use super::analysis::{self, THRESHOLD};
use super::provenance::*;
use super::Constructor;
use std::collections::HashSet;
use regex::RegexSet;
use pretty_assertions::assert_eq;
use petgraph::algo;
... | code_fim | hard | {
"lang": "rust",
"repo": "kylerky/kvmi-rs",
"path": "/observer/src/graph/construction/tests.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[test]
fn test_forward_analysis() {
let (provenance, _, (cost, path)) = gen_ref_graph();
let provenance = ProvenanceGraph::from(provenance);
let actual = analysis::forward_construction(&provenance, path, cost + THRESHOLD)
.expect("Should give a result graph");
let (reference, _,... | code_fim | hard | {
"lang": "rust",
"repo": "kylerky/kvmi-rs",
"path": "/observer/src/graph/construction/tests.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> match maybe_number_ref { // Reference match expression
// Reference pattern, explicit borrow using 'ref'
&Some(ref borrows_box) => {
// Dereference borrow, then dereference Box
let x = **borrows_box;
println!("Found something: {}", x);
},
... | code_fim | hard | {
"lang": "rust",
"repo": "KevinWMatthews/rust-pattern-matching",
"path": "/src/non_copy_type_references.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: KevinWMatthews/rust-pattern-matching path: /src/non_copy_type_references.rs
fn main() {
borrow_matched();
old_borrow_matched1();
old_borrow_matched2();
}
fn borrow_matched() {
// Uses match ergonomics
let maybe_number = Some(Box::new(42));
// let maybe_number: Option<Box... | code_fim | hard | {
"lang": "rust",
"repo": "KevinWMatthews/rust-pattern-matching",
"path": "/src/non_copy_type_references.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Compiler error - cannot move out of borrowed content
/*
match maybe_number_ref {
// Binds the Option as a reference but tries to own the box.
// Can't move from behind a reference
&Some(owns_box) => {},
&None => {},
}
*/
}
fn old_borrow_matched1() {
... | code_fim | hard | {
"lang": "rust",
"repo": "KevinWMatthews/rust-pattern-matching",
"path": "/src/non_copy_type_references.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let data = fs::read_to_string("realinput").expect("Error");
let vec: Vec<&str> = data.split_whitespace().collect();
let mut graph: HashMap<&str, Vec<_>> = HashMap::new();
let mut keys: Vec<&str> = vec![];
for instruction in vec {
let orbit: Vec<&str> = instruction.split(")").co... | code_fim | medium | {
"lang": "rust",
"repo": "janhrastnik/adventofcode",
"path": "/aoc2019/day6-2/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: janhrastnik/adventofcode path: /aoc2019/day6-2/src/main.rs
use std::collections::HashMap;
use std::fs;
fn get_visited_nodes<'a>(
curr_node: &str,
target_node: &str,
visited: Vec<&'a str>,
nodesmap: &mut HashMap<&str, Vec<&'a str>>,
) -> Vec<&'a str> {
if curr_node == target_... | code_fim | medium | {
"lang": "rust",
"repo": "janhrastnik/adventofcode",
"path": "/aoc2019/day6-2/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: akovacs/discovery path: /src/07-registers/src/main.rs
#![no_std]
extern crate aux7;
fn main() {
<|fim_suffix|> // Turn off the North LED
gpioe.bsrr.write(|w| w.br9().set_bit());
// Turn off the East LED
gpioe.bsrr.write(|w| w.br11().set_bit());
}<|fim_middle|> let gpioe = au... | code_fim | medium | {
"lang": "rust",
"repo": "akovacs/discovery",
"path": "/src/07-registers/src/main.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Turn off the North LED
gpioe.bsrr.write(|w| w.br9().set_bit());
// Turn off the East LED
gpioe.bsrr.write(|w| w.br11().set_bit());
}<|fim_prefix|>// repo: akovacs/discovery path: /src/07-registers/src/main.rs
#![no_std]
extern crate aux7;
fn main() {
let gpioe = aux7::init().1;
... | code_fim | medium | {
"lang": "rust",
"repo": "akovacs/discovery",
"path": "/src/07-registers/src/main.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Turn on the North LED
gpioe.bsrr.write(|w| w.bs9().set_bit());
// Turn on the East LED
gpioe.bsrr.write(|w| w.bs11().set_bit());
// Turn off the North LED
gpioe.bsrr.write(|w| w.br9().set_bit());
// Turn off the East LED
gpioe.bsrr.write(|w| w.br11().set_bit());
}<|fi... | code_fim | easy | {
"lang": "rust",
"repo": "akovacs/discovery",
"path": "/src/07-registers/src/main.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let state = State::new(0);
assert_eq!(state.is_handle(), false);
}
#[test]
fn test_is_awaiter_returns_true() {
let state = State::new(AWAITER);
assert_eq!(state.is_awaiter(), true);
}
#[test]
fn test_is_awaiter_returns_false() {
let state =... | code_fim | hard | {
"lang": "rust",
"repo": "creativcoder/bastion",
"path": "/src/lightproc/src/state.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn test_is_completed_returns_false() {
let state = State::new(0);
assert_eq!(state.is_completed(), false);
}
#[test]
fn test_is_closed_returns_true() {
let state = State::new(CLOSED);
assert_eq!(state.is_closed(), true);
}
#[test]
f... | code_fim | hard | {
"lang": "rust",
"repo": "creativcoder/bastion",
"path": "/src/lightproc/src/state.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: creativcoder/bastion path: /src/lightproc/src/state.rs
/// Set if the proc is scheduled for running.
///
/// A proc is considered to be scheduled whenever its `LightProc` reference exists. It is in scheduled
/// state at the moment of creation and when it gets unpaused either by its `ProcHandle`... | code_fim | hard | {
"lang": "rust",
"repo": "creativcoder/bastion",
"path": "/src/lightproc/src/state.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: alexander-jackson/aoc19 path: /day5/src/main.rs
use std::env;
use std::fs;
use std::io;
#[derive(Debug, PartialEq)]
struct Op {
a: i8,
b: i8,
c: i8,
d: i8,
}
fn format_input(input: &str) -> Vec<i32> {
input
.trim()
.split(',')
.filter(|x| !x.is_empty... | code_fim | hard | {
"lang": "rust",
"repo": "alexander-jackson/aoc19",
"path": "/day5/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> second = if op.b == 0 {
input[second as usize]
} else {
second
};
input[third as usize] = if first < second { 1 } else { 0 };
*index += 4;
}
fn equals_op(input: &mut Vec<i32>, index: &mut i32, op: Op) {
let uindex: usize = *index as usize;
let mut first: i32... | code_fim | hard | {
"lang": "rust",
"repo": "alexander-jackson/aoc19",
"path": "/day5/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: amirnateghi1980/evebox path: /src/server/asset.rs
// Copyright (C) 2020 Jason Ish
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
... | code_fim | medium | {
"lang": "rust",
"repo": "amirnateghi1980/evebox",
"path": "/src/server/asset.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn new_static_or_404(path: &str) -> Box<dyn warp::Reply> {
debug!("Loading asset {}", path);
let path = format!("public/{}", path);
let asset = crate::resource::Resource::get(&path);
if let Some(asset) = asset {
let content_type = {
if path.ends_with(".html") {
... | code_fim | medium | {
"lang": "rust",
"repo": "amirnateghi1980/evebox",
"path": "/src/server/asset.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let client = reqwest::Client::new();
let mut response = client
.get(&url)
.query(¶ms)
.headers(headers)
.send()
.unwrap();
let text = response.text().expect("text conversion");
let json = json::parse(&text).ex... | code_fim | hard | {
"lang": "rust",
"repo": "int08h/evmobserver",
"path": "/src/histpx/coinapi.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: int08h/evmobserver path: /src/histpx/coinapi.rs
// Copyright 2018 int08h, LLC 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 obtain a copy of the License at
//
// http:/... | code_fim | hard | {
"lang": "rust",
"repo": "int08h/evmobserver",
"path": "/src/histpx/coinapi.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut headers = Headers::new();
headers.set_raw("X-CoinAPI-Key", "<your key here>");
let params = Vec::from(
[
("period_id", "5MIN"),
("time_start", &start_date),
("include_empty_items", "false"),
("limi... | code_fim | hard | {
"lang": "rust",
"repo": "int08h/evmobserver",
"path": "/src/histpx/coinapi.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: nicochatzi/rume path: /rume/src/lib.rs
#![cfg_attr(not(feature = "std"), no_std)]
<|fim_suffix|>#[cfg(not(feature = "std"))]
pub use alloc::boxed::Box;<|fim_middle|>pub use rume_core::*;
pub use rume_macros::*;
#[cfg(feature = "std")]
pub mod processors;
#[cfg(feature = "std")]
pub use proces... | code_fim | medium | {
"lang": "rust",
"repo": "nicochatzi/rume",
"path": "/rume/src/lib.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(not(feature = "std"))]
extern crate alloc;
#[cfg(not(feature = "std"))]
pub use alloc::boxed::Box;<|fim_prefix|>// repo: nicochatzi/rume path: /rume/src/lib.rs
#![cfg_attr(not(feature = "std"), no_std)]
<|fim_middle|>pub use rume_core::*;
pub use rume_macros::*;
#[cfg(feature = "std")]
pub mod p... | code_fim | medium | {
"lang": "rust",
"repo": "nicochatzi/rume",
"path": "/rume/src/lib.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(not(feature = "std"))]
pub use alloc::boxed::Box;<|fim_prefix|>// repo: nicochatzi/rume path: /rume/src/lib.rs
#![cfg_attr(not(feature = "std"), no_std)]
pub use rume_core::*;
pub use rume_macros::*;
#[cfg(feature = "std")]
pub mod processors;
#[cfg(feature = "std")]
pub use processors::*;
<|fi... | code_fim | easy | {
"lang": "rust",
"repo": "nicochatzi/rume",
"path": "/rume/src/lib.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: bchallenor/drawbridge path: /src/cloud/mem/instance.rs
use crate::cloud::Instance;
use crate::cloud::InstanceRunningState;
use crate::cloud::InstanceType;
use crate::dns::DnsTarget;
use failure::Error;
use std::cell::RefCell;
use std::fmt;
use std::net::Ipv4Addr;
use std::rc::Rc;
#[derive(Clone... | code_fim | hard | {
"lang": "rust",
"repo": "bchallenor/drawbridge",
"path": "/src/cloud/mem/instance.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn try_ensure_instance_type(&self, instance_type: &InstanceType) -> Result<(), Error> {
let mut state = self.state.borrow_mut();
if state.instance_type == *instance_type {
Ok(())
} else if !state.is_running {
state.instance_type = instance_type.clone();
... | code_fim | hard | {
"lang": "rust",
"repo": "bchallenor/drawbridge",
"path": "/src/cloud/mem/instance.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut state = self.state.borrow_mut();
let running_state = InstanceRunningState {
instance_type: state.instance_type.clone(),
addr: DnsTarget::A(state.ip_addr),
};
state.is_running = true;
Ok(running_state)
}
fn ensure_stopped(&sel... | code_fim | hard | {
"lang": "rust",
"repo": "bchallenor/drawbridge",
"path": "/src/cloud/mem/instance.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Jansen-del/Rust path: /section4/rough/src/main.rs
fn main() {
let x = 3.0;
let y = 1.0;
//option
let result =
if y!= 0.0 {Some(x/y)} else {None};
// println!{"res<|fim_suffix|>}={}",x, y, z),
None => println!("cannot divide by zero")
}
}<|fim_middle|>... | code_fim | medium | {
"lang": "rust",
"repo": "Jansen-del/Rust",
"path": "/section4/rough/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>}={}",x, y, z),
None => println!("cannot divide by zero")
}
}<|fim_prefix|>// repo: Jansen-del/Rust path: /section4/rough/src/main.rs
fn main() {
let x = 3.0;
let y = 1.0;
//option
let r<|fim_middle|>esult =
if y!= 0.0 {Some(x/y)} else {None};
// println!{"res... | code_fim | medium | {
"lang": "rust",
"repo": "Jansen-del/Rust",
"path": "/section4/rough/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(Foo::deserialize(deserializer("Bar")).unwrap(), Foo::Bar);
assert_eq!(Foo::deserialize(deserializer("Baz")).unwrap(), Foo::Baz);
assert!(Foo::deserialize(deserializer("Foo")).is_err());
}
#[test]
fn test_numbers() {
assert_eq!( i8::deserialize(deseri... | code_fim | hard | {
"lang": "rust",
"repo": "cambricorp/configure",
"path": "/configure/src/default/env_deserializer.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[derive(Deserialize, Eq, PartialEq, Debug)]
enum Foo {
Bar,
Baz,
}
assert_eq!(Foo::deserialize(deserializer("Bar")).unwrap(), Foo::Bar);
assert_eq!(Foo::deserialize(deserializer("Baz")).unwrap(), Foo::Baz);
assert!(Foo::deserialize(... | code_fim | hard | {
"lang": "rust",
"repo": "cambricorp/configure",
"path": "/configure/src/default/env_deserializer.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: cambricorp/configure path: /configure/src/default/env_deserializer.rs
use std::borrow::Cow;
use serde::de::*; use serde::de::{Error as ErrorTrait};
use erased_serde::Error;
pub struct EnvDeserializer<'a>(pub Cow<'a, str>);
impl<'a, 'de> IntoDeserializer<'de, Error> for EnvDeserializer<'a> {
... | code_fim | hard | {
"lang": "rust",
"repo": "cambricorp/configure",
"path": "/configure/src/default/env_deserializer.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> render_pass.set_scissor_rect(rect.x, rect.y, rect.width, rect.height);
}
match primitive {
Primitive::Mesh(mesh) => {
let index_buffer_slice = index_buffer_slices.next().unwrap();
let vertex_buffer_slice = ver... | code_fim | hard | {
"lang": "rust",
"repo": "Weasy666/egui",
"path": "/crates/egui-wgpu/src/renderer.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let (_user_texture, user_texture_binding) = self
.textures
.get_mut(&id)
.expect("Tried to update a texture that has not been allocated yet.");
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
compare: None,
..sampl... | code_fim | hard | {
"lang": "rust",
"repo": "Weasy666/egui",
"path": "/crates/egui-wgpu/src/renderer.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Weasy666/egui path: /crates/egui-wgpu/src/renderer.rs
t,
]
}
}
/// Uniform buffer used when rendering.
#[derive(Clone, Copy, Debug, bytemuck::Pod, bytemuck::Zeroable)]
#[repr(C)]
struct UniformBuffer {
screen_size_in_points: [f32; 2],
// Uniform buffers need to be at least 1... | code_fim | hard | {
"lang": "rust",
"repo": "Weasy666/egui",
"path": "/crates/egui-wgpu/src/renderer.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Dobiasd/bouncing-spheres path: /src/raytracer/render.rs
use rand::{Rng, SeedableRng};
use rand::prelude::StdRng;
use rayon::prelude::*;
use crate::raytracer::camera::{CameraRange, get_ray_camera_blend};
use crate::raytracer::color::{blend_colors, Color};
use crate::raytracer::image::Image;
use ... | code_fim | hard | {
"lang": "rust",
"repo": "Dobiasd/bouncing-spheres",
"path": "/src/raytracer/render.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[inline(always)]
fn ray_color(rng: &mut StdRng, ray: &Ray, world: &World,
depth: usize, sky: &Sky) -> Color {
if depth <= 0 {
return Color::black();
}
let t_min = 0.001;
let t_max = 9999999999.9;
match world.hit(ray, t_min, t_max) {
Some(rec) => {
... | code_fim | hard | {
"lang": "rust",
"repo": "Dobiasd/bouncing-spheres",
"path": "/src/raytracer/render.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> depth: usize, sky: &Sky) -> Color {
if depth <= 0 {
return Color::black();
}
let t_min = 0.001;
let t_max = 9999999999.9;
match world.hit(ray, t_min, t_max) {
Some(rec) => {
return match rec.material.scatter(rng, &ray, &rec) {
So... | code_fim | hard | {
"lang": "rust",
"repo": "Dobiasd/bouncing-spheres",
"path": "/src/raytracer/render.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jbaublitz/shush path: /src/sensu/endpoint.rs
use std::convert::TryInto;
use hyper::Uri;
/// Enum representing the endpoints in Sensu as a type that shush accesses
#[derive(Clone)]
pub enum SensuEndpoint<'a> {
/// Endpoint for listing silences
Silenced,
/// Endpoint for clearing sil... | code_fim | medium | {
"lang": "rust",
"repo": "jbaublitz/shush",
"path": "/src/sensu/endpoint.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> match self {
SensuEndpoint::Silenced => "/silenced".parse::<Uri>().map_err(|e| format!("{}", e)),
SensuEndpoint::Clear => "/silenced/clear".parse::<Uri>().map_err(|e| format!("{}", e)),
SensuEndpoint::Client(c) => format!("/clients/{}", c).parse::<Uri>()
... | code_fim | medium | {
"lang": "rust",
"repo": "jbaublitz/shush",
"path": "/src/sensu/endpoint.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn try_into(self) -> Result<Uri, Self::Error> {
match self {
SensuEndpoint::Silenced => "/silenced".parse::<Uri>().map_err(|e| format!("{}", e)),
SensuEndpoint::Clear => "/silenced/clear".parse::<Uri>().map_err(|e| format!("{}", e)),
SensuEndpoint::Client(c)... | code_fim | medium | {
"lang": "rust",
"repo": "jbaublitz/shush",
"path": "/src/sensu/endpoint.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: paolorechia/pokedex path: /scraper/src/bin/load_root_html.rs
use std::boxed::Box;
use std::fs;
use std::path::Path;
use std::result::Result;
<|fim_suffix|>#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let settings = load_config();
let data_folder = Path::ne... | code_fim | medium | {
"lang": "rust",
"repo": "paolorechia/pokedex",
"path": "/scraper/src/bin/load_root_html.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let data_folder = Path::new(&settings.data_folder);
let pokemon_list_html = data_folder.join(&settings.root_html_file);
let resp = reqwest::get(&settings.poke_list_url).await?;
let body = resp.text().await?;
fs::write(pokemon_list_html, body).expect("Could not write HTML file.");
... | code_fim | medium | {
"lang": "rust",
"repo": "paolorechia/pokedex",
"path": "/scraper/src/bin/load_root_html.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: devdoshi/awair-local-api-prometheus-exporter path: /src/main.rs
use chrono::DateTime;
use chrono::Utc;
use env_logger::{Builder, Env};
use log::info;
use prometheus_exporter::prometheus::register_gauge;
use serde::Deserialize;
use std::net::SocketAddr;
use std::env;
/*
example:
{
"timestamp... | code_fim | hard | {
"lang": "rust",
"repo": "devdoshi/awair-local-api-prometheus-exporter",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Start exporter
let exporter = prometheus_exporter::start(addr).expect("can not start exporter");
// Create metrics
let score =
register_gauge!("score", "will display score").expect("could not create gauge score");
let dew_point = register_gauge!("dew_point", "will display ... | code_fim | hard | {
"lang": "rust",
"repo": "devdoshi/awair-local-api-prometheus-exporter",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(ret.color, "red");
}
#[test]
fn should_support_pvm_contract_call() {
let (mut service, mut context, address) = deploy_test_code!();
let args =
json!({"method": "test_contract_call", "address": address.as_hex(), "call_args": json!({"method": "_ret_self"}).to_string()})
... | code_fim | hard | {
"lang": "rust",
"repo": "akki2825/huobi-chain",
"path": "/services/riscv/src/tests/duktape.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: akki2825/huobi-chain path: /services/riscv/src/tests/duktape.rs
use std::time::{SystemTime, UNIX_EPOCH};
use protocol::{
types::{Hash, ServiceContext},
Bytes,
};
use serde::{Deserialize, Serialize};
use serde_json::json;
use super::{TestContext, TestRiscvService, CALLER, CYCLE_LIMIT};
... | code_fim | hard | {
"lang": "rust",
"repo": "akki2825/huobi-chain",
"path": "/services/riscv/src/tests/duktape.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> ];
vec.sort();
println!("{:?}", vec)
}
fn main() {
f1();
}<|fim_prefix|>// repo: stormtracks/rust-examples path: /sort/examples/ex01.rs
fn f1() {
let mut vec: Vec<Vec<&str>> = vec![
["qwe", "123", "nope"].to_vec(),
["qwe", "456", "nope"].to_vec(),
["as<|fim_midd... | code_fim | medium | {
"lang": "rust",
"repo": "stormtracks/rust-examples",
"path": "/sort/examples/ex01.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: stormtracks/rust-examples path: /sort/examples/ex01.rs
fn f1() {
let mut vec: Vec<Vec<&str>> = vec![
["qwe", "123",<|fim_suffix|>d", "456", "nope"].to_vec(),
["asd", "123", "nope"].to_vec(),
];
vec.sort();
println!("{:?}", vec)
}
fn main() {
f1();
}<|fim_midd... | code_fim | medium | {
"lang": "rust",
"repo": "stormtracks/rust-examples",
"path": "/sort/examples/ex01.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>d", "456", "nope"].to_vec(),
["asd", "123", "nope"].to_vec(),
];
vec.sort();
println!("{:?}", vec)
}
fn main() {
f1();
}<|fim_prefix|>// repo: stormtracks/rust-examples path: /sort/examples/ex01.rs
fn f1() {
let mut vec: Vec<Vec<&str>> = vec![
["qwe", "123",<|fim_midd... | code_fim | medium | {
"lang": "rust",
"repo": "stormtracks/rust-examples",
"path": "/sort/examples/ex01.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jgoldschrafe/hackerrank-rust path: /array-left-rotation/src/main.rs
use std::io;
fn main() {
let mut params_buf = String::new();
io::stdin().read_line(&mut params_buf);
let params: Vec<u32> = params_buf
.trim_end()
.split_whitespace()
.map(|s| s.parse().unwra... | code_fim | hard | {
"lang": "rust",
"repo": "jgoldschrafe/hackerrank-rust",
"path": "/array-left-rotation/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let rotated_nums: Vec<String> = (0..nums.len())
.map(|i| nums[(i + d as usize) % nums.len()].to_string())
.collect();
println!("{}", rotated_nums.join(" "));
}<|fim_prefix|>// repo: jgoldschrafe/hackerrank-rust path: /array-left-rotation/src/main.rs
use std::io;
fn main() {
l... | code_fim | hard | {
"lang": "rust",
"repo": "jgoldschrafe/hackerrank-rust",
"path": "/array-left-rotation/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut from: usize = 0;
let mut to = LAYER_LEN;
let mut min_zeros = LAYER_LEN;
let mut result: usize = 0;
while from < data.len() {
let layer: Vec<i32> = data[from..to].chars().map(|ch| ch.to_string().parse::<i32>().unwrap()).collect();
let zeros = count_num(&layer, ... | code_fim | medium | {
"lang": "rust",
"repo": "amoshkina/aoc2019",
"path": "/day8/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: amoshkina/aoc2019 path: /day8/src/main.rs
use std::fs::read_to_string;
use std::error::Error;
type MyResult<T> = Result<T, Box<dyn Error>>;
const WIDTH: usize = 25;
const HEIGHT: usize = 6;
const LAYER_LEN: usize = WIDTH * HEIGHT;
fn count_num(layer: &Vec<i32>, num: i32) -> usize {
layer.... | code_fim | hard | {
"lang": "rust",
"repo": "amoshkina/aoc2019",
"path": "/day8/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rkusa/DATIS path: /crates/srs/src/client.rs
use std::net::SocketAddr;
use std::sync::Arc;
use crate::message::{create_sguid, Coalition, GameMessage, LatLngPosition};
use crate::voice_stream::{VoiceStream, VoiceStreamError};
use futures::channel::mpsc;
use tokio::sync::oneshot::Receiver;
use to... | code_fim | hard | {
"lang": "rust",
"repo": "rkusa/DATIS",
"path": "/crates/srs/src/client.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> /**
Start sending updates to the specified server. If `game_source` is None,
the client will act as a stationary transmitter using the position and
frequency specified in the `Client` struct. It will not request any voice
messages
If the `game_source` is set, the positio... | code_fim | hard | {
"lang": "rust",
"repo": "rkusa/DATIS",
"path": "/crates/srs/src/client.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn sguid(&self) -> &str {
&self.sguid
}
pub fn name(&self) -> &str {
&self.name
}
pub fn freq(&self) -> u64 {
self.freq
}
pub async fn position(&self) -> LatLngPosition {
let p = self.pos.read().await;
p.clone()
}
pub fn p... | code_fim | hard | {
"lang": "rust",
"repo": "rkusa/DATIS",
"path": "/crates/srs/src/client.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // when casting any value to an unsigned type, T,
// T::MAX + 1 is added or subtracted until the value
// fits into the new type
// 1000 already fits in a u16
println!("1000 as a u16 is: {}", 1000 as u16);
// 1000 - 256 - 256 - 256 = 232
// Under the hood, the first 8 least s... | code_fim | medium | {
"lang": "rust",
"repo": "anthonytranDev/rust-tutorials",
"path": "/tutorials/5.types/5.1.casting/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: anthonytranDev/rust-tutorials path: /tutorials/5.types/5.1.casting/main.rs
// Rust provides no implicit type conversion (coercion) between primitive types.
// But, explicit type conversion (casting) can be performed using the as keyword.
// Suppress all warnings from casts which overflow.
#![al... | code_fim | hard | {
"lang": "rust",
"repo": "anthonytranDev/rust-tutorials",
"path": "/tutorials/5.types/5.1.casting/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> use super::*;
/// Should succeed either when responding was successful or there was an error on the client side.
#[test]
fn test_error_logger_succeeds() {
let result = Err(fidl::Error::ServerResponseWrite(zx::Status::PEER_CLOSED));
result.log_fidl_response_error("");
... | code_fim | hard | {
"lang": "rust",
"repo": "carbonatedcaffeine/zircon-rpi",
"path": "/garnet/bin/setui/src/switchboard/base.rs",
"mode": "spm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// The events generated in response to SettingAction.
#[derive(PartialEq, Clone, Debug)]
pub enum SettingEvent {
/// The setting's data has changed. The setting type associated with this
/// event is implied by the association of the signature of the sending
/// proxy to the setting type. Thi... | code_fim | hard | {
"lang": "rust",
"repo": "carbonatedcaffeine/zircon-rpi",
"path": "/garnet/bin/setui/src/switchboard/base.rs",
"mode": "spm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: carbonatedcaffeine/zircon-rpi path: /garnet/bin/setui/src/switchboard/base.rs
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use std::collections::HashSet;
use fuchsia_syslog::f... | code_fim | hard | {
"lang": "rust",
"repo": "carbonatedcaffeine/zircon-rpi",
"path": "/garnet/bin/setui/src/switchboard/base.rs",
"mode": "psm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: yepchris/cryptopals path: /src/sets/first/three.rs
use crate::util::*;
pub fn run(input: &str) -> Result<<|fim_suffix|>ode(input)?;
let most_likely = brute_char(&ct);
Ok(std::str::from_utf8(&most_likely.2)?.to_string())
}<|fim_middle|>String, Box<std::error::Error>> {
let ct = hex::... | code_fim | easy | {
"lang": "rust",
"repo": "yepchris/cryptopals",
"path": "/src/sets/first/three.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> Ok(std::str::from_utf8(&most_likely.2)?.to_string())
}<|fim_prefix|>// repo: yepchris/cryptopals path: /src/sets/first/three.rs
use crate::util::*;
pub fn run(input: &str) -> Result<<|fim_middle|>String, Box<std::error::Error>> {
let ct = hex::decode(input)?;
let most_likely = brute_char(&ct);
... | code_fim | medium | {
"lang": "rust",
"repo": "yepchris/cryptopals",
"path": "/src/sets/first/three.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let v1_iter = v1.iter();
assert_eq!(6, v1_iter.sum()); // takes ownership of v1_iter
let v1_iter = v1.iter();
let v2: Vec<_> = v1_iter.map(|x| x+1).collect();
assert_eq!(v2, vec![2, 3, 4]);
let shoes = vec![
Shoe { size:10, style: String::from("sneaker") },
Sho... | code_fim | hard | {
"lang": "rust",
"repo": "laomaiweng/rust-101",
"path": "/iterators/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> for i in 12..buffer.len() {
let prediction = coefficients.iter()
.zip(&buffer[i - 12..i])
.map(|(&c, &s)| c * s as i64)
.sum::<i64>() >> qlp_shift;
let delta = buffer[i];
... | code_fim | hard | {
"lang": "rust",
"repo": "laomaiweng/rust-101",
"path": "/iterators/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: laomaiweng/rust-101 path: /iterators/src/main.rs
extern crate rand;
use rand::prelude::*;
struct Counter {
count: u32
}
impl Counter {
fn new() -> Counter {
Counter { count: 0 }
}
}
impl Iterator for Counter {
type Item = u32;
fn next(&mut self) -> Option<Self::I... | code_fim | hard | {
"lang": "rust",
"repo": "laomaiweng/rust-101",
"path": "/iterators/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: emirayka/nia_interpreter_core path: /src/interpreter/library/infect/infect_object_builtin_function.rs
use crate::BuiltinFunction;
use crate::BuiltinFunctionType;
use crate::Error;
use crate::Function;
use crate::Interpreter;
use crate::ObjectId;
use crate::Value;
<|fim_suffix|> let function ... | code_fim | hard | {
"lang": "rust",
"repo": "emirayka/nia_interpreter_core",
"path": "/src/interpreter/library/infect/infect_object_builtin_function.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> interpreter.set_object_property(object_id, name, function_value)?;
Ok(())
}<|fim_prefix|>// repo: emirayka/nia_interpreter_core path: /src/interpreter/library/infect/infect_object_builtin_function.rs
use crate::BuiltinFunction;
use crate::BuiltinFunctionType;
use crate::Error;
use crate::Functio... | code_fim | hard | {
"lang": "rust",
"repo": "emirayka/nia_interpreter_core",
"path": "/src/interpreter/library/infect/infect_object_builtin_function.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: iCodeIN/roctogen path: /src/adapters/mod.rs
use serde::{Deserialize, ser};
use crate::auth::Auth;
#[cfg(feature = "isahc")]
pub mod isahc;
#[cfg(feature = "isahc")]
pub use self::isahc::AdapterError;
#[cfg(feature = "isahc")]
pub(crate) use {
self::isahc::fetch,
self::isahc::fetch_as... | code_fim | hard | {
"lang": "rust",
"repo": "iCodeIN/roctogen",
"path": "/src/adapters/mod.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(all(not(feature = "isahc"), not(target_arch = "wasm32")))]
pub(crate) type FromJsonType = Vec<u8>;
#[cfg(all(not(feature = "isahc"), not(target_arch = "wasm32")))]
impl GitHubResponseExt for http::Response<Vec<u8>> {
fn is_success(&self) -> bool {
unimplemented!("Use a client adapter fe... | code_fim | hard | {
"lang": "rust",
"repo": "iCodeIN/roctogen",
"path": "/src/adapters/mod.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.