text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_suffix|> #[test]
fn test_multiplication() {
assert_eq!(Value::Num(1.0), multiplication(Vec::<Value>::new()));
let items = (1..=10).map(i32::to_value).collect();
let production = i32::try_from(&multiplication(items)).unwrap();
assert_eq!((1..=10).fold(1, |acc, x| acc * x), pr... | code_fim | hard | {
"lang": "rust",
"repo": "Pagliacii/sicp-reg-machine",
"path": "/src/math.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Pagliacii/sicp-reg-machine path: /src/math.rs
use crate::machine::value::Value;
pub fn addition(items: Vec<Value>) -> Value {
items.into_iter().fold(Value::zero(), |acc, x| acc + x)
}
pub fn subtraction(mut items: Vec<Value>) -> Value {
if items.is_empty() {
panic!("[SUBTRACTIO... | code_fim | hard | {
"lang": "rust",
"repo": "Pagliacii/sicp-reg-machine",
"path": "/src/math.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let uint a = 4u;
let uint b = 1u;
log_err (safe_slice("kitties", a, b));
}<|fim_prefix|>// repo: sayrer/rust path: /src/test/compile-fail/fn-constraint.rs
// error-pattern: Unsatisfied precondition constraint (for example, le(a, b)
use std;
import std::str::*;
<|fim_middle|>fn main() {
| code_fim | easy | {
"lang": "rust",
"repo": "sayrer/rust",
"path": "/src/test/compile-fail/fn-constraint.rs",
"mode": "spm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: sayrer/rust path: /src/test/compile-fail/fn-constraint.rs
// error-pattern: Unsatisfied precondition constraint (for example, le(a, b)
use std;
import std::str::*;
<|fim_suffix|> let uint a = 4u;
let uint b = 1u;
log_err (safe_slice("kitties", a, b));
}<|fim_middle|>fn main() {
| code_fim | easy | {
"lang": "rust",
"repo": "sayrer/rust",
"path": "/src/test/compile-fail/fn-constraint.rs",
"mode": "psm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(Solution::num_decodings("12".to_string()), 2);
assert_eq!(Solution::num_decodings("226".to_string()), 3);
assert_eq!(Solution::num_decodings("0".to_string()), 0);
assert_eq!(Solution::num_decodings("06".to_string()), 0);
assert_eq!(Solution::num_decodings... | code_fim | hard | {
"lang": "rust",
"repo": "livexia/algorithm",
"path": "/blind_75_leetcode/src/solution/s0091_decode_ways.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: livexia/algorithm path: /blind_75_leetcode/src/solution/s0091_decode_ways.rs
#![allow(dead_code)]
pub struct Solution {}
impl Solution {
pub fn num_decodings(s: String) -> i32 {
let l = s.len();
let mut before_last = 0;
let mut last = 1;
<|fim_suffix|> assert... | code_fim | hard | {
"lang": "rust",
"repo": "livexia/algorithm",
"path": "/blind_75_leetcode/src/solution/s0091_decode_ways.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Shirataki2/api-template path: /crates/sqlx-helper/src/bin/test2.rs
#![allow(unused_variables)]
use chrono::NaiveDateTime;
use sqlx_helper::{Create, Delete, Get, Update};
#[derive(Debug, Clo<|fim_suffix|>uage: String,
pub point: i32,
pub length: i32,
pub execution_time: i32,
pub ... | code_fim | hard | {
"lang": "rust",
"repo": "Shirataki2/api-template",
"path": "/crates/sqlx-helper/src/bin/test2.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>uage: String,
pub point: i32,
pub length: i32,
pub execution_time: i32,
pub account_id: i64,
}
fn main() {}<|fim_prefix|>// repo: Shirataki2/api-template path: /crates/sqlx-helper/src/bin/test2.rs
#![allow(unused_variables)]
use chrono::NaiveDateTime;
use sqlx_helper::{Create, Delete, Ge... | code_fim | medium | {
"lang": "rust",
"repo": "Shirataki2/api-template",
"path": "/crates/sqlx-helper/src/bin/test2.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> file.read_to_string(&mut content).unwrap();
content.split('\n').map(|s| s.to_owned()).collect()
}
pub fn get_int_input_vec(file: &str) -> Vec<i32> {
get_input_vec(file)
.iter()
.map(|s| s.parse::<i32>().unwrap())
.collect()
}
#[cfg(test)]
mod tests {
use super::p... | code_fim | hard | {
"lang": "rust",
"repo": "Mackiovello/advent_of_code",
"path": "/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Mackiovello/advent_of_code path: /src/lib.rs
#![feature(vec_remove_item)]
#![feature(cell_update)]
extern crate chrono;
extern crate regex;
use std::fs::File;
use std::io::prelude::*;
use std::path::Path;
mod eight;
mod five;
mod four;
mod nine;
mod one;
mod seven;
mod six;
mod three;
mod two... | code_fim | hard | {
"lang": "rust",
"repo": "Mackiovello/advent_of_code",
"path": "/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: danieldk/microfun path: /src/font.rs
// The MIT License (MIT)
//
// Copyright (c) 2016 British Broadcasting Corporation.
// Copyright (c) 2019 Daniël de Kok
//
// This software is provided by Lancaster University by arrangement with the BBC.
// Permission is hereby granted, free of charge, to an... | code_fim | hard | {
"lang": "rust",
"repo": "danieldk/microfun",
"path": "/src/font.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> if ch < ASCII_RANGE.start || ch >= ASCII_RANGE.end {
ch = b'?';
}
// BBC micro:bit font encoding, each byte represents a row.
// Since the display is 5x5, 5 bytes represent the whole LED
// array.
let offset = (ch - ASCII_RANGE.start) as usize *... | code_fim | hard | {
"lang": "rust",
"repo": "danieldk/microfun",
"path": "/src/font.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut buffer = [0; 512];
stream.read(&mut buffer).unwrap();
let mut req = str::from_utf8(&buffer).unwrap().split_whitespace();
let response = match [req.next(), req.next(), req.next()] {
[Some("GET"), Some(path), Some(_ver)] => {
let mut path = path.split("/");
path.next(); // starts with ... | code_fim | hard | {
"lang": "rust",
"repo": "touhou-towers/gap",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: touhou-towers/gap path: /src/main.rs
#![recursion_limit = "128"]
#[macro_use]
extern crate diesel;
extern crate dotenv;
extern crate serde;
extern crate serde_json;
extern crate lazy_static;
mod database;
use lazy_static::lazy_static;
use database::*;
use std::collections::HashSet;
use std::io... | code_fim | hard | {
"lang": "rust",
"repo": "touhou-towers/gap",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn create_heart_beat_msg(id: String) -> Result<String, Error> {
to_string(&structs::HeartBeatRequest {
type_: String::from( HEART_BEAT_REQUEST ),
receivingPlayerId: id
})
}
pub fn create_client_info_msg() -> Result<String, Error> {
to_string(&structs::ClientInfo {
... | code_fim | hard | {
"lang": "rust",
"repo": "Rembane/snakebot-client-rust",
"path": "/src/messages.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Rembane/snakebot-client-rust path: /src/messages.rs
use structs;
use serde_json::{ from_str, to_string, Error };
use target_info::Target;
use rustc_version;
// Inbound
pub const GAME_ENDED: &'static str =
"se.cygni.snake.api.event.GameEndedEvent";
pub const TOURNAMENT_ENDED: &'static str =
... | code_fim | hard | {
"lang": "rust",
"repo": "Rembane/snakebot-client-rust",
"path": "/src/messages.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn find_ints(dirs_l: &[(Direction, usize)], dirs_r: &[(Direction, usize)]) -> Vec<((isize, isize), usize)> {
let pos_l = make_positions(dirs_l);
let pos_r = make_positions(dirs_r);
println!("Len: {}, {}", pos_l.len(), pos_r.len());
let found = pos_l.into_iter().collect::<HashMap<(isize, i... | code_fim | hard | {
"lang": "rust",
"repo": "SuperTails/advent-of-code-2019",
"path": "/day3/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> for (dir, amount) in dirs {
println!("Row: {}, dir: {:?}, amount: {}", row, dir, amount);
for _ in 0..*amount {
match dir {
Direction::Up => row -= 1,
Direction::Down => row += 1,
Direction::Left => col -= 1,
D... | code_fim | hard | {
"lang": "rust",
"repo": "SuperTails/advent-of-code-2019",
"path": "/day3/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: SuperTails/advent-of-code-2019 path: /day3/src/main.rs
use std::collections::HashMap;
#[derive(Debug, Clone, Copy)]
pub enum Direction {
Right,
Down,
Left,
Up
}
impl Direction {
pub fn parse(c: char) -> Direction {
match c {
'R' => Direction::Right,
... | code_fim | hard | {
"lang": "rust",
"repo": "SuperTails/advent-of-code-2019",
"path": "/day3/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> //// Content Nodes
User, // Inserts the current user
OrigenCommand(String), // The origen command being executed
Timestamp, // Inserts a timestamp
Mode, // Inserts the current mode
TargetsStacked, // Inserts the current targets a... | code_fim | hard | {
"lang": "rust",
"repo": "Origen-SDK/o2",
"path": "/rust/origen/src/generator/nodes.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> //// Text (Comment) nodes
//// Useful for formatting comment blocks in the AST.
TextSection(Option<String>, Option<u8>), // The start of a new section.
TextBoundaryLine, // Inserts a 'boundary'. This will be resolve to a line of '*'
// How exactly this will look in the output is up to ... | code_fim | hard | {
"lang": "rust",
"repo": "Origen-SDK/o2",
"path": "/rust/origen/src/generator/nodes.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Origen-SDK/o2 path: /rust/origen/src/generator/nodes.rs
use super::utility::transaction::Transaction;
use crate::services::swd::Acknowledgements;
use crate::testers::SupportedTester;
use indexmap::IndexMap;
use crate::om::TypedValueMap;
pub type Id = usize;
type Metadata = Option<TypedValueMap>... | code_fim | hard | {
"lang": "rust",
"repo": "Origen-SDK/o2",
"path": "/rust/origen/src/generator/nodes.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>me, None, privatekey_filepath.as_path(), None)
.unwrap();
assert!(session.authenticated());
(tcp, session)
}<|fim_prefix|>// repo: hhatto/rust-snippets path: /networking/src/sshutil.rs
use ssh2::Session;
use std::net::TcpStream;
pub fn ssh_login(addr: &'static str, username: &'static... | code_fim | medium | {
"lang": "rust",
"repo": "hhatto/rust-snippets",
"path": "/networking/src/sshutil.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: hhatto/rust-snippets path: /networking/src/sshutil.rs
use ssh2::Session;
use std::net::TcpStream;
pub fn ssh_login(addr: &'static str, username: &'static str) -> (TcpStream, Session) {
let tcp = TcpStream::connect(addr).unwrap();
let mut session = Session::new().unwrap();
session.ha... | code_fim | medium | {
"lang": "rust",
"repo": "hhatto/rust-snippets",
"path": "/networking/src/sshutil.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: reinterpretcat/vrp path: /vrp-core/src/solver/search/recreate/recreate_with_regret.rs
use crate::construction::heuristics::*;
use crate::construction::heuristics::{InsertionContext, InsertionResult};
use crate::models::problem::Job;
use crate::solver::search::{ConfigurableRecreate, Recreate};
us... | code_fim | hard | {
"lang": "rust",
"repo": "reinterpretcat/vrp",
"path": "/vrp-core/src/solver/search/recreate/recreate_with_regret.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> if regret_index < job_results.len() {
let worst = job_results.swap_remove(regret_index);
let best = job_results.swap_remove(0);
Some((worst.cost - &best.cost, best))
} else {
None
... | code_fim | hard | {
"lang": "rust",
"repo": "reinterpretcat/vrp",
"path": "/vrp-core/src/solver/search/recreate/recreate_with_regret.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> &self,
insertion_ctx: &InsertionContext,
route_ctx: &RouteContext,
jobs: &[&Job],
leg_selection: &LegSelection,
result_selector: &(dyn ResultSelector + Send + Sync),
) -> InsertionResult {
self.fallback_evaluator.evaluate_route(insertion_ctx, rou... | code_fim | hard | {
"lang": "rust",
"repo": "reinterpretcat/vrp",
"path": "/vrp-core/src/solver/search/recreate/recreate_with_regret.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> Ok(Json(user_info))
}
/// 登出
///
/// ## Example
///
/// HTTP 请求:
/// ```
/// POST /user/signOut
/// ```
///
/// HTTP 响应:
/// ```
/// HTTP/1.1 200 OK
/// content-length: 0
/// content-type: text/plain; charset=utf-8
/// set-cookie: identity=; Max-Age=0; Expires=Sat, 23 Feb 2019 13:30:39 GMT
/// date: ... | code_fim | hard | {
"lang": "rust",
"repo": "gengteng/admino",
"path": "/src/controller/user.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: gengteng/admino path: /src/controller/user.rs
//! 用户及登录相关控制器
//!
//! TODO: 待拆分成用户的增删改查、用户注册登录登出和验证码相关两部分(或三部分?)
use super::IntoJsonResult;
use crate::controller::EmptyBody;
use crate::error::{Error, Kind};
use crate::model::{
AddPasswordParams, AuthType, GetAuthCodeParams, RegisterParams, Ro... | code_fim | hard | {
"lang": "rust",
"repo": "gengteng/admino",
"path": "/src/controller/user.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// 为当前用户新增登录密码
///
/// ## Example
///
/// HTTP 请求:
/// ```
/// POST /user/addPassword
/// Content-Type: application/json
///
/// {"password": "!23QweAsd"}
/// ```
///
/// HTTP 响应:
/// ```
/// HTTP/1.1 200 OK
/// content-length: 0
/// content-type: text/plain; charset=utf-8
/// set-cookie: identity=; Max-... | code_fim | hard | {
"lang": "rust",
"repo": "gengteng/admino",
"path": "/src/controller/user.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let infection_r = INFLUENCE_RADIUS;
for p in full_pop.iter_mut() {
//p.tick(self.current_time, &mut self.rng);
let bound = QuadTreeRegion::new(p.position.x - infection_r, p.position.y - infection_r,
p.position.x + infectio... | code_fim | hard | {
"lang": "rust",
"repo": "GyrosOfWar/sickness-sim-rs",
"path": "/src/simulation.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.current_time += 1;
true
}
fn is_finished(&self, population: &Vec<&Person>) -> bool {
population.len() == 0 ||
population
.iter()
.filter(|p| p.status != Status::Healthy)
.count() == 0
}
}
// TODO tests<|fim_pref... | code_fim | hard | {
"lang": "rust",
"repo": "GyrosOfWar/sickness-sim-rs",
"path": "/src/simulation.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: GyrosOfWar/sickness-sim-rs path: /src/simulation.rs
use person::{Person, Status};
use constants::*;
use rand::{weak_rng, XorShiftRng, Rng};
use cgmath::Point2;
use ntree::NTree;
use quadtree::{QuadTreeRegion, QuadTree};
//#[derive(Debug)]
pub struct Simulation {
population: QuadTree,
rn... | code_fim | hard | {
"lang": "rust",
"repo": "GyrosOfWar/sickness-sim-rs",
"path": "/src/simulation.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> format!("{},{}", x, y)
}
fn part2(&mut self, input: &mut dyn Read) -> String {
let serial = read_single_input(input);
self.compute_summed_area(serial);
let mut best_result = 0;
let mut best_option = None;
for size in 1..=300 {
let (x, y,... | code_fim | hard | {
"lang": "rust",
"repo": "bertptrs/adventofcode",
"path": "/2018/src/day11.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(4, power_at(8, (3, 5)));
assert_eq!(-5, power_at(57, (122, 79)));
assert_eq!(0, power_at(39, (217, 196)));
assert_eq!(4, power_at(71, (101, 153)));
}
#[test]
fn sample_part1() {
let mut instance = Day11::new();
assert_eq!("33,45", ins... | code_fim | hard | {
"lang": "rust",
"repo": "bertptrs/adventofcode",
"path": "/2018/src/day11.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: bertptrs/adventofcode path: /2018/src/day11.rs
use std::i32;
use std::io::Read;
use common::read_single_input;
use common::Solution;
fn power_at(serial: i32, (x, y): (i32, i32)) -> i32 {
let rack_id = x + 10;
let mut power_level = rack_id * y;
power_level += serial;
power_level... | code_fim | hard | {
"lang": "rust",
"repo": "bertptrs/adventofcode",
"path": "/2018/src/day11.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: m9s/xmc1000 path: /xmc1000/src/usic0_ch0/ccfg/mod.rs
#[doc = r" Value read from the register"]
pub struct R {
bits: u32,
}
impl super::CCFG {
#[doc = r" Reads the contents of the register"]
#[inline]
pub fn read(&self) -> R {
R {
bits: self.register.get(),
... | code_fim | hard | {
"lang": "rust",
"repo": "m9s/xmc1000",
"path": "/xmc1000/src/usic0_ch0/ccfg/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>allow(missing_docs)]
#[doc(hidden)]
#[inline]
pub fn _from(value: bool) -> IISR {
match value {
false => IISR::VALUE1,
true => IISR::VALUE2,
}
}
#[doc = "Checks if the value of the field is `VALUE1`"]
#[inline]
pub fn is_value1(&self) -> ... | code_fim | hard | {
"lang": "rust",
"repo": "m9s/xmc1000",
"path": "/xmc1000/src/usic0_ch0/ccfg/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rust-lang/rust-analyzer path: /crates/ide/src/move_item.rs
ken(
file.syntax().token_at_offset(range.range.start()),
|kind| match kind {
SyntaxKind::IDENT | SyntaxKind::LIFETIME_IDENT => 2,
kind if kind.is_trivia() => 0,
_ =>... | code_fim | hard | {
"lang": "rust",
"repo": "rust-lang/rust-analyzer",
"path": "/crates/ide/src/move_item.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn test_moves_generic_arg_up() {
check(
r#"
struct Test<A, B>(A, B);
fn main() {
let t = Test::<i32, &str$0$0>(123, "yay");
}
"#,
expect![[r#"
struct Test<A, B>(A, B);
fn main() {
let t = Test::<&str$... | code_fim | hard | {
"lang": "rust",
"repo": "rust-lang/rust-analyzer",
"path": "/crates/ide/src/move_item.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rust-lang/rust-analyzer path: /crates/ide/src/move_item.rs
ange, helpers::pick_best_token, RootDatabase};
use itertools::Itertools;
use syntax::{algo, ast, match_ast, AstNode, SyntaxElement, SyntaxKind, SyntaxNode, TextRange};
use text_edit::{TextEdit, TextEditBuilder};
#[derive(Copy, Clone, De... | code_fim | hard | {
"lang": "rust",
"repo": "rust-lang/rust-analyzer",
"path": "/crates/ide/src/move_item.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: starcoinorg/starcoin path: /state/state-tree/src/state_tree.rs
use anyhow::Result;
use forkable_jellyfish_merkle::blob::Blob;
use forkable_jellyfish_merkle::iterator::{JellyfishMerkleIntoIterator, JellyfishMerkleIterator};
use forkable_jellyfish_merkle::node_type::{Node, NodeKey};
use forkable_j... | code_fim | hard | {
"lang": "rust",
"repo": "starcoinorg/starcoin",
"path": "/state/state-tree/src/state_tree.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// get last changes root_hash
pub fn last_change_sets(&self) -> Option<(HashValue, TreeUpdateBatch<K>)> {
let cache_guard = self.cache.lock();
cache_guard.change_set_list.last().cloned()
}
// TODO: to keep atomic with other commit.
// TODO: think about the WriteBatch ... | code_fim | hard | {
"lang": "rust",
"repo": "starcoinorg/starcoin",
"path": "/state/state-tree/src/state_tree.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut array = vec![9, 8, 7, 6, 5, 4, 3, 2, 1];
selection_sort(&mut array);
assert_eq!(array, vec![1, 2, 3, 4, 5, 6, 7, 8, 9]);
}
}<|fim_prefix|>// repo: hunterlester/rusty_algo_structs path: /src/algorithms/sorting/selection_sort.rs
/// O((n**2)/2)
fn selection_sort(array: &... | code_fim | medium | {
"lang": "rust",
"repo": "hunterlester/rusty_algo_structs",
"path": "/src/algorithms/sorting/selection_sort.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn test_selection_sort() {
let mut array = vec![9, 8, 7, 6, 5, 4, 3, 2, 1];
selection_sort(&mut array);
assert_eq!(array, vec![1, 2, 3, 4, 5, 6, 7, 8, 9]);
}
}<|fim_prefix|>// repo: hunterlester/rusty_algo_structs path: /src/algorithms/sorting/selection_sort.rs... | code_fim | medium | {
"lang": "rust",
"repo": "hunterlester/rusty_algo_structs",
"path": "/src/algorithms/sorting/selection_sort.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: hunterlester/rusty_algo_structs path: /src/algorithms/sorting/selection_sort.rs
/// O((n**2)/2)
fn selection_sort(array: &mut Vec<i32>) {
let mut iterations = 0;
for i in 0..array.len() - 1 {
let mut min_index = i;
for j in i + 1..array.len() {
iterations += 1... | code_fim | medium | {
"lang": "rust",
"repo": "hunterlester/rusty_algo_structs",
"path": "/src/algorithms/sorting/selection_sort.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Ploppz/gui path: /gui/src/default/button.rs
use super::*;
use crate::*;
use interactive::*;
pub trait ButtonStyle: StyleBound {
/// Style of contained text field
type TextField: TextFieldStyle;
}
#[derive(Debug)]
pub struct Button<Style> {
pub style: Style,
}
impl<Style: ButtonStyl... | code_fim | hard | {
"lang": "rust",
"repo": "Ploppz/gui",
"path": "/gui/src/default/button.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> for event in local_events {
if id == event.id {
if let EventKind::Press = event.kind {
self.state = !self.state;
ctx.gui
.borrow_mut()
.push_event(Event::change(event.id, Self::state... | code_fim | hard | {
"lang": "rust",
"repo": "Ploppz/gui",
"path": "/gui/src/default/button.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut score_accumulators = score_params.iter().map(|params| ScoreAccumulator::new(&world, params)).collect::<Vec<_>>();
let mut action_emitter = ActionEmitter::new(&strategy);
for score_accumulator in score_accumulators.iter_mut() {
score_accumulator.evaluate_strategy(&strategy);
... | code_fim | hard | {
"lang": "rust",
"repo": "raysplaceinspace/codevszombies",
"path": "/src/rollouts.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: raysplaceinspace/codevszombies path: /src/rollouts.rs
pub use super::model::*;
use super::evaluation::{ScoreAccumulator, ScoreParams};
use super::simulator;
const MAX_ROLLOUT_TICKS: i32 = 50;
#[derive(Clone)]
pub struct Rollout {
pub strategy: Strategy,
pub events: Vec<Event>,
pub... | code_fim | hard | {
"lang": "rust",
"repo": "raysplaceinspace/codevszombies",
"path": "/src/rollouts.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>st
have
the
final
value
without
knowledge
of
if
this
is
/
/
unique
or
shared
.
So
the
hack
is
to
just
assume
Ver
:
:
Http2
means
/
/
shared
.
.
.
:
(
let
mut
pool_ref
=
WeakOpt
:
:
none
(
)
;
if
!
value
.
can_share
(
)
{
if
let
Some
(
ref
enabled
)
=
self
.
inner
{
pool_ref
=
WeakOpt
:
:
downgrade
(
enabl... | code_fim | hard | {
"lang": "rust",
"repo": "marco-c/gecko-dev-wordified",
"path": "/third_party/rust/hyper/src/client/pool.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>try
}
;
entry
.
map
(
|
e
|
self
.
pool
.
reuse
(
&
self
.
key
e
.
value
)
)
}
}
impl
<
T
:
Poolable
>
Future
for
Checkout
<
T
>
{
type
Output
=
crate
:
:
Result
<
Pooled
<
T
>
>
;
fn
poll
(
mut
self
:
Pin
<
&
mut
Self
>
cx
:
&
mut
task
:
:
Context
<
'
_
>
)
-
>
Poll
<
Self
:
:
Output
>
{
if
let
Some
(
po... | code_fim | hard | {
"lang": "rust",
"repo": "marco-c/gecko-dev-wordified",
"path": "/third_party/rust/hyper/src/client/pool.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: marco-c/gecko-dev-wordified path: /third_party/rust/hyper/src/client/pool.rs
)
;
}
#
[
cfg
(
feature
=
"
runtime
"
)
]
fn
spawn_idle_interval
(
&
mut
self
pool_ref
:
&
Arc
<
Mutex
<
PoolInner
<
T
>
>
>
)
{
let
(
dur
rx
)
=
{
if
self
.
idle_interval_ref
.
is_some
(
)
{
return
;
}
if
let
Some
(
du... | code_fim | hard | {
"lang": "rust",
"repo": "marco-c/gecko-dev-wordified",
"path": "/third_party/rust/hyper/src/client/pool.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: plugblockchain/plug-blockchain path: /frame/contracts/src/wasm/code_cache.rs
// This file is part of Substrate.
// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use ... | code_fim | hard | {
"lang": "rust",
"repo": "plugblockchain/plug-blockchain",
"path": "/frame/contracts/src/wasm/code_cache.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// Increment the refcount of a code in-storage by one.
pub fn increment_refcount<T: Config>(code_hash: CodeHash<T>) -> Result<u32, DispatchError>
where
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>
{
<CodeStorage<T>>::mutate(code_hash, |existing| {
if let Some(module) = existing {
increment_6... | code_fim | hard | {
"lang": "rust",
"repo": "plugblockchain/plug-blockchain",
"path": "/frame/contracts/src/wasm/code_cache.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: asomers/mockall path: /mockall/tests/automock_self_by_value.rs
// vim: tw=80
//! A method that consumes self
#![deny(warnings)]
use mockall::*;
pub struct MethodByValue {}
#[automock]
impl MethodByValue {
pub fn foo(self, _x: u32) -> i64 {0}
#[allow(unused_mut)]
pub fn bar(mut sel... | code_fim | medium | {
"lang": "rust",
"repo": "asomers/mockall",
"path": "/mockall/tests/automock_self_by_value.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[automock]
impl MethodByValue {
pub fn foo(self, _x: u32) -> i64 {0}
#[allow(unused_mut)]
pub fn bar(mut self) {}
}
#[test]
fn immutable() {
let mut mock = MockMethodByValue::new();
mock.expect_foo()
.returning(|x| i64::from(x) + 1);
assert_eq!(5, mock.foo(4));
}
#[test]... | code_fim | medium | {
"lang": "rust",
"repo": "asomers/mockall",
"path": "/mockall/tests/automock_self_by_value.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(fst.lookup_key("すし"), true);
assert_eq!(fst.lookup_key("🍣"), true);
assert_eq!(fst.lookup_key("🍜"), false);
// TODO false-positive case
}
#[test]
fn lookup_range_test() {
let fst = build();
// [すし, すしや)
let results_in_u8s: Vec<Vec<u8>> = fst.lookup_range("すし", t... | code_fim | medium | {
"lang": "rust",
"repo": "laysakura/fst-rs",
"path": "/tests/test.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // TODO false-positive case
}
#[test]
fn lookup_range_test() {
let fst = build();
// [すし, すしや)
let results_in_u8s: Vec<Vec<u8>> = fst.lookup_range("すし", true, "すしや", false);
let results_in_str: Vec<&str> = results_in_u8s
.iter()
.map(|u8s| str::from_utf8(u8s).unwrap()... | code_fim | medium | {
"lang": "rust",
"repo": "laysakura/fst-rs",
"path": "/tests/test.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: laysakura/fst-rs path: /tests/test.rs
use fst_rs::{Fst, FstBuilder};
use std::str;
fn build() -> Fst<u8> {
let mut builder = FstBuilder::new();
builder.push("すし");
builder.push("すしや");
builder.push("すしだね");
builder.push("すしづめ");
builder.push("すしめし");
builder.push("すし... | code_fim | hard | {
"lang": "rust",
"repo": "laysakura/fst-rs",
"path": "/tests/test.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>
pub fn main() {
match &12 {
&0...9 => {}
//~^ WARN `...` range patterns are deprecated
//~| HELP use `..=` for an inclusive range
&10..=15 => {}
//~^ ERROR the range pattern here has ambiguous interpretation
//~^^ HELP add parentheses to clarify the pre... | code_fim | medium | {
"lang": "rust",
"repo": "IThawk/rust-project",
"path": "/rust-master/src/test/ui/range/range-inclusive-pattern-precedence.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: IThawk/rust-project path: /rust-master/src/test/ui/range/range-inclusive-pattern-precedence.rs
// In expression, `&a..=b` is treated as `(&a)..=(b)` and `box a..=b` is
// `(box a)..=(b)`. In a pattern, however, `&a..=b` means `&(a..=b)`. This may
// lead to confusion.
//
// We are going to disal... | code_fim | hard | {
"lang": "rust",
"repo": "IThawk/rust-project",
"path": "/rust-master/src/test/ui/range/range-inclusive-pattern-precedence.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl<T> EmailAddress for T
where
T: List,
{
/// By default email addresses with IP address host part are not supported.
/// If you need support for that, enable the `net` feature.
fn parse_email_address<'a>(&self, name: &'a str) -> Result<'a, email::Address<'a>> {
email::Address::p... | code_fim | medium | {
"lang": "rust",
"repo": "addr-rs/addr",
"path": "/src/parser.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: addr-rs/addr path: /src/parser.rs
//! Parser traits
use crate::{dns, domain, email, Result};
use psl_types::List;
/// Parses a domain using the list
pub trait DomainName {
/// This method tries to stick to restrictions usually imposed by domain registries
/// when registering domain na... | code_fim | hard | {
"lang": "rust",
"repo": "addr-rs/addr",
"path": "/src/parser.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl<T> DnsName for T
where
T: List,
{
fn parse_dns_name<'a>(&self, name: &'a str) -> Result<'a, dns::Name<'a>> {
dns::Name::parse(self, name).map_err(|kind| kind.error_with(name))
}
}
/// Parses an email address using the list
pub trait EmailAddress {
fn parse_email_address<'a>(&... | code_fim | hard | {
"lang": "rust",
"repo": "addr-rs/addr",
"path": "/src/parser.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_ne!(result_len, 0);
let result = unsafe {
std::slice::from_raw_parts(result_ptr as *const u8, result_len as usize)
};
let result = std::str::from_utf8(result).unwrap();
println!("\nc_result:\n{}", result);
assert_eq!(result, "Hello C");
js_snap_instance_delete(instance);
}<|fim_... | code_fim | medium | {
"lang": "rust",
"repo": "austinEng/js-snap",
"path": "/tests/c_api_test.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let result = std::str::from_utf8(result).unwrap();
println!("\nc_result:\n{}", result);
assert_eq!(result, "Hello C");
js_snap_instance_delete(instance);
}<|fim_prefix|>// repo: austinEng/js-snap path: /tests/c_api_test.rs
use js_snap::*;
#[test]
fn c_api_simple() {
js_snap_init();
let inst... | code_fim | medium | {
"lang": "rust",
"repo": "austinEng/js-snap",
"path": "/tests/c_api_test.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: austinEng/js-snap path: /tests/c_api_test.rs
use js_snap::*;
#[test]
fn c_api_simple() {
js_snap_init();
let instance = js_snap_instance_from_source(
std::ffi::CString::new("const fns = { Greet: (params) => params };").unwrap().as_ptr(),
std::ffi::CString::new("fns").unwrap().as_ptr... | code_fim | hard | {
"lang": "rust",
"repo": "austinEng/js-snap",
"path": "/tests/c_api_test.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: knight110001/yastl path: /src/lib.rs
//! A library to provide a thread pool that can run scoped and unscoped threads.
//!
//!
//! It can be used to spawn threads, that are guaranteed to be finished if the scope ends,
//! and thus make it possible to borrow values from the stack (not requiring th... | code_fim | hard | {
"lang": "rust",
"repo": "knight110001/yastl",
"path": "/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
#[should_panic]
fn pool_panic() {
let _pool = Pool::new(num_cpus::get());
panic!();
}
#[test]
#[should_panic]
fn zoomed_scoped_execute_panic() {
let pool = Pool::new(num_cpus::get());
pool.scoped(|scope| scope.zoom(|scope2| scope2.execut... | code_fim | hard | {
"lang": "rust",
"repo": "knight110001/yastl",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jakubclark/hue.rs path: /src/lib.rs
use thiserror::Error;
#[derive(Error, Debug)]
pub enum HueError {
#[error("An error occured while performing an HTTP request")]
Ureq(#[from] ureq::Error),
#[error("An error occurred while manipulating JSON")]
SerdeJson(#[from] serde_json::Erro... | code_fim | hard | {
"lang": "rust",
"repo": "jakubclark/hue.rs",
"path": "/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>yError { msg: String },
#[error("This action requires an username to be registered")]
NoUsername,
#[error("Error occured while de-serializing JSON {0}")]
DeserializationError(#[from] std::io::Error),
}
pub mod bridge;
mod disco;<|fim_prefix|>// repo: jakubclark/hue.rs path: /src/lib.rs
u... | code_fim | hard | {
"lang": "rust",
"repo": "jakubclark/hue.rs",
"path": "/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: joshuamegnauth54/steam_user_reviews path: /steam_rev_query/steam_review_api/src/language.rs
#[cfg(feature = "convenience_structs")]
use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer};
use std::{
fmt::{self, Display, Formatter},
str::FromStr,
};
/// Languages as rep... | code_fim | hard | {
"lang": "rust",
"repo": "joshuamegnauth54/steam_user_reviews",
"path": "/steam_rev_query/steam_review_api/src/language.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Shorthand language code as represented by the Steam web API.
pub fn language_code(self) -> &'static str {
use Language::*;
match self {
All => "all",
Arabic => "ar",
Bulgarian => "bg",
SimplifiedChinese => "zh-CN",
Tra... | code_fim | hard | {
"lang": "rust",
"repo": "joshuamegnauth54/steam_user_reviews",
"path": "/steam_rev_query/steam_review_api/src/language.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Display for Language {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl FromStr for Language {
type Err = LangParseError;
/// String slice to Language.
/// Native names as well as shorthands are handled.
///
/// ## Err... | code_fim | hard | {
"lang": "rust",
"repo": "joshuamegnauth54/steam_user_reviews",
"path": "/steam_rev_query/steam_review_api/src/language.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn one_anon_operation() {
expect_passes_rule!(
factory,
r#"
{
field
}
"#,
);
}
#[test]
fn multiple_named_operations() {
expect_passes_rule!(
factory,
r#"
q... | code_fim | hard | {
"lang": "rust",
"repo": "mwilliammyers/async-graphql",
"path": "/src/validation/rules/lone_anonymous_operation.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mwilliammyers/async-graphql path: /src/validation/rules/lone_anonymous_operation.rs
use crate::parser::types::{ExecutableDefinition, ExecutableDocument, OperationDefinition};
use crate::validation::visitor::{Visitor, VisitorContext};
use crate::Positioned;
#[derive(Default)]
pub struct LoneAnon... | code_fim | hard | {
"lang": "rust",
"repo": "mwilliammyers/async-graphql",
"path": "/src/validation/rules/lone_anonymous_operation.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn multiple_anon_operations() {
expect_fails_rule!(
factory,
r#"
{
fieldA
}
{
fieldB
}
"#,
);
}
#[test]
fn anon_operation_with_a_mutation() {
expect_fails_ru... | code_fim | hard | {
"lang": "rust",
"repo": "mwilliammyers/async-graphql",
"path": "/src/validation/rules/lone_anonymous_operation.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: KawaharaLab/CaterpillarSimulatorLib path: /lib/src/calculations.rs
pub fn differentiate(previous_val: f64, current_val:<|fim_suffix|> None
} else {
Some((current_val - previous_val) / dt)
}
}
#[cfg(test)]
mod test {}<|fim_middle|> f64, dt: f64) -> Option<f64> {
if dt ==... | code_fim | easy | {
"lang": "rust",
"repo": "KawaharaLab/CaterpillarSimulatorLib",
"path": "/lib/src/calculations.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>previous_val) / dt)
}
}
#[cfg(test)]
mod test {}<|fim_prefix|>// repo: KawaharaLab/CaterpillarSimulatorLib path: /lib/src/calculations.rs
pub fn differentiate(previous_val: f64, current_val:<|fim_middle|> f64, dt: f64) -> Option<f64> {
if dt == 0. {
None
} else {
Some((curren... | code_fim | medium | {
"lang": "rust",
"repo": "KawaharaLab/CaterpillarSimulatorLib",
"path": "/lib/src/calculations.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut hoge = minilisp::environment::cdr(&mut ss);
println!("{:?}", hoge);
println!("{}", minilisp::parser::print(hoge));
}<|fim_prefix|>// repo: komi1230/lisp-in-rust path: /src/main.rs
extern crate minilisp;
fn main() {
<|fim_middle|> println!("Hello, world!");
let s = " (+ 1 (... | code_fim | medium | {
"lang": "rust",
"repo": "komi1230/lisp-in-rust",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let s = " (+ 1 (- \"2.2\" 3))";
println!("Before : {}", s);
let mut ss = minilisp::parser::tokenize(s);
println!("Tokens: {:?}", ss);
let mut hoge = minilisp::environment::cdr(&mut ss);
println!("{:?}", hoge);
println!("{}", minilisp::parser::print(hoge));
}<|fim_prefix|>/... | code_fim | easy | {
"lang": "rust",
"repo": "komi1230/lisp-in-rust",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: komi1230/lisp-in-rust path: /src/main.rs
extern crate minilisp;
fn main() {
println!("Hello, world!");
<|fim_suffix|> let mut hoge = minilisp::environment::cdr(&mut ss);
println!("{:?}", hoge);
println!("{}", minilisp::parser::print(hoge));
}<|fim_middle|> let s = " (+ 1 (... | code_fim | medium | {
"lang": "rust",
"repo": "komi1230/lisp-in-rust",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> println!("Starting benchmark!");
let start = time::Instant::now();
let mut elapsed_secs: f64;
let mut num_puts: i64 = 0;
let mut num_updates: i64 = 0;
loop {
num_puts += 1;
num_updates += batch_size * width as i64;
number_putter.put(vec![batch_size.into()]);... | code_fim | hard | {
"lang": "rust",
"repo": "omegablitz/distributary",
"path": "/benchmarks/multitail/multitail.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: omegablitz/distributary path: /benchmarks/multitail/multitail.rs
extern crate distributary;
#[macro_use]
extern crate clap;
use std::{thread, time};
use distributary::{Blender, Base, Aggregation, Mutator, Token, JoinBuilder};
struct Backend {
data: Option<Mutator>,
number: Option<Mut... | code_fim | hard | {
"lang": "rust",
"repo": "omegablitz/distributary",
"path": "/benchmarks/multitail/multitail.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let total_process_time: u64 = node_map.iter().map(|&(_, ns)| ns.process_time).sum();
println!("Domain {:?}: wait fraction = {:.3}, unaccounted = {:.3}",
domain_index,
wait_time / total_time,
1.0 - (total_process_time as... | code_fim | hard | {
"lang": "rust",
"repo": "omegablitz/distributary",
"path": "/benchmarks/multitail/multitail.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[ink(message)]
pub fn parse_usd(&self, json: String) -> Option<Usd> {
let decoded: SerdeUsd = serde_json::from_str(&json).ok()?;
Some(Usd {
usd: (decoded.usd * 100.0) as u128,
})
}
}
}<|fim_prefix|>// repo: Phala-Network/phal... | code_fim | hard | {
"lang": "rust",
"repo": "Phala-Network/phala-blockchain",
"path": "/e2e/contracts/indeterministic_functions/lib.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Phala-Network/phala-blockchain path: /e2e/contracts/indeterministic_functions/lib.rs
#![cfg_attr(not(feature = "std"), no_std, no_main)]
extern crate alloc;
pub use indeterministic_functions::*;
#[ink::contract]
mod indeterministic_functions {
use alloc::string::String;
use scale::{Dec... | code_fim | medium | {
"lang": "rust",
"repo": "Phala-Network/phala-blockchain",
"path": "/e2e/contracts/indeterministic_functions/lib.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: softdevteam/grmtools path: /lrpar/cttests_macro/src/lib.rs
extern crate proc_macro;
use glob::glob;
use proc_macro::TokenStream;
use proc_macro2::Span;
use quote::quote;
use syn::{parse_macro_input, Ident, LitStr};
#[proc_macro]
pub fn generate_codegen_fail_tests(item: TokenStream) -> TokenStrea... | code_fim | hard | {
"lang": "rust",
"repo": "softdevteam/grmtools",
"path": "/lrpar/cttests_macro/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>Tokens` a bounds given by `quote!`.
let path = file.display().to_string();
let stem = file.file_stem().unwrap().to_string_lossy();
let ident = Ident::new(&format!("codegen_fail_{}", stem), Span::call_site());
out.push(quote! {
#[should_panic]
#[test]... | code_fim | hard | {
"lang": "rust",
"repo": "softdevteam/grmtools",
"path": "/lrpar/cttests_macro/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[derive(Copy, Clone)]
pub struct WrappedFn {
wrapper: fn(Ref<[Slot]>) -> GResult<Slot>,
pub(crate) arg_limits: (usize, Option<usize>)
}
impl WrappedFn {
#[doc(hidden)]
pub fn new(wrapper: fn(Ref<[Slot]>) -> GResult<Slot>,
arg_limits: (usize, Option<usize>)) -> WrappedFn {
Wra... | code_fim | hard | {
"lang": "rust",
"repo": "AlbertoGP/glsp",
"path": "/glsp-engine/src/wrap.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: AlbertoGP/glsp path: /glsp-engine/src/wrap.rs
the ideal evaluation order would be make_temps, make_args, make_temps_libs,
//then make_args_libs, but there seems to be no straightforward way to achieve that, at least
//without risking poor performance or increasing compile times...
tuple_im... | code_fim | hard | {
"lang": "rust",
"repo": "AlbertoGP/glsp",
"path": "/glsp-engine/src/wrap.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: AlbertoGP/glsp path: /glsp-engine/src/wrap.rs
romVal for $t {
#[inline(always)]
fn from_val(val: &Val) -> GResult<Self> {
match *val {
Val::Int(i) if i >= $t::MIN as i32 && i <= $t::MAX as i32 => {
Ok(i as $t)
}
Val::Int(i) => {
bail!("expecte... | code_fim | hard | {
"lang": "rust",
"repo": "AlbertoGP/glsp",
"path": "/glsp-engine/src/wrap.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: verdantred/rusterio path: /src/main.rs
// Main server code
// New plugin feature in use to get macros included
#![feature(plugin)]
#![plugin(rocket_codegen, dotenv_macros)]
// Libs
extern crate rocket;
extern crate rocket_contrib;
extern crate dotenv;
extern crate serde_json;
// Libs with mac... | code_fim | hard | {
"lang": "rust",
"repo": "verdantred/rusterio",
"path": "/src/main.rs",
"mode": "psm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> use schema::users;
let con = connect_to_db();
let n_user = user.into_inner();
println!("{:?}", n_user);
let rows = diesel::insert(&n_user).into(users::table).execute(&con).expect("Error saving new user");
return format!("New user inserted, {:?} rows affected", rows);
}
#[get("/use... | code_fim | hard | {
"lang": "rust",
"repo": "verdantred/rusterio",
"path": "/src/main.rs",
"mode": "spm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Output factors
println!("factors: {:?}", factors);
// Statistics
println!("defined_factors: {:?}", defined_factors);
}<|fim_prefix|>// repo: kampersanda/lzd-rs path: /examples/factorize.rs
use lzd::compressor::Compressor;
fn main() {
<|fim_middle|> // Input text
let text = "ab... | code_fim | hard | {
"lang": "rust",
"repo": "kampersanda/lzd-rs",
"path": "/examples/factorize.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: kampersanda/lzd-rs path: /examples/factorize.rs
use lzd::compressor::Compressor;
fn main() {
// Input text
let text = "abaaabababaabbabab".as_bytes();
// Factorization
let mut factors = Vec::new();
let defined_factors = Compressor::run(text, |id: usize| {
factors.pu... | code_fim | medium | {
"lang": "rust",
"repo": "kampersanda/lzd-rs",
"path": "/examples/factorize.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Statistics
println!("defined_factors: {:?}", defined_factors);
}<|fim_prefix|>// repo: kampersanda/lzd-rs path: /examples/factorize.rs
use lzd::compressor::Compressor;
fn main() {
// Input text
let text = "abaaabababaabbabab".as_bytes();
// Factorization
let mut factors = Vec... | code_fim | medium | {
"lang": "rust",
"repo": "kampersanda/lzd-rs",
"path": "/examples/factorize.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: zackyancey/CritFail path: /critfail-app/src/gui/examples.rs
use crate::gui::style;
use crate::gui::{Message, ResultBox, ResultMessage};
use critfail::{AdvState, Roll, RollExpression};
use iced::{button, Button, Color, Column, Element, Length, Row, Text};
#[derive(Debug, Clone, Copy)]
pub enum S... | code_fim | hard | {
"lang": "rust",
"repo": "zackyancey/CritFail",
"path": "/critfail-app/src/gui/examples.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.examples
.iter_mut()
.enumerate()
.fold(Column::new().spacing(20), |col, (i, ex)| {
col.push(
ex.view().map(move |ExampleMessage::Roll(adv)| {
Message::ExampleRolled(section, i, adv)
... | code_fim | hard | {
"lang": "rust",
"repo": "zackyancey/CritFail",
"path": "/critfail-app/src/gui/examples.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.