text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_prefix|>// repo: BartMassey/fasthello path: /fast.rs
use std::io::Write;
fn main() {
let stdout = std::io::stdout();
let lock = std<|fim_suffix|>= itoa::write(&mut buf, i).unwrap();
let _ = buf.write(b"\t").unwrap();
}
}<|fim_middle|>out.lock();
let mut buf = std::io::BufWriter::with_cap... | code_fim | medium | {
"lang": "rust",
"repo": "BartMassey/fasthello",
"path": "/fast.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>= itoa::write(&mut buf, i).unwrap();
let _ = buf.write(b"\t").unwrap();
}
}<|fim_prefix|>// repo: BartMassey/fasthello path: /fast.rs
use std::io::Write;
fn main() {
let stdout = std::io::stdout();
let lock = stdout.lock();
let mut buf = std::io::BufWriter::with_capacity(32 * 102... | code_fim | medium | {
"lang": "rust",
"repo": "BartMassey/fasthello",
"path": "/fast.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jamescoleuk/runsh path: /src/pretty_printer.rs
use crate::models::Script;
use colored::*;
use pad::{Alignment, PadStr};
// TODO: make this a Display impl on Script?
pub fn print_script(script: Script) {
let script_path = script.path.into_os_string().into_string().unwrap();
if script.fun... | code_fim | hard | {
"lang": "rust",
"repo": "jamescoleuk/runsh",
"path": "/src/pretty_printer.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Then follow up with the comment lines
function.comment.iter().enumerate().for_each(|(i, line)| {
if i == 0 {
println!(" {}", line);
} else {
println!(
"{} {}",
... | code_fim | hard | {
"lang": "rust",
"repo": "jamescoleuk/runsh",
"path": "/src/pretty_printer.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: slonopotamus/octobuild path: /src/cmd/native/unix.rs
use std::ffi::{OsStr, OsString};
// Parsing command line arguments from singe line.
pub fn parse(cmd: &str) -> crate::Result<Vec<String>> {
shlex::split(cmd)
.ok_or_else(|| crate::Error::Generic(format!("Unable to parse commandlin... | code_fim | hard | {
"lang": "rust",
"repo": "slonopotamus/octobuild",
"path": "/src/cmd/native/unix.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(
parse(r#"begin ' some text " foo\ bar\' end"#).unwrap(),
["begin", r#" some text " foo\ bar\"#, "end"]
);
}
#[test]
fn test_parse_10() {
assert_eq!(
parse(r#"begin some\ text end"#).unwrap(),
["begin", "some text", "end"]
);
}<|fim_prefix|>// re... | code_fim | hard | {
"lang": "rust",
"repo": "slonopotamus/octobuild",
"path": "/src/cmd/native/unix.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tadast/rubyfmt path: /librubyfmt/src/ripper_tree_types.rs
lLeft::MethodAddArg(MethodAddArg(_, left, an)) => {
let mut res = left.into_call_chain();
res.push(args_as_cc(an));
res
}
CallLeft::MethodAddBlock(MethodAddBlock(_, l... | code_fim | hard | {
"lang": "rust",
"repo": "tadast/rubyfmt",
"path": "/librubyfmt/src/ripper_tree_types.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tadast/rubyfmt path: /librubyfmt/src/ripper_tree_types.rs
a trailing
// comma (presumably because of f params). Params lists for functions do
// not allow this.
//
// valid:
// ```ruby
// lambda { |x,| }
// lambda { |x, ;f }
// ```
// not valid:
// ``` ruby
// def foo(x,)
// end
// ```
//
// th... | code_fim | hard | {
"lang": "rust",
"repo": "tadast/rubyfmt",
"path": "/librubyfmt/src/ripper_tree_types.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>def_tag!(paren_expr_tag, "paren");
#[derive(Deserialize, Debug, Clone)]
pub struct ParenExpr(pub paren_expr_tag, pub ParenExpressionOrExpressions);
def_tag!(dot2_tag, "dot2");
#[derive(Deserialize, Debug, Clone)]
pub struct Dot2(
pub dot2_tag,
pub Option<Box<Expression>>,
pub Option<Box<Expre... | code_fim | hard | {
"lang": "rust",
"repo": "tadast/rubyfmt",
"path": "/librubyfmt/src/ripper_tree_types.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>
pub static START: Samotop<EchoService> = Samotop {
default_port: "localhost:25",
default_service: EchoService,
};<|fim_prefix|>// repo: azul/Samotop path: /src/lib.rs
#[macro_use]
extern crate log;
extern crate env_logger;
extern crate regex;
extern crate bytes;
#[macro_use]
extern crate futures... | code_fim | medium | {
"lang": "rust",
"repo": "azul/Samotop",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: azul/Samotop path: /src/lib.rs
#[macro_use]
extern crate log;
extern crate env_logger;
extern crate regex;
extern crate bytes;
#[macro_use]
extern crate futures;
extern crate tokio;
extern crate tokio_codec;
extern crate hostname;
pub mod model;
pub mod protocol;
pub mod server;
pub mod service... | code_fim | medium | {
"lang": "rust",
"repo": "azul/Samotop",
"path": "/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>ensions::IMAFDC, true);
let disasm = Disassembler::new(instructions);
let _ = disasm.fmt_inst(inst_bits);
}
}
}
});<|fim_prefix|>// repo: tymcauley/spike-dasm-rs path: /fuzz/fuzz_targets/fuzz_disasm.rs
#![no_main]
use libfuzzer_sys::fuzz_target;
us... | code_fim | hard | {
"lang": "rust",
"repo": "tymcauley/spike-dasm-rs",
"path": "/fuzz/fuzz_targets/fuzz_disasm.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tymcauley/spike-dasm-rs path: /fuzz/fuzz_targets/fuzz_disasm.rs
#![no_main]
use libfuzzer_sys::fuzz_target;
use spike_dasm_rs::disasm::Disassembler;
use spike_dasm_rs::instruction::{self, InstructionBits};
use spike_dasm_rs::parser;
u<|fim_suffix|>alue(s) {
if let Ok(inst_bits) = In... | code_fim | medium | {
"lang": "rust",
"repo": "tymcauley/spike-dasm-rs",
"path": "/fuzz/fuzz_targets/fuzz_disasm.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>alue(s) {
if let Ok(inst_bits) = InstructionBits::new(x) {
let instructions =
instruction::gen_instructions(Xlen::Rv64, Extensions::IMAFDC, true);
let disasm = Disassembler::new(instructions);
let _ = disasm.fmt_inst(inst_bits... | code_fim | medium | {
"lang": "rust",
"repo": "tymcauley/spike-dasm-rs",
"path": "/fuzz/fuzz_targets/fuzz_disasm.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(3, add_one(2));
}
}<|fim_prefix|>// repo: KeAiMianYang/work_repo_training path: /Rust/book/14_03_workspaces/add-one/src/lib.rs
// the package name is add-one,
// the crate name is add-one
<|fim_middle|>pub fn add_one(x: i32) -> i32 {
x + 1
}
#[cfg(test)]
mod tests {
use s... | code_fim | medium | {
"lang": "rust",
"repo": "KeAiMianYang/work_repo_training",
"path": "/Rust/book/14_03_workspaces/add-one/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: KeAiMianYang/work_repo_training path: /Rust/book/14_03_workspaces/add-one/src/lib.rs
// the package name is add-one,
// the crate name is add-one
<|fim_suffix|>#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
assert_eq!(3, add_one(2));
}
}<|fim_middle|>pub ... | code_fim | easy | {
"lang": "rust",
"repo": "KeAiMianYang/work_repo_training",
"path": "/Rust/book/14_03_workspaces/add-one/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> ast_stack.push(Ast::Multiply(
Box::new(left_multiplier),
Box::new(right_multiplier),
));
}
pub(crate) fn ast_create_number(ast_stack: &mut Vec<Ast>) {
ast_stack.push(Ast::Number(0));
}<|fim_prefix|>// repo: niklasbuechner/parser-experiments path: /slr-parser/src/ast.rs
#[deri... | code_fim | hard | {
"lang": "rust",
"repo": "niklasbuechner/parser-experiments",
"path": "/slr-parser/src/ast.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: niklasbuechner/parser-experiments path: /slr-parser/src/ast.rs
#[derive(Debug, PartialEq)]
pub(crate) enum Ast {
Add(Box<Ast>, Box<Ast>),
Calculation(Box<Ast>),
Multiply(Box<Ast>, Box<Ast>),
Number(usize),
}
<|fim_suffix|> ast_stack.push(Ast::Multiply(
Box::new(left_m... | code_fim | hard | {
"lang": "rust",
"repo": "niklasbuechner/parser-experiments",
"path": "/slr-parser/src/ast.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: po-gl/Raytracer path: /src/pattern/perturbed_pattern.rs
/// # Perturbed Patterns
/// `perturbed` is a module to represent a "perturbed" patterns
/// or a more organic looking pattern
use crate::color::Color;
use crate::tuple::Tuple;
use crate::matrix::Matrix4;
use crate::pattern::Pattern;
use s... | code_fim | hard | {
"lang": "rust",
"repo": "po-gl/Raytracer",
"path": "/src/pattern/perturbed_pattern.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>
#[cfg(test)]
mod tests {
// use super::*;
// use crate::pattern::ring_pattern::RingPattern;
// use crate::tuple::point;
#[test]
fn perturbed_patterns() {
// // Rings that should add up to purple
// let pattern_a = RingPattern::new(Color::from_hex("FF0000"), Color::black())... | code_fim | hard | {
"lang": "rust",
"repo": "po-gl/Raytracer",
"path": "/src/pattern/perturbed_pattern.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let bush = Bush {
prime_base: 3,
dimensions: 2,
strength: 2,
};
let oa = bush.gen().unwrap();
assert!(normalize(&oa, 0.0, true).is_ok());
assert!(normalize(&oa, 1.0, true).is_ok());
}<|fim_prefix|>// repo: afnanenayet/oars path: /oars/tests/bush_tests.rs
/// Un... | code_fim | hard | {
"lang": "rust",
"repo": "afnanenayet/oars",
"path": "/oars/tests/bush_tests.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: afnanenayet/oars path: /oars/tests/bush_tests.rs
/// Unit tests for the Bose array constructor
use oars::constructors::Bush;
use oars::oa::{normalize, verify, OAConstructor};
#[cfg(feature = "parallel")]
use oars::oa::ParOAConstructor;
#[test]
fn test_bush_init_verify() {
let bush = Bush {... | code_fim | hard | {
"lang": "rust",
"repo": "afnanenayet/oars",
"path": "/oars/tests/bush_tests.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> resolve::methodinvocation::go(&mut node, modifiers, current, kinds, globals)
}
Some(ref l) if l == "Name" => resolve::name::go(node, modifiers, current, kinds, globals),
_ => {
match node.token.kind {
TokenKind::And | TokenKind::BitAnd | TokenKind::O... | code_fim | hard | {
"lang": "rust",
"repo": "TheKevJames/juicyj",
"path": "/src/analysis/types/resolve/expression.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: TheKevJames/juicyj path: /src/analysis/types/resolve/expression.rs
use analysis::environment::ClassOrInterface;
use analysis::environment::ClassOrInterfaceEnvironment;
use analysis::environment::VariableEnvironment;
use analysis::types::obj::Type;
use analysis::types::resolve;
use scanner::ASTNo... | code_fim | hard | {
"lang": "rust",
"repo": "TheKevJames/juicyj",
"path": "/src/analysis/types/resolve/expression.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.caves
.iter()
.filter(|c| c.label == label)
.cloned()
.next()
}
}
#[test]
fn test_very_simple() {
let input = "start-a
a-end";
let system = parse_caves(input).expect("A cave system was expected");
let paths = system.find_all_pat... | code_fim | hard | {
"lang": "rust",
"repo": "mathw/adventofcode",
"path": "/aoc2021/src/day12.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mathw/adventofcode path: /aoc2021/src/day12.rs
use crate::day::{DayResult, PartResult};
#[cfg(test)]
use maplit::hashset;
use rayon::prelude::*;
use std::collections::{HashMap, HashSet, VecDeque};
use std::error::Error;
use std::hash::{Hash, Hasher};
pub fn run() -> Result<DayResult, Box<dyn Er... | code_fim | hard | {
"lang": "rust",
"repo": "mathw/adventofcode",
"path": "/aoc2021/src/day12.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[test]
fn test_find_next_caves_simple() {
let input = "start-a
a-end";
let system = parse_caves(input).expect("A cave system was expected");
let start = system
.starting_cave()
.expect("A starting cave was expected");
let mut path = Path::new();
path.push(start);
l... | code_fim | hard | {
"lang": "rust",
"repo": "mathw/adventofcode",
"path": "/aoc2021/src/day12.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> match self.op_mode(instruction, op) {
0 => self.input[self.pc + op] as usize,
1 => self.pc + op,
x => panic!("Unexpected input {:?}", x),
}
}
fn step(&mut self) {
let instruction = self.next();
// println!(
// ... | code_fim | hard | {
"lang": "rust",
"repo": "milanaleksic/adventofcode2019",
"path": "/src/advent05/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: milanaleksic/adventofcode2019 path: /src/advent05/lib.rs
use std::fmt::{Debug, Error, Formatter};
use crate::common::read_input_as_csv;
enum Instruction {
ADD(i32),
MUL(i32),
WRITE,
READ(i32),
JIT(i32),
JIF(i32),
LT(i32),
EQ(i32),
INT,
}
impl Debug for Inst... | code_fim | hard | {
"lang": "rust",
"repo": "milanaleksic/adventofcode2019",
"path": "/src/advent05/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> for row_of_rooms in encoded_maze.iter() {
let row: String = row_of_rooms.iter().map(|r| r.borders_as_char()).collect();
// println!("Writing row: {}", row);
file_buffer
.write_all(row.as_bytes())
.expect("Writing row of rooms failed.");
file_buff... | code_fim | hard | {
"lang": "rust",
"repo": "breezykermo/1-maze-rs",
"path": "/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: breezykermo/1-maze-rs path: /src/lib.rs
pub mod common;
use std::fs::File;
use std::fs::OpenOptions;
use std::io::{self, BufRead, Write};
use std::path::Path;
/* GENERATOR LIB */
fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
where
P: AsRef<Path>,
{
let fi... | code_fim | hard | {
"lang": "rust",
"repo": "breezykermo/1-maze-rs",
"path": "/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: migerh/aoc2018-rs path: /src/day21/ops.rs
use super::data::State;
// addr (add register) stores into register C the result of adding register A and register B.
pub fn addr(state: &mut State, a: i128, b: i128, c: i128) {
apply_rr(state, a, b, c, |x, y| x + y);
}
// addi (add immediate) stores... | code_fim | hard | {
"lang": "rust",
"repo": "migerh/aoc2018-rs",
"path": "/src/day21/ops.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn apply_rr<F>(mut state: &mut State, a: i128, b: i128, c: i128, f: F)
where F: Fn(i128, i128) -> i128 {
if valid(a) && valid(b) && valid(c) {
state.registers[c as usize] = f(state.registers[a as usize], state.registers[b as usize]);
}
}
fn apply_ri<F>(mut state: &mut State, a: i128, b: i128, c... | code_fim | hard | {
"lang": "rust",
"repo": "migerh/aoc2018-rs",
"path": "/src/day21/ops.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: yaymukund/suzanne-metadata path: /src/music_library.rs
use folder_list::FolderList;
use indicatif::{ProgressBar, ProgressStyle};
use serde_json;
use std::fs::File;
use std::io::Error;
use std::path::Path;
use track_list::TrackList;
use walkdir::{DirEntry, WalkDir};
const FILENAME: &str = "metad... | code_fim | hard | {
"lang": "rust",
"repo": "yaymukund/suzanne-metadata",
"path": "/src/music_library.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> for entry in entries {
debug!("Processing entry: {:?}", entry.path());
let name = entry
.path()
.file_name()
.unwrap()
.to_str()
.unwrap()
.to_string()
.clone();
... | code_fim | hard | {
"lang": "rust",
"repo": "yaymukund/suzanne-metadata",
"path": "/src/music_library.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[test]
fn test() {
let cases = vec![
(1, 2, "0.5"),
(2, 1, "2"),
(2, 3, "0.(6)"),
(-1, 7, "-0.(142857)"),
(std::i32::MIN, -1, "2147483648"),
];
for (up, down, expect) in cases {
assert_eq!(fraction_to_decimal(up, down), expect);
}
}<|fim_pre... | code_fim | hard | {
"lang": "rust",
"repo": "CNife/leetcode",
"path": "/rust/finished/src/fraction_to_recurring_decimal.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut map: HashMap<i64, usize> = HashMap::new();
while rem != 0 {
match map.get(&rem) {
Some(&i) => {
buf.insert(i, '(');
buf.push(')');
break;
}
None => {
map.insert(rem, buf.len());
... | code_fim | hard | {
"lang": "rust",
"repo": "CNife/leetcode",
"path": "/rust/finished/src/fraction_to_recurring_decimal.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: CNife/leetcode path: /rust/finished/src/fraction_to_recurring_decimal.rs
use std::collections::HashMap;
pub fn fraction_to_decimal(up: i32, down: i32) -> String {
if down == 0 {
return "".into();
}
if up == 0 {
return "0".into();
}
let up = up as i64;
le... | code_fim | hard | {
"lang": "rust",
"repo": "CNife/leetcode",
"path": "/rust/finished/src/fraction_to_recurring_decimal.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>mod rvs_context_new;
mod rvs_seed;
mod rvs_parse;
mod rvs_get;
mod rvs_next;
mod rvs_write_definitions;<|fim_prefix|>// repo: rfdonnelly/rvs path: /c-api/src/tests/mod.rs
use super::*;
use rvs;
use std::ffi::CString;
use std::ffi::CStr;
use error::{rvs_error_free, rvs_error_new, rvs_error_test};
fn g... | code_fim | medium | {
"lang": "rust",
"repo": "rfdonnelly/rvs",
"path": "/c-api/src/tests/mod.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn next_by_name(model: *mut rvs::Model, name: &str) -> u32 {
let handle = rvs_get(model, CString::new(name).unwrap().as_ptr());
assert!(handle != 0);
rvs_next(model, handle)
}
mod rvs_context_new;
mod rvs_seed;
mod rvs_parse;
mod rvs_get;
mod rvs_next;
mod rvs_write_definitions;<|fim_prefix|... | code_fim | hard | {
"lang": "rust",
"repo": "rfdonnelly/rvs",
"path": "/c-api/src/tests/mod.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rfdonnelly/rvs path: /c-api/src/tests/mod.rs
use super::*;
use rvs;
use std::ffi::CString;
use std::ffi::CStr;
use error::{rvs_error_free, rvs_error_new, rvs_error_test};
fn get_error_message(error: *mut Error) -> String {
let c_buf = rvs_error_message(error);
let c_str = unsafe { CS... | code_fim | hard | {
"lang": "rust",
"repo": "rfdonnelly/rvs",
"path": "/c-api/src/tests/mod.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> Ok(loop {
let (pos, dist, iss) = candidates
.pop_front()
.ok_or_else(|| crate::Error::boxed(Error::NoPathFound))?;
for dir in 1..=4 {
let mut iss = iss.clone();
iss.feed_input(dir);
match iss.run()? {
StopRea... | code_fim | hard | {
"lang": "rust",
"repo": "madmax28/aoc2019",
"path": "/src/day15/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: madmax28/aoc2019 path: /src/day15/mod.rs
use crate::day09::{Iss, StopReason, Value};
use std::collections::{HashSet, VecDeque};
#[derive(Debug)]
enum Error {
InvalidDirection,
NoPathFound,
UnexpectedIssResult,
}
type Pos = (Value, Value);
fn step(p: Pos, d: Value) -> crate::Resul... | code_fim | hard | {
"lang": "rust",
"repo": "madmax28/aoc2019",
"path": "/src/day15/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> match iss.run()? {
StopReason::Output(0) => (),
StopReason::Output(1) => {
let pos = step(pos, dir)?;
if !visited.insert(pos) {
continue;
}
candidates.push_... | code_fim | hard | {
"lang": "rust",
"repo": "madmax28/aoc2019",
"path": "/src/day15/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Arnavion/k8s-openapi path: /k8s-openapi-codegen/src/supported_version.rs
pub(crate) const ALL: &[SupportedVersion] = &[
SupportedVersion::V1_22,
SupportedVersion::V1_23,
SupportedVersion::V1_24,
SupportedVersion::V1_25,
SupportedVersion::V1_26,
SupportedVersion::V1_27,
];... | code_fim | hard | {
"lang": "rust",
"repo": "Arnavion/k8s-openapi",
"path": "/k8s-openapi-codegen/src/supported_version.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> SupportedVersion::V1_24 => &[
crate::fixups::upstream_bugs::connect_options_gvk,
crate::fixups::upstream_bugs::optional_properties::eventsv1beta1_event,
crate::fixups::upstream_bugs::optional_properties::eventsv1_event,
crate::fix... | code_fim | hard | {
"lang": "rust",
"repo": "Arnavion/k8s-openapi",
"path": "/k8s-openapi-codegen/src/supported_version.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ethanabrooks/autograder path: /autograder/src/labels.rs
use crate::error::{LabelsParseError, ReadError};
use crate::Result;
use serde::{Deserialize, Serialize};
use snafu::ResultExt;
use std::fs;
use std::path::Path;
<|fim_suffix|>impl Labels {
pub fn from_path(path: &Path) -> Result<Self> ... | code_fim | medium | {
"lang": "rust",
"repo": "ethanabrooks/autograder",
"path": "/autograder/src/labels.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Labels {
pub fn from_path(path: &Path) -> Result<Self> {
let yaml = fs::read_to_string(path).context(ReadError { path })?;
serde_yaml::from_str(&yaml).context(LabelsParseError { yaml })
}
}<|fim_prefix|>// repo: ethanabrooks/autograder path: /autograder/src/labels.rs
use crat... | code_fim | medium | {
"lang": "rust",
"repo": "ethanabrooks/autograder",
"path": "/autograder/src/labels.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn override_colors(&self, colors: &mut HashMap<ID, Color>, ui: &UI) {
let color = ui
.cs
.get_def("something associated with something else", Color::PURPLE);
match self {
ShowAssociatedState::BuildingSelected(_, cars) => {
for c i... | code_fim | hard | {
"lang": "rust",
"repo": "cyrex562/abstreet",
"path": "/game/src/debug/associated.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: cyrex562/abstreet path: /game/src/debug/associated.rs
use crate::helpers::ID;
use crate::render::ExtraShapeID;
use crate::ui::UI;
use ezgui::Color;
use map_model::{BuildingID, DirectedRoadID, IntersectionID};
use sim::{AgentID, CarID};
use std::collections::{HashMap, HashSet};
// TODO Maybe jus... | code_fim | hard | {
"lang": "rust",
"repo": "cyrex562/abstreet",
"path": "/game/src/debug/associated.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Riduidel/codingame path: /src/main/9 - community/porcupine_fever.rs
use std::io;
use std::cmp;
macro_rules! parse_input {
($x:expr, $t:ident) => ($x.trim().parse::<$t>().unwrap())
}
#[derive(Debug, Copy, Clone)]
struct Cage {
pub sick:i32,
pub healthy:i32,
pub alive:... | code_fim | hard | {
"lang": "rust",
"repo": "Riduidel/codingame",
"path": "/src/main/9 - community/porcupine_fever.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut input_line = String::new();
io::stdin().read_line(&mut input_line).unwrap();
// Number of porcupine cages
let n = parse_input!(input_line, i32);
let mut input_line = String::new();
io::stdin().read_line(&mut input_line).unwrap();
// Number of years to wait
le... | code_fim | medium | {
"lang": "rust",
"repo": "Riduidel/codingame",
"path": "/src/main/9 - community/porcupine_fever.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl From<String> for OperatingSystem {
fn from(item: String) -> Self {
match &item[..] {
// Values based on https://doc.rust-lang.org/std/env/consts/constant.OS.html
"linux" => Self::Linux,
"macos" => Self::MacOS,
_ => Self::Unsupported,
... | code_fim | hard | {
"lang": "rust",
"repo": "gnoliyil/fuchsia",
"path": "/src/developer/ffx/plugins/emulator/configuration/src/enumerations.rs",
"mode": "spm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: gnoliyil/fuchsia path: /src/developer/ffx/plugins/emulator/configuration/src/enumerations.rs
// Copyright 2021 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//! This module holds the common data ... | code_fim | hard | {
"lang": "rust",
"repo": "gnoliyil/fuchsia",
"path": "/src/developer/ffx/plugins/emulator/configuration/src/enumerations.rs",
"mode": "psm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: j-rock/fortress path: /fortress/src/lib/control/controller.rs
use crate::{
app::StatusOr,
control::{
ControlEvent,
ControllerId,
ControllerEvent,
GamepadControls,
KeyboardControls
},
file::{
ConfigWatcher,
SimpleConfigManage... | code_fim | hard | {
"lang": "rust",
"repo": "j-rock/fortress",
"path": "/fortress/src/lib/control/controller.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Controller {
pub fn new(config_watcher: &mut ConfigWatcher) -> StatusOr<Controller> {
let config_manager = SimpleConfigManager::from_config_resource(config_watcher, "gamepad.conf")?;
Ok(Controller {
keyboard: KeyboardControls::new(),
gamepad: GamepadControl... | code_fim | hard | {
"lang": "rust",
"repo": "j-rock/fortress",
"path": "/fortress/src/lib/control/controller.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: w0rdsm1th/advent_code_2019_rust path: /src/own_macros/hashmap.rs
// TODO - can share macro with main.rs but not with other modules, e.g. dayX.rs
<|fim_suffix|>
#[macro_export]
macro_rules! hashmap {
($( $key: expr => $val: expr ),*) => {{
let mut map = ::std::collections::HashMap:... | code_fim | hard | {
"lang": "rust",
"repo": "w0rdsm1th/advent_code_2019_rust",
"path": "/src/own_macros/hashmap.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>// https://doc.rust-lang.org/std/collections/struct.HashMap.html#examples
// let timber_resources: HashMap<&str, i32> = [("Norway", 100), ("Denmark", 50), ("Iceland", 10)]
// .iter().cloned().collect();<|fim_prefix|>// repo: w0rdsm1th/advent_code_2019_rust path: /src/own_macros/hashmap.rs
// TODO - can ... | code_fim | hard | {
"lang": "rust",
"repo": "w0rdsm1th/advent_code_2019_rust",
"path": "/src/own_macros/hashmap.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: AlvaroEFMota/aprendendo_rust path: /src/threads.rs
use std::sync::mpsc;
use std::thread;
use std::time::Duration;
use std::sync::{Arc, Mutex};
pub fn run() {
let handle = thread::spawn(|| {
for i in 1..10 {
println!("hi number {} from the spawned thread!", i);
... | code_fim | hard | {
"lang": "rust",
"repo": "AlvaroEFMota/aprendendo_rust",
"path": "/src/threads.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Using channels
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
let val = String::from("Hi");
tx.send(val).unwrap();
});
let receiver = rx.recv().unwrap();
println!("Got: {}", receiver);
//Producer and Consumer
let (tx, rx) = mpsc::channel();
... | code_fim | hard | {
"lang": "rust",
"repo": "AlvaroEFMota/aprendendo_rust",
"path": "/src/threads.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: GitHubdeWill/music_generator path: /src/lib.rs
#![crate_name = "music_generator"]
<|fim_suffix|>/// There are 12 simi-tone notes in an octave.
static NOTES_PER_OCTAVE: i32 = 12;<|fim_middle|>pub mod representations;
pub use representations::note::Note;
pub use representations::interval::Interva... | code_fim | medium | {
"lang": "rust",
"repo": "GitHubdeWill/music_generator",
"path": "/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// There are 12 simi-tone notes in an octave.
static NOTES_PER_OCTAVE: i32 = 12;<|fim_prefix|>// repo: GitHubdeWill/music_generator path: /src/lib.rs
#![crate_name = "music_generator"]
<|fim_middle|>pub mod representations;
pub use representations::note::Note;
pub use representations::interval::Interva... | code_fim | medium | {
"lang": "rust",
"repo": "GitHubdeWill/music_generator",
"path": "/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: user-signal/typeclasses-noel-des-speakers path: /code/Rust/src/ord.rs
pub trait Ordered {
fn gt(l: &Self, r: &Self) -> bool;
fn eq(l: &Self, r: &Self) -> bool;
}
impl Ordered for i32 {
fn gt(l: &Self, r: &Self) -> bool { return l > r; }
fn eq(l: &Self, r: &Self) -> bool { return... | code_fim | medium | {
"lang": "rust",
"repo": "user-signal/typeclasses-noel-des-speakers",
"path": "/code/Rust/src/ord.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> A::gt(&l.0, &r.0) || (A::eq(&l.0, &r.0) && B::gt(&l.1, &r.1))
}
fn eq(l: &Self, r: &Self) -> bool {
A::eq(&l.0, &r.0) && B::eq(&l.1, &r.1)
}
}<|fim_prefix|>// repo: user-signal/typeclasses-noel-des-speakers path: /code/Rust/src/ord.rs
pub trait Ordered {
fn gt(l: &Self, r:... | code_fim | hard | {
"lang": "rust",
"repo": "user-signal/typeclasses-noel-des-speakers",
"path": "/code/Rust/src/ord.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>}
impl<A: Ordered, B: Ordered> Ordered for (A, B) {
fn gt(l: &Self, r: &Self) -> bool {
A::gt(&l.0, &r.0) || (A::eq(&l.0, &r.0) && B::gt(&l.1, &r.1))
}
fn eq(l: &Self, r: &Self) -> bool {
A::eq(&l.0, &r.0) && B::eq(&l.1, &r.1)
}
}<|fim_prefix|>// repo: user-signal/typeclas... | code_fim | hard | {
"lang": "rust",
"repo": "user-signal/typeclasses-noel-des-speakers",
"path": "/code/Rust/src/ord.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // run through all the other rooms and see if they intersect with this one
let failed = rooms
.iter()
.any(|other_room| new_room.intersects_with(other_room));
if !failed {
create_room(new_room, &mut map);
if rooms.is_empty() {
... | code_fim | hard | {
"lang": "rust",
"repo": "ncoif/tcod-roguelike",
"path": "/src/dungeon_generator.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ncoif/tcod-roguelike path: /src/dungeon_generator.rs
extern crate rand;
use rand::Rng;
use std::cmp;
pub const MAP_WIDTH: i32 = 120;
pub const MAP_HEIGHT: i32 = 80;
const ROOM_MAX_SIZE: i32 = 10;
const ROOM_MIN_SIZE: i32 = 6;
const MAX_ROOMS: i32 = 50;
pub type Map = Vec<Vec<Tile>>;
pub fn ... | code_fim | hard | {
"lang": "rust",
"repo": "ncoif/tcod-roguelike",
"path": "/src/dungeon_generator.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: nabijaczleweli/checksums path: /src/error.rs
/// Enum representing each way the appication can fail.
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum Error {
/// No errors occured, everything executed correctly.
NoError,
/// Parsing of command-line options failed.
Opti... | code_fim | hard | {
"lang": "rust",
"repo": "nabijaczleweli/checksums",
"path": "/src/error.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl From<i32> for Error {
fn from(i: i32) -> Self {
match i {
0 => Error::NoError,
1 => Error::OptionParsingError,
2 => Error::HashLengthDiffers,
3 => Error::HashesFileParsingFailure,
i => Error::NFilesDiffer(i - 3),
}
}
... | code_fim | hard | {
"lang": "rust",
"repo": "nabijaczleweli/checksums",
"path": "/src/error.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let camera = Camera::new(look_from, look_at, Vec3::new(0.0, 1.0, 0.0), 15.0, width as f64 / height as f64, aperture, dist_to_focus);
let mut list: Vec<Box<dyn Hitable>> = vec![];
list.push(Box::new(Sphere::new(Vec3::new(0.0, 1.0, 0.0), 1.0, Material::Dielectric {refraction: 1.5})));
list... | code_fim | hard | {
"lang": "rust",
"repo": "jackyarndley/rust-ray",
"path": "/src/util/scenes.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> for a in -11..11 {
for b in -11..11 {
let choose_mat = rng.gen::<f64>();
let center = Vec3::new(a as f64 + 0.9 * rng.gen::<f64>(), 0.2, b as f64 + 0.9 * rng.gen::<f64>());
if (center - Vec3::new(4.0, 0.2, 0.0)).length() > 0.9 {
if choose_mat ... | code_fim | hard | {
"lang": "rust",
"repo": "jackyarndley/rust-ray",
"path": "/src/util/scenes.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jackyarndley/rust-ray path: /src/util/scenes.rs
use crate::objects::{HitableList, Sphere, Hitable, Triangle};
use crate::material::Material;
use crate::util::{load_model, Vec3, Camera};
use rand::{thread_rng, Rng};
pub fn simple_scene(width: usize, height: usize) -> (Camera, HitableList) {
... | code_fim | hard | {
"lang": "rust",
"repo": "jackyarndley/rust-ray",
"path": "/src/util/scenes.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let inner = match &self.state {
State::Euclid(state) => {
let (a, b, n) = state.congruence;
let res = euclid::congruence(a, b, n);
let congruence_html = match &res {
Ok(result) => html! {
<div>{... | code_fim | hard | {
"lang": "rust",
"repo": "oeb25/web-dm",
"path": "/web/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: oeb25/web-dm path: /web/src/main.rs
:*};
mod euclid;
#[derive(Debug)]
enum Msg {
ChangeState(State),
// Euclid
GcdLeft(InputData),
GcdRight(InputData),
CongruenceA(InputData),
CongruenceB(InputData),
CongruenceN(InputData),
ChiniseB1(InputData),
ChiniseN1(In... | code_fim | hard | {
"lang": "rust",
"repo": "oeb25/web-dm",
"path": "/web/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let expect = logic.expect.clone();
let expect_str = format!("Expecting {}", if expect { "true" } else { "false" });
html! {
<div>
<textarea oninput=|e| Msg::Change(e), />
<input type="chec... | code_fim | hard | {
"lang": "rust",
"repo": "oeb25/web-dm",
"path": "/web/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> &self.0
}
}
#[doc = "Field `ADMA` writer - ADMA Error Signal Enable"]
pub struct ADMA_W<'a> {
w: &'a mut W,
}
impl<'a> ADMA_W<'a> {
#[doc = r"Writes `variant` to the field"]
#[inline(always)]
pub fn variant(self, variant: ADMA_A) -> &'a mut W {
self.bit(variant.into())
... | code_fim | hard | {
"lang": "rust",
"repo": "atsamd-rs/atsamd",
"path": "/pac/atsame51j/src/sdhc0/eisier_emmc_mode.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: atsamd-rs/atsamd path: /pac/atsame51j/src/sdhc0/eisier_emmc_mode.rs
{
#[inline(always)]
pub(crate) fn new(bits: bool) -> Self {
DATTEO_R(crate::FieldReader::new(bits))
}
#[doc = r"Get enumerated values variant"]
#[inline(always)]
pub fn variant(&self) -> DATTEO_A... | code_fim | hard | {
"lang": "rust",
"repo": "atsamd-rs/atsamd",
"path": "/pac/atsame51j/src/sdhc0/eisier_emmc_mode.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> variant as u8 != 0
}
}
#[doc = "Field `ACMD` reader - Auto CMD Error Signal Enable"]
pub struct ACMD_R(crate::FieldReader<bool, ACMD_A>);
impl ACMD_R {
#[inline(always)]
pub(crate) fn new(bits: bool) -> Self {
ACMD_R(crate::FieldReader::new(bits))
}
#[doc = r"Get enumer... | code_fim | hard | {
"lang": "rust",
"repo": "atsamd-rs/atsamd",
"path": "/pac/atsame51j/src/sdhc0/eisier_emmc_mode.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Check they are treated as the same even though their underlying ports are different.
assert_eq!(peer_addr1, peer_addr2);
assert_eq!(peer_addr1.0, socket_addr1);
assert_eq!(peer_addr2.0, socket_addr2);
assert_eq!(peer_addr1.0.port(), 8080);
assert_eq!(peer_addr2.0.port(), 8081);
}<|fim_prefix|>// ... | code_fim | hard | {
"lang": "rust",
"repo": "mimblewimble/grin",
"path": "/p2p/tests/peer_addr.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mimblewimble/grin path: /p2p/tests/peer_addr.rs
// Copyright 2021 The Grin Developers
//
// 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://www.apache.o... | code_fim | hard | {
"lang": "rust",
"repo": "mimblewimble/grin",
"path": "/p2p/tests/peer_addr.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>e, Qname};
pub use self::uri_qualified_name::{ParsedUriQualifiedName, UriQualifiedName};<|fim_prefix|>// repo: lo48576/xml-string path: /src/names.rs
//! Name types.
mod chars;
mod error;
mod name;
mod ncname;
mod nmtoken;
mod qname;
mo<|fim_middle|>d uri_qualified_name;
pub use self::error::NameError;... | code_fim | medium | {
"lang": "rust",
"repo": "lo48576/xml-string",
"path": "/src/names.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: lo48576/xml-string path: /src/names.rs
//! Name types.
mod chars;
mod error;
mod name;
mod ncname;
mod nmtoken;
mod qname;
mo<|fim_suffix|>e, Qname};
pub use self::uri_qualified_name::{ParsedUriQualifiedName, UriQualifiedName};<|fim_middle|>d uri_qualified_name;
pub use self::error::NameError;... | code_fim | medium | {
"lang": "rust",
"repo": "lo48576/xml-string",
"path": "/src/names.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn variadic(name: &str, params_fixed: usize) -> Self {
Self {
name: name.into(),
params_fixed,
is_variadic: true,
}
}
}
// ArgMode represents an argument being passed to a targeted ConsoleFunc.
#[derive(Debug, Copy, Clone)]
pub enum ArgMode ... | code_fim | hard | {
"lang": "rust",
"repo": "rfwatson/weblog",
"path": "/weblog-proc-macro/src/weblog_impl.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rfwatson/weblog path: /weblog-proc-macro/src/weblog_impl.rs
use proc_macro::TokenStream;
use proc_macro2::{Ident, Span, TokenStream as TokenStream2};
use quote::quote;
use std::cmp;
use syn::parse::{Parse, ParseStream};
use syn::punctuated::Punctuated;
use syn::{parse_macro_input, Expr, Result, ... | code_fim | hard | {
"lang": "rust",
"repo": "rfwatson/weblog",
"path": "/weblog-proc-macro/src/weblog_impl.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: matt-thomson/advent-of-code path: /2022/day05/src/step.rs
use std::str::FromStr;
use eyre::ErrReport;
#[derive(Debug)]
pub struct Step {
pub count: usize,
pub from: usize,
pub to: usize,
}
impl FromStr for Step {
type Err = ErrReport;
<|fim_suffix|> let count = parts[1... | code_fim | medium | {
"lang": "rust",
"repo": "matt-thomson/advent-of-code",
"path": "/2022/day05/src/step.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn from_str(input: &str) -> Result<Self, Self::Err> {
let parts: Vec<_> = input.split_whitespace().collect();
let count = parts[1].parse()?;
let from = parts[3].parse()?;
let to = parts[5].parse()?;
Ok(Self { count, from, to })
}
}<|fim_prefix|>// repo: ma... | code_fim | easy | {
"lang": "rust",
"repo": "matt-thomson/advent-of-code",
"path": "/2022/day05/src/step.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let a = Rc::new(RefCell::new(RefTreeNode { left: RefTree::Empty, right: RefTree::Empty }));
let mut b = Vec::<Ref<RefTreeNode>>::new();
let mut c = RefTreeNode { left: RefTree::Empty, right: RefTree::Empty };
b.push(a.borrow());
let d: Ref<RefTreeNode> = a.borrow();
let e = RefTreeNode { left:... | code_fim | medium | {
"lang": "rust",
"repo": "baban/rust_test",
"path": "/ref_cell.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> //println!("{:?}", a);
//println!("{:?}", a.borrow());
// b.push(a.borrow());
//println!("{:?}", *(a.borrow()));
//short_lifetime(b);
}<|fim_prefix|>// repo: baban/rust_test path: /ref_cell.rs
use std::rc::Rc;
use std::cell::Cell;
use std::cell::RefCell;
use std::cell::Ref;
struct TreeNode {
... | code_fim | hard | {
"lang": "rust",
"repo": "baban/rust_test",
"path": "/ref_cell.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: baban/rust_test path: /ref_cell.rs
use std::rc::Rc;
use std::cell::Cell;
use std::cell::RefCell;
use std::cell::Ref;
struct TreeNode {
left: Tree,
right: Tree
}
enum Tree {
Node(Box<TreeNode>),
Leaf { value: i32 },
Empty
}
struct RefTreeNode {
left: RefTree,
right: RefTree
}
<|... | code_fim | medium | {
"lang": "rust",
"repo": "baban/rust_test",
"path": "/ref_cell.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[test]
fn is_prime_999983() {
assert!(primes::is_prime(999983));
}
#[test]
fn is_prime_1000999983() {
assert!(!primes::is_prime(1000999983));
}<|fim_prefix|>// repo: mvertescher/primes-testing-workshop-rs path: /tests/large_primes.rs
//! Determine if 999983 is prime
<|fim_middle|>use primes_te... | code_fim | easy | {
"lang": "rust",
"repo": "mvertescher/primes-testing-workshop-rs",
"path": "/tests/large_primes.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mvertescher/primes-testing-workshop-rs path: /tests/large_primes.rs
//! Determine if 999983 is prime
<|fim_suffix|> assert!(primes::is_prime(999983));
}
#[test]
fn is_prime_1000999983() {
assert!(!primes::is_prime(1000999983));
}<|fim_middle|>use primes_testing_workshop as primes;
#[te... | code_fim | medium | {
"lang": "rust",
"repo": "mvertescher/primes-testing-workshop-rs",
"path": "/tests/large_primes.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), io::Error>> {
Pin::new(&mut self.inner).poll_close(cx)
}
}<|fim_prefix|>// repo: Sushisource/hubtain path: /src/progresswriter.rs
use futures::{io::AsyncWrite, task::Context};
use std::{
io::{self},
pin::... | code_fim | hard | {
"lang": "rust",
"repo": "Sushisource/hubtain",
"path": "/src/progresswriter.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Sushisource/hubtain path: /src/progresswriter.rs
use futures::{io::AsyncWrite, task::Context};
use std::{
io::{self},
pin::Pin,
sync::{atomic::AtomicUsize, atomic::Ordering, Arc},
task::Poll,
};
/// A wrapper around an `AsyncWrite` stream which counts the number of bytes that ha... | code_fim | hard | {
"lang": "rust",
"repo": "Sushisource/hubtain",
"path": "/src/progresswriter.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl<W> ProgressWriter<W> {
// / Returns the number of bytes that have been written to the stream so far
// pub fn get_written(&self) -> usize {
// self.bytes_writen.load(Ordering::SeqCst)
// }
}
impl<W> AsyncWrite for ProgressWriter<W>
where
W: AsyncWrite + Unpin,
{
fn poll_w... | code_fim | medium | {
"lang": "rust",
"repo": "Sushisource/hubtain",
"path": "/src/progresswriter.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[aoc(day8, part1)]
pub fn part1(program: &HashMap<usize, Instruction>) -> i32 {
match evaluate_program(&program) {
ProgramOutput::Error(v) => v,
ProgramOutput::Ok(_) => panic!("shouldn't have gotten here"),
}
}
#[aoc(day8, part2)]
pub fn part2(program_original: &HashMap<usize, In... | code_fim | hard | {
"lang": "rust",
"repo": "C-Saunders/advent-of-code-2020",
"path": "/src/day8.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[aoc(day8, part2)]
pub fn part2(program_original: &HashMap<usize, Instruction>) -> i32 {
let mut line_number_to_change = 1;
loop {
let mut program = program_original.clone();
let current_line = program.entry(line_number_to_change);
current_line.and_modify(|mut instruction... | code_fim | hard | {
"lang": "rust",
"repo": "C-Saunders/advent-of-code-2020",
"path": "/src/day8.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: C-Saunders/advent-of-code-2020 path: /src/day8.rs
use std::collections::{HashMap, HashSet};
use aoc_runner_derive::{aoc, aoc_generator};
use regex::Regex;
#[derive(Clone, Copy)]
enum OpCode {
Nop,
Acc,
Jmp,
}
impl OpCode {
fn from_str(value: &str) -> OpCode {
match val... | code_fim | hard | {
"lang": "rust",
"repo": "C-Saunders/advent-of-code-2020",
"path": "/src/day8.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: japaric-archived/seq.rs path: /tests/seq.rs
extern crate collect;
#[macro_use]
extern crate seq;
use std::collections::{BitVec, HashMap, HashSet, VecMap};
use collect::{TreeMap, TreeSet};
#[test]
fn bitvec() {
let mut v = BitVec::new();
assert_eq!(v, seq![]);
v.push(true);
v.p... | code_fim | hard | {
"lang": "rust",
"repo": "japaric-archived/seq.rs",
"path": "/tests/seq.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[test]
fn treemap() {
let mut m = TreeMap::new();
assert_eq!(m, seq!{});
m.insert('b', "banana".to_string());
m.insert('c', "coconut".to_string());
m.insert('a', "apple".to_string());
assert_eq!(m, seq!{
'a' => "apple".to_string(),
'b' => "banana".to_string(),
... | code_fim | hard | {
"lang": "rust",
"repo": "japaric-archived/seq.rs",
"path": "/tests/seq.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[test]
fn treeset() {
let mut s = TreeSet::new();
assert_eq!(s, seq!{});
s.insert("three");
s.insert("one");
s.insert("two");
assert_eq!(s, seq!["one", "two", "three"]);
}
#[test]
fn vec() {
let mut v = Vec::new();
let rhs: Vec<_> = seq![];
assert_eq!(v, rhs);
v... | code_fim | hard | {
"lang": "rust",
"repo": "japaric-archived/seq.rs",
"path": "/tests/seq.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.