text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_suffix|> Some(self)
}
fn open(&self, _window: Box<dyn AnyWindowBuilder>) -> bool {
false
}
}
fn schedule_timer(timer: &Timer, period: Duration) {
let weak_timer = timer.downgrade();
// TODO this should be refactored to reuse the same closure rather than rescheduling it.
le... | code_fim | hard | {
"lang": "rust",
"repo": "BarePotato/gooey",
"path": "/frontends/browser/src/lib.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>// See https://en.wikipedia.org/wiki/GUID_Partition_Table for partition types.
pub const GPT_PARTITION_TYPES: Map<u128, &'static str> = phf_map! {
0x00000000000000000000000000000000u128 => "Empty",
0x024dee4133e711d39d690008c781f39fu128 => "MBR partition scheme",
0xc12a7328f81f11d2ba4b00a0c93e... | code_fim | hard | {
"lang": "rust",
"repo": "dacut/disk-image-inspector",
"path": "/bin/disk-image-inspector/src/gpt.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dacut/disk-image-inspector path: /bin/disk-image-inspector/src/gpt.rs
use phf::{phf_map, Map};
use std::{
convert::TryInto,
error::Error,
fmt::{Display, Formatter, Result as FmtResult},
io::{Read, Seek, SeekFrom},
};
use uuid::Uuid;
use crate::errors::ImageError;
pub const GPT_... | code_fim | hard | {
"lang": "rust",
"repo": "dacut/disk-image-inspector",
"path": "/bin/disk-image-inspector/src/gpt.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: nilsso/challenge-solutions path: /leetcode/problems/reorder-list/rust_safe/src/main.rs
#[derive(Debug)]
pub struct ListNode {
pub val: i32,
pub next: Option<Box<ListNode>>,
}
impl ListNode {
pub fn new(val: i32) -> Self {
Self {
val,
next: None,
... | code_fim | hard | {
"lang": "rust",
"repo": "nilsso/challenge-solutions",
"path": "/leetcode/problems/reorder-list/rust_safe/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> if let Some(mut l1_node) = l1 {
if let Some(mut l2_node) = l2 {
let l1_next = l1_node.next.take();
let l2_next = l2_node.next.take();
l2_node.next = shuffle_list(l1_next, l2_next);
l1_node.next = Some(l2_node);
}
Some(l1_node)
... | code_fim | hard | {
"lang": "rust",
"repo": "nilsso/challenge-solutions",
"path": "/leetcode/problems/reorder-list/rust_safe/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: bertiespell/rusty_canvas path: /src/drawing_app/canvas.rs
use serde::{Deserialize, Serialize};
/// Represents a single point on the canvas
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Point {
pub x: i32,
pub y: i32,
} // this could be stored simply as a tuple, with x, y or... | code_fim | hard | {
"lang": "rust",
"repo": "bertiespell/rusty_canvas",
"path": "/src/drawing_app/canvas.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(expected, actual);
}
#[test]
fn test_from_chars() {
let canvas_string = " .......\n .......\n .......\nOOOOOOOO .......\nO O .......\nO XXXXX .......\nOOOOOXXXXX \n XXXXX \n";
... | code_fim | hard | {
"lang": "rust",
"repo": "bertiespell/rusty_canvas",
"path": "/src/drawing_app/canvas.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Game {
pub const fn new() -> Self {
Self {}
}
fn display(&self) -> Result<()> {
unimplemented!()
}
fn game_loop(&mut self) -> Result<Never> {
loop {
block_on(self.update_state())?;
self.display();
}
}
async fn read... | code_fim | hard | {
"lang": "rust",
"repo": "U007D/game_engine",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn display(&self) -> Result<()> {
unimplemented!()
}
fn game_loop(&mut self) -> Result<Never> {
loop {
block_on(self.update_state())?;
self.display();
}
}
async fn read_inputs(&self) -> Result<Inputs> {
// TODO: Ensure `join` ru... | code_fim | hard | {
"lang": "rust",
"repo": "U007D/game_engine",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: U007D/game_engine path: /src/lib.rs
// To use the `unsafe` keyword, change to `#![allow(unsafe_code)]` (do not remove); aids auditing.
#![forbid(unsafe_code)]
#![forbid(bare_trait_objects)]
#![warn(clippy::all, clippy::nursery, clippy::pedantic, rust_2018_idioms)]
// Safety-critical application ... | code_fim | hard | {
"lang": "rust",
"repo": "U007D/game_engine",
"path": "/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Drain any other updates that might have the same time; accumulate difference.
while self.target_worklist.peek().map(|x| ((x.0).0 == time) && ((x.0).1 == target)).unwrap_or(false) {
diff += (self.target_worklist.pop().unwrap().0).2;
}
// O... | code_fim | hard | {
"lang": "rust",
"repo": "longbinlai/timely-dataflow",
"path": "/src/progress/nested/reachability_neu.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: longbinlai/timely-dataflow path: /src/progress/nested/reachability_neu.rs
.
//!
//! Timely dataflow is concerned with understanding and communicating the potential
//! for capabilities to reach nodes in a directed graph, by following paths through
//! the graph (along edges and through nodes). T... | code_fim | hard | {
"lang": "rust",
"repo": "longbinlai/timely-dataflow",
"path": "/src/progress/nested/reachability_neu.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut compiled_node = vec![Vec::new(); inputs];
for input in 0 .. inputs {
for output in 0 .. outputs {
for summary in builder.nodes[node][input][output].elements().iter() {
for &target in builder.edges[node][output].ite... | code_fim | hard | {
"lang": "rust",
"repo": "longbinlai/timely-dataflow",
"path": "/src/progress/nested/reachability_neu.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: davenza/Python_Rust_benchmark path: /benches/bench_main.rs
#[macro_use]
extern crate criterion;
extern crate ndarray;
extern crate rand;
use criterion::Criterion;
use ndarray::{Array, ArrayD, ArrayViewD, ArrayBase, Axis};
use rand::{Rand,Rng};
fn insert_axes_first<S>(array : &ArrayD<S>, n_axis... | code_fim | hard | {
"lang": "rust",
"repo": "davenza/Python_Rust_benchmark",
"path": "/benches/bench_main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut a = array.view();
for _ in 0..n_axis {
let axis = Axis(a.ndim());
a = a.insert_axis(axis);
}
a
}
fn random_array<S: Rand>(shape: Vec<usize>) -> ArrayD<S>
{
let n_elements = shape.iter().fold(1, |accum, &elem| accum * elem);
let mut rng = rand::thread_rng();... | code_fim | hard | {
"lang": "rust",
"repo": "davenza/Python_Rust_benchmark",
"path": "/benches/bench_main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jjcomer/hogan path: /src/app/datadogstatsd.rs
use dogstatsd::{Client, Options};
use std::env;
#[derive(Debug)]
pub struct DdMetrics {
default_tags: Vec<String>,
client: Client,
enabled: bool,
}
impl Default for DdMetrics {
fn default() -> Self {
DdMetrics::new(true)
... | code_fim | hard | {
"lang": "rust",
"repo": "jjcomer/hogan",
"path": "/src/app/datadogstatsd.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn time(&self, name: &str, additional_tags: Option<Vec<String>>, value: i64) {
if !self.enabled {
return;
}
self.client
.timing(
name,
value,
additional_tags
.unwrap_or_default()
... | code_fim | hard | {
"lang": "rust",
"repo": "jjcomer/hogan",
"path": "/src/app/datadogstatsd.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> for (condition, _) in selections {
new_expr = Box::new(Expression::Select(new_expr, condition));
}
new_expr
},
Expression::Except(expr1, expr2) => Box::new(Expression::Except(
push_down_selections(expr1, selections.clone()),... | code_fim | hard | {
"lang": "rust",
"repo": "yann-a/Rust-DB-engine",
"path": "/src/optimize.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut cont = true;
while cont {
match *expression {
Expression::Select(expr, condition) if selection.is_none() => {
selection = Some(condition);
expression = expr;
},
Expression::Project(e... | code_fim | hard | {
"lang": "rust",
"repo": "yann-a/Rust-DB-engine",
"path": "/src/optimize.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: yann-a/Rust-DB-engine path: /src/optimize.rs
, columns) => columns.iter().cloned().collect(),
Expression::Product(expr1, expr2) => {
// Pour les product, on dit qu'on "utilise" un sur ensemble de fields, et on corrige les problèmes dans les load et rename
let mut ... | code_fim | hard | {
"lang": "rust",
"repo": "yann-a/Rust-DB-engine",
"path": "/src/optimize.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[serde(bound = "")]
pub struct Party2FirstMessage<E: Curve> {
pub seed: Scalar<E>,
}
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[serde(bound = "")]
pub struct Party1SecondMessage<E: Curve> {
pub proof: PedersenBlindingPro... | code_fim | hard | {
"lang": "rust",
"repo": "Polkadex-Substrate/curv",
"path": "/src/cryptographic_primitives/twoparty/coin_flip_optimal_rounds.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> crate::test_for_all_curves!(test_coin_toss);
pub fn test_coin_toss<E: Curve>() {
let (party1_first_message, m1, r1) = Party1FirstMessage::<E>::commit();
let party2_first_message = Party2FirstMessage::share(&party1_first_message.proof);
let (party1_second_message, random1) =... | code_fim | hard | {
"lang": "rust",
"repo": "Polkadex-Substrate/curv",
"path": "/src/cryptographic_primitives/twoparty/coin_flip_optimal_rounds.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Polkadex-Substrate/curv path: /src/cryptographic_primitives/twoparty/coin_flip_optimal_rounds.rs
/*
This file is part of Curv library
Copyright 2018 by Kzen Networks
(https://github.com/KZen-networks/curv)
License MIT: <https://github.com/KZen-networks/curv/blob/master/LICENSE>
*... | code_fim | hard | {
"lang": "rust",
"repo": "Polkadex-Substrate/curv",
"path": "/src/cryptographic_primitives/twoparty/coin_flip_optimal_rounds.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> env_logger::init();
let mut args = std::env::args();
let addr = match args.nth(1).as_ref().map(String::as_str) {
Some(addr) => addr.to_string(),
None => return Err(anyhow!("Usage: server <addr>")),
};
let mut p = Publisher::new("s4", &addr);
for i in 0.. {
let s = format!("hello ... | code_fim | medium | {
"lang": "rust",
"repo": "MDGSF/psmsg",
"path": "/examples/tcp_publisher_4.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: MDGSF/psmsg path: /examples/tcp_publisher_4.rs
use anyhow::{anyhow, Result};
use psmsg::{self, Publisher};
use std::time::Duration;
fn main() -> Result<()> {
<|fim_suffix|> let mut args = std::env::args();
let addr = match args.nth(1).as_ref().map(String::as_str) {
Some(addr) => addr.to_... | code_fim | medium | {
"lang": "rust",
"repo": "MDGSF/psmsg",
"path": "/examples/tcp_publisher_4.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut args = std::env::args();
let addr = match args.nth(1).as_ref().map(String::as_str) {
Some(addr) => addr.to_string(),
None => return Err(anyhow!("Usage: server <addr>")),
};
let mut p = Publisher::new("s4", &addr);
for i in 0.. {
let s = format!("hello world, {}", i);
p.p... | code_fim | medium | {
"lang": "rust",
"repo": "MDGSF/psmsg",
"path": "/examples/tcp_publisher_4.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: bretzle/raytrace path: /src/matrix/iter.rs
use super::{Dim, Matrix};
impl<T, M, N> Matrix<T, M, N>
where
M: Dim,
N: Dim,
{
/// Iterate over all elements
pub fn iter(&self) -> impl Iterator<Item = &T> {
self.data.iter()
}
<|fim_suffix|> /// Iterate over all rows of the matrix
pub fn ite... | code_fim | hard | {
"lang": "rust",
"repo": "bretzle/raytrace",
"path": "/src/matrix/iter.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Iterate over all rows of the matrix
pub fn iter_cols(&self) -> impl Iterator<Item = impl Iterator<Item = &T>> {
(0..N::SIZE).map(move |j| self.iter_col(j))
}
/// Iterate over 3-tuples (i, j, self[(i,j)])
pub fn iter_indexed(&self) -> impl Iterator<Item = (usize, usize, &T)> {
self.iter_rows(... | code_fim | hard | {
"lang": "rust",
"repo": "bretzle/raytrace",
"path": "/src/matrix/iter.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Iterate over the ith row of the matrix
pub fn iter_row(&self, i: usize) -> impl Iterator<Item = &T> {
self.iter().skip(i * N::SIZE).take(N::SIZE)
}
/// Iterate over the jth coloumn of the matrix
pub fn iter_col(&self, j: usize) -> impl Iterator<Item = &T> {
self.iter().skip(j).step_by(N::SIZ... | code_fim | medium | {
"lang": "rust",
"repo": "bretzle/raytrace",
"path": "/src/matrix/iter.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: TheSamsa/langtons-ente path: /.backup/field.rs
use log::info;
use super::command_queue::{Command, CommandQueue};
#[derive(Default)]
pub struct Field<'a> {
command_queue: CommandQueue<'a>,
}
impl Field<'_> {
pub fn new() -> Self {
Self {
command_queue: CommandQueue:... | code_fim | medium | {
"lang": "rust",
"repo": "TheSamsa/langtons-ente",
"path": "/.backup/field.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(field.advance_queue(), Command::TurnRight);
assert_eq!(field.advance_queue(), Command::TurnLeft);
assert_eq!(field.advance_queue(), Command::TurnRight);
assert_eq!(field.advance_queue(), Command::TurnLeft);
}
}<|fim_prefix|>// repo: TheSamsa/langtons-ente pa... | code_fim | medium | {
"lang": "rust",
"repo": "TheSamsa/langtons-ente",
"path": "/.backup/field.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: fajarvm/symbol-sdk-rust path: /src/clients/async_client/mod.rs
/*
* // Copyright 2021 BlockPuppets.
* //
* // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
* // https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
* // <LICENSE-MIT or https://opensource.org/li... | code_fim | hard | {
"lang": "rust",
"repo": "fajarvm/symbol-sdk-rust",
"path": "/src/clients/async_client/mod.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>mod block_routes;
mod chain_routes;
mod client;
mod http_client;
mod mosaic_routes;
mod network_routes;
mod node_routes;
pub(crate) mod request;<|fim_prefix|>// repo: fajarvm/symbol-sdk-rust path: /src/clients/async_client/mod.rs
/*
* // Copyright 2021 BlockPuppets.
* //
* // Licensed under the Apache... | code_fim | hard | {
"lang": "rust",
"repo": "fajarvm/symbol-sdk-rust",
"path": "/src/clients/async_client/mod.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: fomkin/gus path: /src/config.rs
extern crate toml;
use common;
use std::env;
use std::path::{PathBuf, Path};
use std::fs::File;
use std::io::prelude::*;
use std::collections::HashMap;
pub type Config = HashMap<String, common::User>;
pub fn path(maybe_path: Option<&str>) -> PathBuf {
mayb... | code_fim | hard | {
"lang": "rust",
"repo": "fomkin/gus",
"path": "/src/config.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn read(path: PathBuf) -> String {
File::open(path)
.map(|mut f| {
let mut contents = String::new();
f.read_to_string(&mut contents).expect("Can't read config file");
contents
})
.expect("Can't open config file")
}
pub fn parse(config_da... | code_fim | hard | {
"lang": "rust",
"repo": "fomkin/gus",
"path": "/src/config.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn parse(config_data: String) -> Config {
toml::from_str(config_data.as_ref())
.expect("Can't parse config")
}
pub fn save(path: PathBuf, config: Config) {
File::create(path)
.map(|mut f| {
let data = toml::to_string(&config).expect("Can't serialize config");
... | code_fim | hard | {
"lang": "rust",
"repo": "fomkin/gus",
"path": "/src/config.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: danielSanchezQ/chain-wallet-libs path: /keygen/src/lib.rs
use rand_chacha::rand_core::SeedableRng;
use rand_chacha::ChaCha20Rng;
use std::convert::TryInto;
use wasm_bindgen::prelude::*;
mod utils;
pub use utils::set_panic_hook;
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: w... | code_fim | hard | {
"lang": "rust",
"repo": "danielSanchezQ/chain-wallet-libs",
"path": "/keygen/src/lib.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn bytes(&self) -> Box<[u8]> {
self.0.clone().leak_secret().as_ref().into()
}
}
#[wasm_bindgen]
pub struct Ed25519Public(chain_crypto::PublicKey<chain_crypto::Ed25519>);
#[wasm_bindgen]
impl Ed25519Public {
pub fn bytes(&self) -> Box<[u8]> {
self.0.as_ref().into()
}
... | code_fim | hard | {
"lang": "rust",
"repo": "danielSanchezQ/chain-wallet-libs",
"path": "/keygen/src/lib.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rust-lang/rust-bindgen path: /bindgen-tests/tests/expectations/tests/template-param-usage-10.rs
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct DoublyIndirectUsage<T, U> {
pub doubly_indirect: DoublyIndire... | code_fim | hard | {
"lang": "rust",
"repo": "rust-lang/rust-bindgen",
"path": "/bindgen-tests/tests/expectations/tests/template-param-usage-10.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn edge_resistibility(&self, graph: &mut G, from: usize, to: usize) -> usize {
graph.remove_edge(from, to);
let resistance = Resistance::new_with_colouriser(C::new());
let resistance = resistance.edge_resistance(graph);
graph.add_edge(from, to);
resistance.u... | code_fim | hard | {
"lang": "rust",
"repo": "jkbstrmen/snark-tool",
"path": "/src/service/chromatic_properties/resistibility.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn vertices_resistibility(&mut self) -> Vec<usize> {
let mut local_graph = self.graph.clone();
let mut v_resistibilities = vec![0; self.graph.size()];
for vertex in self.graph.vertices() {
if self.vertex_resistibilities[vertex.index()].is_none() {
... | code_fim | hard | {
"lang": "rust",
"repo": "jkbstrmen/snark-tool",
"path": "/src/service/chromatic_properties/resistibility.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jkbstrmen/snark-tool path: /src/service/chromatic_properties/resistibility.rs
use crate::graph::edge::Edge;
use crate::graph::graph::Graph;
use crate::graph::vertex::Vertex;
use crate::service::chromatic_properties::resistance::Resistance;
use crate::service::colour::colouriser::Colouriser;
use ... | code_fim | hard | {
"lang": "rust",
"repo": "jkbstrmen/snark-tool",
"path": "/src/service/chromatic_properties/resistibility.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: GaloisInc/mir-verifier path: /lib/libstd/sys/unix/process/process_common.rs
use crate::os::unix::prelude::*;
use crate::collections::BTreeMap;
use crate::ffi::{CStr, CString, OsStr, OsString};
use crate::fmt;
use crate::io;
use crate::ptr;
use crate::sys::fd::FileDesc;
use crate::sys::fs::File;... | code_fim | hard | {
"lang": "rust",
"repo": "GaloisInc/mir-verifier",
"path": "/lib/libstd/sys/unix/process/process_common.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> result
}
impl Stdio {
pub fn to_child_stdio(&self, readable: bool) -> io::Result<(ChildStdio, Option<AnonPipe>)> {
match *self {
Stdio::Inherit => Ok((ChildStdio::Inherit, None)),
// Make sure that the source descriptors are not an stdio
// descriptor,... | code_fim | hard | {
"lang": "rust",
"repo": "GaloisInc/mir-verifier",
"path": "/lib/libstd/sys/unix/process/process_common.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: muntasirraihan/rust-algs4 path: /examples/collinear.rs
// http://coursera.cs.princeton.edu/algs4/assignments/collinear.html
extern crate algs4;
use std::io::prelude::*;
use std::io;
use std::fmt;
use std::cmp::Ordering;
use algs4::sorting::quick_sort;
use algs4::sorting::comparator::Comparator... | code_fim | hard | {
"lang": "rust",
"repo": "muntasirraihan/rust-algs4",
"path": "/examples/collinear.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>
// examines 4 points at a time and checks whether they all lie on the same line segment,
// printing out any such line segments to standard output and drawing them using standard drawing.
// To check whether the 4 points p, q, r, and s are collinear, check whether the slopes between
// p and q, between p... | code_fim | hard | {
"lang": "rust",
"repo": "muntasirraihan/rust-algs4",
"path": "/examples/collinear.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let n = points.len();
let mut points = points.to_vec();
assert!(n > 4);
let mut result: Vec<Vec<Point>> = Vec::new();
for i in 1 .. n {
// 0th is the origin
points.swap(0, i);
let mut points = points.clone();
let p = points[0].clone();
//
... | code_fim | hard | {
"lang": "rust",
"repo": "muntasirraihan/rust-algs4",
"path": "/examples/collinear.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // upgrade request to Websocket request, leading to open, persistent connection
let resp = ws::start(ws, &req, stream)?;
Ok(resp)
}<|fim_prefix|>// repo: mc962/chatter path: /src/router.rs
use crate::lobby::Lobby;
use crate::ws::WsConn;
use actix::Addr;
use actix_web::{get, web::Data, web::Pa... | code_fim | hard | {
"lang": "rust",
"repo": "mc962/chatter",
"path": "/src/router.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mc962/chatter path: /src/router.rs
use crate::lobby::Lobby;
use crate::ws::WsConn;
use actix::Addr;
use actix_web::{get, web::Data, web::Path, web::Payload, Error, HttpRequest, HttpResponse};
use actix_web_actors::ws;
use uuid::Uuid;
<|fim_suffix|> // upgrade request to Websocket request, le... | code_fim | hard | {
"lang": "rust",
"repo": "mc962/chatter",
"path": "/src/router.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: robhardwick/apollo path: /lib/apollo/src/rhythm/error.rs
use failure::Fail;
#[derive(Clone, Debug, Fail)]
pub enum Rhyth<|fim_suffix|>ighted distribution for beat lengths")]
DistributionCreate,
}<|fim_middle|>mError {
#[fail(display = "Unable to choose time signature unit")]
UnitCho... | code_fim | medium | {
"lang": "rust",
"repo": "robhardwick/apollo",
"path": "/lib/apollo/src/rhythm/error.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>ighted distribution for beat lengths")]
DistributionCreate,
}<|fim_prefix|>// repo: robhardwick/apollo path: /lib/apollo/src/rhythm/error.rs
use failure::Fail;
#[derive(Clone, Debug, Fail)]
pub enum RhythmError {
#[fail(display = "Unable to choose time signature un<|fim_middle|>it")]
UnitCho... | code_fim | medium | {
"lang": "rust",
"repo": "robhardwick/apollo",
"path": "/lib/apollo/src/rhythm/error.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>it")]
UnitChoose,
#[fail(display = "Unable to create weighted distribution for beat lengths")]
DistributionCreate,
}<|fim_prefix|>// repo: robhardwick/apollo path: /lib/apollo/src/rhythm/error.rs
use failure::Fail;
#[derive(Clone, Debug, Fail)]
pub enum Rhyth<|fim_middle|>mError {
#[fai... | code_fim | medium | {
"lang": "rust",
"repo": "robhardwick/apollo",
"path": "/lib/apollo/src/rhythm/error.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> stats::record("prediction error", distance);
let replay = true;
if replay {
// Reset to auth state of player entities
//debug!("resetting");
self.reset(world, auth_snapshot);
/... | code_fim | hard | {
"lang": "rust",
"repo": "leod/hooks",
"path": "/hooks_game/src/game/predict.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: leod/hooks path: /hooks_game/src/game/predict.rs
use std::collections::BTreeMap;
use std::f32;
use nalgebra::norm_squared;
use specs::prelude::*;
use hooks_util::{join, stats};
use defs::{PlayerId, PlayerInput, TickNum};
use event;
use game::{self, input};
use physics::{self, Orientation, Pos... | code_fim | hard | {
"lang": "rust",
"repo": "leod/hooks",
"path": "/hooks_game/src/game/predict.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> &mut self,
world: &mut World,
physics_runner: &mut physics::sim::Runner,
tick_data: &tick::Data<game::EntitySnapshot>,
) -> Result<(), repl::Error> {
if let Some(last_input_tick) = tick_data.last_input_tick {
//debug!("got correction for {}", last_in... | code_fim | hard | {
"lang": "rust",
"repo": "leod/hooks",
"path": "/hooks_game/src/game/predict.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: f2006116/fuchsia path: /garnet/bin/pkg_resolver/src/resolver_service.rs
_lot::RwLock,
std::sync::Arc,
};
// The error amber returns if it could not find the merkle for this package.
const PACKAGE_NOT_FOUND: &str = "merkle not found for package";
pub async fn run_resolver_service<A>(
re... | code_fim | hard | {
"lang": "rust",
"repo": "f2006116/fuchsia",
"path": "/garnet/bin/pkg_resolver/src/resolver_service.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: f2006116/fuchsia path: /garnet/bin/pkg_resolver/src/resolver_service.rs
ter().map(|s| s.as_str()), dir_request))
.map_err(|err| {
fx_log_err!("error opening {}: {:?}", merkle, err);
Status::INTERNAL
})?;
Ok(())
}
// Checks for the error amber returns... | code_fim | hard | {
"lang": "rust",
"repo": "f2006116/fuchsia",
"path": "/garnet/bin/pkg_resolver/src/resolver_service.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> // no merkle('d') since we didn't ask to update "buz".
test.check_dir(test.pkgfs.path(), &vec![gen_merkle('a'), gen_merkle('b'), gen_merkle('c')]);
}
#[fuchsia_async::run_singlethreaded(test)]
async fn test_resolve_package() {
let test = ResolveTestBuilder::new()
... | code_fim | hard | {
"lang": "rust",
"repo": "f2006116/fuchsia",
"path": "/garnet/bin/pkg_resolver/src/resolver_service.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: memorysafety/sudo-rs path: /test-framework/sudo-compliance-tests/src/sudo/sudoers/env.rs
let sudo_env = helpers::parse_env_output(&stdout)?;
assert_eq!(Some(value), sudo_env.get(TZ).copied());
}
Ok(())
}
fn equal_single(env_list: EnvList) -> Result<()> {
let env_name ... | code_fim | hard | {
"lang": "rust",
"repo": "memorysafety/sudo-rs",
"path": "/test-framework/sudo-compliance-tests/src/sudo/sudoers/env.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: memorysafety/sudo-rs path: /test-framework/sudo-compliance-tests/src/sudo/sudoers/env.rs
udo_env = helpers::parse_env_output(&stdout)?;
assert_eq!(Some(value), sudo_env.get(name).copied());
Ok(())
}
#[test]
fn checks_applied_if_in_both_lists() -> Result<()> {
let name = "SHOULD_BE... | code_fim | hard | {
"lang": "rust",
"repo": "memorysafety/sudo-rs",
"path": "/test-framework/sudo-compliance-tests/src/sudo/sudoers/env.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let env_name = "SHOULD_BE_REMOVED";
let env_val = "42";
let env = Env([
SUDOERS_ALL_ALL_NOPASSWD,
&format!("Defaults {env_list} -= {env_name}"),
])
.build()?;
let output = Command::new("env")
.arg(format!("{env_name}={env_val}"))
.args(["sudo", "env... | code_fim | hard | {
"lang": "rust",
"repo": "memorysafety/sudo-rs",
"path": "/test-framework/sudo-compliance-tests/src/sudo/sudoers/env.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: image-rs/imageproc path: /examples/font.rs
//! An example of drawing text. Writes to the user-provided target file.
use image::{Rgb, RgbImage};
use imageproc::drawing::{draw_text_mut, text_size};
use rusttype::{Font, Scale};
use std::env;
use std::path::Path;
fn main() {
let arg = if env::... | code_fim | medium | {
"lang": "rust",
"repo": "image-rs/imageproc",
"path": "/examples/font.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let path = Path::new(&arg);
let mut image = RgbImage::new(200, 200);
let font = Vec::from(include_bytes!("DejaVuSans.ttf") as &[u8]);
let font = Font::try_from_vec(font).unwrap();
let height = 12.4;
let scale = Scale {
x: height * 2.0,
y: height,
};
let ... | code_fim | medium | {
"lang": "rust",
"repo": "image-rs/imageproc",
"path": "/examples/font.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let height = 12.4;
let scale = Scale {
x: height * 2.0,
y: height,
};
let text = "Hello, world!";
draw_text_mut(&mut image, Rgb([0u8, 0u8, 255u8]), 0, 0, scale, &font, text);
let (w, h) = text_size(scale, &font, text);
println!("Text size: {}x{}", w, h);
l... | code_fim | hard | {
"lang": "rust",
"repo": "image-rs/imageproc",
"path": "/examples/font.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pack_store: *const c_char,
parsed_packs: *mut ParsedPacks
) -> Result<*mut UpdatePoll> {
let conf_bld = ConfigBuilder::new();
let conf_bld = if !pack_store.is_null() {
let pstore = unsafe { CStr::from_ptr(pack_store) }.to_string_lossy();
conf_bld... | code_fim | hard | {
"lang": "rust",
"repo": "theotherjimmy/cmsis-pack-manager",
"path": "/rust/cmsis-cffi/src/pack.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: theotherjimmy/cmsis-pack-manager path: /rust/cmsis-cffi/src/pack.rs
use slog::Logger;
use std::os::raw::c_char;
use std::ffi::CStr;
use std::sync::Arc;
use std::sync::mpsc::channel;
use std::sync::atomic::{AtomicBool, Ordering};
use std::thread;
use failure::err_msg;
use cmsis_update::install;... | code_fim | hard | {
"lang": "rust",
"repo": "theotherjimmy/cmsis-pack-manager",
"path": "/rust/cmsis-cffi/src/pack.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> for s in data.iter() {
let chunks: Vec<_> = s.split_whitespace().collect();
let dir = chunks[0];
let value = chunks[1].parse::<i32>().unwrap();
if dir == "forward" {
horizontal += value;
depth += value * aim;
} else if dir == "down" {
... | code_fim | medium | {
"lang": "rust",
"repo": "MartinSandstrom/adventofcode",
"path": "/2021/day_2/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: MartinSandstrom/adventofcode path: /2021/day_2/src/main.rs
use std::fs;
fn part_one(data: Vec<&str>) {
let mut horizontal: i32 = 0;
let mut depth: i32 = 0;
for s in data.iter() {
let chunks: Vec<_> = s.split_whitespace().collect();
let dir = chunks[0];
let v... | code_fim | medium | {
"lang": "rust",
"repo": "MartinSandstrom/adventofcode",
"path": "/2021/day_2/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rincewound/mu-common path: /src/crc.rs
use super::Flasher;
pub fn check_crc<T>(start_adr: usize, len: usize, checksum: usize, flasher: &T) -> bool
where T: Flasher
{
let mut crc = 0xFFFFFFFF as u32;
let mut bytes_left = len;
let mut index = 0;
while bytes_left > 0
{
... | code_fim | hard | {
"lang": "rust",
"repo": "rincewound/mu-common",
"path": "/src/crc.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> {
let mut fl = FakeFlasher::new();
copy_to_flasher(&mut fl, 0, &[0xAA,0xBB,0xCC,0xDD,0xEE,0xFF,0x11,0x22]);
assert!(true == check_crc(0, 8, 0x65133A42, &mut fl))
}
}<|fim_prefix|>// repo: rincewound/mu-common path: /src/crc.rs
use super::Flasher;
pub fn check_crc... | code_fim | hard | {
"lang": "rust",
"repo": "rincewound/mu-common",
"path": "/src/crc.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn can_calc_crc()
{
let mut fl = FakeFlasher::new();
copy_to_flasher(&mut fl, 0, &[0xAA,0xBB,0xCC,0xDD,0xEE,0xFF,0x11,0x22]);
assert!(true == check_crc(0, 8, 0x65133A42, &mut fl))
}
}<|fim_prefix|>// repo: rincewound/mu-common path: /src/crc.rs
use... | code_fim | hard | {
"lang": "rust",
"repo": "rincewound/mu-common",
"path": "/src/crc.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: abaybektursun/rust_collection path: /Mathematics/sequences_series/src/main.rs
fn bad_fib(n: u64) -> u64{
if n == 0 {
return 0;
}else if n == 1 {
return 1;
}else{
return bad_fib(n-1) + bad_fib(n-2);
}
}
//boooooii
fn main(){
<|fim_suffix|> return (n as f... | code_fim | hard | {
"lang": "rust",
"repo": "abaybektursun/rust_collection",
"path": "/Mathematics/sequences_series/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>// Stirling's approximation of factorial
fn Stirling_approximation(n: u64) -> f64{
return (n as f64 / std::f64::consts::E).powf(n as f64) * (2.0 * std::f64::consts::PI * n as f64).powf(0.5);
}
// Naive factorial
fn factorial(n: u64) -> u64{
if n == 0 || n == 1{
return 1;
}
return f... | code_fim | medium | {
"lang": "rust",
"repo": "abaybektursun/rust_collection",
"path": "/Mathematics/sequences_series/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>async fn client() {
let cli_args = CliArgs::from_args();
mbus_api::message_bus_init(cli_args.url).await;
let nodes = GetNodes {}.request().await.unwrap();
info!("Received Nodes: {:?}", nodes);
}<|fim_prefix|>// repo: teamrebuild/Mayastor path: /services/examples/node-client/main.rs
use ... | code_fim | hard | {
"lang": "rust",
"repo": "teamrebuild/Mayastor",
"path": "/services/examples/node-client/main.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> client().await;
}
async fn client() {
let cli_args = CliArgs::from_args();
mbus_api::message_bus_init(cli_args.url).await;
let nodes = GetNodes {}.request().await.unwrap();
info!("Received Nodes: {:?}", nodes);
}<|fim_prefix|>// repo: teamrebuild/Mayastor path: /services/examples/n... | code_fim | hard | {
"lang": "rust",
"repo": "teamrebuild/Mayastor",
"path": "/services/examples/node-client/main.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: teamrebuild/Mayastor path: /services/examples/node-client/main.rs
use mbus_api::{v0::*, *};
use structopt::StructOpt;
use tracing::info;
#[derive(Debug, StructOpt)]
struct CliArgs {
/// The Nats Server URL to connect to
/// (supports the nats schema)
/// Default: nats://127.0.0.1:42... | code_fim | medium | {
"lang": "rust",
"repo": "teamrebuild/Mayastor",
"path": "/services/examples/node-client/main.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> file.flush();
// save the command
let mut add_check_point_line = String::from("checkpoint ");
add_check_point_line.push_str(check_point_file_index.to_string().as_str());
add_check_point_line.push_str("\n");
let mut buf = add_check_point_line.as_str().as_by... | code_fim | hard | {
"lang": "rust",
"repo": "liufoyang/utopia",
"path": "/consensus/src/lib/command_executor.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // save the command
let mut add_check_point_line = String::from("checkpoint ");
add_check_point_line.push_str(check_point_file_index.to_string().as_str());
add_check_point_line.push_str("\n");
let mut buf = add_check_point_line.as_str().as_bytes();
self.bus... | code_fim | hard | {
"lang": "rust",
"repo": "liufoyang/utopia",
"path": "/consensus/src/lib/command_executor.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: liufoyang/utopia path: /consensus/src/lib/command_executor.rs
use std::fs::File;
use std::fs::OpenOptions;
use std::str::FromStr;
use std::string::String;
use std::vec::Vec;
use std::io::{self, Write, Read, Seek, SeekFrom};
use std::convert::Infallible;
use std::result::Result;
use super::thread... | code_fim | hard | {
"lang": "rust",
"repo": "liufoyang/utopia",
"path": "/consensus/src/lib/command_executor.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> for dependency_to_remove in dependencies_to_remove {
data.remove_dependency(&dependency_to_remove);
}
}
fn connected_ids(&self, data: &D, id: u64) -> HashSet<u64> {
let mut result = HashSet::new();
let mut ids_to_search = vec![id];
while let S... | code_fim | hard | {
"lang": "rust",
"repo": "Kethku/Pando",
"path": "/src/widgets/flow.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Kethku/Pando path: /src/widgets/flow.rs
use std::collections::{HashMap, HashSet};
use std::cmp::Ordering;
use std::fmt::Debug;
use druid::{
Point, WidgetPod, Vec2, Selector
};
use druid::kurbo::CubicBez;
use druid::theme;
use druid::widget::*;
use druid::widget::prelude::*;
use serde::{Seri... | code_fim | hard | {
"lang": "rust",
"repo": "Kethku/Pando",
"path": "/src/widgets/flow.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn break_dependencies_to(&mut self, data: &mut D, pin_id: u64) {
let mut dependencies_to_remove = Vec::new();
for dependency in data.dependencies() {
if dependency.from_id == pin_id || dependency.to_id == pin_id {
dependencies_to_remove.push(dependency.clone... | code_fim | hard | {
"lang": "rust",
"repo": "Kethku/Pando",
"path": "/src/widgets/flow.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: victor-zed/tink-rust path: /tests/tests/mac/key_templates_test.rs
// Copyright 2020 The Tink-Rust Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// ... | code_fim | hard | {
"lang": "rust",
"repo": "victor-zed/tink-rust",
"path": "/tests/tests/mac/key_templates_test.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> template: tink_proto::KeyTemplate,
key_size: usize,
tag_size: usize,
) -> Result<(), TinkError> {
if template.type_url != tink_tests::AES_CMAC_TYPE_URL {
return Err("TypeUrl is incorrect".into());
}
let format = tink_proto::AesCmacKeyFormat::decode(template.value.as_ref())
... | code_fim | hard | {
"lang": "rust",
"repo": "victor-zed/tink-rust",
"path": "/tests/tests/mac/key_templates_test.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> // we work with the approximated digits `w(n)`, which is initially equal to `plus1 -
// plus1 % 10^kappa`. after running the loop body `n` times, `w(n) = plus1 -
// plus1 % 10^kappa - n * 10^kappa`. we set `plus1w(n) = plus1 - w(n) =
// plus1 % 10^kappa + n ... | code_fim | hard | {
"lang": "rust",
"repo": "GaloisInc/mir-verifier",
"path": "/lib/libcore/num/flt2dec/strategy/grisu.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: GaloisInc/mir-verifier path: /lib/libcore/num/flt2dec/strategy/grisu.rs
;
debug_assert_eq!(plus.e, v.e);
// +- actual range of minus
// | <---|---------------------- unsafe region --------------------------> |
// | | ... | code_fim | hard | {
"lang": "rust",
"repo": "GaloisInc/mir-verifier",
"path": "/lib/libcore/num/flt2dec/strategy/grisu.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: GaloisInc/mir-verifier path: /lib/libcore/num/flt2dec/strategy/grisu.rs
ximations (error < 1 ulp).
// as we don't know the error is positive or negative, we use two approximations spaced equally
// and have the maximal error of 2 ulps.
//
// the "unsafe region" is a liberal inter... | code_fim | hard | {
"lang": "rust",
"repo": "GaloisInc/mir-verifier",
"path": "/lib/libcore/num/flt2dec/strategy/grisu.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: pietgeursen/jsonrpc path: /core-client/transports/src/transports/duplex.rs
//! Duplex transport
use failure::format_err;
use futures::prelude::*;
use futures::sync::{mpsc, oneshot};
use jsonrpc_core::Id;
use log::debug;
use serde_json::Value;
use std::collections::HashMap;
use std::collections:... | code_fim | hard | {
"lang": "rust",
"repo": "pietgeursen/jsonrpc",
"path": "/core-client/transports/src/transports/duplex.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl<TSink, TStream> Future for Duplex<TSink, TStream>
where
TSink: Sink<SinkItem = String, SinkError = RpcError>,
TStream: Stream<Item = String, Error = RpcError>,
{
type Item = ();
type Error = RpcError;
fn poll(&mut self) -> Result<Async<Self::Item>, Self::Error> {
// Handle requests from the c... | code_fim | hard | {
"lang": "rust",
"repo": "pietgeursen/jsonrpc",
"path": "/core-client/transports/src/transports/duplex.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// Creates a new `Duplex`, along with a channel to communicate
pub fn duplex<TSink, TStream>(sink: TSink, stream: TStream) -> (Duplex<TSink, TStream>, RpcChannel) {
let (sender, receiver) = mpsc::channel(0);
let client = Duplex::new(sink, stream, receiver);
(client, sender.into())
}
impl<TSink, TStre... | code_fim | hard | {
"lang": "rust",
"repo": "pietgeursen/jsonrpc",
"path": "/core-client/transports/src/transports/duplex.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn customize_from_rustproto_for_field(source: &FieldOptions) -> Customize {
let expose_oneof = None;
let expose_fields = rustproto::exts::expose_fields_field.get(source);
let generate_accessors = rustproto::exts::generate_accessors_field.get(source);
let generate_getter = rustproto::ex... | code_fim | hard | {
"lang": "rust",
"repo": "XiangQingW/rust-protobuf",
"path": "/protobuf-codegen/src/customize.rs",
"mode": "spm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: XiangQingW/rust-protobuf path: /protobuf-codegen/src/customize.rs
use protobuf::rustproto;
use protobuf::descriptor::FieldOptions;
use protobuf::descriptor::MessageOptions;
use protobuf::descriptor::FileOptions;
/// Specifies style of generated code.
/// Generated files can be customized using... | code_fim | hard | {
"lang": "rust",
"repo": "XiangQingW/rust-protobuf",
"path": "/protobuf-codegen/src/customize.rs",
"mode": "psm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|>mber
in
members
.
iter_mut
(
)
{
let
info
=
calculate_offset
(
member
.
ty
meta
layout
types
errors
)
;
let
member_alignment
=
info
.
align
;
span
=
member_alignment
.
round_up
(
span
)
;
align
=
member_alignment
.
max
(
align
)
;
member
.
ty
=
info
.
ty
;
member
.
offset
=
span
;
span
+
=
info
.
span
;
}... | code_fim | hard | {
"lang": "rust",
"repo": "marco-c/gecko-dev-wordified-and-comments-removed",
"path": "/third_party/rust/naga/src/front/glsl/offset.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: marco-c/gecko-dev-wordified-and-comments-removed path: /third_party/rust/naga/src/front/glsl/offset.rs
use
super
:
:
{
ast
:
:
StructLayout
error
:
:
{
Error
ErrorKind
}
Span
}
;
use
crate
:
:
{
proc
:
:
Alignment
Handle
Type
TypeInner
UniqueArena
}
;
#
[
derive
(
Debug
)
]
pub
struct
TypeAlignS... | code_fim | hard | {
"lang": "rust",
"repo": "marco-c/gecko-dev-wordified-and-comments-removed",
"path": "/third_party/rust/naga/src/front/glsl/offset.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> match new_offset {
Some(new_offset) if new_offset < 0 => Err(Error::new(EINVAL)),
Some(new_offset) => Ok(cmp::min(new_offset, buf_len)),
None => Err(Error::new(EOVERFLOW))
}
}<|fim_prefix|>// repo: redox-os/syscall path: /src/scheme/seek.rs
use core::cmp;
use core::convert... | code_fim | hard | {
"lang": "rust",
"repo": "redox-os/syscall",
"path": "/src/scheme/seek.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: redox-os/syscall path: /src/scheme/seek.rs
use core::cmp;
use core::convert::TryFrom;
use crate::error::*;
use crate::flag::*;
/// Helper for seek calls
/// In most cases it's easier to use a usize to track the offset and buffer size internally,
/// but the seek interface uses isize. This wrap... | code_fim | hard | {
"lang": "rust",
"repo": "redox-os/syscall",
"path": "/src/scheme/seek.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: VerKnowSys/sysapi path: /src/soload.rs
use libc::*;
use libloading::os::unix::*;
use std::{mem::forget, thread::spawn, thread::sleep, sync::{Arc, Mutex}, sync::atomic::{AtomicUsize, Ordering}};
use colored::Colorize;
use std::time::Duration;
use crate::{*, helpers::empty_list_string};
#[allow(... | code_fim | hard | {
"lang": "rust",
"repo": "VerKnowSys/sysapi",
"path": "/src/soload.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// Call kernel directly through C++ function from kvmpro library:
pub fn processes_of_uid_short(uid: uid_t) -> String {
spawn(
move || {
match SOLOAD_MT_CALLS_SYNCHRONIZER.try_lock() {
Ok(locked_resource) => {
locked_resource.fetch_add(1, Orderi... | code_fim | hard | {
"lang": "rust",
"repo": "VerKnowSys/sysapi",
"path": "/src/soload.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>
/// Call kernel directly through C++ function from kvmpro library:
pub fn processes_of_uid_short(uid: uid_t) -> String {
spawn(
move || {
match SOLOAD_MT_CALLS_SYNCHRONIZER.try_lock() {
Ok(locked_resource) => {
locked_resource.fetch_add(1, Order... | code_fim | hard | {
"lang": "rust",
"repo": "VerKnowSys/sysapi",
"path": "/src/soload.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // make the components for the new type
let cloned_components = asmblgr.assemblages[&built_from]
.iter()
.map(|c| c.boxed_clone())
.collect::<Vec<_>>();
// ease of use copy of the string since it's used to make the new type and add
// the... | code_fim | hard | {
"lang": "rust",
"repo": "cedric-h/stockRPG",
"path": "/src/dev_ui.rs",
"mode": "spm",
"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.