text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_suffix|> test_derive! {
visit_entities_derive {
struct Foo<T> {
entity_stuff: T,
}
}
expands to {
#[allow(non_upper_case_globals)]
const _DERIVE_specs_visitor_VisitEntities_FOR_Foo: () = {
impl<T> ::specs_vi... | code_fim | hard | {
"lang": "rust",
"repo": "isgasho/tin",
"path": "/specs-visitor-derive/src/tests.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> where
V: ::specs_visitor::EntityVisitor,
{
match *self {
Foo {
entity_stuff: ref __binding_0,
} => {{
... | code_fim | hard | {
"lang": "rust",
"repo": "isgasho/tin",
"path": "/specs-visitor-derive/src/tests.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: isgasho/tin path: /specs-visitor-derive/src/tests.rs
use specs;
use super::visit_entities_derive;
use super::visit_entities_mut_derive;
#[test]
fn simple() {
test_derive! {
visit_entities_derive {
struct Foo {
entity: specs::Entity,
}
... | code_fim | hard | {
"lang": "rust",
"repo": "isgasho/tin",
"path": "/specs-visitor-derive/src/tests.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: astral-sh/ruff path: /crates/ruff_python_formatter/src/statement/suite.rs
use ruff_formatter::{write, FormatOwnedWithRule, FormatRefWithRule, FormatRuleWithOptions};
use ruff_python_ast::helpers::is_compound_statement;
use ruff_python_ast::{self as ast, Constant, Expr, Ranged, Stmt, Suite};
use ... | code_fim | hard | {
"lang": "rust",
"repo": "astral-sh/ruff",
"path": "/crates/ruff_python_formatter/src/statement/suite.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> FormatRefWithRule::new(self, FormatSuite::default())
}
}
impl<'ast> IntoFormat<PyFormatContext<'ast>> for Suite {
type Format = FormatOwnedWithRule<Suite, FormatSuite, PyFormatContext<'ast>>;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule::new(self, FormatSuite::d... | code_fim | hard | {
"lang": "rust",
"repo": "astral-sh/ruff",
"path": "/crates/ruff_python_formatter/src/statement/suite.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: vkill/books-rs path: /book/examples/ch16-03-counter.rs
//! Counter with [Mutex<T>]
//!
//! [mutex<t>]: https://doc.rust-lang.org/book/ch16-03-shared-state.html
use std::sync::Arc;
use std::thread::{self, Result};
<|fim_suffix|>fn main() -> Result<()> {
let mut handlers = Vec::with_capacity(... | code_fim | medium | {
"lang": "rust",
"repo": "vkill/books-rs",
"path": "/book/examples/ch16-03-counter.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> for _ in 0..1_000 {
let counter = counter.clone();
let handler = thread::spawn(move || counter.inc(2_000_000));
handlers.push(handler);
}
for handler in handlers {
handler.join()?
}
assert_eq!(2_000_000_100, counter.get());
Ok(())
}<|fim_prefix|>// r... | code_fim | medium | {
"lang": "rust",
"repo": "vkill/books-rs",
"path": "/book/examples/ch16-03-counter.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let result = get_solution_part1();
assert_eq!(result, "1651");
}
#[test_case(get_example_input1, 19; "input1")]
#[test_case(get_example_input2, 23; "input2")]
#[test_case(get_example_input3, 23; "input3")]
#[test_case(get_example_input4, 29; "input4")]
#[test_case... | code_fim | hard | {
"lang": "rust",
"repo": "pavel1269/advent-of-code",
"path": "/2022/src/day06/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: pavel1269/advent-of-code path: /2022/src/day06/mod.rs
use std::collections::HashSet;
pub fn get_solution_part1() -> String {
let input = get_input();
let result = detect_signal_start(input, 4);
return result.to_string();
}
pub fn get_solution_part2() -> String {
let input = get... | code_fim | hard | {
"lang": "rust",
"repo": "pavel1269/advent-of-code",
"path": "/2022/src/day06/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let a: i32 = 20; // i32 is a datatype for numbers
let b: i32 = 10;
let c: i32;
c = add(a, b);
println!("The addition of {} and {} is {}", a, b, c);
}<|fim_prefix|>// repo: Naimul-Islam-Siam/Practice path: /Rust/rust-fundamentals/src/datatypes.rs
fn add(num1: i32, num2: i32) -> i32 {
<|fi... | code_fim | easy | {
"lang": "rust",
"repo": "Naimul-Islam-Siam/Practice",
"path": "/Rust/rust-fundamentals/src/datatypes.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> println!("The addition of {} and {} is {}", a, b, c);
}<|fim_prefix|>// repo: Naimul-Islam-Siam/Practice path: /Rust/rust-fundamentals/src/datatypes.rs
fn add(num1: i32, num2: i32) -> i32 {
return num1 + num2;
}
fn main() {
let a: i32 = 20; // i32 is a datatype for numbers
let b: i32 = 10;
... | code_fim | easy | {
"lang": "rust",
"repo": "Naimul-Islam-Siam/Practice",
"path": "/Rust/rust-fundamentals/src/datatypes.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Naimul-Islam-Siam/Practice path: /Rust/rust-fundamentals/src/datatypes.rs
fn add(num1: i32, num2: i32) -> i32 {
return num1 + num2;
}
fn main() {
<|fim_suffix|> c = add(a, b);
println!("The addition of {} and {} is {}", a, b, c);
}<|fim_middle|> let a: i32 = 20; // i32 is a datatype ... | code_fim | medium | {
"lang": "rust",
"repo": "Naimul-Islam-Siam/Practice",
"path": "/Rust/rust-fundamentals/src/datatypes.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl FromStr for OptionType {
type Err = io::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"C" => Ok(Self::Call),
"P" => Ok(Self::Put),
_ => Err(io::Error::new(io::ErrorKind::Other, "Error parsing option type."))
}
}
}<... | code_fim | hard | {
"lang": "rust",
"repo": "mattboran/stonks_cli",
"path": "/src/data/options.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl FromStr for Option {
//Root Symbol|Options Closing Type|Options Type|Expiration Date|Explicit Strike Price|Underlying Symbol|Underlying Issue Name|Pending
type Err = io::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let components: Vec<&str> = s.split("|").collect();
... | code_fim | hard | {
"lang": "rust",
"repo": "mattboran/stonks_cli",
"path": "/src/data/options.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mattboran/stonks_cli path: /src/data/options.rs
use std::io;
use std::str::FromStr;
use chrono::{Date, FixedOffset, TimeZone};
#[derive(Debug, Clone, Copy)]
pub enum OptionType {
Call,
Put
}
type Dollars = f32;
<|fim_suffix|>impl FromStr for OptionType {
type Err = io::Error;
... | code_fim | hard | {
"lang": "rust",
"repo": "mattboran/stonks_cli",
"path": "/src/data/options.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: abhijeetbhagat/genmei path: /src/transports/longpollingtransport.rs
use transports::clienttransport::ClientTransport;
use futures::future::Future;
use negotiationresponse::NegotiationResponse;
use httpclient::HttpClient;
use urlbuilder::UrlBuilder;
use connection::Connection;
use serde_json::{Ma... | code_fim | hard | {
"lang": "rust",
"repo": "abhijeetbhagat/genmei",
"path": "/src/transports/longpollingtransport.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn send(
&mut self,
url: &str,
connection_data: &str,
connection_token: &str,
protocol: &str,
data: String,
) -> Box<Future<Item = (), Error = ()>> {
unimplemented!();
}
fn abort(&self) -> Box<Future<Item = (), Error = ()>> {
... | code_fim | hard | {
"lang": "rust",
"repo": "abhijeetbhagat/genmei",
"path": "/src/transports/longpollingtransport.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn disable(&mut self) { self.enabled = false; }
fn set_config(&mut self, var: &str, val: &[&str]) {
//
}
}
impl ChatSpam {
}<|fim_prefix|>// repo: msfwaifu/RainStorm path: /src/cheats/chatspam.rs
use core::prelude::*;
use collections::MutableSeq;
use Cheat;
use GamePointers;
use Vec;
use sdk;
pub... | code_fim | hard | {
"lang": "rust",
"repo": "msfwaifu/RainStorm",
"path": "/src/cheats/chatspam.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> ptrs.ivengineclient.client_cmd(*self.messages.get(self.curr_msg));
self.curr_msg += 1;
if self.curr_msg >= self.messages.len() {
self.curr_msg = 0
}
}
fn enable(&mut self) { self.enabled = true; }
fn disable(&mut self) { self.enabled = false; }
fn set_config(&mut self, var: &str, val: &[&st... | code_fim | hard | {
"lang": "rust",
"repo": "msfwaifu/RainStorm",
"path": "/src/cheats/chatspam.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: msfwaifu/RainStorm path: /src/cheats/chatspam.rs
use core::prelude::*;
use collections::MutableSeq;
use Cheat;
use GamePointers;
use Vec;
<|fim_suffix|> ptrs.ivengineclient.client_cmd(*self.messages.get(self.curr_msg));
self.curr_msg += 1;
if self.curr_msg >= self.messages.len() {
self.... | code_fim | hard | {
"lang": "rust",
"repo": "msfwaifu/RainStorm",
"path": "/src/cheats/chatspam.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> if x > u32::MAX as usize {
self.upgrade_to_usize();
} else if x > u16::MAX as usize {
self.upgrade_to_u32();
} else if x > u8::MAX as usize {
self.upgrade_to_u16();
}
}
fn get(&self, i: usize) -> usize {
match self.mode {... | code_fim | hard | {
"lang": "rust",
"repo": "I3ck/rust-3d",
"path": "/src/dynamic_precision_index_vec.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: I3ck/rust-3d path: /src/dynamic_precision_index_vec.rs
/*
Copyright 2020 Martin Buck
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without ... | code_fim | hard | {
"lang": "rust",
"repo": "I3ck/rust-3d",
"path": "/src/dynamic_precision_index_vec.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn len(&self) -> usize {
match self.mode {
Mode::U8(ref vec) => vec.len(),
Mode::U16(ref vec) => vec.len(),
Mode::U32(ref vec) => vec.len(),
Mode::Usize(ref vec) => vec.len(),
}
}
fn reserve(&mut self, n: usize) {
match s... | code_fim | hard | {
"lang": "rust",
"repo": "I3ck/rust-3d",
"path": "/src/dynamic_precision_index_vec.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: oliverdunk/AdventOfCode-Rust path: /src/bin/day_seven.rs
use std::fs;
use std::vec;
fn get_params(memory: &Vec<i32>, pc: usize, count: i32) -> Vec<i32> {
let mut params = vec::Vec::new();
let instruction = memory[pc];
for i in 1..=count {
let mut mode = 0;
let param = memory[pc +... | code_fim | hard | {
"lang": "rust",
"repo": "oliverdunk/AdventOfCode-Rust",
"path": "/src/bin/day_seven.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> memory[dest] = if op_a == op_b { 1 } else { 0 };
*pc = *pc + 4;
},
99 => { return None; },
_ => { panic!("Unknown opcode") },
};
}
}
fn run_amplifiers(program: Vec<i32>, phases: Vec<i32>) -> i32 {
// For each amplifier, we store the memory and pc
let mut amplif... | code_fim | hard | {
"lang": "rust",
"repo": "oliverdunk/AdventOfCode-Rust",
"path": "/src/bin/day_seven.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: atsheehan/zero-to-gamedev path: /block_peers/src/piece.rs
use rand::Rng;
use serde::{Deserialize, Serialize};
use crate::brick::{BrickType, GridCell};
use crate::image::Image;
// --------
// Piece
// --------
type PieceShape = [bool; 16];
#[rustfmt::skip]
const SHAPES: [PieceShape; 7] = [
... | code_fim | hard | {
"lang": "rust",
"repo": "atsheehan/zero-to-gamedev",
"path": "/block_peers/src/piece.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.current_row += 1;
self.current_col = 0;
}
None
}
}
// --------
// Rotation
// --------
#[derive(Serialize, Deserialize, Debug, PartialEq, Copy, Clone)]
enum Rotation {
Zero,
Ninety,
OneEighty,
TwoSeventy,
}
impl Rotation {
fn next(sel... | code_fim | hard | {
"lang": "rust",
"repo": "atsheehan/zero-to-gamedev",
"path": "/block_peers/src/piece.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ejlangev/rust_os path: /src/main.rs
#![cfg_attr(not(test), no_std)]
#![cfg_attr(not(test), no_main)]
#![cfg_attr(test, allow(unused_imports))]
use core::panic::PanicInfo;
<|fim_suffix|>#[cfg(not(test))]
#[no_mangle]
pub extern "C" fn _start() -> ! {
debug!(DebugLevel::Core, "Hello {}\nGoodb... | code_fim | hard | {
"lang": "rust",
"repo": "ejlangev/rust_os",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> clear_screen!();
debug!(DebugLevel::Core, "Starting boot...");
loop {}
}<|fim_prefix|>// repo: ejlangev/rust_os path: /src/main.rs
#![cfg_attr(not(test), no_std)]
#![cfg_attr(not(test), no_main)]
#![cfg_attr(test, allow(unused_imports))]
use core::panic::PanicInfo;
mod vga_buffer;
use crate::v... | code_fim | hard | {
"lang": "rust",
"repo": "ejlangev/rust_os",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: isgasho/doctave path: /src/lib.rs
#[deny(clippy::all)]
#[cfg(test)]
#[macro_use]
extern crate indoc;
#[macro_use]
extern crate lazy_static;
mod build;
pub mod config;
mod error;
mod frontmatter;
mod init;
mod livereload_server;
mod navigation;
mod preview_server;
#[allow(dead_code, unused_vari... | code_fim | hard | {
"lang": "rust",
"repo": "isgasho/doctave",
"path": "/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// The path to the HTML file on disk that will be generated
fn html_path(&self) -> PathBuf {
// TODO(Nik): Refactor this mess to be readable
match self.rename {
None => self.path.with_file_name(&format!(
"{}.html",
self.path.file_stem().... | code_fim | hard | {
"lang": "rust",
"repo": "isgasho/doctave",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: HdrHistogram/HdrHistogram_rust path: /benches/quantiles.rs
#![feature(test)]
extern crate test;
use hdrhistogram::*;
use test::{black_box, Bencher};
<|fim_suffix|> let mut h = Histogram::<u32>::new_with_bounds(1, 100_000, 3).unwrap();
for i in 0..100_000 {
h.record(i).unwrap();... | code_fim | easy | {
"lang": "rust",
"repo": "HdrHistogram/HdrHistogram_rust",
"path": "/benches/quantiles.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut h = Histogram::<u32>::new_with_bounds(1, 100_000, 3).unwrap();
for i in 0..100_000 {
h.record(i).unwrap();
}
b.iter(|| {
black_box(h.quantile_below(black_box(10)));
black_box(h.quantile_below(black_box(90_000)));
})
}<|fim_prefix|>// repo: HdrHistogram/... | code_fim | easy | {
"lang": "rust",
"repo": "HdrHistogram/HdrHistogram_rust",
"path": "/benches/quantiles.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let client = spawn_client_server();
b.iter(move || {
let s = rand::thread_rng()
.gen_ascii_chars()
.take(10)
.collect::<String>();
let mut req = consensus::ReplaceRequest::new();
req.set_payload(s.into_bytes());
client
... | code_fim | hard | {
"lang": "rust",
"repo": "summerhhh/ekiden",
"path": "/consensus/benches/benchmarks.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: summerhhh/ekiden path: /consensus/benches/benchmarks.rs
#![feature(test)]
extern crate consensus as lib;
extern crate grpc;
extern crate rand;
extern crate test;
use rand::Rng;
use std::{thread, time};
use test::Bencher;
use lib::generated::consensus;
use lib::generated::consensus_grpc;
use l... | code_fim | hard | {
"lang": "rust",
"repo": "summerhhh/ekiden",
"path": "/consensus/benches/benchmarks.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn haversine_distance(&self, origin_lat: f64, origin_lon: f64, dest_lat: f64, dest_lon: f64) -> f64 {
static R: f64 = 6372.8;
let diff = origin_lon - dest_lon;
let ori_lon = diff.to_radians();
let ori_lat = origin_lat.to_radians();
let dest_lat = dest_lat.to_rad... | code_fim | hard | {
"lang": "rust",
"repo": "andrewgy8/ende",
"path": "/src/maps.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: andrewgy8/ende path: /src/maps.rs
use core::convert::From;
use core::option::Option;
use core::option::Option::{None, Some};
use osm4routing::models::{Edge, Node};
use petgraph::graph::NodeIndex;
pub struct Map {
pub nodes: Vec<Node>,
pub edges: Vec<Edge>,
}
impl From<&String> for Map ... | code_fim | hard | {
"lang": "rust",
"repo": "andrewgy8/ende",
"path": "/src/maps.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: manuel-woelker/rust-pdf path: /src/pd/pd_document_information.rs
#[derive(Debug, Clone, Default)]
pub struct PDDocumentInformation {
<|fim_suffix|>on {
pub fn new() -> PDDocumentInformation {
Default::default()
}
}<|fim_middle|>pub title: Option<String>,
pub author: Option<String>,
pub... | code_fim | medium | {
"lang": "rust",
"repo": "manuel-woelker/rust-pdf",
"path": "/src/pd/pd_document_information.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>tion<String>,
pub keywords: Option<String>,
}
impl PDDocumentInformation {
pub fn new() -> PDDocumentInformation {
Default::default()
}
}<|fim_prefix|>// repo: manuel-woelker/rust-pdf path: /src/pd/pd_document_information.rs
#[derive(Debug, Clone, Default)]
pub struct PDDocumentInformation {
<|... | code_fim | medium | {
"lang": "rust",
"repo": "manuel-woelker/rust-pdf",
"path": "/src/pd/pd_document_information.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Decode a single block.
///
/// The `output` buffer must be empty upon calling this method.
#[throws]
pub fn decode_block(&mut self, output: &mut Vec<u8>, dictionary: &[u8]) {
assert!(output.is_empty(), "You must pass an empty buffer to this interface.");
if... | code_fim | hard | {
"lang": "rust",
"repo": "RANGER-RX/rust-lz-fear",
"path": "/src/framed/decompress.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: RANGER-RX/rust-lz-fear path: /src/framed/decompress.rs
use byteorder::{LE, ReadBytesExt};
use std::hash::Hasher;
use std::io::{self, Read, BufRead, ErrorKind};
use std::cmp;
use std::convert::TryInto;
use twox_hash::XxHash32;
use thiserror::Error;
use fehler::{throw, throws};
use super::{MAGIC,... | code_fim | hard | {
"lang": "rust",
"repo": "RANGER-RX/rust-lz-fear",
"path": "/src/framed/decompress.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(
1,
1,
"Greeting did not contain name, value was `{}`", 1
);
}
#[test]
#[should_panic(expected = "this function should be `panic!` !")]
fn test4() {
// panic!("this is the panic! message")
}
}<|fim_prefix|>// repo: ... | code_fim | medium | {
"lang": "rust",
"repo": "HillBamboo/learn_rust",
"path": "/src/rust_book/ch11_testing.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: HillBamboo/learn_rust path: /src/rust_book/ch11_testing.rs
#[cfg(test)]
mod tests {
#[test]
fn test() {
assert_eq!(2 + 2, 4);
}
<|fim_suffix|> assert_eq!(3 * 4, 12);
}
#[test]
fn test3() {
assert_eq!(
1,
1,
"G... | code_fim | easy | {
"lang": "rust",
"repo": "HillBamboo/learn_rust",
"path": "/src/rust_book/ch11_testing.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: DennisVanEe/rust_prism path: /pmath/src/bbox.rs
use crate::numbers::Float;
use crate::ray::Ray;
use crate::vector::{Vec2, Vec3};
use num_traits::Bounded;
use std::cmp::PartialOrd;
use std::ops::{Index, Sub};
/// A 2d bounding box.
#[derive(Clone, Copy, Debug)]
pub struct BBox2<T: PartialOrd + B... | code_fim | hard | {
"lang": "rust",
"repo": "DennisVanEe/rust_prism",
"path": "/pmath/src/bbox.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let tz_min = (self[is_dir_neg[2]].z - ray.org.z) * inv_dir.z;
let tz_max = (self[1 - is_dir_neg[2]].z - ray.org.z) * inv_dir.z;
// let tz_max = tz_max * (1. + 2. * gamma_f64(3));
if t_min > tz_max || tz_min > t_max {
return false;
}
let t_min =... | code_fim | hard | {
"lang": "rust",
"repo": "DennisVanEe/rust_prism",
"path": "/pmath/src/bbox.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn test_0() {
assert_eq!(Solution::first_missing_positive(vec![1, 2, 0]), 3);
}
#[test]
fn test_1() {
assert_eq!(Solution::first_missing_positive(vec![3, 4, -1, 1]), 2);
}
#[test]
fn test_2() {
assert_eq!(Solution::first_missing_positive(ve... | code_fim | medium | {
"lang": "rust",
"repo": "santosh241/Windary",
"path": "/Rust/src/0041_first_missing_positive.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: santosh241/Windary path: /Rust/src/0041_first_missing_positive.rs
//! Given an unsorted integer array, find the smallest missing positive integer.
//!
//! ```
//! Example 1:
//!
//! Input: [1,2,0]
//! Output: 3
//! ```
//!
//! ```
//! Example 2:
//!
//! Input: [3,4,-1,1]
//! Output: 2
//! ```
//... | code_fim | hard | {
"lang": "rust",
"repo": "santosh241/Windary",
"path": "/Rust/src/0041_first_missing_positive.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let satisfactory_backends = wgpu::BackendBit::from_bits(
wgpu::BackendBit::PRIMARY.bits() | wgpu::BackendBit::SECONDARY.bits(),
)
.unwrap();
let adapter_options = wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::Default,
compatible_surface: Some(&sur... | code_fim | hard | {
"lang": "rust",
"repo": "chances/deno-wgpu",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: chances/deno-wgpu path: /src/lib.rs
#[macro_use]
extern crate deno_core;
extern crate futures;
extern crate futures_executor;
extern crate serde;
extern crate serde_json;
use deno_core::plugin_api::Interface;
use deno_core::plugin_api::Op;
use deno_core::plugin_api::ZeroCopyBuf;
use futures::fu... | code_fim | hard | {
"lang": "rust",
"repo": "chances/deno-wgpu",
"path": "/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Search for the recipient in a private channel
pub fn get_recipient(&self, channel: &Channel, me: usize) -> Option<&User> {
if channel.private { return None; }
self.get_recipient_unchecked(channel.id, me)
}
/// Search for the recipient in a private channel.
/// If t... | code_fim | hard | {
"lang": "rust",
"repo": "synac-chat/synac-rs",
"path": "/src/state.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: synac-chat/synac-rs path: /src/state.rs
use common::*;
use std::collections::HashMap;
/// A struct that remembers stuff previous packets have informed about
pub struct State {
pub channels: HashMap<usize, Channel>,
pub users: HashMap<usize, User>
}
<|fim_suffix|> /// Search for t... | code_fim | hard | {
"lang": "rust",
"repo": "synac-chat/synac-rs",
"path": "/src/state.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> find_library("libprofiler", "profiler");
#[cfg(feature = "heap")] find_library("libtcmalloc", "tcmalloc");
}<|fim_prefix|>// repo: dfinity-lab/rust-gperftools path: /build.rs
extern crate pkg_config;
/// Configures the crate to link against `lib_name`.
///
/// The library is first searched via t... | code_fim | medium | {
"lang": "rust",
"repo": "dfinity-lab/rust-gperftools",
"path": "/build.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dfinity-lab/rust-gperftools path: /build.rs
extern crate pkg_config;
/// Configures the crate to link against `lib_name`.
///
/// The library is first searched via the pkg-config file provided in
/// `pc_name`, which provides us accurate information on how to find the
/// library to link to. Bu... | code_fim | medium | {
"lang": "rust",
"repo": "dfinity-lab/rust-gperftools",
"path": "/build.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn main () {
find_library("libprofiler", "profiler");
#[cfg(feature = "heap")] find_library("libtcmalloc", "tcmalloc");
}<|fim_prefix|>// repo: dfinity-lab/rust-gperftools path: /build.rs
extern crate pkg_config;
/// Configures the crate to link against `lib_name`.
///
/// The library is first s... | code_fim | medium | {
"lang": "rust",
"repo": "dfinity-lab/rust-gperftools",
"path": "/build.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn up_to_cast<R, F: Fn(Arc<dyn Node>) -> Option<R>>(self: &Arc<Self>, f: F) -> Option<R> {
let mut current = Some(self.clone());
while let Some(nav) = current {
if let Some(n) = f(nav.node.clone()) {
return Some(n);
}
current = na... | code_fim | hard | {
"lang": "rust",
"repo": "aspen-lang/aspen",
"path": "/aspen/src/syntax/navigator.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: aspen-lang/aspen path: /aspen/src/syntax/navigator.rs
use crate::syntax::{Expression, MessageSend, Node, TypeExpression};
use crate::Location;
use std::sync::Arc;
#[derive(Clone, Debug)]
pub struct Navigator {
parent: Option<Arc<Navigator>>,
pub node: Arc<dyn Node>,
}
impl Navigator {
... | code_fim | hard | {
"lang": "rust",
"repo": "aspen-lang/aspen",
"path": "/aspen/src/syntax/navigator.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> parent = p.parent();
}
None
}
pub fn all_expressions(self: &Arc<Self>) -> impl Iterator<Item = Arc<Expression>> {
self.traverse()
.filter_map(|n| n.node.clone().as_expression())
}
pub fn all_type_expressions(self: &Arc<Self>) -> impl Itera... | code_fim | hard | {
"lang": "rust",
"repo": "aspen-lang/aspen",
"path": "/aspen/src/syntax/navigator.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tianenchen/leetcode-rs path: /src/offer/exchange.rs
struct Solution;
#[allow(dead_code)]
impl Solution {
pub fn exchange(nums: Vec<i32>) -> Vec<i32> {
let mut res = vec![0_i32; nums.len()];
let (mut head, mut tail) = (0, nums.len() - 1);
for i in nums.into_iter() {
... | code_fim | medium | {
"lang": "rust",
"repo": "tianenchen/leetcode-rs",
"path": "/src/offer/exchange.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(Solution::exchange(vec![1, 2, 3, 4, 5]), vec![1, 3, 5, 4, 2]);
}<|fim_prefix|>// repo: tianenchen/leetcode-rs path: /src/offer/exchange.rs
struct Solution;
#[allow(dead_code)]
impl Solution {
pub fn exchange(nums: Vec<i32>) -> Vec<i32> {
let mut res = vec![0_i32; nums.len()];
... | code_fim | hard | {
"lang": "rust",
"repo": "tianenchen/leetcode-rs",
"path": "/src/offer/exchange.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jiegec/blog-frontend path: /src/main.rs
#![recursion_limit = "1024"]
mod article;
use stdweb::web::*;
use yew::{html, prelude::*};
struct Model {
article: Option<String>,
}
enum Msg {}
impl Component for Model {
type Message = Msg;
type Properties = ();
<|fim_suffix|> if ... | code_fim | hard | {
"lang": "rust",
"repo": "jiegec/blog-frontend",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> if let Some(url) = &self.article {
html! {
<div>
<article::Model: article=url.clone(),/>
</div>
}
} else {
html! {
<div>
{ "404 Not Found" }
</div>
... | code_fim | hard | {
"lang": "rust",
"repo": "jiegec/blog-frontend",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rstibora/aoc2019 path: /src/year2019/day_08.rs
use crate::aoc_error::{AocError, AocResult};
use crate::utils::input_conversion;
const IMAGE_SIZE: (usize, usize) = (25, 6);
pub fn first_star(input: &str) -> AocResult {
let input: Vec<String> = input_conversion::input_to_lines(input).map_err... | code_fim | hard | {
"lang": "rust",
"repo": "rstibora/aoc2019",
"path": "/src/year2019/day_08.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut zeros_count = 0;
let mut ones_count = 0;
let mut twos_count = 0;
for pixel in layer {
match pixel {
0 => zeros_count += 1,
1 => ones_count += 1,
2 => twos_count += 1,
_ => (),
};
}
(zeros_count, ones_count * t... | code_fim | hard | {
"lang": "rust",
"repo": "rstibora/aoc2019",
"path": "/src/year2019/day_08.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(test)]
mod tests {
use super::hello;
#[test]
fn test_hello() {
assert_eq!("it's me dio", hello())
}
}<|fim_prefix|>// repo: qwerty22121998/learning-rust path: /13 - crates/executeable-crate/src/lib.rs
pub fn sum(a: i64, b: i64) -> i64 {
a + b
}
<|fim_middle|>pub fn hello() -> String... | code_fim | easy | {
"lang": "rust",
"repo": "qwerty22121998/learning-rust",
"path": "/13 - crates/executeable-crate/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: qwerty22121998/learning-rust path: /13 - crates/executeable-crate/src/lib.rs
pub fn sum(a: i64, b: i64) -> i64 {
a + b
}
<|fim_suffix|>#[cfg(test)]
mod tests {
use super::hello;
#[test]
fn test_hello() {
assert_eq!("it's me dio", hello())
}
}<|fim_middle|>pub fn hello() -> String... | code_fim | easy | {
"lang": "rust",
"repo": "qwerty22121998/learning-rust",
"path": "/13 - crates/executeable-crate/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!("it's me dio", hello())
}
}<|fim_prefix|>// repo: qwerty22121998/learning-rust path: /13 - crates/executeable-crate/src/lib.rs
pub fn sum(a: i64, b: i64) -> i64 {
a + b
}
pub fn hello() -> String {
"it's me dio".to_string()
}
<|fim_middle|>#[cfg(test)]
mod tests {
use super::hell... | code_fim | medium | {
"lang": "rust",
"repo": "qwerty22121998/learning-rust",
"path": "/13 - crates/executeable-crate/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn basic() {
let inputs = vec![
Transaction {
ty: TransactionType::Deposit,
client: 1,
tx: 1,
amount: Some(10000),
disputed: false,
... | code_fim | hard | {
"lang": "rust",
"repo": "scrblue/transaction-processor",
"path": "/src/transaction_processing.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: scrblue/transaction-processor path: /src/transaction_processing.rs
use super::*;
/// Process a single transaction
pub async fn process_transaction(
db: &mut impl db_layer::DbLayer,
transaction: Transaction,
) -> Result<(), Error> {
// If there is already a client with that ID, modif... | code_fim | hard | {
"lang": "rust",
"repo": "scrblue/transaction-processor",
"path": "/src/transaction_processing.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: racklet/bmc-experiments path: /rtic-testing/src/main_old.rs
#![no_std]
#![no_main]
extern crate itsybitsy_m4 as hal;
extern crate panic_halt;
use hal::clock::GenericClockController;
use hal::delay::Delay;
use hal::entry;
use hal::pac::{CorePeripherals, Peripherals};
use hal::prelude::*;
use ha... | code_fim | hard | {
"lang": "rust",
"repo": "racklet/bmc-experiments",
"path": "/rtic-testing/src/main_old.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut pins = hal::Pins::new(peripherals.PORT);
let mut red_led = pins.d13.into_open_drain_output(&mut pins.port);
let dotstar = hal::pins::Dotstar {
ci: pins.dotstar_ci,
di: pins.dotstar_di,
nc: pins.dotstar_nc,
};
let mut rgb = hal::dotstar_bitbang(dotstar,... | code_fim | hard | {
"lang": "rust",
"repo": "racklet/bmc-experiments",
"path": "/rtic-testing/src/main_old.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: LegNeato/juniper path: /juniper/src/tests/subscriptions.rs
use std::{iter, iter::FromIterator as _, pin::Pin};
use futures::{self, StreamExt as _};
use crate::{
http::GraphQLRequest, Context, DefaultScalarValue, EmptyMutation, ExecutionError, FieldError,
GraphQLObject, Object, RootNode... | code_fim | hard | {
"lang": "rust",
"repo": "LegNeato/juniper",
"path": "/juniper/src/tests/subscriptions.rs",
"mode": "psm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[test]
fn resolves_nontyped_inline_fragments() {
let query = r#"subscription {
... {
asyncHuman(id: "32") {
id
}
}
}"#
.to_string();
let (names, collected_values) = create_and_execute(query).expect("Got er... | code_fim | hard | {
"lang": "rust",
"repo": "LegNeato/juniper",
"path": "/juniper/src/tests/subscriptions.rs",
"mode": "spm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[derive(PartialEq, Clone)]
pub enum Image {
Player(player::Image),
}
impl Image {
pub fn radius(self: &Self) -> units::Distance {
match *self {
Image::Player(_) => 10.into(),
}
}
}
pub trait Display {
fn image(self: &Self) -> Option<Image>;
}
pub fn image_of... | code_fim | medium | {
"lang": "rust",
"repo": "spiveeworks/circle-collision-demo",
"path": "/lib-internal/src/entities/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: spiveeworks/circle-collision-demo path: /lib-internal/src/entities/mod.rs
use std::any;
use sulphate;
use units;
pub use self::player::Player;
pub mod player;
#[derive(PartialEq, Clone)]
pub enum Image {
Player(player::Image),
}
<|fim_suffix|>}
pub fn image_of(
matter: &sulphate::E... | code_fim | hard | {
"lang": "rust",
"repo": "spiveeworks/circle-collision-demo",
"path": "/lib-internal/src/entities/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let res = client.execute(request).await?;
// println!("Authorized response: {:?}", res);
let status = res.status();
match status {
StatusCode::OK => Ok(()),
_ => Err("Cannot access resource".into()),
}
... | code_fim | hard | {
"lang": "rust",
"repo": "Oyelowo/federation-graphql-rust",
"path": "/products-service/src/authorization/guard.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Oyelowo/federation-graphql-rust path: /products-service/src/authorization/guard.rs
use crate::config::APP_CONFIG;
use async_graphql::{async_trait, guard::Guard};
use async_graphql::{Context, Result};
use async_trait::async_trait;
use log::info;
use reqwest::StatusCode;
use serde::{Deserialize, S... | code_fim | hard | {
"lang": "rust",
"repo": "Oyelowo/federation-graphql-rust",
"path": "/products-service/src/authorization/guard.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let m_i = cos_phi_i.max(0.0);
let m_o = cos_phi_o.max(0.0);
let u = u_gaussian(phi_d);
let masking = (1.0 - u) * m_i * m_o + u * m_i.min(m_o);
let p_i = cos_psi_i.max(0.0);
... | code_fim | hard | {
"lang": "rust",
"repo": "MatchaChoco010/path_tracer_cloth",
"path": "/src/path_trace.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: MatchaChoco010/path_tracer_cloth path: /src/path_trace.rs
.0001
|| (normal.dot(&Vector3::y()) + 1.0).abs() <= 0.0001
{
Vector3::z()
} else {
Vector3::y()
};
... | code_fim | hard | {
"lang": "rust",
"repo": "MatchaChoco010/path_tracer_cloth",
"path": "/src/path_trace.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let sin_theta_i = wi.dot(&u).min(1.0).max(-1.0);
let theta_i = sin_theta_i.asin();
let sin_theta_o = wo.dot(&u).min(1.0).max(-1.0);
let theta_o = sin_theta_o.asin();
let wi_on_normal = ... | code_fim | hard | {
"lang": "rust",
"repo": "MatchaChoco010/path_tracer_cloth",
"path": "/src/path_trace.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: zeroeightysix/ozelot path: /src/errors.rs
//! The error types used
error_chain! {
foreign_links {
Curl(::curl::Error);
Io(::std::io::Error);
O<|fim_suffix|>::Error);
FromUtf8(::std::string::FromUtf8Error);
}
}<|fim_middle|>penssl(::openssl::error::ErrorSt... | code_fim | medium | {
"lang": "rust",
"repo": "zeroeightysix/ozelot",
"path": "/src/errors.rs",
"mode": "psm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_suffix|>::Error);
FromUtf8(::std::string::FromUtf8Error);
}
}<|fim_prefix|>// repo: zeroeightysix/ozelot path: /src/errors.rs
//! The error types used
error_chain! {
foreign_links {
<|fim_middle|> Curl(::curl::Error);
Io(::std::io::Error);
Openssl(::openssl::error::ErrorSt... | code_fim | medium | {
"lang": "rust",
"repo": "zeroeightysix/ozelot",
"path": "/src/errors.rs",
"mode": "spm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: flyq/datastruct-algorithm path: /leetcode/p1207/src/main.rs
fn main() {
println!("Hello, world!");
}
pub struct Solution{}
<|fim_suffix|>/*
执行结果:
通过
显示详情
执行用时 :
0 ms
, 在所有 rust 提交中击败了
100.00%
的用户
内存消耗 :
2 MB
, 在所有 rust 提交中击败了
100.00%
的用户
*/<|fim_middle|>use std::collections::HashMap;
impl S... | code_fim | hard | {
"lang": "rust",
"repo": "flyq/datastruct-algorithm",
"path": "/leetcode/p1207/src/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub struct Error {
inner: Box<dyn std::error::Error>,
op: String,
}
// This isn't something that is normally a good idea, but panicking in errors
// tends to be very unhelpful because it doesn't explain the error.
impl fmt::Debug for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::R... | code_fim | hard | {
"lang": "rust",
"repo": "rojo-rbx/rbx-dom",
"path": "/rbx_xml/src/tests/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rojo-rbx/rbx-dom path: /rbx_xml/src/tests/mod.rs
//! Tests to ensure the functionality of the parser.
mod basic;
mod edge_cases;
mod formatting;
mod models;
use std::{fmt, fs, path::PathBuf};
use rbx_dom_weak::DomViewer;
/// Runs several tests over the provided file.
pub fn test_suite(path: P... | code_fim | hard | {
"lang": "rust",
"repo": "rojo-rbx/rbx-dom",
"path": "/rbx_xml/src/tests/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> surface.swap_buffers();
}
pub fn update_scene_if_necessary(&mut self) {
let new_scene = self.scene_loader
.as_mut()
.and_then(|loader| loader.load_if_updated());
match new_scene {
Some(Ok(new_scene)) => {
match new_scene... | code_fim | hard | {
"lang": "rust",
"repo": "Epsylon42/sdf-walker",
"path": "/src/rendering/onscreen.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Epsylon42/sdf-walker path: /src/rendering/onscreen.rs
use super::*;
use std::time::{Instant, Duration};
impl CtxDetails for GlutinSurface {
type FbCol = ();
fn swap_buffers(&mut self) {
self.swap_buffers();
}
fn update_backbuffer(&mut self) -> Framebuffer<Self::Backend... | code_fim | hard | {
"lang": "rust",
"repo": "Epsylon42/sdf-walker",
"path": "/src/rendering/onscreen.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> Event::WindowEvent { event, .. } => match event {
WindowEvent::MouseInput {
button: MouseButton::Left,
state,
..
} => {
self.holding_lmb = state == Elemen... | code_fim | hard | {
"lang": "rust",
"repo": "Epsylon42/sdf-walker",
"path": "/src/rendering/onscreen.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: prisma/prisma-engines path: /schema-engine/connectors/sql-schema-connector/src/introspection/introspection_pair/default.rs
use either::Either;
use prisma_value::PrismaValue;
use psl::{datamodel_connector::constraint_names::ConstraintNames, parser_database::walkers};
use sql::postgres::PostgresSc... | code_fim | hard | {
"lang": "rust",
"repo": "prisma/prisma-engines",
"path": "/schema-engine/connectors/sql-schema-connector/src/introspection/introspection_pair/default.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> if !variant_name.prisma_name().is_empty() {
Some(DefaultKind::EnumVariant(variant_name.prisma_name()))
} else {
Some(DefaultKind::DbGenerated(variant_name.mapped_name()))
}
}
(Some(sql::DefaultK... | code_fim | hard | {
"lang": "rust",
"repo": "prisma/prisma-engines",
"path": "/schema-engine/connectors/sql-schema-connector/src/introspection/introspection_pair/default.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ermakov-oleg/statsd-proxy path: /src/main.rs
#![warn(rust_2018_idioms)]
use log::warn;
use structopt::StructOpt;
use statsd_proxy::{proxy, Result, Serve};
<|fim_suffix|>#[derive(Debug, StructOpt)]
#[structopt(name = "classify")]
pub struct ApplicationArguments {
#[structopt(subcommand)]
... | code_fim | medium | {
"lang": "rust",
"repo": "ermakov-oleg/statsd-proxy",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[async_std::main]
async fn main() -> Result<()> {
env_logger::init();
let opt = ApplicationArguments::from_args();
match opt.command {
Command::Serve(params) => {
warn!("{:?}", params);
proxy(params).await?
}
};
Ok(())
}<|fim_prefix|>// repo: ... | code_fim | medium | {
"lang": "rust",
"repo": "ermakov-oleg/statsd-proxy",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[inline(always)]
pub(crate) fn unregister_stream(
&mut self,
id: &I,
) -> Option<mpsc::UnboundedSender<Result<R, E>>> {
self.stream_reply.remove(id)
}
pub(crate) fn reply_to_stream(
&self,
id: &I,
response: Result<R, E>,
) -> Result... | code_fim | hard | {
"lang": "rust",
"repo": "hussein-aitlahcen/async_ib",
"path": "/src/message/dispatcher.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub(crate) fn reply_to(&mut self, id: &I, response: Result<R, E>) -> Result<(), Result<R, E>> {
if self.container_in_stream(id) {
return self.reply_to_stream(id, response);
}
if self.container_in_oneshot(id) {
return self.reply_to_oneshot(id, response);... | code_fim | hard | {
"lang": "rust",
"repo": "hussein-aitlahcen/async_ib",
"path": "/src/message/dispatcher.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: hussein-aitlahcen/async_ib path: /src/message/dispatcher.rs
//use super::identifiable::Identifiable;
use futures::sync::{mpsc, oneshot};
use std::collections::HashMap;
use std::fmt::Debug;
use std::hash::Hash;
#[derive(Debug)]
pub struct Dispatcher<I: Hash + Eq, R, E> {
oneshot_reply: HashM... | code_fim | hard | {
"lang": "rust",
"repo": "hussein-aitlahcen/async_ib",
"path": "/src/message/dispatcher.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>/(2**64)`th of a circle.
//! * This means that adding and subtracting angles (with wrapping) will always be correct, and
//! always within the specified range. (No more range reduction!)
//! * This also means that you can (inside the library) *cast* an angle from `u64` to `i64` and
//! end up with the... | code_fim | hard | {
"lang": "rust",
"repo": "jordanbray/angles",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jordanbray/angles path: /src/lib.rs
//! # Angles Done With Integers
//!
//! ```
//! use integer_angles::Angle;
//!
//! assert_eq!(Angle::pi_2().cos::<f64>(), 0.0f64);
//! ```
//!
//! Here we go, down the rabbit hole of floating-point instability and all sorts of crazy problems
//! that come with... | code_fim | hard | {
"lang": "rust",
"repo": "jordanbray/angles",
"path": "/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn add_context(&mut self, key: &'a str, value: &'a Serialize) -> &mut LogBuilder<'a>;
fn log(&mut self) -> ();
}<|fim_prefix|>// repo: BrandonArp/rust-steno path: /src/log_builder.rs
use std::error::Error;
use erased_serde::Serialize;
<|fim_middle|>pub trait LogBuilder<'a> {
fn set_event(&mu... | code_fim | hard | {
"lang": "rust",
"repo": "BrandonArp/rust-steno",
"path": "/src/log_builder.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: BrandonArp/rust-steno path: /src/log_builder.rs
use std::error::Error;
use erased_serde::Serialize;
<|fim_suffix|> fn set_error(&mut self, error: &'a Error) -> &mut LogBuilder<'a>;
fn add_data(&mut self, key: &'a str, value: &'a Serialize) -> &mut LogBuilder<'a>;
fn add_context(&mut ... | code_fim | medium | {
"lang": "rust",
"repo": "BrandonArp/rust-steno",
"path": "/src/log_builder.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Hirevo/alexandrie path: /crates/alexandrie/src/frontend/account/manage/passwd.rs
use std::num::NonZeroU32;
use diesel::prelude::*;
use ring::digest as hasher;
use ring::pbkdf2;
use serde::{Deserialize, Serialize};
use tide::{Request, StatusCode};
use crate::db::schema::*;
use crate::utils;
use... | code_fim | hard | {
"lang": "rust",
"repo": "Hirevo/alexandrie",
"path": "/crates/alexandrie/src/frontend/account/manage/passwd.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> //? Derive the hashed password data with PBKDF2 (100'000 rounds).
let encoded_derived_hash = {
let mut out = [0u8; hasher::SHA512_OUTPUT_LEN];
let iteration_count = unsafe { NonZeroU32::new_unchecked(100_000) };
pbkdf2::derive(
pbkdf2::PB... | code_fim | hard | {
"lang": "rust",
"repo": "Hirevo/alexandrie",
"path": "/crates/alexandrie/src/frontend/account/manage/passwd.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.