text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_prefix|>// repo: tobz1000/mines-rs path: /src/server/js/mod.rs
mod api;
use api::req::{JsServerRequest, NewGameRequest, TurnRequest};
use api::resp::{CellInfo as JsCellInfo, CellState, ServerResponse};
use hyper_sync::header::{ContentLength, ContentType};
use hyper_sync::Client;
use serde::ser::Serialize;
use s... | code_fim | hard | {
"lang": "rust",
"repo": "tobz1000/mines-rs",
"path": "/src/server/js/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> if line.starts_with("LOCAL_MODULE")
{
module.id = parsed;
}
else if line.starts_with("LOCAL_SRC_FILES")
{
if concat_type == Concat::Set
{
modu... | code_fim | hard | {
"lang": "rust",
"repo": "raftario/QuestPackageManager-Rust",
"path": "/src/data/android_mk.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: raftario/QuestPackageManager-Rust path: /src/data/android_mk.rs
use std::io::{Read, Write};
#[derive(Debug, Default)]
pub struct Module {
pub prefix_lines: Vec<String>,
pub id: String,
pub src: Vec<String>,
pub export_includes: String,
pub static_libs: Vec<String>,
pub s... | code_fim | hard | {
"lang": "rust",
"repo": "raftario/QuestPackageManager-Rust",
"path": "/src/data/android_mk.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> module.src.append(&mut parse_line(&parsed));
}
else if line.starts_with("LOCAL_EXPORT_C_INCLUDES")
{
if concat_type == Concat::Set
{
module.export_includes.clear();
... | code_fim | hard | {
"lang": "rust",
"repo": "raftario/QuestPackageManager-Rust",
"path": "/src/data/android_mk.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut repl = Repl::builder()
.add("hello", command! {
"Say hello",
(name: String) => |name| {
println!("Hello {}!", name);
Ok(CommandStatus::Done)
}
})
.add("add", command! {
"Add X to Y",
... | code_fim | hard | {
"lang": "rust",
"repo": "Escapingbug/easy-repl",
"path": "/examples/minimal.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Escapingbug/easy-repl path: /examples/minimal.rs
use easy_repl::{Repl, CommandStatus, command};
use anyhow::{self, Context};
<|fim_suffix|> let mut repl = Repl::builder()
.add("hello", command! {
"Say hello",
(name: String) => |name| {
println!... | code_fim | hard | {
"lang": "rust",
"repo": "Escapingbug/easy-repl",
"path": "/examples/minimal.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl DerefMut for GossipListenAddr {
fn deref_mut(&mut self) -> &mut SocketAddr { &mut self.0 }
}
impl ToSocketAddrs for GossipListenAddr {
type Iter = option::IntoIter<SocketAddr>;
fn to_socket_addrs(&self) -> io::Result<Self::Iter> { self.0.to_socket_addrs() }
}
habitat_core::env_config_s... | code_fim | hard | {
"lang": "rust",
"repo": "habitat-sh/habitat",
"path": "/components/common/src/types.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: habitat-sh/habitat path: /components/common/src/types.rs
rde
// https://github.com/serde-rs/serde/issues/723. The easiest way to get around the issue is to use
// these proxy types.
#[serde(try_from = "String", into = "String")]
pub struct EventStreamMetaPair(String, String);
impl FromStr for E... | code_fim | hard | {
"lang": "rust",
"repo": "habitat-sh/habitat",
"path": "/components/common/src/types.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: habitat-sh/habitat path: /components/common/src/types.rs
alue.is_empty() => {
Ok(Self(String::from(*key), String::from(*value)))
}
_ => {
let e = format!("Invalid key-value pair given (must be '='-delimited pair of \
... | code_fim | hard | {
"lang": "rust",
"repo": "habitat-sh/habitat",
"path": "/components/common/src/types.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jpJuni0r/WebGrid path: /core/src/services/orchestrator/core/jobs/slot_reclaim.rs
use super::super::Context;
use crate::libraries::helpers::lua::terminate_session;
use crate::libraries::resources::{ResourceManager, ResourceManagerProvider};
use crate::with_shared_redis_resource;
use anyhow::Resul... | code_fim | hard | {
"lang": "rust",
"repo": "jpJuni0r/WebGrid",
"path": "/core/src/services/orchestrator/core/jobs/slot_reclaim.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> local alive = ((not wasAlive) and managerAlive) or (wasAlive and nodeAlive)
if alive then
table.insert(inUse, slot)
else
table.insert(dead, slot)
... | code_fim | hard | {
"lang": "rust",
"repo": "jpJuni0r/WebGrid",
"path": "/core/src/services/orchestrator/core/jobs/slot_reclaim.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>// load_test_data(&mut con).await;
// let job = SlotReclaimJob::new();
// let (dead, orphaned) = job.reclaim_slots(&mut con, &"test").await.unwrap();
// assert_eq!(dead.len(), 2);
// assert!(dead.contains(&"slot3".to_string()));
// ... | code_fim | hard | {
"lang": "rust",
"repo": "jpJuni0r/WebGrid",
"path": "/core/src/services/orchestrator/core/jobs/slot_reclaim.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: djcsdy/wildflower-codec path: /src/decode/tags/actions/go_to_frame_2.rs
use crate::decode::bit_read::BitRead;
use crate::decode::read_ext::SwfTypesReadExt;
use std::io::Result;
<|fim_suffix|>impl GoToFrame2 {
pub fn read<R: BitRead>(reader: &mut R) -> Result<Self> {
reader.read_ub8(... | code_fim | medium | {
"lang": "rust",
"repo": "djcsdy/wildflower-codec",
"path": "/src/decode/tags/actions/go_to_frame_2.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl GoToFrame2 {
pub fn read<R: BitRead>(reader: &mut R) -> Result<Self> {
reader.read_ub8(6)?;
let scene_bias_flag = reader.read_bit()?;
let play = reader.read_bit()?;
let scene_bias = if scene_bias_flag {
reader.read_u16()?
} else {
0
... | code_fim | medium | {
"lang": "rust",
"repo": "djcsdy/wildflower-codec",
"path": "/src/decode/tags/actions/go_to_frame_2.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(
::std::mem::size_of::<__darwin_pthread_handler_rec>(),
24usize,
concat!("Size of: ", stringify!(__darwin_pthread_handler_rec))
);
assert_eq!(
::std::mem::align_of::<__darwin_pthread_handler_rec>(),
8usize,
concat!("Alignment of ", str... | code_fim | hard | {
"lang": "rust",
"repo": "MarkZuber/rpiled",
"path": "/rpiledbind/src/bindings.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> arg3: ::std::os::raw::c_int,
) -> ::std::os::raw::c_int,
>,
arg4: ::std::option::Option<
unsafe extern "C" fn(
arg1: *mut ::std::os::raw::c_void,
arg2: fpos_t,
arg3: ::std::os::raw::c_int,
) -> fpos_t,
... | code_fim | hard | {
"lang": "rust",
"repo": "MarkZuber/rpiled",
"path": "/rpiledbind/src/bindings.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: MarkZuber/rpiled path: /rpiledbind/src/bindings.rs
),
"::",
stringify!(__arg)
)
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<__darwin_pthread_handler_rec>())).__next as *const _ as usize
},
16usize,
concat!(
... | code_fim | hard | {
"lang": "rust",
"repo": "MarkZuber/rpiled",
"path": "/rpiledbind/src/bindings.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: 16yuki0702/rust-leetcode path: /src/lib.rs
}
}
}
// Relative Ranks
pub fn find_relative_ranks(nums: Vec<i32>) -> Vec<String> {
let (mut ns, mut m) = (nums.clone(), std::collections::HashMap::new());
ns.sort_by_key(|&n| -n);
ns.into_iter().enumerate().for_each(|(i, n)| {
... | code_fim | hard | {
"lang": "rust",
"repo": "16yuki0702/rust-leetcode",
"path": "/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> res.push(current.clone());
let mut i = 0;
while i < nums.len() {
current.push(nums[i]);
backtrack(&nums[i + 1..], current, res);
current.remove(current.len() - 1);
i += 1;
while i < nums.le... | code_fim | hard | {
"lang": "rust",
"repo": "16yuki0702/rust-leetcode",
"path": "/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> for (&map, &state) in board_map.map.iter() {
self.map.insert(map, state);
}
}
pub fn write(&self, path: String) {
let conn = Connection::open(path).unwrap();
conn.execute_batch("
CREATE TABLE IF NOT EXISTS boards (
board BLOB... | code_fim | hard | {
"lang": "rust",
"repo": "hakatashi/nine-grids-shogi-analyzer",
"path": "/src/BoardMap.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // TODO: リファクタリング
if result == BoardResult::Unknown {
self.map.insert(board, BoardState {
result: result,
depth: None,
routes: None,
is_good: None,
});
} else... | code_fim | hard | {
"lang": "rust",
"repo": "hakatashi/nine-grids-shogi-analyzer",
"path": "/src/BoardMap.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: hakatashi/nine-grids-shogi-analyzer path: /src/BoardMap.rs
extern crate fnv;
extern crate rusqlite;
use self::fnv::FnvHashMap;
use self::rusqlite::Connection;
use self::rusqlite::types::Null;
use self::rusqlite::params;
use ::Board::{Board, BoardResult};
use ::Piece::Piece;
use ::Grid::Grid;
#... | code_fim | hard | {
"lang": "rust",
"repo": "hakatashi/nine-grids-shogi-analyzer",
"path": "/src/BoardMap.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: songlinshu/BeagleRE path: /src/workspace.rs
use crate::memory::Layout;
use crate::architecture::Architecture;
<|fim_suffix|>impl Workspace {
pub fn new(arch: Box<Architecture>) -> Workspace {
Workspace {
memory: Layout::new(),
arch,
}
}
}<|fim_middle|>pub struct Workspace {
pub mem... | code_fim | medium | {
"lang": "rust",
"repo": "songlinshu/BeagleRE",
"path": "/src/workspace.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Workspace {
pub fn new(arch: Box<Architecture>) -> Workspace {
Workspace {
memory: Layout::new(),
arch,
}
}
}<|fim_prefix|>// repo: songlinshu/BeagleRE path: /src/workspace.rs
use crate::memory::Layout;
use crate::architecture::Architecture;
<|fim_middle|>pub struct Workspace {
pub mem... | code_fim | medium | {
"lang": "rust",
"repo": "songlinshu/BeagleRE",
"path": "/src/workspace.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[test]
fn getuid_test() {
let ctx = ffi::getuid_context();
ctx.expect()
.return_const(42u32);
getuid();
}<|fim_prefix|>// repo: gnoliyil/fuchsia path: /third_party/rust_crates/vendor/mockall-0.9.0/examples/ffi.rs
// vim: tw=80
//! An example of unit testing involving mocked FFI funct... | code_fim | medium | {
"lang": "rust",
"repo": "gnoliyil/fuchsia",
"path": "/third_party/rust_crates/vendor/mockall-0.9.0/examples/ffi.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: gnoliyil/fuchsia path: /third_party/rust_crates/vendor/mockall-0.9.0/examples/ffi.rs
// vim: tw=80
//! An example of unit testing involving mocked FFI functions
#![cfg(unix)]
#[cfg(test)]
use mockall::automock;
use mockall_double::double;
#[cfg_attr(test, automock)]
pub mod mockable_ffi {
... | code_fim | medium | {
"lang": "rust",
"repo": "gnoliyil/fuchsia",
"path": "/third_party/rust_crates/vendor/mockall-0.9.0/examples/ffi.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> unsafe { ffi::getuid() }
}
fn main() {
println!("My uid is {}", getuid() );
}
#[test]
fn getuid_test() {
let ctx = ffi::getuid_context();
ctx.expect()
.return_const(42u32);
getuid();
}<|fim_prefix|>// repo: gnoliyil/fuchsia path: /third_party/rust_crates/vendor/mockall-0.9.... | code_fim | medium | {
"lang": "rust",
"repo": "gnoliyil/fuchsia",
"path": "/third_party/rust_crates/vendor/mockall-0.9.0/examples/ffi.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ClemensFMN/RustStuff path: /basics/99-problems_1.rs
fn prob_1(vec: &Vec<i32>) -> Option<i32> {
let ind_last = vec.len();
match ind_last {
0 => None,
_ => Some(vec[ind_last-1]),
}
}
fn prob_6(vec1: &Vec<i32>, vec2: &Vec<i32>) -> bool {
if vec1.len() != vec2.len()... | code_fim | hard | {
"lang": "rust",
"repo": "ClemensFMN/RustStuff",
"path": "/basics/99-problems_1.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>
// find last element of a list
fn prob_1_test() {
let v1 = vec![1,2,3];
let res1 = prob_1(&v1);
println!("res1 = {:?}", res1);
let v2 = vec![];
let res2 = prob_1(&v2);
println!("res1 = {:?}", res2);
}
// not really problem 6, but check whether two vecs have the same elements
fn... | code_fim | hard | {
"lang": "rust",
"repo": "ClemensFMN/RustStuff",
"path": "/basics/99-problems_1.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>
// not really problem 6, but check whether two vecs have the same elements
fn prob_6_test() {
let v1 = vec![1,2,3];
let v2 = vec![1,2,3];
let v3 = vec![1,2];
let v4 = vec![1,2,6];
println!("v1, v2 = {}", prob_6(&v1, &v2));
println!("v1, v3 = {}", prob_6(&v1, &v3));
println!("... | code_fim | hard | {
"lang": "rust",
"repo": "ClemensFMN/RustStuff",
"path": "/basics/99-problems_1.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn map<U: 'static>(self, f: impl 'static + Fn(T) -> U) -> Stream<U> {
match self {
Stream::Empty => Stream::empty(),
Stream::Pair(a, d) => Stream::cons(f(a), d.map(f)),
Stream::Suspension(sup) => Stream::suspension(|| sup().map(f)),
}
}
}
im... | code_fim | hard | {
"lang": "rust",
"repo": "mbillingr/miniKANREN",
"path": "/rust-canonical/src/core/stream.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn append_map_inf(self, g: impl 'static + Clone + Goal<T>) -> Self {
match self {
Stream::Empty => Stream::Empty,
Stream::Pair(a, d) => Stream::append_inf(g.apply(a), d.append_map_inf(g)),
Stream::Suspension(sup) => Stream::suspension(|| sup().append_map... | code_fim | hard | {
"lang": "rust",
"repo": "mbillingr/miniKANREN",
"path": "/rust-canonical/src/core/stream.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mbillingr/miniKANREN path: /rust-canonical/src/core/stream.rs
//! Lazy stream implementation.
use crate::core::goal::Goal;
/// Possibly infinite sequence of values.
pub enum Stream<T> {
Empty,
Pair(T, Box<Stream<T>>),
Suspension(Box<dyn FnOnce() -> Stream<T>>),
}
impl<T> Stream<T>... | code_fim | hard | {
"lang": "rust",
"repo": "mbillingr/miniKANREN",
"path": "/rust-canonical/src/core/stream.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jay-tyler/rust_toy_raytracer path: /src/hitable.rs
use vectors::ThreeVector;
use rays::Ray;
use std::vec;
use sphere::Sphere;
use std::f64;
#[derive(Copy, Clone)]
pub struct HitRecord {
pub t: f64,
pub p: ThreeVector,
pub normal: ThreeVector,
}
pub trait Hitable {
fn hit(&self,... | code_fim | medium | {
"lang": "rust",
"repo": "jay-tyler/rust_toy_raytracer",
"path": "/src/hitable.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub struct HitableList {
pub list: vec::Vec<Sphere>
}
impl Hitable for HitableList {
fn hit(&self, r: &Ray,
t_min: f64, t_max: f64,
rec: &mut HitRecord) -> bool {
let mut temp_rec = HitRecord{
t: f64::MAX,
p: ThreeVector(f64::NAN,f64::NAN,f64:... | code_fim | medium | {
"lang": "rust",
"repo": "jay-tyler/rust_toy_raytracer",
"path": "/src/hitable.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> t_min: f64, t_max: f64,
rec: &mut HitRecord) -> bool {
let mut temp_rec = HitRecord{
t: f64::MAX,
p: ThreeVector(f64::NAN,f64::NAN,f64::NAN), //TODO: OK?
normal: ThreeVector(f64::NAN,f64::NAN,f64::NAN), //TODO: OK?
};
let mu... | code_fim | medium | {
"lang": "rust",
"repo": "jay-tyler/rust_toy_raytracer",
"path": "/src/hitable.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert!(user.is_some());
let user = user.unwrap();
user.set().name("Mike".into()).save().await.unwrap();
}<|fim_prefix|>// repo: pksunkara/reign path: /reign_derive/tests/ui/compile_fail/model_updateable_tag.rs
use reign::{model::diesel, prelude::*};
mod schema {
use reign::model::dies... | code_fim | hard | {
"lang": "rust",
"repo": "pksunkara/reign",
"path": "/reign_derive/tests/ui/compile_fail/model_updateable_tag.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let user = user.unwrap();
user.set().name("Mike".into()).save().await.unwrap();
}<|fim_prefix|>// repo: pksunkara/reign path: /reign_derive/tests/ui/compile_fail/model_updateable_tag.rs
use reign::{model::diesel, prelude::*};
mod schema {
use reign::model::diesel;
diesel::table! {
... | code_fim | medium | {
"lang": "rust",
"repo": "pksunkara/reign",
"path": "/reign_derive/tests/ui/compile_fail/model_updateable_tag.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: pksunkara/reign path: /reign_derive/tests/ui/compile_fail/model_updateable_tag.rs
use reign::{model::diesel, prelude::*};
mod schema {
use reign::model::diesel;
diesel::table! {
users (id) {
id -> Int4,
name -> Varchar,
}
}
}
<|fim_suffix|>#... | code_fim | medium | {
"lang": "rust",
"repo": "pksunkara/reign",
"path": "/reign_derive/tests/ui/compile_fail/model_updateable_tag.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: yutiansut/actix-server-alt path: /actix-service-alt/src/factory/then.rs
use core::future::Future;
use crate::service::then::ThenService;
use super::ServiceFactory;
pub struct ThenFactory<F1, F2> {
f1: F1,
f2: F2,
}
impl<F1, F2> ThenFactory<F1, F2> {
pub fn new(f1: F1, f2: F2) -> ... | code_fim | medium | {
"lang": "rust",
"repo": "yutiansut/actix-server-alt",
"path": "/actix-service-alt/src/factory/then.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl<F1, Req, F2> ServiceFactory<Req> for ThenFactory<F1, F2>
where
F1: ServiceFactory<Req>,
F1::Config: Clone,
F2: ServiceFactory<F1::Response, Config = F1::Config>,
F1::InitError: From<F2::InitError>,
F1::Error: From<F2::Error>,
{
type Response = F2::Response;
type Error = F... | code_fim | medium | {
"lang": "rust",
"repo": "yutiansut/actix-server-alt",
"path": "/actix-service-alt/src/factory/then.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let s1 = self.f1.new_service(cfg.clone());
let s2 = self.f2.new_service(cfg);
async move {
let s1 = s1.await?;
let s2 = s2.await?;
Ok(ThenService::new(s1, s2))
}
}
}<|fim_prefix|>// repo: yutiansut/actix-server-alt path: /actix-serv... | code_fim | hard | {
"lang": "rust",
"repo": "yutiansut/actix-server-alt",
"path": "/actix-service-alt/src/factory/then.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: faustfu/hello_rust path: /src/flows/macro3.rs
// 1. Prodedural macros could change token stream actively.
<|fim_suffix|> assert_eq!("hello from impl A".to_string(), A.a());
}
#[test]
fn test_foo() {
assert_eq!(foo(), "Hello, Rust!");
}<|fim_middle|>use hello_proc_macro::A;
use hello_proc_ma... | code_fim | hard | {
"lang": "rust",
"repo": "faustfu/hello_rust",
"path": "/src/flows/macro3.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>// case 2(use custom attribute to replace implementation of fn:foo)
#[attr_with_args("Hello, Rust!")]
fn foo() {}
#[test]
fn test_derive_a() {
assert_eq!("hello from impl A".to_string(), A.a());
}
#[test]
fn test_foo() {
assert_eq!(foo(), "Hello, Rust!");
}<|fim_prefix|>// repo: faustfu/hello_rust ... | code_fim | medium | {
"lang": "rust",
"repo": "faustfu/hello_rust",
"path": "/src/flows/macro3.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: evernym/indy-sdk path: /vcx/dummy-cloud-agent/build.rs
use std::env;
use std::fs;
use std::path::Path;
fn main() {
let target = env::var("TARGET").unwrap();
println!("target={}", target);
if target.find("-windows-").is_some() {
println!("cargo:rustc-link-lib=indy.dll");
... | code_fim | hard | {
"lang": "rust",
"repo": "evernym/indy-sdk",
"path": "/vcx/dummy-cloud-agent/build.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let files = vec!["indy.dll", "libeay32md.dll", "libsodium.dll", "libzmq.dll", "ssleay32md.dll"];
for f in files.iter() {
if let Ok(_) = fs::copy(&indy_dir.join(f), &dst.join(f)) {
println!("copy {} -> {}", &indy_dir.join(f).display(), &dst.join(f).display());
... | code_fim | hard | {
"lang": "rust",
"repo": "evernym/indy-sdk",
"path": "/vcx/dummy-cloud-agent/build.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let dst = output_dir.join("..\\..\\..");
println!("cargo:rustc-flags=-L {}", indy_dir.as_os_str().to_str().unwrap());
let files = vec!["indy.dll", "libeay32md.dll", "libsodium.dll", "libzmq.dll", "ssleay32md.dll"];
for f in files.iter() {
if let Ok(_) = fs::cop... | code_fim | hard | {
"lang": "rust",
"repo": "evernym/indy-sdk",
"path": "/vcx/dummy-cloud-agent/build.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: gloatoriginal/freshlinux path: /freshlinux/lib/intro.rs
pub fn intro() {
//intro
println!("Thank you for using the fresh installer, I bundled up programs/runtimes I like to install on new debian machines");
println!("Written by Gloat");
println!("***Warning works only wi<|fim_suf... | code_fim | hard | {
"lang": "rust",
"repo": "gloatoriginal/freshlinux",
"path": "/freshlinux/lib/intro.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>ame.len() <= 0 || literal_name.len() <= 0 {
println!("one of the text files has nothing in it->");
println!("common.txt: {}\napt_literal.txt: {}", common_name.len(), literal_name.len());
true
}
else if common_name.len() != literal_name.len() {
println!("apt text ... | code_fim | hard | {
"lang": "rust",
"repo": "gloatoriginal/freshlinux",
"path": "/freshlinux/lib/intro.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let _output = process::Command::new("shutdown")
.args(&["-h", "now"])
.output()
.expect("Failed to shutdown.");
}<|fim_prefix|>// repo: bendurston/rpi-shutdown-button path: /shutdown-button/src/main.rs
extern crate rust_gpiozero;
use std::process;
use std::env;
use... | code_fim | hard | {
"lang": "rust",
"repo": "bendurston/rpi-shutdown-button",
"path": "/shutdown-button/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: bendurston/rpi-shutdown-button path: /shutdown-button/src/main.rs
extern crate rust_gpiozero;
use std::process;
use std::env;
use std::{thread, time};
use rust_gpiozero::{Button, LED};
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() != 3 {
println!(... | code_fim | medium | {
"lang": "rust",
"repo": "bendurston/rpi-shutdown-button",
"path": "/shutdown-button/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> Button::wait_for_press(button, None);
}
fn shutdown() {
let _output = process::Command::new("shutdown")
.args(&["-h", "now"])
.output()
.expect("Failed to shutdown.");
}<|fim_prefix|>// repo: bendurston/rpi-shutdown-button path: /shutdown-button/src/main.rs
ex... | code_fim | medium | {
"lang": "rust",
"repo": "bendurston/rpi-shutdown-button",
"path": "/shutdown-button/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[derive(Debug, Clone, Insertable, Queryable)]
#[table_name = "props_fixed_treasure_chest_category_assets"]
pub struct NewPropsFixedTreasureChestCategoryAsset {
pub aid: i64,
pub item_id: i64,
pub sub_item_id: i64,
pub amounts: i32,
}<|fim_prefix|>// repo: LeJane/rust path: /v1/src/models... | code_fim | hard | {
"lang": "rust",
"repo": "LeJane/rust",
"path": "/v1/src/models/props_fixed_treasure_chest_category_assets.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: LeJane/rust path: /v1/src/models/props_fixed_treasure_chest_category_assets.rs
use crate::schema::props_fixed_treasure_chest_category_assets;
use chrono::NaiveDateTime;
use serde::{Serialize,Deserialize};
<|fim_suffix|>#[derive(Debug, Clone, Insertable, Queryable)]
#[table_name = "props_fixed_t... | code_fim | hard | {
"lang": "rust",
"repo": "LeJane/rust",
"path": "/v1/src/models/props_fixed_treasure_chest_category_assets.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: sjep/autopass path: /src/hash.rs
use crypto::digest::Digest;
use crypto::sha3::Sha3;
use crypto::sha2::Sha256;
use crypto::md5::Md5;
use serde::{Serialize, Deserialize};
#[derive(Debug)]
pub enum HashAlg {
MD5,
SHA256,
SHA3
}
#[derive(Deserialize, Serialize, Clone, Debug)]
pub enu... | code_fim | medium | {
"lang": "rust",
"repo": "sjep/autopass",
"path": "/src/hash.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn get_digest(hash_alg: HashAlg) -> Box<dyn Digest> {
match hash_alg {
HashAlg::MD5 => Box::new(Md5::new()),
HashAlg::SHA256 => Box::new(Sha256::new()),
HashAlg::SHA3 => Box::new(Sha3::sha3_256())
}
}<|fim_prefix|>// repo: sjep/autopass path: /src/hash.rs
use crypto::d... | code_fim | hard | {
"lang": "rust",
"repo": "sjep/autopass",
"path": "/src/hash.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: austinhyde/adventofcode20 path: /day4-passport-processing/src/main.rs
use std::collections::HashMap;
fn main() {
let input = include_str!("input.txt");
println!("Part 1 Answer: {}", part1(input));
// Correct answer: 170
println!("Part 2 Answer: {}", part2(input));
}
/** Part 1:... | code_fim | hard | {
"lang": "rust",
"repo": "austinhyde/adventofcode20",
"path": "/day4-passport-processing/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let input = include_str!("example1.txt");
let expected = 2;
assert_eq!(expected, part1(input));
}
#[test]
fn part2_example1() {
let input = include_str!("example1.txt");
let expected = 0;
assert_eq!(expected, part2(input));
}
}<|fim_prefix|>... | code_fim | hard | {
"lang": "rust",
"repo": "austinhyde/adventofcode20",
"path": "/day4-passport-processing/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: gregokent/tms570 path: /src/dcan4/if3upd56/mod.rs
Returns `true` if the bit is clear (0)"]
#[inline]
pub fn bit_is_clear(&self) -> bool {
!self.bit()
}
#[doc = r" Returns `true` if the bit is set (1)"]
#[inline]
pub fn bit_is_set(&self) -> bool {
self.bit... | code_fim | hard | {
"lang": "rust",
"repo": "gregokent/tms570",
"path": "/src/dcan4/if3upd56/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: gregokent/tms570 path: /src/dcan4/if3upd56/mod.rs
pub struct IF3UPDEN92R {
bits: bool,
}
impl IF3UPDEN92R {
#[doc = r" Value of the field as raw bits"]
#[inline]
pub fn bit(&self) -> bool {
self.bits
}
#[doc = r" Returns `true` if the bit is clear (0)"]
#[inli... | code_fim | hard | {
"lang": "rust",
"repo": "gregokent/tms570",
"path": "/src/dcan4/if3upd56/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>ate Enabled for Message Object 69"]
#[inline]
pub fn if3upden69(&self) -> IF3UPDEN69R {
let bits = {
const MASK: bool = true;
const OFFSET: u8 = 4;
((self.bits >> OFFSET) & MASK as u32) != 0
};
IF3UPDEN69R { bits }
}
#[doc = "Bit ... | code_fim | hard | {
"lang": "rust",
"repo": "gregokent/tms570",
"path": "/src/dcan4/if3upd56/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: TGElder/rust path: /isometric/src/engine.rs
use std::sync::Arc;
use commons::async_channel::{unbounded, Receiver, Sender, TryRecvError};
use coords::*;
use cursor_handler::*;
use event_handlers::*;
use events::{EventConsumer, EventHandler, EventHandlerAdapter};
use glutin::event_loop::ControlFl... | code_fim | hard | {
"lang": "rust",
"repo": "TGElder/rust",
"path": "/isometric/src/engine.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn command_tx(&self) -> Sender<Vec<Command>> {
self.command_tx.clone()
}
pub fn add_event_consumer<T>(&mut self, event_consumer: T)
where
T: EventConsumer + 'static,
{
self.event_consumers.push(Box::new(event_consumer));
}
pub fn add_event_handler<... | code_fim | hard | {
"lang": "rust",
"repo": "TGElder/rust",
"path": "/isometric/src/engine.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> TermLogger::init(
self.get_level_filter(),
Config::default(),
TerminalMode::Mixed,
)
.unwrap_or(());
}
}
/// This trait is designed to provide a rude form of default value for options
/// If an option doesn't have a default value, it will im... | code_fim | hard | {
"lang": "rust",
"repo": "pizzamig/structopt-flags",
"path": "/src/lib.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: pizzamig/structopt-flags path: /src/lib.rs
//! `structopt-flags` is a collection of reusable CLI flags and options
//! based on structopt
//!
//! Every flag or option is already pre-configured and can be used marking the field as `flatten`
//!
//! # Verbosity
//! Currently, a set of verbosity fl... | code_fim | hard | {
"lang": "rust",
"repo": "pizzamig/structopt-flags",
"path": "/src/lib.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// When to publish the animation.
///
/// If [`Some`] publish the animation according to the `Publish`. Otherwise, don't publish it.
pub publish_at: Option<Publish>,
/// What kind of animation this is.
pub variant: AnimationKind,
/// Should the animation loop?
pub is_loo... | code_fim | hard | {
"lang": "rust",
"repo": "NaomiLea/ji-cloud",
"path": "/shared/rust/src/domain/animation.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: NaomiLea/ji-cloud path: /shared/rust/src/domain/animation.rs
//! Types for animations.
use chrono::{DateTime, Utc};
#[cfg(feature = "backend")]
use paperclip::actix::Apiv2Schema;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::Publish;
/// Animation Variants
#[derive(Debug, Co... | code_fim | hard | {
"lang": "rust",
"repo": "NaomiLea/ji-cloud",
"path": "/shared/rust/src/domain/animation.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: DoNotDoughnut/voxel-rs path: /network/tests/common/mod.rs
use super::SocketAddr;
use rand::{
distributions::{Distribution, Uniform},
thread_rng,
};
use std::collections::{BinaryHeap, HashMap};
use std::sync::Mutex;
use std::time::{Duration, Instant};
use voxel_rs_network::Socket;
lazy_s... | code_fim | hard | {
"lang": "rust",
"repo": "DoNotDoughnut/voxel-rs",
"path": "/network/tests/common/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut map = PACKET_QUEUES.lock().unwrap();
if let Some(packet_queue) = map.get_mut(&self.addr) {
if let Some(next_message) = packet_queue.peek_mut() {
if next_message.arrival_time < Instant::now() {
return {
let msg ... | code_fim | hard | {
"lang": "rust",
"repo": "DoNotDoughnut/voxel-rs",
"path": "/network/tests/common/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: AuroransSolis/officer_velvet path: /src/help.rs
#![allow(clippy::unreadable_literal)]
use crate::{
gulag::GulagApp,
misc::{escape_formatting, get_help_msg, is_administrator},
release::ReleaseSearchCriteriumApp,
tasks::{
date_conditional_task::DateConditionalTask, message... | code_fim | hard | {
"lang": "rust",
"repo": "AuroransSolis/officer_velvet",
"path": "/src/help.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[command]
pub async fn help(ctx: &Context, message: &Message) -> CommandResult {
println!("HL | Start handling help command.");
let start = Instant::now();
let trimmed_content = message.content.trim_start_matches("=>help").trim();
let icon_url = ctx.http.get_current_user().await?.avatar_u... | code_fim | hard | {
"lang": "rust",
"repo": "AuroransSolis/officer_velvet",
"path": "/src/help.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> 0x0B => ops.dec16(BC),
0x1B => ops.dec16(DE),
0x2B => ops.dec16(HL),
0x3B => ops.dec16(SP),
// misc
0x27 => ops.daa(),
0x2F => ops.cpl(),
0x3F => ops.ccf(),
0x37 => ops.scf(),
0x00 => ops.nop(),
0x76 => ops.halt(),
... | code_fim | hard | {
"lang": "rust",
"repo": "kcsongor/gbc-emulator",
"path": "/src/cpu/ops.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: kcsongor/gbc-emulator path: /src/cpu/ops.rs
);
fn load16_hlsp(&mut self, offset: i8); // Load SP + n into HL
fn push<I: In16>(&mut self, i: I);
fn pop<O: Out16>(&mut self, o: O);
// 8-bit arithmetic
fn add<I: In8>(&mut self, i: I);
fn adc<I: In8>(&mut self, i: I);
fn ... | code_fim | hard | {
"lang": "rust",
"repo": "kcsongor/gbc-emulator",
"path": "/src/cpu/ops.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> 0x3A => println!("warning: Unimplemented LDD A, (HL)"),
0x32 => println!("warning: Unimplemented LDD (HL), A"),
0x2A => println!("warning: Unimplemented LDI A, (HL)"),
0x22 => println!("warning: Unimplemented LDI (HL), A"),
0xE0 => op2!(ops, load, A, Indirec... | code_fim | hard | {
"lang": "rust",
"repo": "kcsongor/gbc-emulator",
"path": "/src/cpu/ops.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl<'a> EntryGen<'a> {
pub fn new(asto: &'a AstObjects, tco: &'a TCObjects, bk: IdentKey) -> EntryGen<'a> {
EntryGen {
objects: Box::pin(VMObjects::new()),
ast_objs: asto,
tc_objs: tco,
dummy_gcv: GcoVec::new(),
packages: Vec::new(),... | code_fim | hard | {
"lang": "rust",
"repo": "geometryolife/goscript",
"path": "/codegen/src/entry.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: geometryolife/goscript path: /codegen/src/entry.rs
#![allow(dead_code)]
use super::codegen::CodeGen;
use super::emit::{CallStyle, Emitter};
use super::interface::IfaceMapping;
use super::package::PkgVarPairs;
use super::types::TypeCache;
use goscript_parser::ast::Ident;
use goscript_parser::erro... | code_fim | hard | {
"lang": "rust",
"repo": "geometryolife/goscript",
"path": "/codegen/src/entry.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn parse_check_gen(
path: &str,
config: &Config,
fset: &mut FileSet,
el: &ErrorList,
) -> Result<ByteCode, usize> {
let asto = &mut AstObjects::new();
let tco = &mut goscript_types::TCObjects::new();
let results = &mut HashMap::new();
let pkgs = &mut HashMap::new();
... | code_fim | hard | {
"lang": "rust",
"repo": "geometryolife/goscript",
"path": "/codegen/src/entry.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut getters = Vec::new();
for _ in 0..4 {
let manager_clone = manager.clone();
let stop_clone = stop.clone();
let t = thread::spawn(move || {
let mut last_si = 0;
while !stop_clone.load(Ordering::Relaxed) {
... | code_fim | hard | {
"lang": "rust",
"repo": "alibaba/GraphScope",
"path": "/interactive_engine/executor/store/groot/src/db/graph/table_manager.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: alibaba/GraphScope path: /interactive_engine/executor/store/groot/src/db/graph/table_manager.rs
#![allow(dead_code)]
use super::version::*;
use crate::db::api::*;
use crate::db::common::bytes::util::{UnsafeBytesReader, UnsafeBytesWriter};
pub type TableId = i64;
/// Every type has a table mana... | code_fim | hard | {
"lang": "rust",
"repo": "alibaba/GraphScope",
"path": "/interactive_engine/executor/store/groot/src/db/graph/table_manager.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn test_simple_table_manager() {
let manager = TableManager::new();
assert!(manager.add(-1, 100).is_err());
assert!(manager.add(0, 100).is_err());
for i in 1..=100 {
manager.add(i, i as TableId).unwrap();
}
assert_eq!(manager.size... | code_fim | hard | {
"lang": "rust",
"repo": "alibaba/GraphScope",
"path": "/interactive_engine/executor/store/groot/src/db/graph/table_manager.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> match (t1.clone(),t2.clone()){
(None,None)|(_,None)=>(),
(None,t2)=>{
*t1=t2.clone();
},
(Some(t1),Some(t2))=>{
let mut t1=t1.borrow_mut();
t1.val+=t2.borrow().val;
... | code_fim | hard | {
"lang": "rust",
"repo": "peanut996/Leetcode",
"path": "/Rust/src/617. Merge Two Binary Trees.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: peanut996/Leetcode path: /Rust/src/617. Merge Two Binary Trees.rs
/*617. Merge Two Binary Trees
给定两个二叉树,想象当你将它们中的一个覆盖到另一个上时,两个二叉树的一些节点便会重叠。
你需要将他们合并为一个新的二叉树。合并的规则是如果两个节点重叠,那么将他们的值相加作为节点合并后的新值,否则不为 NULL 的节点将直接作为新二叉树的节点。
输入:
Tree 1 Tree 2
1 ... | code_fim | hard | {
"lang": "rust",
"repo": "peanut996/Leetcode",
"path": "/Rust/src/617. Merge Two Binary Trees.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn listen(addr: &SocketAddr) -> Result<Self, io::Error> {
let listener = mio::net::TcpListener::bind(addr)?;
Ok(Self::new(listener.accept()?.0))
}
pub fn local_addr(&self) -> Result<SocketAddr, io::Error> {
self.stream.get_ref().get_ref().local_addr()
}
pu... | code_fim | hard | {
"lang": "rust",
"repo": "JustusAdam/noria",
"path": "/noria/src/channel/rpc.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: JustusAdam/noria path: /noria/src/channel/rpc.rs
use super::tcp::{SendError, TryRecvError};
use super::{DeserializeReceiver, NonBlockingWriter, ReceiveError};
use bincode;
use bufstream::BufStream;
use byteorder::{NetworkEndian, WriteBytesExt};
use mio::{self, Evented, Poll, PollOpt, Ready, Toke... | code_fim | hard | {
"lang": "rust",
"repo": "JustusAdam/noria",
"path": "/noria/src/channel/rpc.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> Self {
n,
count: 0,
discount,
p2p: products.into_iter().zip(prices.into_iter()).collect()
}
}
fn get_bill(&mut self, product: Vec<i32>, amount: Vec<i32>) -> f64 {
self.count += 1;
let mut bill: f64 = product.iter(... | code_fim | hard | {
"lang": "rust",
"repo": "gKevinK/LeetCode",
"path": "/1357_Apply_Discount_Every_n_Orders.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.count += 1;
let mut bill: f64 = product.iter().zip(amount.iter()).map(|(p, a)| {
*self.p2p.get(p).unwrap() as f64 * *a as f64
}).sum();
if self.count == self.n {
self.count = 0;
bill = (bill * (100 - self.discount) as f64).round() / ... | code_fim | hard | {
"lang": "rust",
"repo": "gKevinK/LeetCode",
"path": "/1357_Apply_Discount_Every_n_Orders.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: gKevinK/LeetCode path: /1357_Apply_Discount_Every_n_Orders.rs
struct Cashier {
n: i32,
count: i32,
discount: i32,
p2p: std::collections::HashMap<i32, i32>,
}
<|fim_suffix|> Self {
n,
count: 0,
discount,
p2p: products.into_it... | code_fim | hard | {
"lang": "rust",
"repo": "gKevinK/LeetCode",
"path": "/1357_Apply_Discount_Every_n_Orders.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Solution {
pub fn to_lower_case(str: String) -> String {
str.to_lowercase()
}
}<|fim_prefix|>// repo: szhongren/leetcode path: /709/main.rs
fn main() {
println!(
"{:?}",
Solution::to_lower_case("Hello".to_string())
);
println!(
"{:?}",
... | code_fim | easy | {
"lang": "rust",
"repo": "szhongren/leetcode",
"path": "/709/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: szhongren/leetcode path: /709/main.rs
fn main() {
println!(
"{:?}",
Solution::to_lower_case("Hello".to_string())
);
println!(
"{:?}",
Solution::to_lower_case("here".to_string())
);
println!(
"{:?}",
Solution::to_lower... | code_fim | easy | {
"lang": "rust",
"repo": "szhongren/leetcode",
"path": "/709/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> item = Vec::new();
}
}
if group.iter().any(|items| {
items.len() > 5 || (items.len() == 5 && *items.get(0).unwrap_or(&0xFF) > HIGH_BYTE_MAX)
})
{
Err("overflow u32 ")
} else {
Ok(
group... | code_fim | hard | {
"lang": "rust",
"repo": "billnote/rust-exercism",
"path": "/variable-length-quantity/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> acc
});
result
}
/// Given a stream of bytes, extract all numbers which are encoded in there.
pub fn from_bytes(bytes: &[u8]) -> Result<Vec<u32>, &'static str> {
if bytes[bytes.len() - 1] >= FLAG {
return Err("error byte.");
} else {
let mut group: Vec<Vec<u8>> = ... | code_fim | hard | {
"lang": "rust",
"repo": "billnote/rust-exercism",
"path": "/variable-length-quantity/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: billnote/rust-exercism path: /variable-length-quantity/src/lib.rs
/// Convert a list of numbers to a stream of bytes encoded with variable length encoding.
const FLAG: u8 = 0x80;
const HIGH_BYTE_MAX: u8 = 0x0F;
const VLQ_PAIR: &'static [(u32, usize)] = &[
(0xF0000000, 28),
(0xFE00000, 21... | code_fim | hard | {
"lang": "rust",
"repo": "billnote/rust-exercism",
"path": "/variable-length-quantity/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> for (n, xs) in h {
for x in xs {
m.insert(x.to_lowercase().next().unwrap(), *n);
}
}
m
}<|fim_prefix|>// repo: prakhar1989/exercism path: /rust/etl/src/lib.rs
use std::collections::BTreeMap;
<|fim_middle|>pub fn transform(h: &BTreeMap<i32, Vec<char>>) -> BTreeMap... | code_fim | medium | {
"lang": "rust",
"repo": "prakhar1989/exercism",
"path": "/rust/etl/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: prakhar1989/exercism path: /rust/etl/src/lib.rs
use std::collections::BTreeMap;
<|fim_suffix|> for (n, xs) in h {
for x in xs {
m.insert(x.to_lowercase().next().unwrap(), *n);
}
}
m
}<|fim_middle|>pub fn transform(h: &BTreeMap<i32, Vec<char>>) -> BTreeMap... | code_fim | medium | {
"lang": "rust",
"repo": "prakhar1989/exercism",
"path": "/rust/etl/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: plugblockchain/plug-blockchain path: /prml/attestation/src/mock.rs
// Copyright 2019-2020
// by Centrality Investments Ltd.
// and Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
// it under the terms... | code_fim | hard | {
"lang": "rust",
"repo": "plugblockchain/plug-blockchain",
"path": "/prml/attestation/src/mock.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Module, ... | code_fim | hard | {
"lang": "rust",
"repo": "plugblockchain/plug-blockchain",
"path": "/prml/attestation/src/mock.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mikialex/rendiation path: /utils/reactive/src/signal_stream.rs
rt is actually
// polled inactively.
let waker = futures::task::noop_waker_ref();
let mut cx = Context::from_waker(waker);
do_updates_by(stream, &mut cx, on_update)
}
pub fn do_updates_by<T: Stream + Unpin>(
stream: &mut T... | code_fim | hard | {
"lang": "rust",
"repo": "mikialex/rendiation",
"path": "/utils/reactive/src/signal_stream.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> send.unbounded_send(10).unwrap();
send.unbounded_send(3).unwrap();
send.unbounded_send(31).unwrap();
let waker = futures::task::noop_waker_ref();
let mut cx = Context::from_waker(waker);
let r = c.poll_next_unpin(&mut cx);
assert_eq!(r, Poll::Ready(Some(10)));
assert_eq!(front, 3);
ass... | code_fim | hard | {
"lang": "rust",
"repo": "mikialex/rendiation",
"path": "/utils/reactive/src/signal_stream.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl<S, F, X> Stream for FilterMapSync<S, F>
where
S: Stream,
F: FnMut(S::Item) -> Option<X>,
{
type Item = X;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
let mut this = self.project();
loop {
if let Poll::Ready(v) = this.inner.as_mut().poll_ne... | code_fim | hard | {
"lang": "rust",
"repo": "mikialex/rendiation",
"path": "/utils/reactive/src/signal_stream.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jyn514/rust path: /library/std/src/sys/unix/thread_parker/netbsd.rs
use crate::ffi::{c_int, c_void};
use crate::pin::Pin;
use crate::ptr::{null, null_mut};
use crate::sync::atomic::{
AtomicU64,
Ordering::{Acquire, Relaxed, Release},
};
use crate::time::Duration;
use libc::{_lwp_self, clo... | code_fim | hard | {
"lang": "rust",
"repo": "jyn514/rust",
"path": "/library/std/src/sys/unix/thread_parker/netbsd.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.