text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_prefix|>// repo: agelito/rust-raytracer-in-a-weekend path: /src/math/vec3.rs
use std::ops::{Add, Div, Mul, Neg, Sub};
#[derive(Debug, Copy, Clone)]
pub struct Vec3 {
pub x: f64,
pub y: f64,
pub z: f64,
}
impl Vec3 {
pub fn new(x: f64, y: f64, z: f64) -> Vec3 {
Vec3 { x: x, y: y, z: z }
... | code_fim | hard | {
"lang": "rust",
"repo": "agelito/rust-raytracer-in-a-weekend",
"path": "/src/math/vec3.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> Vec3 {
x: self.x / other.x,
y: self.y / other.y,
z: self.z / other.z,
}
}
}
impl Div<f64> for Vec3 {
type Output = Self;
fn div(self, other: f64) -> Self::Output {
Vec3 {
x: self.x / other,
y: self.y / other,... | code_fim | hard | {
"lang": "rust",
"repo": "agelito/rust-raytracer-in-a-weekend",
"path": "/src/math/vec3.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> GithubAuthenticationError,
/// Represents a failure when attempting to write to the specified file
#[error("Failed to write to a file: {filename:?}")]
FileWriteFail { filename: String },
/// Represents a failure when attempting to build a Docker image
#[error("Something went wrong ... | code_fim | hard | {
"lang": "rust",
"repo": "seanchen1991/temploy",
"path": "/src/errors.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: seanchen1991/temploy path: /src/errors.rs
use std::path::PathBuf;
use thiserror::Error;
/// All possible errors that could be returned by this library
#[derive(Error, Debug)]
pub enum TemployError {
/// Represents an invalid command that was passed to the CLI
#[error("Invalid CLI comman... | code_fim | hard | {
"lang": "rust",
"repo": "seanchen1991/temploy",
"path": "/src/errors.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>d to read entry: {source:?}")]
FailedToReadEntry { source: walkdir::Error },
/// Represents a failure when attempting to strip the prefix from a path
#[error("Failed to strip path prefix")]
FailedToStripPrefix,
/// Represents an invalid github link
#[error("Invalid GitHub link {lin... | code_fim | hard | {
"lang": "rust",
"repo": "seanchen1991/temploy",
"path": "/src/errors.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jpc0016/Rust-Examples path: /ch3-scripts/return-values.rs
// returning values from a loop pg. 55
fn main() {
// initialize counter to 0. It will change so it must be mutable
let mut counter = 0;
<|fim_suffix|> // prints "The result is 20"
println!("The result is {}", result);
}<... | code_fim | hard | {
"lang": "rust",
"repo": "jpc0016/Rust-Examples",
"path": "/ch3-scripts/return-values.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // prints "The result is 20"
println!("The result is {}", result);
}<|fim_prefix|>// repo: jpc0016/Rust-Examples path: /ch3-scripts/return-values.rs
// returning values from a loop pg. 55
fn main() {
// initialize counter to 0. It will change so it must be mutable
let mut counter = 0;
... | code_fim | hard | {
"lang": "rust",
"repo": "jpc0016/Rust-Examples",
"path": "/ch3-scripts/return-values.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>;
} else {
i += 2;
}
}
println!("{}", i)
}<|fim_prefix|>// repo: Baelyk/programmings path: /project-euler/rust/problem-003/src/main.rs
fn main() {
let mut big_bad_num: u64 = 600851475143;
let mut i = 3;
<|fim_middle|> while big_bad_num % 2 == 0 {
big... | code_fim | medium | {
"lang": "rust",
"repo": "Baelyk/programmings",
"path": "/project-euler/rust/problem-003/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Baelyk/programmings path: /project-euler/rust/problem-003/src/main.rs
fn main() {
let mut big_bad_num: u64 = 600851475143;
let mut i = 3;
<|fim_suffix|>;
} else {
i += 2;
}
}
println!("{}", i)
}<|fim_middle|> while big_bad_num % 2 == 0 {
big... | code_fim | medium | {
"lang": "rust",
"repo": "Baelyk/programmings",
"path": "/project-euler/rust/problem-003/src/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tverghis/aoc_2019 path: /rust/day_05/src/program/program.rs
use crate::program::{Instruction, OpCode, Parameter, ParameterMode};
use std::cmp::Ordering;
use std::convert::TryInto;
use std::io;
#[derive(Debug)]
pub(crate) struct Program {
inputs: Vec<i32>,
instr_ptr: usize,
}
impl Progr... | code_fim | hard | {
"lang": "rust",
"repo": "tverghis/aoc_2019",
"path": "/rust/day_05/src/program/program.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let x = self.get_parameter_value(instr.parameters[0]);
let y = self.get_parameter_value(instr.parameters[1]);
let output_idx = instr.parameters[2].value as usize;
self.inputs[output_idx] = x + y;
self.instr_ptr += instr.opcode.instr_len();
}
fn do_multipl... | code_fim | hard | {
"lang": "rust",
"repo": "tverghis/aoc_2019",
"path": "/rust/day_05/src/program/program.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: EFanZh/LeetCode path: /src/problem_1171_remove_zero_sum_consecutive_nodes_from_linked_list/mod.rs
use crate::data_structures::ListNode;
pub mod greedy;
pub trait Solution {
fn remove_zero_sum_sublists(head: Option<Box<ListNode>>) -> Option<Box<ListNode>>;
<|fim_suffix|> pub fn run<S: So... | code_fim | medium | {
"lang": "rust",
"repo": "EFanZh/LeetCode",
"path": "/src/problem_1171_remove_zero_sum_consecutive_nodes_from_linked_list/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn run<S: Solution>() {
let test_cases = [
(&[1, 2, -3, 3, 1] as &[_], &[&[3, 1] as &[_], &[1, 2, 1]] as &[&[_]]),
(&[1, 2, 3, -3, 4], &[&[1, 2, 4]]),
(&[1, 2, 3, -3, -2], &[&[1]]),
(&[1, 3, 2, -3, -2, 5, 100, -100, 1], &[&[1, 5, 1], &[1, 3, ... | code_fim | medium | {
"lang": "rust",
"repo": "EFanZh/LeetCode",
"path": "/src/problem_1171_remove_zero_sum_consecutive_nodes_from_linked_list/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: kingreatwill/rust_study path: /fist_rust/hello_world.rs
fn main() {
let tup: (i32, f64, u8) = (500, 6.4, 1);
// tup.0 等于 500
// tup.1 等于 6.4
// tup.2 等于 1
let (x, y, z) = tup;
let a = [1, 2, 3, 4, 5];
// a 是一个长度为 5 的整型数组
let b = ["January", "February", "March"];
... | code_fim | hard | {
"lang": "rust",
"repo": "kingreatwill/rust_study",
"path": "/fist_rust/hello_world.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // let s1 = String::from("hello");
// let s2 = s1;
// println!("{}, world!", s1); // 错误!s1 已经失效
let s1 = String::from("hello");
let s2 = &s1;
println!("s1 is {}, s2 is {}", s1, s2);
let s1 = String::from("hello");
let mut s2 = s1.clone();
println!("s1 = {}, s2 = {}",... | code_fim | hard | {
"lang": "rust",
"repo": "kingreatwill/rust_study",
"path": "/fist_rust/hello_world.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> //shift
let d = 10;
println!("{} shifted >> 2 = {}", d, d >> 2);
}<|fim_prefix|>// repo: mbbhalla/rust-learn path: /simple_programs/src/main_2_2.rs
fn main() {
//operators
let a = 3;
let a_cubed = i32::pow(a, 3);
println!("a_cubed = {}", a_cubed);
let b = 0.5;
let b_... | code_fim | medium | {
"lang": "rust",
"repo": "mbbhalla/rust-learn",
"path": "/simple_programs/src/main_2_2.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mbbhalla/rust-learn path: /simple_programs/src/main_2_2.rs
fn main() {
//operators
let a = 3;
let a_cubed = i32::pow(a, 3);
println!("a_cubed = {}", a_cubed);
<|fim_suffix|> //shift
let d = 10;
println!("{} shifted >> 2 = {}", d, d >> 2);
}<|fim_middle|> let b = 0... | code_fim | hard | {
"lang": "rust",
"repo": "mbbhalla/rust-learn",
"path": "/simple_programs/src/main_2_2.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ortegacesar06/api-rust path: /src/v1/mod.rs
mod users;
use actix_web::web::{self, ServiceConfig};
<|fim_suffix|>pub fn service<R: Repository>(cfg: &mut ServiceConfig) {
cfg.service(web::scope("/v1").configure(users::service::<R>));
}<|fim_middle|>use crate::repository::Repository;
| code_fim | easy | {
"lang": "rust",
"repo": "ortegacesar06/api-rust",
"path": "/src/v1/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn service<R: Repository>(cfg: &mut ServiceConfig) {
cfg.service(web::scope("/v1").configure(users::service::<R>));
}<|fim_prefix|>// repo: ortegacesar06/api-rust path: /src/v1/mod.rs
mod users;
use actix_web::web::{self, ServiceConfig};
<|fim_middle|>use crate::repository::Repository;
| code_fim | easy | {
"lang": "rust",
"repo": "ortegacesar06/api-rust",
"path": "/src/v1/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: pixelistik/request_log_analyzer path: /src/result/mod.rs
use crate::analyzer;
#[derive(PartialEq, Debug, Clone)]
pub<|fim_suffix|>Option<analyzer::aggregated_error_rates::ErrorRatesResult>,
}<|fim_middle|> struct RequestLogAnalyzerResult {
pub count: usize,
pub timing: Option<analyzer::... | code_fim | medium | {
"lang": "rust",
"repo": "pixelistik/request_log_analyzer",
"path": "/src/result/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>Option<analyzer::aggregated_error_rates::ErrorRatesResult>,
}<|fim_prefix|>// repo: pixelistik/request_log_analyzer path: /src/result/mod.rs
use crate::analyzer;
#[derive(PartialEq, Debug, Clone)]
pub struct RequestLogAnalyzerResult {
pub count: usize,
<|fim_middle|> pub timing: Option<analyzer::... | code_fim | medium | {
"lang": "rust",
"repo": "pixelistik/request_log_analyzer",
"path": "/src/result/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: JustAnotherStrange/CafeBot path: /src/money/scratchoff.rs
// use scratchoff tickets that are purchased in the shop
use crate::database::database::{gen_connection, get_so, money_increment_with_lost};
use crate::money::blackjack::edit_embed;
use crate::tools::help::EditContent;
use rand::{thread_r... | code_fim | hard | {
"lang": "rust",
"repo": "JustAnotherStrange/CafeBot",
"path": "/src/money/scratchoff.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // take away the ticket they used
match tier {
1 => conn.execute(
"update users set so_tier1 = so_tier1 - 1 where id = ?1",
params![&msg.author.id.as_u64()],
)?,
2 => conn.execute(
"update users set so_tier2 = so_tier2 - 1 where id = ?1",... | code_fim | hard | {
"lang": "rust",
"repo": "JustAnotherStrange/CafeBot",
"path": "/src/money/scratchoff.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn vprord_5() {
run_test(&Instruction { mnemonic: Mnemonic::VPRORD, operand1: Some(Direct(XMM19)), operand2: Some(IndirectScaledIndexed(RDI, RDI, Two, Some(OperandSize::Xmmword), None)), operand3: Some(Literal8(77)), operand4: None, lock: false, rounding_mode: None, merge_mode: Some(MergeMode::Zero), ... | code_fim | hard | {
"lang": "rust",
"repo": "purpleposeidon/rust-x86asm",
"path": "/src/test/instruction_tests/vprord.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> run_test(&Instruction { mnemonic: Mnemonic::VPRORD, operand1: Some(Direct(YMM4)), operand2: Some(Indirect(RSI, Some(OperandSize::Ymmword), None)), operand3: Some(Literal8(85)), operand4: None, lock: false, rounding_mode: None, merge_mode: Some(MergeMode::Zero), sae: false, mask: Some(MaskReg::K4), bro... | code_fim | hard | {
"lang": "rust",
"repo": "purpleposeidon/rust-x86asm",
"path": "/src/test/instruction_tests/vprord.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: purpleposeidon/rust-x86asm path: /src/test/instruction_tests/vprord.rs
use ::{BroadcastMode, Instruction, MaskReg, MergeMode, Mnemonic, OperandSize, Reg, RoundingMode};
use ::RegType::*;
use ::instruction_def::*;
use ::Operand::*;
use ::Reg::*;
use ::RegScale::*;
fn vprord_1() {
run_test(&I... | code_fim | hard | {
"lang": "rust",
"repo": "purpleposeidon/rust-x86asm",
"path": "/src/test/instruction_tests/vprord.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let s = seq!(0;1;0.01);
let a = matrix(s.clone(), s.len(), 1, Col);
let b = a.fmap(|x| x.powf(2.));
let c = cbind!(a, b);
c.write("dat.csv");
}<|fim_prefix|>// repo: Axect/Rust path: /Test/peroxide_test/src/main.rs
extern crate peroxide;
<|fim_middle|>use peroxide::*;
fn main() {
| code_fim | easy | {
"lang": "rust",
"repo": "Axect/Rust",
"path": "/Test/peroxide_test/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Axect/Rust path: /Test/peroxide_test/src/main.rs
extern crate peroxide;
use peroxide::*;
<|fim_suffix|> let s = seq!(0;1;0.01);
let a = matrix(s.clone(), s.len(), 1, Col);
let b = a.fmap(|x| x.powf(2.));
let c = cbind!(a, b);
c.write("dat.csv");
}<|fim_middle|>fn main() {
| code_fim | easy | {
"lang": "rust",
"repo": "Axect/Rust",
"path": "/Test/peroxide_test/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn main() {
let s = seq!(0;1;0.01);
let a = matrix(s.clone(), s.len(), 1, Col);
let b = a.fmap(|x| x.powf(2.));
let c = cbind!(a, b);
c.write("dat.csv");
}<|fim_prefix|>// repo: Axect/Rust path: /Test/peroxide_test/src/main.rs
extern crate peroxide;
<|fim_middle|>use peroxide::*;
| code_fim | easy | {
"lang": "rust",
"repo": "Axect/Rust",
"path": "/Test/peroxide_test/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> println!("This point won't be reached!");
// `_x` should get destroyed at this point
}<|fim_prefix|>// repo: diegopacheco/rust-playground path: /panic-attack-fun/src/main.rs
// Re-implementation of integer division (/)
fn division(dividend: i32, divisor: i32) -> i32 {
if divisor == 0 {
... | code_fim | medium | {
"lang": "rust",
"repo": "diegopacheco/rust-playground",
"path": "/panic-attack-fun/src/main.rs",
"mode": "spm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: diegopacheco/rust-playground path: /panic-attack-fun/src/main.rs
// Re-implementation of integer division (/)
fn division(dividend: i32, divisor: i32) -> i32 {
<|fim_suffix|>// The `main` task
fn main() {
// Heap allocated integer
let _x = Box::new(0i32);
// This operation will trig... | code_fim | medium | {
"lang": "rust",
"repo": "diegopacheco/rust-playground",
"path": "/panic-attack-fun/src/main.rs",
"mode": "psm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_suffix|> // This operation will trigger a task failure
division(3, 0);
println!("This point won't be reached!");
// `_x` should get destroyed at this point
}<|fim_prefix|>// repo: diegopacheco/rust-playground path: /panic-attack-fun/src/main.rs
// Re-implementation of integer division (/)
fn divi... | code_fim | hard | {
"lang": "rust",
"repo": "diegopacheco/rust-playground",
"path": "/panic-attack-fun/src/main.rs",
"mode": "spm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: efficient/libinger path: /src/tcb.rs
#![allow(unused)]
use gotcha::prctl::ARCH_GET_CPUID;
use gotcha::prctl::ARCH_GET_FS;
use gotcha::prctl::ARCH_GET_GS;
use gotcha::prctl::ARCH_SET_CPUID;
use gotcha::prctl::ARCH_SET_FS;
use gotcha::prctl::ARCH_SET_GS;
use gotcha::Group;
use std::io::Error;
use... | code_fim | hard | {
"lang": "rust",
"repo": "efficient/libinger",
"path": "/src/tcb.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut dealloc = None;
if let Some(MaybeMut::Mut(fs)) = self.this.take() {
unsafe {
__call_tls_dtors();
}
dealloc = Some(fs);
}
unsafe {
self.parent.install_unguarded(None).unwrap();
}
if let Some(fs) = dealloc {
unsafe {
_dl_deallocate_tls(fs, true);
}
}
}
}
enu... | code_fim | hard | {
"lang": "rust",
"repo": "efficient/libinger",
"path": "/src/tcb.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: lukechu10/yew-functional-TodoMVC path: /src/item.rs
use crate::{cb, TodoEntry, TodoStatus};
use yew::prelude::*;
use yew_functional::*;
#[derive(Properties, Clone, PartialEq)]
pub struct ItemProps {
pub todo: TodoEntry,
/// Called whenever todo.status should be toggled.
pub toggle_c... | code_fim | hard | {
"lang": "rust",
"repo": "lukechu10/yew-functional-TodoMVC",
"path": "/src/item.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let handle_edit = cb!((set_editing, input_ref) move |_ev| {
set_editing(true);
input_ref
.borrow()
.cast::<web_sys::HtmlInputElement>()
.unwrap()
.focus()
.unwrap(); // focus input
});
let handle_blur = cb!((set_editi... | code_fim | hard | {
"lang": "rust",
"repo": "lukechu10/yew-functional-TodoMVC",
"path": "/src/item.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let handle_submit = cb!((handle_blur, input_ref, props) move |ev: KeyboardEvent| {
match ev.key().as_str() {
"Enter" => handle_blur.emit(()),
"Escape" => {
input_ref
.borrow()
.cast::<web_sys::HtmlInputElement>()
... | code_fim | hard | {
"lang": "rust",
"repo": "lukechu10/yew-functional-TodoMVC",
"path": "/src/item.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Collidable for Paddle {
type S = shape::Cuboid<f32>;
fn to_iso(&self) -> Isometry<f32> {
Isometry::new(
Vector2::new(self.pos.x + self.dim.x / 2.0, self.pos.y - self.dim.y / 2.0),
0.0,
)
}
fn to_shape(&self) -> Self::S {
shape::Cuboid::n... | code_fim | hard | {
"lang": "rust",
"repo": "dannyfritz/pong-rs",
"path": "/pong_lib/src/game/paddle.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dannyfritz/pong-rs path: /pong_lib/src/game/paddle.rs
use super::FIELD_TOP;
use game::Collidable;
use ncollide2d::{shape, math::{Isometry, Vector as Vector2}};
<|fim_suffix|>impl Collidable for Paddle {
type S = shape::Cuboid<f32>;
fn to_iso(&self) -> Isometry<f32> {
Isometry::n... | code_fim | hard | {
"lang": "rust",
"repo": "dannyfritz/pong-rs",
"path": "/pong_lib/src/game/paddle.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: abadrinath15/rust-leetcode path: /easy_problems/src/solution_files/problem_26.rs
use crate::solution_files::Solution;
impl Solution {
pub fn remove_duplicates(nums: &mut Vec<i32>) -> i32 {
nums.dedup();
nums.len() as i32
}
}
#[cfg(test)]
mod tests {
use super::*;
... | code_fim | medium | {
"lang": "rust",
"repo": "abadrinath15/rust-leetcode",
"path": "/easy_problems/src/solution_files/problem_26.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut input_2 = vec![0, 0, 1, 1, 1, 2, 2, 3, 3, 4];
assert_eq!(5, Solution::remove_duplicates(&mut input_2));
}
}<|fim_prefix|>// repo: abadrinath15/rust-leetcode path: /easy_problems/src/solution_files/problem_26.rs
use crate::solution_files::Solution;
impl Solution {
pub fn r... | code_fim | medium | {
"lang": "rust",
"repo": "abadrinath15/rust-leetcode",
"path": "/easy_problems/src/solution_files/problem_26.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: drwilco/aoc path: /2020/day9/src/bin/second.rs
use anyhow::{anyhow, Result};
use itertools::Itertools;
use std::{collections::VecDeque, fs};
fn find_abberation(input: &Vec<u64>, preamble_length: usize) -> u64 {
let mut ring = VecDeque::<u64>::new();
input
.iter()
.enumer... | code_fim | hard | {
"lang": "rust",
"repo": "drwilco/aoc",
"path": "/2020/day9/src/bin/second.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let input = input
.lines()
.map(|n| n.parse::<u64>().unwrap())
.collect::<Vec<u64>>();
let abberation = find_abberation(&input, preamble_length);
find_sequence(&input, abberation)
}
fn main() -> Result<()> {
let input = fs::read_to_string("input.txt")?;
println... | code_fim | hard | {
"lang": "rust",
"repo": "drwilco/aoc",
"path": "/2020/day9/src/bin/second.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(test)]
mod tests {
use super::*;
#[test]
fn second() {
let input = "35
20
15
25
47
40
62
55
65
95
102
117
150
182
127
219
299
277
309
576";
assert_eq!(62, do_the_thing(&input, 5).unwrap());
}
}<|fim_prefix|>// repo: drwilco/aoc path: /2020/day9/src/bin/second.rs
use... | code_fim | hard | {
"lang": "rust",
"repo": "drwilco/aoc",
"path": "/2020/day9/src/bin/second.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dearshuto/RayTracer path: /sjrt/src/brdf/lambert.rs
use crate::{IBidirectionalReflectanceDistributionFunction, Vector3f};
pub struct Lambert {}
<|fim_suffix|> fn calculate(
&self,
normal: &Vector3f,
_in_direction: &Vector3f,
out_direction: &Vector3f,
) ->... | code_fim | medium | {
"lang": "rust",
"repo": "dearshuto/RayTracer",
"path": "/sjrt/src/brdf/lambert.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> Self {}
}
fn calculate(
&self,
normal: &Vector3f,
_in_direction: &Vector3f,
out_direction: &Vector3f,
) -> f32 {
debug_assert!((normal.norm() - 1.0).abs() < 0.01);
debug_assert!((out_direction.norm() - 1.0).abs() < 0.01);
let do... | code_fim | medium | {
"lang": "rust",
"repo": "dearshuto/RayTracer",
"path": "/sjrt/src/brdf/lambert.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let dot_value = normal.dot(&out_direction).max(0.0);
let result = dot_value / std::f32::consts::PI;
result
}
}<|fim_prefix|>// repo: dearshuto/RayTracer path: /sjrt/src/brdf/lambert.rs
use crate::{IBidirectionalReflectanceDistributionFunction, Vector3f};
pub struct Lambert {}... | code_fim | hard | {
"lang": "rust",
"repo": "dearshuto/RayTracer",
"path": "/sjrt/src/brdf/lambert.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: pepyakin/emcc-bindgen-repro path: /build.rs
extern crate bindgen;
use std::path::PathBuf;
use std::process::Command;
use std::env;
fn gen_bindings() {
let bindings = bindgen::Builder::default()
.header("adder.h")
// Uncomment this to make build successful
// .trust_... | code_fim | hard | {
"lang": "rust",
"repo": "pepyakin/emcc-bindgen-repro",
"path": "/build.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> println!("cargo:rustc-link-search=native={}", current_dir.to_str().unwrap());
println!("cargo:rustc-link-lib=static=adder");
}<|fim_prefix|>// repo: pepyakin/emcc-bindgen-repro path: /build.rs
extern crate bindgen;
use std::path::PathBuf;
use std::process::Command;
use std::env;
fn gen_bindings... | code_fim | hard | {
"lang": "rust",
"repo": "pepyakin/emcc-bindgen-repro",
"path": "/build.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: R1tschY/rustjvm path: /components/classfile/src/parse/mod.rs
use std::convert::TryInto;
use std::io::Read;
use byteorder::{BigEndian, ReadBytesExt};
use cesu8::from_java_cesu8;
use crate::error::{JvmParseError, JvmParseResult};
use crate::model::constants::{Constant, ConstantIndex, ConstantPoo... | code_fim | hard | {
"lang": "rust",
"repo": "R1tschY/rustjvm",
"path": "/components/classfile/src/parse/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> Ok(AccessFlags::from_bits_truncate(
reader.read_u16::<BigEndian>()?,
))
}
}
impl ClassFileEntry for Field {
fn parse<T: Read>(reader: &mut T, cpool: &ConstantPool) -> JvmParseResult<Field> {
Ok(Field {
access_flags: reader.parse(cpool)?,
... | code_fim | hard | {
"lang": "rust",
"repo": "R1tschY/rustjvm",
"path": "/components/classfile/src/parse/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> Ok(Field {
access_flags: reader.parse(cpool)?,
name_index: reader.parse(cpool)?,
descriptor_index: reader.parse(cpool)?,
attributes: reader.parse(cpool)?,
})
}
}
impl ClassFileEntry for Method {
fn parse<T: Read>(reader: &mut T, cpoo... | code_fim | hard | {
"lang": "rust",
"repo": "R1tschY/rustjvm",
"path": "/components/classfile/src/parse/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn main() {
let x: &dyn A2 = todo!();
let x: &dyn B2 = todo!();
}<|fim_prefix|>// repo: rust-lang/rust path: /tests/ui/object-safety/issue-102933.rs
// check-pass
use std::future::Future;
pub trait Service {
type Response;
type Future: Future<Output = Self::Response>;
}
pub trait A1: S... | code_fim | hard | {
"lang": "rust",
"repo": "rust-lang/rust",
"path": "/tests/ui/object-safety/issue-102933.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rust-lang/rust path: /tests/ui/object-safety/issue-102933.rs
// check-pass
use std::future::Future;
pub trait Service {
type Response;
type Future: Future<Output = Self::Response>;
}
pub trait A1: Service<Response = i32> {}
pub trait A2: Service<Future = Box<dyn Future<Output = i32>>... | code_fim | easy | {
"lang": "rust",
"repo": "rust-lang/rust",
"path": "/tests/ui/object-safety/issue-102933.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub trait B2: Service<Response = i32> + B1 {
fn foo(&self) {}
}
fn main() {
let x: &dyn A2 = todo!();
let x: &dyn B2 = todo!();
}<|fim_prefix|>// repo: rust-lang/rust path: /tests/ui/object-safety/issue-102933.rs
// check-pass
use std::future::Future;
pub trait Service {
type Response;... | code_fim | medium | {
"lang": "rust",
"repo": "rust-lang/rust",
"path": "/tests/ui/object-safety/issue-102933.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: TimNN/channel path: /src/flavors/zero.rs
//! Zero-capacity channel.
//!
//! Also known as *rendezvous* channel.
use std::time::Instant;
use err::{RecvTimeoutError, SendTimeoutError, TryRecvError, TrySendError};
use exchanger::{Exchanger, ExchangeError};
use select::CaseId;
/// A zero-capacity... | code_fim | hard | {
"lang": "rust",
"repo": "TimNN/channel",
"path": "/src/flavors/zero.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Attempts to send `value` into the channel until the specified `deadline`.
pub fn send_until(
&self,
value: T,
deadline: Option<Instant>,
case_id: CaseId,
) -> Result<(), SendTimeoutError<T>> {
match self.exchanger.left().exchange_until(Some(value), d... | code_fim | hard | {
"lang": "rust",
"repo": "TimNN/channel",
"path": "/src/flavors/zero.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dmitry-pechersky/algorithms path: /leetcode/646_Maximum_Length_of_Pair_Chain.rs
struct Solution {}
impl Solution {
pub fn find_longest_chain(pairs: Vec<Vec<i32>>) -> i32 {
let mut pairs = pairs;
let mut cnt = 0;
let mut end = i32::MIN;
pairs.sort();
... | code_fim | medium | {
"lang": "rust",
"repo": "dmitry-pechersky/algorithms",
"path": "/leetcode/646_Maximum_Length_of_Pair_Chain.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(3, Solution::find_longest_chain(vec![vec![1,2],vec![7,8],vec![4,5]]));
}<|fim_prefix|>// repo: dmitry-pechersky/algorithms path: /leetcode/646_Maximum_Length_of_Pair_Chain.rs
struct Solution {}
impl Solution {
pub fn find_longest_chain(pairs: Vec<Vec<i32>>) -> i32 {
let mut pa... | code_fim | medium | {
"lang": "rust",
"repo": "dmitry-pechersky/algorithms",
"path": "/leetcode/646_Maximum_Length_of_Pair_Chain.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(2, Solution::find_longest_chain(vec![vec![1,2],vec![2,3],vec![3,4]]));
}
#[test]
fn test_2() {
assert_eq!(3, Solution::find_longest_chain(vec![vec![1,2],vec![7,8],vec![4,5]]));
}<|fim_prefix|>// repo: dmitry-pechersky/algorithms path: /leetcode/646_Maximum_Length_of_Pair_Chain.rs
stru... | code_fim | medium | {
"lang": "rust",
"repo": "dmitry-pechersky/algorithms",
"path": "/leetcode/646_Maximum_Length_of_Pair_Chain.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: google/bongo path: /examples/simple_earley.rs
use bongo::grammar::{
build, Elem, Grammar, NonTerminal, ProdElement, Terminal,
};
use bongo::parsers::earley::parse;
use bongo::parsers::{tree::TreeOwner, Token};
use bongo::start_grammar::wrap_grammar_with_start;
use bongo::utils::Name;
fn main(... | code_fim | medium | {
"lang": "rust",
"repo": "google/bongo",
"path": "/examples/simple_earley.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let tree: TreeOwner<_, _, &'static str> = TreeOwner::new();
let node = parse(
&g,
&tree.handle(),
vec![
Token::new(lp_t.clone(), "("),
Token::new(v_t.clone(), "Hello!"),
Token::new(rp_t.clone(), ")"),
],
)
.unwrap();
println!("{}", node.to_dot());
}<|fim_prefi... | code_fim | hard | {
"lang": "rust",
"repo": "google/bongo",
"path": "/examples/simple_earley.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> for data_to_check in data {
let proof = tree.get_proof(data_to_check);
assert!(proof.is_some());
let result = proof.unwrap().validate(tree.root_hash());
assert!(result);
}
}
#[test]
fn test_inclusion_fail() {
let data = vec![format!("one"), format!("two"), for... | code_fim | medium | {
"lang": "rust",
"repo": "skletsun/merkle-simple",
"path": "/tests/proof.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let data = vec![format!("one"), format!("two"), format!("three"), format!("four")];
let tree = MerkleTree::from_vector(data.clone()).unwrap();
for data_to_check in data {
let proof = tree.get_proof(data_to_check);
assert!(proof.is_some());
let result = proof.unwrap().... | code_fim | medium | {
"lang": "rust",
"repo": "skletsun/merkle-simple",
"path": "/tests/proof.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: skletsun/merkle-simple path: /tests/proof.rs
extern crate merkle_simple;
#[allow(unused_imports)]
use merkle_simple::{MerkleTree, Hashable};
#[test]
fn test_inclusion_success() {
let data = vec![format!("one"), format!("two"), format!("three"), format!("four")];
let tree = MerkleTree::... | code_fim | medium | {
"lang": "rust",
"repo": "skletsun/merkle-simple",
"path": "/tests/proof.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Lifars/ioc-checker-probe path: /src/windows_bindings.rs
#[allow(dead_code)]
pub enum PoolType {
NonPagedPool,
PagedPool,
NonPagedPoolMustSucceed,
DontUseT<|fim_suffix|>pe,
NonPagedPoolSession,
PagedPoolSession,
NonPagedPoolMustSucceedSession,
DontUseThisTypeSessio... | code_fim | medium | {
"lang": "rust",
"repo": "Lifars/ioc-checker-probe",
"path": "/src/windows_bindings.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pe,
NonPagedPoolSession,
PagedPoolSession,
NonPagedPoolMustSucceedSession,
DontUseThisTypeSession,
NonPagedPoolCacheAlignedSession,
PagedPoolCacheAlignedSession,
NonPagedPoolCacheAlignedMustSSession,
}<|fim_prefix|>// repo: Lifars/ioc-checker-probe path: /src/windows_bindings.... | code_fim | medium | {
"lang": "rust",
"repo": "Lifars/ioc-checker-probe",
"path": "/src/windows_bindings.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: denoland/deno_lint path: /src/rules/no_case_declarations.rs
// Copyright 2020-2021 the Deno authors. All rights reserved. MIT license.
use super::{Context, LintRule};
use crate::handler::{Handler, Traverse};
use crate::Program;
use deno_ast::view::{Decl, Stmt, SwitchCase, VarDeclKind};
use deno_... | code_fim | hard | {
"lang": "rust",
"repo": "denoland/deno_lint",
"path": "/src/rules/no_case_declarations.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // nested switch
r#"
switch (foo) {
case 1:
switch (bar) {
case 2:
let a = "a";
break;
}
break;
}
"#: [
{
line: 5,
col: 6,
message: MESSAGE,
hint: HINT,
}
],
r#"
switch (foo) {
default... | code_fim | hard | {
"lang": "rust",
"repo": "denoland/deno_lint",
"path": "/src/rules/no_case_declarations.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> x % 3 == 0 || x.to_string().ends_with("3")
}
let ans = (1..).filter(|&x| !dislike(x)).nth(k - 1).unwrap();
println!("{}", ans);
}<|fim_prefix|>// repo: ia7ck/competitive-programming path: /Codeforces/r739/src/bin/a/main.rs
use procon_reader::ProconReader;
fn main() {
<|fim_middle|> ... | code_fim | hard | {
"lang": "rust",
"repo": "ia7ck/competitive-programming",
"path": "/Codeforces/r739/src/bin/a/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ia7ck/competitive-programming path: /Codeforces/r739/src/bin/a/main.rs
use procon_reader::ProconReader;
fn main() {
let stdin = std::io::stdin();
let mut rd = ProconReader::new(stdin.lock());
<|fim_suffix|>fn solve(k: usize) {
fn dislike(x: usize) -> bool {
x % 3 == 0 || x.... | code_fim | medium | {
"lang": "rust",
"repo": "ia7ck/competitive-programming",
"path": "/Codeforces/r739/src/bin/a/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn make_deserialized_update_channel() -> UpdateChannel {
UpdateChannel::new(1, 12.3, [0; 32]).unwrap()
}
fn make_serialized_update_channel() -> Vec<u8> {
return vec![
0x01, 0x00, 0x00, 0x00, // channel_id
0xcd, 0xcc, 0x44, 0x41, // nominal_hash_rate
... | code_fim | hard | {
"lang": "rust",
"repo": "mason0510/rust-stratum-v2",
"path": "/stratumv2/src/mining/update_channel.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mason0510/rust-stratum-v2 path: /stratumv2/src/mining/update_channel.rs
use crate::{error::Result, impl_message, types::U256};
impl_message!(
/// UpdateChannel is sent from the Client to a Server. This message is used by
/// the Client to notify the server about specific changes to a ch... | code_fim | medium | {
"lang": "rust",
"repo": "mason0510/rust-stratum-v2",
"path": "/stratumv2/src/mining/update_channel.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let start = Instant::now();
// u32: every 2 bits is a triangle in row 0 red, 1 green, 2 red, 3 unknown (used in g_up)
let mut up: Vec<u64> = vec![1, 1, 1, 0];
for i in 1..8 {
let mut down = vec![0u64; 3 * 4i32.pow(i - 1) as usize];
let mut newup = vec![0u64; 3 * 4i32.pow(i... | code_fim | hard | {
"lang": "rust",
"repo": "MANGO1234/ProjectEuler",
"path": "/problems/rust/P189/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: MANGO1234/ProjectEuler path: /problems/rust/P189/main.rs
mod euler;
use std::time::Instant;
#[allow(unused_imports)]
use euler::eratosthenes_sieve::EratosthenesSieve;
fn g_up(k: u64, n: u32, acc: usize, j: usize, up: &mut Vec<u64>) {
if n == 0 {
if j & 3 != 0 {
up[(acc ... | code_fim | medium | {
"lang": "rust",
"repo": "MANGO1234/ProjectEuler",
"path": "/problems/rust/P189/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dmvict/wTools path: /rust/impl/censor/instruction.rs
/// Private namespace of the module.
pub( crate ) mod private
{
pub use wtools::error::{ err, BasicError };
use std::collections::HashMap;
///
/// Instruction.
///
#[ derive( Debug, PartialEq, Eq ) ]
pub struct Instruction
{
... | code_fim | hard | {
"lang": "rust",
"repo": "dmvict/wTools",
"path": "/rust/impl/censor/instruction.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> {
Self
{
err : None,
command_name : Default::default(),
subject : Default::default(),
properties_map : Default::default(),
}
}
}
//
///
/// Adapter for instruction.
///
pub trait InstructionParseParamsAdapter
{
/// Print info... | code_fim | hard | {
"lang": "rust",
"repo": "dmvict/wTools",
"path": "/rust/impl/censor/instruction.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // dbg!( );
// super::params::parse_from_splits( );
result
}
// //
//
// fn str_structure_parse()
// {
//
// }
}
///
/// Parameters of instruction.
///
#[ derive( Debug, PartialEq, Eq ) ]
pub struct InstructionParseParams
{
}
impl Instru... | code_fim | hard | {
"lang": "rust",
"repo": "dmvict/wTools",
"path": "/rust/impl/censor/instruction.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: lupyuen/pinetime-lvgl path: /src/core/indev.rs
line]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
let bit_index = if cfg!(target_... | code_fim | hard | {
"lang": "rust",
"repo": "lupyuen/pinetime-lvgl",
"path": "/src/core/indev.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: lupyuen/pinetime-lvgl path: /src/core/indev.rs
e(self._bitfield_1.get(3usize, 5u8) as u16) }
}
#[inline]
pub fn set_red(&mut self, val: u16) {
unsafe {
let val: u16 = ::core::mem::transmute(val);
self._bitfield_1.set(3usize, 5u8, val as u64)
}
... | code_fim | hard | {
"lang": "rust",
"repo": "lupyuen/pinetime-lvgl",
"path": "/src/core/indev.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> unsafe { ::core::mem::zeroed() }
}
}
impl _disp_t {
#[inline]
pub fn del_prev(&self) -> u8 {
unsafe { ::core::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) }
}
#[inline]
pub fn set_del_prev(&mut self, val: u8) {
unsafe {
let val: u8 = :... | code_fim | hard | {
"lang": "rust",
"repo": "lupyuen/pinetime-lvgl",
"path": "/src/core/indev.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Schenk75/Learn-Rust path: /develop/ref/第一行rust/ch2/ex5.rs
use rand::Rng;
use std::io::Read;
fn one_in(n: u32) -> bool {
rand::thread_rng().gen_weighted_bool(n)
}
#[derive(Debug)]
struct FileStruct {
name: String,
data: Vec<u8>
}
fn get_file_as_byte_vec(filename: &String) -> Vec<u8... | code_fim | medium | {
"lang": "rust",
"repo": "Schenk75/Learn-Rust",
"path": "/develop/ref/第一行rust/ch2/ex5.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> FileStruct {name: String::from(name), data: Vec::new()}
}
fn new_with_data(name: &str, data: &Vec<u8>) -> FileStruct {
let mut f = FileStruct::new(name);
f.data = data.clone();
f
}
fn read(self: &FileStruct, save_to: &mut Vec<u8>) -> Result<usize, String> {
... | code_fim | hard | {
"lang": "rust",
"repo": "Schenk75/Learn-Rust",
"path": "/develop/ref/第一行rust/ch2/ex5.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rcore-os-infohub/ossoc2020-iLFTH-daily path: /RUST/编程小练习15题/RUST代码/elevator/src/main.rs
fn main() {
let mut n:i32;
let mut current:i32 = 0;
let mut sumTime:i32 = 0;
let mut a:i32;
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
... | code_fim | hard | {
"lang": "rust",
"repo": "rcore-os-infohub/ossoc2020-iLFTH-daily",
"path": "/RUST/编程小练习15题/RUST代码/elevator/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> if a>current {
sumTime =sumTime + 6*(a-current) + 5;
} else if a < current {
sumTime = sumTime + 4*(current-a) + 5;
} else {
sumTime = sumTime + 5;
}
current = a;
println!("{:?}",sumTime);
}
... | code_fim | hard | {
"lang": "rust",
"repo": "rcore-os-infohub/ossoc2020-iLFTH-daily",
"path": "/RUST/编程小练习15题/RUST代码/elevator/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[derive(Serialize)]
struct DateWrapper {
#[serde(serialize_with = "to_utc")]
date: NaiveDateTime,
}
let d = DateWrapper {
date: NaiveDateTime::from_timestamp(0, 0),
};
let v = serde_json::to_string(&d)?;
assert_e... | code_fim | hard | {
"lang": "rust",
"repo": "mozilla-iam/dino-park-packs",
"path": "/src/utils.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mozilla-iam/dino-park-packs path: /src/utils.rs
use chrono::DateTime;
use chrono::NaiveDateTime;
use chrono::Utc;
use serde::Serialize;
use serde::Serializer;
pub fn to_expiration_ts(days: i32) -> NaiveDateTime {
(Utc::now() + chrono::Duration::days(days as i64)).naive_utc()
}
<|fim_suffix... | code_fim | hard | {
"lang": "rust",
"repo": "mozilla-iam/dino-park-packs",
"path": "/src/utils.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: bouzuya/rust-atcoder path: /cargo-atcoder/contests/abc269/src/bin/c.rs
use std::collections::BTreeSet;
use proconio::input;
fn main() {
<|fim_suffix|> let mut ans = BTreeSet::new();
for bits in 0..1 << ks.len() {
let mut a = 0_usize;
for i in 0..ks.len() {
if... | code_fim | medium | {
"lang": "rust",
"repo": "bouzuya/rust-atcoder",
"path": "/cargo-atcoder/contests/abc269/src/bin/c.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> input! {
n: usize,
};
let mut ks = vec![];
for k in 0..60 {
if (n & (1 << k)) != 0 {
ks.push(k);
}
}
let mut ans = BTreeSet::new();
for bits in 0..1 << ks.len() {
let mut a = 0_usize;
for i in 0..ks.len() {
if (bi... | code_fim | medium | {
"lang": "rust",
"repo": "bouzuya/rust-atcoder",
"path": "/cargo-atcoder/contests/abc269/src/bin/c.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let args = Args {
jobs: value_t!(matches.value_of("requests"), usize)?,
database: PathBuf::from(matches.value_of("database").unwrap()),
nixpkgs: matches
.value_of("nixpkgs")
.expect("nixpkgs arg required")
.to_string(),
compression_le... | code_fim | hard | {
"lang": "rust",
"repo": "jordilin/nix-index",
"path": "/src/bin/nix-index.rs",
"mode": "spm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> let fetcher = Fetcher::new(CACHE_URL.to_string()).map_err(|e| ErrorKind::ParseProxy(e))?;
let (files, watch) = match cached {
Some(v) => v,
None => {
errstln!("+ querying available packages");
// These are the paths that show up in `nix-env -qa`.
... | code_fim | hard | {
"lang": "rust",
"repo": "jordilin/nix-index",
"path": "/src/bin/nix-index.rs",
"mode": "spm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jordilin/nix-index path: /src/bin/nix-index.rs
//! Tool for generating a nix-index database.
#[macro_use]
extern crate clap;
extern crate bincode;
extern crate futures;
extern crate hyper;
extern crate nix_index;
extern crate separator;
extern crate tokio_retry;
extern crate void;
extern crate x... | code_fim | hard | {
"lang": "rust",
"repo": "jordilin/nix-index",
"path": "/src/bin/nix-index.rs",
"mode": "psm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ChrisDenton/wintls path: /examples/string_local.rs
// This example creates a type that will return a different value depending on
// which thread uses it.
// Use the std's thread_local for this.
// We still handle drops using this library.
#![feature(thread_local)]
// A module to protect our s... | code_fim | hard | {
"lang": "rust",
"repo": "ChrisDenton/wintls",
"path": "/examples/string_local.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> unsafe {
println!("dropping thread local");
debug_assert_eq!(STATE, 1);
STATE = 2;
core::ptr::drop_in_place(core::ptr::addr_of_mut!(BUFFER));
}
}
unsafe {
match STATE {
0 => {
register_dtor(destroy);
STATE = 1;
}
1 => {}
_ => panic!("the thread local ... | code_fim | hard | {
"lang": "rust",
"repo": "ChrisDenton/wintls",
"path": "/examples/string_local.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> loop {
for sketch in &sketches {
println!("Running {}", sketch);
sketch.spawn();
thread::sleep(Duration::from_secs(5));
Sketch::kill_all();
}
}
}<|fim_prefix|>// repo: osu-cascades/exhibit-x path: /runner/src/main.rs
use sketch::Sket... | code_fim | hard | {
"lang": "rust",
"repo": "osu-cascades/exhibit-x",
"path": "/runner/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: osu-cascades/exhibit-x path: /runner/src/main.rs
use sketch::Sketch;
use std::{fs, path::PathBuf, thread, time::Duration};
mod sketch;
fn main() {
let tech_tri_base = "/home/exhibitx/ExhibitX/exhibit-x/TechTri/".to_string();
<|fim_suffix|> loop {
for sketch in &sketches {
... | code_fim | hard | {
"lang": "rust",
"repo": "osu-cascades/exhibit-x",
"path": "/runner/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let t1 = Node::add_new(None, 1);
let t2 = Node::add_new(t1, 2);
let t2 = Node::add_new(t2, 2);
println!("{:?}", t2);
}
}<|fim_prefix|>// repo: AbrarNitk/algorithmica path: /algorithmica/src/tree/mod.rs
pub mod bst;
pub mod rb;
#[derive(Debug)]
pub struct Node {
pu... | code_fim | hard | {
"lang": "rust",
"repo": "AbrarNitk/algorithmica",
"path": "/algorithmica/src/tree/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: AbrarNitk/algorithmica path: /algorithmica/src/tree/mod.rs
pub mod bst;
pub mod rb;
#[derive(Debug)]
pub struct Node {
pub value: i32,
pub left: Option<Box<Node>>,
pub right: Option<Box<Node>>,
}
impl Node {
pub fn create(value: i32) -> Box<Self> {
Box::new(Node {
... | code_fim | hard | {
"lang": "rust",
"repo": "AbrarNitk/algorithmica",
"path": "/algorithmica/src/tree/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> str: &str,
carts: &mut Vec<Cart>) -> Vec<EnumSet<Dir>> {
let mut result: Vec<EnumSet<Dir>> = Vec::new();
let mut prev_char = ' ';
for i in str.char_indices() {
let tc_dirs = get_possible_dirs(i.1, prev_char);
if tc_dirs.1.is_som... | code_fim | hard | {
"lang": "rust",
"repo": "simbre1/advent_of_code_2018_rust_13",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: simbre1/advent_of_code_2018_rust_13 path: /src/main.rs
#[macro_use]
extern crate enumset;
use std::fs;
use enumset::EnumSet;
use std::fmt;
use std::collections::HashSet;
#[derive(EnumSetType, Debug)]
pub enum Dir { N, E, S, W }
impl Dir {
fn get_next_pos(&self, x: usize, y: usize) -> (usi... | code_fim | hard | {
"lang": "rust",
"repo": "simbre1/advent_of_code_2018_rust_13",
"path": "/src/main.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.