text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_suffix|> let cs = ConstraintSystem::<F>::new_ref();
let parameters_var = SG::ParametersVar::new_constant(cs.clone(), parameters).unwrap();
let signature_var = SG::SignatureVar::new_witness(cs.clone(), || Ok(&sig)).unwrap();
let pk_var = SG::PublicKeyVar::new_witness(cs.clone(), || ... | code_fim | hard | {
"lang": "rust",
"repo": "mimoo/r1cs-tutorial",
"path": "/simple-payments/src/signature/constraints.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mimoo/r1cs-tutorial path: /simple-payments/src/signature/constraints.rs
use ark_ff::Field;
use ark_r1cs_std::prelude::*;
use ark_relations::r1cs::SynthesisError;
use crate::signature::SignatureScheme;
pub trait SigVerifyGadget<S: SignatureScheme, ConstraintF: Field> {
type ParametersVar: A... | code_fim | hard | {
"lang": "rust",
"repo": "mimoo/r1cs-tutorial",
"path": "/simple-payments/src/signature/constraints.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: loloof64/SimpleCalculator path: /src/main.rs
#![windows_subsystem = "windows"]
use relm::{Widget};
use gtk::prelude::*;
use gtk::{Inhibit};
use relm_derive::{Msg, widget};
pub enum Operator {
Plus,
Minus,
Times,
}
pub struct AppModel {
result: Option<i16>
}
#[derive(Msg)]
pub ... | code_fim | hard | {
"lang": "rust",
"repo": "loloof64/SimpleCalculator",
"path": "/src/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> for letter in vec!["+", "-", "*"] {
self.cb_operator.append(Some(letter), letter);
}
}
view! {
gtk::Window {
gtk::Box {
orientation: gtk::Orientation::Horizontal,
#[name="cb_operand_1"]
gtk::ComboBoxTe... | code_fim | hard | {
"lang": "rust",
"repo": "loloof64/SimpleCalculator",
"path": "/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: davidszotten/advent-of-code-2018 path: /src/bin/day24.rs
use aoc2018::{dispatch, Result};
use lazy_static::lazy_static;
use regex::{CaptureMatches, Captures, Regex};
use std::cmp::min;
use std::collections::{HashMap, HashSet};
fn main() {
dispatch(&part1, &part2)
}
#[derive(Debug, Clone)]
... | code_fim | hard | {
"lang": "rust",
"repo": "davidszotten/advent-of-code-2018",
"path": "/src/bin/day24.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>struct UnitWalker<'r, 't> {
caps: CaptureMatches<'r, 't>,
unit_type: UnitType,
counter: usize,
}
impl<'r, 't> UnitWalker<'r, 't> {
fn new<'s: 't + 'r>(unit_type: UnitType, s: &'s str) -> Self {
lazy_static! {
static ref RE: Regex = Regex::new(r"(?P<units>\d+) units eac... | code_fim | hard | {
"lang": "rust",
"repo": "davidszotten/advent-of-code-2018",
"path": "/src/bin/day24.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let caps = RE.captures_iter(s);
UnitWalker {
caps,
unit_type,
counter: 0,
}
}
}
impl<'r, 't> Iterator for UnitWalker<'r, 't> {
type Item = Unit;
fn next(&mut self) -> Option<Unit> {
if let Some(caps) = self.caps.next() {
... | code_fim | hard | {
"lang": "rust",
"repo": "davidszotten/advent-of-code-2018",
"path": "/src/bin/day24.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: nbaraz/rustboyadvance-ng path: /src/debugger/command.rs
use crate::arm7tdmi::bus::Bus;
use crate::arm7tdmi::{Addr, CpuState};
use crate::disass::Disassembler;
use crate::ioregs::consts::*;
use crate::lcd::*;
use crate::GBAError;
use super::palette_view::create_palette_view;
use super::render_vi... | code_fim | hard | {
"lang": "rust",
"repo": "nbaraz/rustboyadvance-ng",
"path": "/src/debugger/command.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> (addr, 0x100)
}
0 => {
if let Some(Command::HexDump(addr, n)) = self.previous_command {
(addr + (4 * n as u32), 0x100)
} else {
(self.gba.... | code_fim | hard | {
"lang": "rust",
"repo": "nbaraz/rustboyadvance-ng",
"path": "/src/debugger/command.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: str4d/zebra path: /zebra-consensus/src/lib.rs
//! Consensus handling for Zebra.
//!
//! `verify::BlockVerifier` verifies blocks and their transactions, then adds them to
//! `zebra_state::ZebraState`.
//!
//! `mempool::MempoolTransactionVerifier` verifies transactions, and adds them to
//! `memp... | code_fim | hard | {
"lang": "rust",
"repo": "str4d/zebra",
"path": "/zebra-consensus/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub mod block;
pub mod chain;
pub mod checkpoint;
pub mod mempool;
pub mod parameters;
pub mod redjubjub;
mod script;
mod transaction;<|fim_prefix|>// repo: str4d/zebra path: /zebra-consensus/src/lib.rs
//! Consensus handling for Zebra.
//!
//! `verify::BlockVerifier` verifies blocks and their transactio... | code_fim | hard | {
"lang": "rust",
"repo": "str4d/zebra",
"path": "/zebra-consensus/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[macro_export]
macro_rules! chmin {
($a: expr, $($rest: expr),+) => {{
let cmp_min = min!($($rest),+);
if $a > cmp_min { $a = cmp_min; true } else { false }
}};
}<|fim_prefix|>// repo: Shirataki2/competitive_submissions path: /abc193/src/bin/e.rs
#![allow(unused_imports)]
use pro... | code_fim | hard | {
"lang": "rust",
"repo": "Shirataki2/competitive_submissions",
"path": "/abc193/src/bin/e.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Shirataki2/competitive_submissions path: /abc193/src/bin/e.rs
#![allow(unused_imports)]
use proconio::{input, fastout, marker::*};
use std::{cmp::*, collections::*};
#[fastout]
fn main() {
input!(n: usize);
for _ in 0..n {
let mut ans = 1i128 << 126;
input!(x: i128, y: i... | code_fim | hard | {
"lang": "rust",
"repo": "Shirataki2/competitive_submissions",
"path": "/abc193/src/bin/e.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let prod = modulii.iter().product::<i128>();
let mut sum = 0;
for (&residue, &modulus) in residues.iter().zip(modulii) {
let p = prod / modulus;
sum += residue * mod_inv(p, modulus)? * p
}
Some(sum % prod)
}
#[macro_export]
macro_rules! min {
($a: expr) => { ... | code_fim | hard | {
"lang": "rust",
"repo": "Shirataki2/competitive_submissions",
"path": "/abc193/src/bin/e.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn parse_text(&mut self) -> dom::Node {
let offset = self.source.find('<').unwrap_or(self.source.len());
dom::text_node(self.source.drain(..offset).collect())
}
fn parse_node(&mut self) -> dom::Node {
self.consume_spaces();
if self.source.starts_with('<') {... | code_fim | hard | {
"lang": "rust",
"repo": "Jasopaum/rust_browser_engine",
"path": "/src/html.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut nodes = Vec::new();
loop {
self.consume_spaces();
if self.eof() || self.source.starts_with("</") {
break
}
nodes.push(self.parse_node());
}
return nodes;
}
fn eof(&self) -> bool {
self.... | code_fim | hard | {
"lang": "rust",
"repo": "Jasopaum/rust_browser_engine",
"path": "/src/html.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Jasopaum/rust_browser_engine path: /src/html.rs
use std::collections::HashMap;
use crate::dom;
use crate::dom::AttrMap;
struct Parser {
source: String,
}
impl Parser {
fn extract_name(&mut self) -> String {
self.consume_spaces();
let end_name = self.source.find(|c: ch... | code_fim | hard | {
"lang": "rust",
"repo": "Jasopaum/rust_browser_engine",
"path": "/src/html.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mengsuenyan/leetcode path: /leetcode-rs/tests/hard/p1.rs
use leetcode_rs::easy::p1::ListNode;
use leetcode_rs::hard::p1;
#[test]
fn test_find_median_sorted_arrays() {
let cases = vec![
(vec![1, 3], vec![2], 2.0f64),
(vec![1, 2], vec![3, 4], 2.5f64),
];
for (i, (in1,... | code_fim | hard | {
"lang": "rust",
"repo": "mengsuenyan/leetcode",
"path": "/leetcode-rs/tests/hard/p1.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[test]
fn test_is_match_ii() {
let cases = vec![
("aa", "a", false),
("aa", "*", true),
("cb", "?a", false),
("adceb", "*a*b", true),
("", "", true),
];
for (i, (s, p, out1)) in cases.into_iter().enumerate() {
assert_eq!(
p1::is_mat... | code_fim | hard | {
"lang": "rust",
"repo": "mengsuenyan/leetcode",
"path": "/leetcode-rs/tests/hard/p1.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Jimskapt/rust-book-fr path: /FRENCH/listings/ch14-more-about-cargo/output-only-03-use-rand/ajout/additioneur/src/main.rs
use ajouter_un;
use rand;
<|fim_suffix|> let nombre = 10;
println!(
"Hello, world ! {} plus un vaut {} !",
nombre,
ajouter_un::ajouter_un(nombr... | code_fim | easy | {
"lang": "rust",
"repo": "Jimskapt/rust-book-fr",
"path": "/FRENCH/listings/ch14-more-about-cargo/output-only-03-use-rand/ajout/additioneur/src/main.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let nombre = 10;
println!(
"Hello, world ! {} plus un vaut {} !",
nombre,
ajouter_un::ajouter_un(nombre)
);
}<|fim_prefix|>// repo: Jimskapt/rust-book-fr path: /FRENCH/listings/ch14-more-about-cargo/output-only-03-use-rand/ajout/additioneur/src/main.rs
use ajouter_un;
... | code_fim | easy | {
"lang": "rust",
"repo": "Jimskapt/rust-book-fr",
"path": "/FRENCH/listings/ch14-more-about-cargo/output-only-03-use-rand/ajout/additioneur/src/main.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jchambers/advent-of-code-2020 path: /src/bin/day13/main.rs
use std::{error, env};
use itertools::Itertools;
use crate::bus::BusSchedule;
mod bus;
fn main() -> Result<(), Box<dyn error::Error>> {
<|fim_suffix|> println!("Alignment timestamp: {}", schedule.get_alignment_timestamp());
... | code_fim | hard | {
"lang": "rust",
"repo": "jchambers/advent-of-code-2020",
"path": "/src/bin/day13/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> println!("Earliest route arriving after {}: {} @ {}", timestamp, earliest_arrival.route, earliest_arrival.arrival);
println!("Wait {} * route {} = {}", BusSchedule::get_wait_time(timestamp, earliest_arrival.route), earliest_arrival.route,
BusSchedule::get_wait_time(timesta... | code_fim | hard | {
"lang": "rust",
"repo": "jchambers/advent-of-code-2020",
"path": "/src/bin/day13/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.registers[instruction.3 as usize] =
if self.registers[instruction.1 as usize] == instruction.2 {
1
} else {
0
};
}
fn eqrr(&mut self, instruction: &Instruction) {
self.registers[instruction.3 as usize] =
... | code_fim | hard | {
"lang": "rust",
"repo": "jwarwick/aoc_2018",
"path": "/day19/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jwarwick/aoc_2018 path: /day19/src/main.rs
extern crate util;
fn main() {
let contents = util::string_from_file("input.txt");
let result1 = background_process(&contents, [0; 6]);
println!("Part 1 Result: {}", result1);
let c1 = compute(919);
println!("Part 1 Computed: {}",... | code_fim | hard | {
"lang": "rust",
"repo": "jwarwick/aoc_2018",
"path": "/day19/src/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[async_std::test]
async fn negative_should_map_request_when_many_header_matches() {
let srv = given("req/headers/matches/negative-many");
get(&srv.url())
.header("Content-Type", "application/json")
.header("X-Some", "application/json")
.await.unwrap()
.assert_ok();... | code_fim | hard | {
"lang": "rust",
"repo": "gmiam/stubr",
"path": "/lib/tests/req/headers/matches.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: gmiam/stubr path: /lib/tests/req/headers/matches.rs
use surf::get;
use crate::utils::*;
#[async_std::test]
async fn should_map_request_when_header_matches() {
let srv = given("req/headers/matches/single");
get(&srv.url()).header("Content-Type", "application/json").await.unwrap().assert... | code_fim | hard | {
"lang": "rust",
"repo": "gmiam/stubr",
"path": "/lib/tests/req/headers/matches.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let inp = FastInput::new();
let sum = inp.next_as_iter::<u64>().product::<u64>();
println!("{}", sum);
}<|fim_prefix|>// repo: KlasafGeijerstam/Kattis path: /rust/jackolanternjuxtaposition.rs
mod fast_input;
use fast_input::FastInput;
<|fim_middle|>fn main() {
| code_fim | easy | {
"lang": "rust",
"repo": "KlasafGeijerstam/Kattis",
"path": "/rust/jackolanternjuxtaposition.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let sum = inp.next_as_iter::<u64>().product::<u64>();
println!("{}", sum);
}<|fim_prefix|>// repo: KlasafGeijerstam/Kattis path: /rust/jackolanternjuxtaposition.rs
mod fast_input;
use fast_input::FastInput;
<|fim_middle|>fn main() {
let inp = FastInput::new();
| code_fim | easy | {
"lang": "rust",
"repo": "KlasafGeijerstam/Kattis",
"path": "/rust/jackolanternjuxtaposition.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: KlasafGeijerstam/Kattis path: /rust/jackolanternjuxtaposition.rs
mod fast_input;
use fast_input::FastInput;
<|fim_suffix|> let inp = FastInput::new();
let sum = inp.next_as_iter::<u64>().product::<u64>();
println!("{}", sum);
}<|fim_middle|>fn main() {
| code_fim | easy | {
"lang": "rust",
"repo": "KlasafGeijerstam/Kattis",
"path": "/rust/jackolanternjuxtaposition.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: duzhanyuan/tsukuyomi path: /tsukuyomi/src/error.rs
//! Error representation during handling the request.
//!
//! Tsukuyomi models the all errors generated during handling HTTP requests with a trait
//! named [`HttpError`]. This trait is a method for converting itself into an HTTP response.
//!
/... | code_fim | hard | {
"lang": "rust",
"repo": "duzhanyuan/tsukuyomi",
"path": "/tsukuyomi/src/error.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> Self {
inner: Box::new(CompatStatus(status)),
}
}
}
impl From<Box<DynStdError>> for Error {
fn from(e: Box<DynStdError>) -> Self {
Self {
inner: Box::new(BoxedStdCompat(e)),
}
}
}
impl Error {
/// Returns an HTTP status code associa... | code_fim | hard | {
"lang": "rust",
"repo": "duzhanyuan/tsukuyomi",
"path": "/tsukuyomi/src/error.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>/*
A possible logic for SystemTimeError:
fn gen_ste() -> SystemTimeError {
(SystemTime::now() + Duration::from_millis(10)).elapsed().unwrap_err()
}
This may however panic from time to time. NTP could also ruin our day!
*/
#[cfg(test)]
mod test {
no_panic_test!(
duration => Duration,
... | code_fim | hard | {
"lang": "rust",
"repo": "Centril/proptest-arbitrary",
"path": "/src/_std/time.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> (SystemTime::now() + Duration::from_millis(10)).elapsed().unwrap_err()
}
This may however panic from time to time. NTP could also ruin our day!
*/
#[cfg(test)]
mod test {
no_panic_test!(
duration => Duration,
instant => Instant,
system_time => SystemTime
);
}<|fim_pre... | code_fim | hard | {
"lang": "rust",
"repo": "Centril/proptest-arbitrary",
"path": "/src/_std/time.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Centril/proptest-arbitrary path: /src/_std/time.rs
//! Arbitrary implementations for `std::time`.
use super::*;
use std::time::*;
arbitrary!(Duration, SMapped<(u64, u32), Self>;
static_map(any::<(u64, u32)>(), |(a, b)| Duration::new(a, b))
);
// Instant::now() "never" returns the same Ins... | code_fim | hard | {
"lang": "rust",
"repo": "Centril/proptest-arbitrary",
"path": "/src/_std/time.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn seek(
mut scores: &mut Vec<i8>,
mut i: &mut Cursor,
mut j: &mut Cursor,
pattern: &[i8]
) -> usize {
let mut offset = 0;
'outer: loop {
while offset + pattern.len() > scores.len() {
step(&mut scores, &mut i, &mut j)
}
for (i, &v) in pattern.ite... | code_fim | medium | {
"lang": "rust",
"repo": "zeddidragon/Advent-of-Code-2018",
"path": "/src/day14.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: zeddidragon/Advent-of-Code-2018 path: /src/day14.rs
struct Cursor {
idx: usize
}
impl Cursor {
fn val(&self, xs: &Vec<i8>) -> i8 {
xs[self.idx]
}
fn spin(&mut self, xs: &Vec<i8>) {
self.idx = (self.idx + 1 + self.val(xs) as usize) % xs.len();
}
}
fn print_s... | code_fim | hard | {
"lang": "rust",
"repo": "zeddidragon/Advent-of-Code-2018",
"path": "/src/day14.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl std::fmt::Display for NiaGetDefinedActionsCommandResult {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
NiaGetDefinedActionsCommandResult::Success(result) => {
write!(f, "{:?}.", result)
}
NiaGetDefine... | code_fim | hard | {
"lang": "rust",
"repo": "emirayka/nia_interpreter_core",
"path": "/src/interpreter/event_loop/interpreter_command_results/get_defined_actions_result.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let message = error.to_string();
if error.is_failure() {
NiaGetDefinedActionsCommandResult::Failure(message)
} else {
NiaGetDefinedActionsCommandResult::Error(message)
}
}
}
impl From<Result<Vec<NamedAction>, Error>>
for NiaGetDefinedAction... | code_fim | medium | {
"lang": "rust",
"repo": "emirayka/nia_interpreter_core",
"path": "/src/interpreter/event_loop/interpreter_command_results/get_defined_actions_result.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub struct Register;
impl PluginRegister for Register {
fn register() {
let arc_reg = plugin_api::PLUGIN_REGISTRY.clone();
let mut reg = arc_reg.lock().unwrap();
reg.register(
String::from("pow"), Box::new(PluginPow::default())
);
}
}<|fim_prefix|>// rep... | code_fim | medium | {
"lang": "rust",
"repo": "mersinvald/rust_plugin_test",
"path": "/plugin_pow/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mersinvald/rust_plugin_test path: /plugin_pow/src/lib.rs
#[macro_use]
extern crate lazy_static;
extern crate plugin_api;
use std::collections::HashMap;
use std::any::Any;
use std::thread;
#[derive(Default, Copy, Clone, Debug)]
struct PluginPow {
x: i32,
pow: i32,
}
impl plugin_api::Pl... | code_fim | medium | {
"lang": "rust",
"repo": "mersinvald/rust_plugin_test",
"path": "/plugin_pow/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let arc_reg = plugin_api::PLUGIN_REGISTRY.clone();
let mut reg = arc_reg.lock().unwrap();
reg.register(
String::from("pow"), Box::new(PluginPow::default())
);
}
}<|fim_prefix|>// repo: mersinvald/rust_plugin_test path: /plugin_pow/src/lib.rs
#[macro_use]
ex... | code_fim | hard | {
"lang": "rust",
"repo": "mersinvald/rust_plugin_test",
"path": "/plugin_pow/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: hitmoon/raytracer path: /src/sphere.rs
use std::rc::Rc;
use crate::hittable::{HitRecord, Hittable};
use crate::material::Material;
use crate::ray::Ray;
use crate::vec3::{length_squared, Point3};
#[derive(Debug)]
pub(crate) struct Sphere {
center: Point3,
radius: f64,
material: Rc<d... | code_fim | hard | {
"lang": "rust",
"repo": "hitmoon/raytracer",
"path": "/src/sphere.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let sqrtd = discriminant.sqrt();
// Find the nearest root that lies in the acceptable range.
let mut root = (-half_b - sqrtd) / a;
if root < t_min || t_max < root {
root = (-half_b + sqrtd) / a;
if root < t_min || t_max < root {
ret... | code_fim | hard | {
"lang": "rust",
"repo": "hitmoon/raytracer",
"path": "/src/sphere.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: marco-c/gecko-dev-comments-removed path: /third_party/rust/wasm-encoder/src/component/aliases.rs
use super::{COMPONENT_SORT, CORE_MODULE_SORT, CORE_SORT, CORE_TYPE_SORT, TYPE_SORT};
use crate::{
encode_section, ComponentExportKind, ComponentSection, ComponentSectionId, Encode, ExportKind,
};... | code_fim | hard | {
"lang": "rust",
"repo": "marco-c/gecko-dev-comments-removed",
"path": "/third_party/rust/wasm-encoder/src/component/aliases.rs",
"mode": "psm",
"license": "LLVM-exception",
"source": "the-stack-v2"
} |
<|fim_suffix|>
pub fn is_empty(&self) -> bool {
self.num_added == 0
}
pub fn alias(&mut self, alias: Alias<'_>) -> &mut Self {
alias.encode(&mut self.bytes);
self.num_added += 1;
self
}
}
impl Encode for ComponentAliasSection {
fn encode(&self, sink: &mut V... | code_fim | hard | {
"lang": "rust",
"repo": "marco-c/gecko-dev-comments-removed",
"path": "/third_party/rust/wasm-encoder/src/component/aliases.rs",
"mode": "spm",
"license": "LLVM-exception",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: fitzgen/preduce path: /src/bin/reducers/chunks.rs
extern crate preduce_chunks_reducer;
extern crate preduce_ranges_reducer;
<|fim_suffix|> run_ranges::<Chunks>()
}<|fim_middle|>use preduce_chunks_reducer::Chunks;
use preduce_ranges_reducer::run_ranges;
fn main() {
| code_fim | medium | {
"lang": "rust",
"repo": "fitzgen/preduce",
"path": "/src/bin/reducers/chunks.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> run_ranges::<Chunks>()
}<|fim_prefix|>// repo: fitzgen/preduce path: /src/bin/reducers/chunks.rs
extern crate preduce_chunks_reducer;
extern crate preduce_ranges_reducer;
<|fim_middle|>use preduce_chunks_reducer::Chunks;
use preduce_ranges_reducer::run_ranges;
fn main() {
| code_fim | medium | {
"lang": "rust",
"repo": "fitzgen/preduce",
"path": "/src/bin/reducers/chunks.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: adwhit/advent-of-code-2017 path: /src/bin/04_high_entropy_passphrases.rs
extern crate advent_of_code;
extern crate failure;
extern crate itertools;
use advent_of_code::Result;
use std::fs;
use std::io::prelude::*;
use itertools::Itertools;
fn get_data() -> Result<Vec<Vec<String>>> {
let m... | code_fim | hard | {
"lang": "rust",
"repo": "adwhit/advent-of-code-2017",
"path": "/src/bin/04_high_entropy_passphrases.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn run() -> Result<()> {
let data = get_data()?;
let data: Vec<Vec<&str>> = data.iter()
.map(|row| row.iter().map(|s| s.as_ref()).collect())
.collect_vec();
let data: Vec<&[&str]> = data.iter().map(|row| row.as_slice()).collect();
let outcome1 = passphrase_v1(&data);
pr... | code_fim | medium | {
"lang": "rust",
"repo": "adwhit/advent-of-code-2017",
"path": "/src/bin/04_high_entropy_passphrases.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: CoreRC/rtsam path: /src/inference/cluster_tree.rs
use crate::inference::FactorGraph;
use std::sync::Arc;
/// A cluster is just a collection of factors
#[derive(Debug)]
pub struct Cluster<Graph: FactorGraph> {
frontals: Vec<u64>,
children: Vec<Box<Self>>,
factors: Graph,
}
/// A Clu... | code_fim | hard | {
"lang": "rust",
"repo": "CoreRC/rtsam",
"path": "/src/inference/cluster_tree.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut factors_1 = SimpleFactorGraph::new();
factors_1.insert(TestFactor {
inner: "cluster1".into(),
_keys: [1].into(),
});
let mut cluster_1 =
Cluster::<SimpleFactorGraph<TestFactor>>::from_single_key(1, &mut factors_1.factors);
... | code_fim | hard | {
"lang": "rust",
"repo": "CoreRC/rtsam",
"path": "/src/inference/cluster_tree.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: SerhoLiu/eakio path: /src/main.rs
extern crate eakio;
<|fim_suffix|> eakio::init_logger();
if let Err(e) = eakio::command() {
println!("Error: {}", e);
process::exit(1)
}
}<|fim_middle|>use std::process;
fn main() {
| code_fim | easy | {
"lang": "rust",
"repo": "SerhoLiu/eakio",
"path": "/src/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> eakio::init_logger();
if let Err(e) = eakio::command() {
println!("Error: {}", e);
process::exit(1)
}
}<|fim_prefix|>// repo: SerhoLiu/eakio path: /src/main.rs
extern crate eakio;
use std::process;
<|fim_middle|>fn main() {
| code_fim | easy | {
"lang": "rust",
"repo": "SerhoLiu/eakio",
"path": "/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: peermaps/osmxq path: /src/bin.rs
#![feature(async_closure,backtrace)]
use async_std::{task,channel};
use std::collections::HashMap;
use osmxq::{XQ,Record,RecordId,Position};
use desert::{varint,ToBytes,FromBytes,CountBytes};
type Error = Box<dyn std::error::Error+Send+Sync+'static>;
#[async_st... | code_fim | hard | {
"lang": "rust",
"repo": "peermaps/osmxq",
"path": "/src/bin.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut size = 0;
for (r_id,r) in records {
let xid = r_id*2 + if r.position.is_some() { 1 } else { 0 };
size += varint::length(xid);
size += r.position.map(|p| p.count_bytes()).unwrap_or(0);
size += r.refs.count_bytes();
}
let mut buf = vec![0u8;size];
let mut ... | code_fim | hard | {
"lang": "rust",
"repo": "peermaps/osmxq",
"path": "/src/bin.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> if buf.is_empty() { return Ok(0) }
let mut offset = 0;
while offset < buf.len() {
let (s,xid) = varint::decode(&buf[offset..])?;
offset += s;
let id = xid/2;
let mut position = None;
if xid % 2 == 1 {
let (s,p) = Position::from_bytes(&buf[offset..])?;
... | code_fim | hard | {
"lang": "rust",
"repo": "peermaps/osmxq",
"path": "/src/bin.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let oc = ray.origin() - center;
let a = ray.direction().dot(ray.direction());
let b = 2.0 * oc.dot(ray.direction());
let c = oc.dot(oc) - radius * radius;
let discriminant = b * b - 4.0 * a * c;
discriminant > 0.0
}<|fim_prefix|>// repo: karvozavr/ray-tracing-engine path: /src/mai... | code_fim | hard | {
"lang": "rust",
"repo": "karvozavr/ray-tracing-engine",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: karvozavr/ray-tracing-engine path: /src/main.rs
use color::Color;
use ray::Ray;
use vec3::Point3;
use vec3::Vec3;
mod color;
mod ray;
mod vec3;
fn main() {
let aspect_ratio = 16.0 / 9.0;
let image_width = 384_usize;
let image_height = (image_width as f64 / aspect_ratio) as usize;
... | code_fim | hard | {
"lang": "rust",
"repo": "karvozavr/ray-tracing-engine",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let origin = Point3::zero();
let horizontal = Vec3::new(viewport_width, 0.0, 0.0);
let vertical = Vec3::new(0.0, viewport_height, 0.0);
let lower_left_corner =
origin - horizontal / 2.0 - vertical / 2.0 - Vec3::new(0.0, 0.0, focal_length);
print!("P3\n{width} {height}\n255\n",... | code_fim | medium | {
"lang": "rust",
"repo": "karvozavr/ray-tracing-engine",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> if bytes_read < 512
{
break;
}
}
println!("Read the Stream!");
println!("\n-----------\n{}\n-------------\n", buffer);
let request = http_request::HttpRequest::parse(&buffer);
match request
{
Err(err_detail) => {
let mut r... | code_fim | hard | {
"lang": "rust",
"repo": "TrecApps/user_auth_service",
"path": "/src/controller/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: TrecApps/user_auth_service path: /src/controller/mod.rs
use std::net::TcpStream;
use std::io::prelude::*;
use std::fs;
pub mod http_request;
pub mod http_response;
pub mod http_response_code;
use http_request::HttpRequest;
use http_response::HttpResponse;
use http_response_code::HttpResponseCo... | code_fim | hard | {
"lang": "rust",
"repo": "TrecApps/user_auth_service",
"path": "/src/controller/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> println!("\n-----------\n{}\n-------------\n", buffer);
let request = http_request::HttpRequest::parse(&buffer);
match request
{
Err(err_detail) => {
let mut response = HttpResponse::new(HttpResponseCode::new(HttpResponseCodeTypes::ClientErr400));
let key... | code_fim | hard | {
"lang": "rust",
"repo": "TrecApps/user_auth_service",
"path": "/src/controller/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> process_describe_log_groups(resp.clone());
while resp.clone().next_token != None {
let describe_log_groups_request = DescribeLogGroupsRequest {
next_token: resp.clone().next_token,
..Default::default()
};
resp = rt.block_on(describe_log_groups(&clie... | code_fim | hard | {
"lang": "rust",
"repo": "rilindo/some_rust_aws_examples",
"path": "/basic/cloudwatch_logs/describe_log_groups/src/main.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rilindo/some_rust_aws_examples path: /basic/cloudwatch_logs/describe_log_groups/src/main.rs
extern crate rusoto_core;
extern crate rusoto_logs;
use rusoto_core::Region;
use rusoto_logs::{
CloudWatchLogs, CloudWatchLogsClient, DescribeLogGroupsRequest, DescribeLogGroupsResponse,
};
async fn... | code_fim | hard | {
"lang": "rust",
"repo": "rilindo/some_rust_aws_examples",
"path": "/basic/cloudwatch_logs/describe_log_groups/src/main.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn main() {
let client = CloudWatchLogsClient::new(Region::default());
let describe_log_groups_request = DescribeLogGroupsRequest {
next_token: None,
..Default::default()
};
let mut rt = tokio::runtime::Runtime::new().unwrap();
let mut resp = rt.block_on(describe_log_... | code_fim | hard | {
"lang": "rust",
"repo": "rilindo/some_rust_aws_examples",
"path": "/basic/cloudwatch_logs/describe_log_groups/src/main.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: AndrewTweddle/CodingExercises path: /cryptopals/src/bin/challenge3.rs
use cryptopals::hex::hex_str_to_bytes;
use cryptopals::xor_bytes_with_key;
use std::collections::HashMap;
const ENCRYPTED_HEX: &str = "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736";
// From: http://ma... | code_fim | hard | {
"lang": "rust",
"repo": "AndrewTweddle/CodingExercises",
"path": "/cryptopals/src/bin/challenge3.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn main() {
let encrypted_bytes = hex_str_to_bytes(ENCRYPTED_HEX).unwrap();
let best_key = (0..=255_u8)
.map(|key| {
let decrypted_bytes = xor_bytes_with_key(&encrypted_bytes, key);
let squared_devs = sum_of_squared_frequency_deviations(&decrypted_bytes);
... | code_fim | hard | {
"lang": "rust",
"repo": "AndrewTweddle/CodingExercises",
"path": "/cryptopals/src/bin/challenge3.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Now attempt to convert to UTF8 (at the risk of failure, if there are invalid characters)...
let message = String::from_utf8(decrypted_bytes).expect("Could not convert the bytes to UTF-8");
println!("Message is: {}", message);
}
// Take the squared deviation from the position in the sequenc... | code_fim | hard | {
"lang": "rust",
"repo": "AndrewTweddle/CodingExercises",
"path": "/cryptopals/src/bin/challenge3.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: MikeTheSapien/rust_cipher path: /cipher/src/lib.rs
use std::fs;
use std::error::Error;
<|fim_suffix|>pub fn encrypt(ui: UserInput) -> Result<(), Box<dyn Error>> {
println!("printing with key: {}", ui.key);
let message = fs::read_to_string(ui.message_path)?;
// println!("{}", message... | code_fim | easy | {
"lang": "rust",
"repo": "MikeTheSapien/rust_cipher",
"path": "/cipher/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn encrypt(ui: UserInput) -> Result<(), Box<dyn Error>> {
println!("printing with key: {}", ui.key);
let message = fs::read_to_string(ui.message_path)?;
// println!("{}", message);
for c in message.bytes() {
println!("{}",c + 3);
}
Ok(())
}<|fim_prefix|>// repo: MikeThe... | code_fim | easy | {
"lang": "rust",
"repo": "MikeTheSapien/rust_cipher",
"path": "/cipher/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> TokenEnvChange::PacketSize(new_value.parse()?, old_value.parse()?)
}
EnvChangeTy::SqlCollation => {
let len = src.read_u8().await? as usize;
let mut new_value = vec![0; len];
src.read_exact(&mut new_value[0..len]).awai... | code_fim | hard | {
"lang": "rust",
"repo": "Niedzwiedzw/tiberius",
"path": "/src/tds/codec/token/token_env_change.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Niedzwiedzw/tiberius path: /src/tds/codec/token/token_env_change.rs
use crate::{
tds::{codec::read_varchar, lcid_to_encoding, sortid_to_encoding},
Error, SqlReadBytes,
};
use encoding::Encoding;
use fmt::Debug;
use futures::io::AsyncReadExt;
use std::net::ToSocketAddrs;
use std::{borrow:... | code_fim | hard | {
"lang": "rust",
"repo": "Niedzwiedzw/tiberius",
"path": "/src/tds/codec/token/token_env_change.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn get_point(self) -> Point {
return self.point;
}
pub fn get_field(self) -> Field {
return self.field;
}
}<|fim_prefix|>// repo: yankuchinsky/snake-game path: /lib/src/lib.rs
mod utils;
mod player;
mod field;
mod point;
use point::Point;
use player::Player;
use field::Field;
use wa... | code_fim | medium | {
"lang": "rust",
"repo": "yankuchinsky/snake-game",
"path": "/lib/src/lib.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn get_player(self) -> Player {
return self.player;
}
pub fn get_point(self) -> Point {
return self.point;
}
pub fn get_field(self) -> Field {
return self.field;
}
}<|fim_prefix|>// repo: yankuchinsky/snake-game path: /lib/src/lib.rs
mod utils;
mod player;
mod field;
mod poi... | code_fim | medium | {
"lang": "rust",
"repo": "yankuchinsky/snake-game",
"path": "/lib/src/lib.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: yankuchinsky/snake-game path: /lib/src/lib.rs
mod utils;
mod player;
mod field;
mod point;
use point::Point;
use player::Player;
use field::Field;
use wasm_bindgen::prelude::*;
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// allocator.
#[cfg(feature = "wee_alloc")]
... | code_fim | hard | {
"lang": "rust",
"repo": "yankuchinsky/snake-game",
"path": "/lib/src/lib.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: stevenlr/HandmadeRust path: /vk/device.rs
return match ret
{
VkResult::SUCCESS => Ok(ret),
_ => Err(ret),
};
}
pub fn allocate_descriptor_sets(
&self,
p_allocate_info: &VkDescriptorSetAllocateInfo,
p_descriptor_sets: &... | code_fim | hard | {
"lang": "rust",
"repo": "stevenlr/HandmadeRust",
"path": "/vk/device.rs",
"mode": "psm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: stevenlr/HandmadeRust path: /vk/device.rs
y_buffer_to_image(
&self,
command_buffer: VkCommandBuffer,
src_buffer: VkBuffer,
dst_image: VkImage,
dst_image_layout: VkImageLayout,
p_regions: &[VkBufferImageCopy],
)
{
let region_count = ... | code_fim | hard | {
"lang": "rust",
"repo": "stevenlr/HandmadeRust",
"path": "/vk/device.rs",
"mode": "psm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn destroy_image(&self, image: VkImage, p_allocator: Option<&VkAllocationCallbacks>)
{
#[allow(unused)]
let ret = unsafe {
self.d.destroy_image(
self.handle,
image,
match p_allocator
{
... | code_fim | hard | {
"lang": "rust",
"repo": "stevenlr/HandmadeRust",
"path": "/vk/device.rs",
"mode": "spm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: thorhs/mk66f18 path: /src/ftm0/fms.rs
]
fn from(variant: FAULTF0_A) -> Self {
match variant {
FAULTF0_A::_0 => false,
FAULTF0_A::_1 => true,
}
}
}
#[doc = "Reader of field `FAULTF0`"]
pub type FAULTF0_R = crate::R<bool, FAULTF0_A>;
impl FAULTF0_R {... | code_fim | hard | {
"lang": "rust",
"repo": "thorhs/mk66f18",
"path": "/src/ftm0/fms.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: thorhs/mk66f18 path: /src/ftm0/fms.rs
= "Writer for register FMS"]
pub type W = crate::W<u32, super::FMS>;
#[doc = "Register FMS `reset()`'s with value 0"]
impl crate::ResetValue for super::FMS {
type Type = u32;
#[inline(always)]
fn reset_value() -> Self::Type {
0
}
}
#... | code_fim | hard | {
"lang": "rust",
"repo": "thorhs/mk66f18",
"path": "/src/ftm0/fms.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> match variant {
FAULTF_A::_0 => false,
FAULTF_A::_1 => true,
}
}
}
#[doc = "Reader of field `FAULTF`"]
pub type FAULTF_R = crate::R<bool, FAULTF_A>;
impl FAULTF_R {
#[doc = r"Get enumerated values variant"]
#[inline(always)]
pub fn variant(&self) -> ... | code_fim | hard | {
"lang": "rust",
"repo": "thorhs/mk66f18",
"path": "/src/ftm0/fms.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn cudnnGetConvolution2dForwardOutputDim(
conv_desc: cudnnConvolutionDescriptor_t,
input_desc: cudnnTensorDescriptor_t,
filter_desc: cudnnFilterDescriptor_t,
n: *mut c_int,
c: *mut c_int,
h: *mut c_int,
w: *mut c_int,
) -> cudnnStatus_t;
pub fn cudnnFind... | code_fim | hard | {
"lang": "rust",
"repo": "bumzack/libcuda_dnn",
"path": "/src/v5/ffi.rs",
"mode": "spm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: bumzack/libcuda_dnn path: /src/v5/ffi.rs
#[derive(Clone, Copy)]
#[repr(C)]
pub enum cudnnAddMode_t {
//SameHW = 0,
Image = 0,
//SameCHW = 1,
FeatureMap = 1,
SameC = 2,
FullTensor = 3,
}
#[derive(Clone, Copy)]
#[repr(C)]
pub enum cudnnConvolutionMode_t {
Conv... | code_fim | hard | {
"lang": "rust",
"repo": "bumzack/libcuda_dnn",
"path": "/src/v5/ffi.rs",
"mode": "psm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: bumzack/libcuda_dnn path: /src/v5/ffi.rs
#[repr(C)]
pub enum cudnnConvolutionBwdFilterPreference_t {
NoWorkspace = 0,
PreferFastest = 1,
SpecifyWorkspaceLimit = 2,
}
#[derive(Clone, Copy, Debug)]
#[repr(C)]
pub enum cudnnConvolutionBwdFilterAlgo_t {
NonDeterministic ... | code_fim | hard | {
"lang": "rust",
"repo": "bumzack/libcuda_dnn",
"path": "/src/v5/ffi.rs",
"mode": "psm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Returns the best move from the perspective of the current player
pub fn best_move(&self) -> Action {
let player = self.state.turn();
let best_child = self
.children
.as_ref()
.expect("Called TreeNode::best_move() on an empty tree")
... | code_fim | hard | {
"lang": "rust",
"repo": "maxencefrenette/pentarust",
"path": "/pentarust/src/mcts/tree_node.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: maxencefrenette/pentarust path: /pentarust/src/mcts/tree_node.rs
use crate::game::Action;
use crate::game::Board;
use crate::game::Outcome;
use crate::mcts::WinStats;
use float_ord::FloatOrd;
use rand::seq::IteratorRandom;
use rand::thread_rng;
use rand::Rng;
use std::time::{Duration, SystemTime... | code_fim | hard | {
"lang": "rust",
"repo": "maxencefrenette/pentarust",
"path": "/pentarust/src/mcts/tree_node.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: abusch/grit path: /src/state.rs
use std::io::Write;
use anyhow::Result;
use termimad::Event;
use crate::{context::AppContext, screen::Screen};
/// The result of applying an event (such as a key press) to the current state. This tells the main
/// loop what action to take e.g. entering a new s... | code_fim | hard | {
"lang": "rust",
"repo": "abusch/grit",
"path": "/src/state.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// Represents a state of the application.
///
/// Different states typically display differently. Examples of states are the log view, or the
/// commit view, or the status view...
pub trait AppState {
fn handle_event(&mut self, event: Event, ctx: &AppContext) -> CommandResult;
fn display(&mut se... | code_fim | hard | {
"lang": "rust",
"repo": "abusch/grit",
"path": "/src/state.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn part2(scans: &std::vec::Vec<i64>) -> i64 {
scans
.into_iter()
.tuple_windows()
.map(|(a, b, c)| a + b + c)
.tuple_windows()
.filter(|(prev, next)| next > prev)
.count() as i64
}<|fim_prefix|>// repo: Hazurl/adventofcode path: /2021/src/day1.rs
use crate::utility;
use itertools::*;
fn par... | code_fim | hard | {
"lang": "rust",
"repo": "Hazurl/adventofcode",
"path": "/2021/src/day1.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Hazurl/adventofcode path: /2021/src/day1.rs
use crate::utility;
use itertools::*;
fn parse_file(base_path_inputs: &str, filename: &str) -> std::vec::Vec<i64> {
<|fim_suffix|> utility::benchmark("1.2.example", &part2, &input_example);
utility::benchmark("1.2", &part2, &input);
}
fn part1(scans... | code_fim | hard | {
"lang": "rust",
"repo": "Hazurl/adventofcode",
"path": "/2021/src/day1.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn run<S: Solution>() {
let test_cases = [((&[1, 4, 8, 10, 20] as &[_], 3), 5), ((&[2, 3, 5, 12, 18], 2), 9)];
for ((houses, k), expected) in test_cases {
assert_eq!(S::min_distance(houses.to_vec(), k), expected);
}
}
}<|fim_prefix|>// repo: EFanZh/LeetCode... | code_fim | easy | {
"lang": "rust",
"repo": "EFanZh/LeetCode",
"path": "/src/problem_1478_allocate_mailboxes/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: EFanZh/LeetCode path: /src/problem_1478_allocate_mailboxes/mod.rs
pub mod dynamic_programming;
pub trait Solution {
fn min_distance(houses: Vec<i32>, k: i32) -> i32;
}
#[cfg(test)]
mod tests {
use super::Solution;
<|fim_suffix|> for ((houses, k), expected) in test_cases {
... | code_fim | medium | {
"lang": "rust",
"repo": "EFanZh/LeetCode",
"path": "/src/problem_1478_allocate_mailboxes/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> for ((houses, k), expected) in test_cases {
assert_eq!(S::min_distance(houses.to_vec(), k), expected);
}
}
}<|fim_prefix|>// repo: EFanZh/LeetCode path: /src/problem_1478_allocate_mailboxes/mod.rs
pub mod dynamic_programming;
pub trait Solution {
fn min_distance(house... | code_fim | medium | {
"lang": "rust",
"repo": "EFanZh/LeetCode",
"path": "/src/problem_1478_allocate_mailboxes/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mkubala/ncollide path: /ncollide_geometry/query/point_internal/point_shape.rs
use math::{Point, Isometry};
use shape::Shape;
use query::{PointQuery, PointProjection};
<|fim_suffix|> self.as_point_query()
.expect("No PointQuery implementation for the underlying shape.")
... | code_fim | hard | {
"lang": "rust",
"repo": "mkubala/ncollide",
"path": "/ncollide_geometry/query/point_internal/point_shape.rs",
"mode": "psm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.as_point_query()
.expect("No PointQuery implementation for the underlying shape.")
.distance_to_point(m, pt, solid)
}
#[inline]
fn contains_point(&self, m: &M, pt: &P) -> bool {
self.as_point_query()
.expect("No PointQuery implementatio... | code_fim | hard | {
"lang": "rust",
"repo": "mkubala/ncollide",
"path": "/ncollide_geometry/query/point_internal/point_shape.rs",
"mode": "spm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[inline]
fn contains_point(&self, m: &M, pt: &P) -> bool {
self.as_point_query()
.expect("No PointQuery implementation for the underlying shape.")
.contains_point(m, pt)
}
}<|fim_prefix|>// repo: mkubala/ncollide path: /ncollide_geometry/query/point_internal/p... | code_fim | hard | {
"lang": "rust",
"repo": "mkubala/ncollide",
"path": "/ncollide_geometry/query/point_internal/point_shape.rs",
"mode": "spm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> where
Self: Sized,
{
MapBatch::<Self::Header, Self>::new(self, transformer)
}
/// Filter out packets, any packets for which `filter_f` returns false are dropped from the batch.
fn filter(self, filter_f: FilterFn<Self::Header, Self::Metadata>) -> FilterBatch<Self::Heade... | code_fim | hard | {
"lang": "rust",
"repo": "SymbioticLab/Kayak",
"path": "/net/framework/src/operators/mod.rs",
"mode": "spm",
"license": "ISC",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: SymbioticLab/Kayak path: /net/framework/src/operators/mod.rs
use self::act::Act;
pub use self::add_metadata::AddMetadataBatch;
use self::add_metadata::MetadataFn;
pub use self::add_metadata_mut::MutableAddMetadataBatch;
use self::add_metadata_mut::MutableMetadataFn;
pub use self::composition_ba... | code_fim | hard | {
"lang": "rust",
"repo": "SymbioticLab/Kayak",
"path": "/net/framework/src/operators/mod.rs",
"mode": "psm",
"license": "ISC",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: daCapricorn/sync-async-tracing-experiments path: /src/routines.rs
mod api;
mod repo;
use futures::future::join_all;
use std::sync::{
atomic::{AtomicUsize, Ordering},
Arc,
};
pub async fn start() {
let mut handlers = vec![];
<|fim_suffix|> join_all(handlers).await;
println!... | code_fim | hard | {
"lang": "rust",
"repo": "daCapricorn/sync-async-tracing-experiments",
"path": "/src/routines.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.