text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_prefix|>// repo: felixzhuologist/wasm-gba path: /src/cpu/arm/mul_long.rs
use ::cpu::CPU;
use ::cpu::arm::mul::mul_cycle_time;
use ::util;
/// The multiply and multiply-accumulate instructions perform integer multiplication
/// on the contents of two registers Rm and Rs and stores the lower 32 bits of the
/// re... | code_fim | hard | {
"lang": "rust",
"repo": "felixzhuologist/wasm-gba",
"path": "/src/cpu/arm/mul_long.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mul = MultiplyLong::parse_instruction(
0b0000_00001_1_1_1_0001_0010_0011_1001_1000);
assert!(mul.is_signed);
assert!(mul.accumulate);
assert!(mul.set_flags);
assert_eq!(mul.rdhi, 1);
assert_eq!(mul.rdlo, 2);
assert_eq!(mul.rs, 3);
... | code_fim | hard | {
"lang": "rust",
"repo": "felixzhuologist/wasm-gba",
"path": "/src/cpu/arm/mul_long.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>where P: ::pool::ParserPool
{
do_parse!(input,string_1: call!(::common::shortstr) >>
string_2: call!(::common::longstr) >>
operation: be_u8 >>
(::primitives::amqp8_0::test::String::new(string_1, string_2, operation))
) // do_parse!
} // fn nom_bytes
} // impl NomBytes
impl<'a> ::NomBytes<'a> for ::primit... | code_fim | hard | {
"lang": "rust",
"repo": "jbelke/amqp-rs",
"path": "/amqp0/parser-nom/pregen/amqp8_0.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jbelke/amqp-rs path: /amqp0/parser-nom/pregen/amqp8_0.rs
// fn nom_bytes
} // impl NomBytes
impl<'a> ::NomBytes<'a> for ::primitives::amqp8_0::queue::PurgeOk {
type Output = Self;
fn nom_bytes<'b, P>(input: &'a [u8], _: &'b mut P) -> IResult<&'a [u8], Self>
where P: ::pool::ParserPool
{
do_par... | code_fim | hard | {
"lang": "rust",
"repo": "jbelke/amqp-rs",
"path": "/amqp0/parser-nom/pregen/amqp8_0.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>where P: ::pool::ParserPool
{
do_parse!(input,(::primitives::amqp8_0::exchange::DeclareOk::new())
) // do_parse!
} // fn nom_bytes
} // impl NomBytes
impl<'a> ::NomBytes<'a> for ::primitives::amqp8_0::exchange::Delete<'a> {
type Output = Self;
fn nom_bytes<'b, P>(input: &'a [u8], _: &'b mut P) -> IResult... | code_fim | hard | {
"lang": "rust",
"repo": "jbelke/amqp-rs",
"path": "/amqp0/parser-nom/pregen/amqp8_0.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>
pub fn run_fn() {
println!("-------------------- {} --------------------", file!());
let m_op = make_movement_energy_operator_cps(Box::new(dump_state));
m_op(12);
m_op(12);
m_op(0);
let energies: Vec<u32> = vec![12, 12, 0];
let energy_states: Vec<Vehicle> = move_over(energies... | code_fim | hard | {
"lang": "rust",
"repo": "artur-augustyniak/rust_design_pattern",
"path": "/facade/src/fn_facade.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>
fn move_over(energies: Vec<u32>, clbk: Box<Fn(&Vehicle) -> ()>) -> Box<Iterator<Item=Vehicle>>
{
Box::new(
energies.into_iter().map(move |energy: u32| {
let torque_eq = |rpm: u32| -> u32 { rpm * 1000 };
let v = move_vehicle(energy, torque_eq);
clbk(&v);
... | code_fim | hard | {
"lang": "rust",
"repo": "artur-augustyniak/rust_design_pattern",
"path": "/facade/src/fn_facade.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: artur-augustyniak/rust_design_pattern path: /facade/src/fn_facade.rs
use std::fmt::Display;
const TORQUE_START_THRESHOLD: u32 = 1000;
#[derive(Debug)]
pub enum Vehicle {
Running,
Stopped
}
fn move_vehicle<T, F>(rpm: T, torque_eq: F) -> Vehicle where F: Fn(T) -> u32, T: Display + Copy... | code_fim | hard | {
"lang": "rust",
"repo": "artur-augustyniak/rust_design_pattern",
"path": "/facade/src/fn_facade.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> config.define("ZSTD_LEGACY_SUPPORT", Some("1"));
// Compile!
config.compile("libzstd.a");
}<|fim_prefix|>// repo: maximelenoir/zstd-rs path: /src/build.rs
extern crate gcc;
extern crate glob;
fn main() {
let mut config = gcc::Config::new();
let globs = &["zstd/lib/common/*.c",
... | code_fim | hard | {
"lang": "rust",
"repo": "maximelenoir/zstd-rs",
"path": "/src/build.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: maximelenoir/zstd-rs path: /src/build.rs
extern crate gcc;
extern crate glob;
fn main() {
let mut config = gcc::Config::new();
<|fim_suffix|> config.define("ZSTD_LEGACY_SUPPORT", Some("1"));
// Compile!
config.compile("libzstd.a");
}<|fim_middle|> let globs = &["zstd/lib/com... | code_fim | hard | {
"lang": "rust",
"repo": "maximelenoir/zstd-rs",
"path": "/src/build.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> loop {
// First get the current identifier/guard.
let (current_identifier, current_guard) = {
let entry = insert_path
.last()
.expect("insert path must never be empty as we descend");
let current_identifier = entry.current_node_identifier().clone();
let current_... | code_fim | hard | {
"lang": "rust",
"repo": "ruggeri/nedbase",
"path": "/src/btree/insertion/descend_toward_key.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ruggeri/nedbase path: /src/btree/insertion/descend_toward_key.rs
use super::InsertPathEntry;
use locking::LockSet;
use node::{Node, TraversalDirection};
#[derive(Clone, Copy, Eq, PartialEq)]
pub enum DescentDecision {
ContinueDescending,
StopEarly,
}
// Descends toward the key. We may stop... | code_fim | hard | {
"lang": "rust",
"repo": "ruggeri/nedbase",
"path": "/src/btree/insertion/descend_toward_key.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ecsumed/rust-tetris path: /src/canvas.rs
use stdweb::traits::*;
use stdweb::unstable::TryInto;
use stdweb::web::html_element::CanvasElement;
use stdweb::web::{document, CanvasRenderingContext2d};
pub struct Canvas {
pub canvas: CanvasElement,
pub ctx: CanvasRenderingContext2d,
width... | code_fim | hard | {
"lang": "rust",
"repo": "ecsumed/rust-tetris",
"path": "/src/canvas.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn clear(&self) {
self.ctx.set_fill_style_color("white");
self.ctx.fill_rect(
0.0,
0.0,
f64::from(self.canvas.width()),
f64::from(self.canvas.height()),
);
}
}<|fim_prefix|>// repo: ecsumed/rust-tetris path: /src/canvas.r... | code_fim | hard | {
"lang": "rust",
"repo": "ecsumed/rust-tetris",
"path": "/src/canvas.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> Ok(())
}
async fn test_persistent_subscription(client: &Client) -> Result<(), Box<dyn Error>> {
let stream_id = fresh_stream_id("persistent_subscription");
let events = generate_events("es6-persistent-subscription-test".to_string(), 5);
client
.create_persistent_subscription(stre... | code_fim | hard | {
"lang": "rust",
"repo": "CengizGumus35/EventStoreDB-Client-Rust",
"path": "/tests/integration.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: CengizGumus35/EventStoreDB-Client-Rust path: /tests/integration.rs
#[macro_use]
extern crate log;
#[macro_use]
extern crate serde_json;
mod images;
use eventstore::{
Client, ClientSettings, EventData, PersistentSubscriptionOptions,
PersistentSubscriptionSettings, Single,
};
use futures... | code_fim | hard | {
"lang": "rust",
"repo": "CengizGumus35/EventStoreDB-Client-Rust",
"path": "/tests/integration.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let max = 10usize;
let handle = tokio::spawn(async move {
let mut count = 0usize;
while let Some(event) = read.try_next().await.unwrap() {
if let eventstore::SubEvent::EventAppeared(event) = event {
write.ack_event(event).await.unwrap();
... | code_fim | hard | {
"lang": "rust",
"repo": "CengizGumus35/EventStoreDB-Client-Rust",
"path": "/tests/integration.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: EFanZh/LeetCode path: /src/problem_0871_minimum_number_of_refueling_stops/greedy.rs
pub struct Solution;
// ------------------------------------------------------ snip ------------------------------------------------------ //
use std::collections::BinaryHeap;
use std::convert::TryInto;
impl S... | code_fim | medium | {
"lang": "rust",
"repo": "EFanZh/LeetCode",
"path": "/src/problem_0871_minimum_number_of_refueling_stops/greedy.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>/lib/gzip_compress.c")
.include("libdeflate/")
.include("libdeflate/lib/")
.include("libdeflate/common/")
.warnings(false)
.compile("libdeflate");
}<|fim_prefix|>// repo: IzumiRaine/libdeflater path: /build.rs
extern crate cc;
fn main() {
cc::Build::new()
... | code_fim | medium | {
"lang": "rust",
"repo": "IzumiRaine/libdeflater",
"path": "/build.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: IzumiRaine/libdeflater path: /build.rs
extern crate cc;
fn main() {
cc::Build::new()
.file("libdeflate/lib/aligned_malloc.c")
.file("libdeflate/lib/deflate_decompress.c")
.file("libdeflate/lib/arm/<|fim_suffix|>lib/zlib_decompress.c")
.file("libdeflate/lib/zl... | code_fim | medium | {
"lang": "rust",
"repo": "IzumiRaine/libdeflater",
"path": "/build.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ToonSpin/advent-of-code-2018-rust path: /src/bin/day24.rs
use std::io;
use std::io::prelude::*;
extern crate nom;
use nom::{
branch::alt,
bytes::complete::{is_not, tag},
character::complete::{alpha1, char as parse_char, digit1},
combinator::{map, map_res, opt},
IResult,
... | code_fim | hard | {
"lang": "rust",
"repo": "ToonSpin/advent-of-code-2018-rust",
"path": "/src/bin/day24.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> get_group_counts(&groups)
}
fn main() -> io::Result<()> {
let mut input = String::new();
io::stdin().lock().read_to_string(&mut input).unwrap();
let input = &input[..];
let groups = get_groups_from_input(input);
let (_found_immune_system, found_infection) = units_left_after_battl... | code_fim | hard | {
"lang": "rust",
"repo": "ToonSpin/advent-of-code-2018-rust",
"path": "/src/bin/day24.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // -------------------------------------------------------- ATTACK PHASE
groups.sort_unstable_by(|a, b| a.initiative.cmp(&b.initiative).reverse());
let attack_order: Vec<usize> = groups.iter().map(|g| g.id).collect();
let mut kills = 0;
for attacker_id in attack_ord... | code_fim | hard | {
"lang": "rust",
"repo": "ToonSpin/advent-of-code-2018-rust",
"path": "/src/bin/day24.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> logger::init(log_level);
let mut interpreter = Interpreter::new();
interpreter.load_program_file(&mut File::open(file_name).expect("Could not open file"));
sdl2::for_interpreter(&mut interpreter, step_mode).expect("Error!");
}<|fim_prefix|>// repo: alex0809/chip8-rust path: /src/main.rs
... | code_fim | hard | {
"lang": "rust",
"repo": "alex0809/chip8-rust",
"path": "/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: alex0809/chip8-rust path: /src/main.rs
use std::fs::File;
use crate::interpreter::Interpreter;
use clap::{App, Arg};
use log::LevelFilter;
mod config;
mod instruction;
mod interpreter;
mod logger;
mod sdl2;
fn main() {
<|fim_suffix|> logger::init(log_level);
let mut interpreter = Inte... | code_fim | hard | {
"lang": "rust",
"repo": "alex0809/chip8-rust",
"path": "/src/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: pgoreutn/rust-server-example path: /src/db/src/users/query.rs
use super::mapper::*;
use chrono::{NaiveDateTime, Utc};
use sqlx::PgConnection;
pub async fn exists_with_email(conn: &mut PgConnection, email: &str) -> crate::Result<bool> {
struct Returning {
count: i64,
}
<|fim_suf... | code_fim | hard | {
"lang": "rust",
"repo": "pgoreutn/rust-server-example",
"path": "/src/db/src/users/query.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub async fn insert(
conn: &mut PgConnection,
new_user: &NewUser<'_>,
) -> crate::Result<(i64, NaiveDateTime)> {
let created_at = Utc::now().naive_utc();
struct Returning {
id: i64,
}
let r = sqlx::query_as!(
Returning,
r#"
INSERT INTO users
(
... | code_fim | hard | {
"lang": "rust",
"repo": "pgoreutn/rust-server-example",
"path": "/src/db/src/users/query.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> Ok((r.id, created_at))
}
pub async fn find_by_email(conn: &mut PgConnection, email: &str) -> crate::Result<User> {
sqlx::query_as!(User, r#"SELECT * FROM users where email = $1"#, email)
.fetch_one(conn)
.await
}
pub async fn find_by_id(conn: &mut PgConnection, id: i64) -> crate:... | code_fim | hard | {
"lang": "rust",
"repo": "pgoreutn/rust-server-example",
"path": "/src/db/src/users/query.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> if number < 0 {
return -number;
}
number
}<|fim_prefix|>// repo: mida-hub/hobby path: /practice/rust/011_020/020_function_2.rs
fn main() {
let mut x1 = 1;
println!("x1 = {}", x1);
x1 = abs(x1);
println!("abs(x1) = {}", x1);
let mut x2 = -1;
println!("x2 = {}", ... | code_fim | easy | {
"lang": "rust",
"repo": "mida-hub/hobby",
"path": "/practice/rust/011_020/020_function_2.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mida-hub/hobby path: /practice/rust/011_020/020_function_2.rs
fn main() {
let mut x1 = 1;
println!("x1 = {}", x1);
x1 = abs(x1);
println!("abs(x1) = {}", x1);
let mut x2 = -1;
println!("x2 = {}", x2);
x2 = abs(x2);
println!("abs(x2) = {}", x2);
}
<|fim_suffix|> ... | code_fim | easy | {
"lang": "rust",
"repo": "mida-hub/hobby",
"path": "/practice/rust/011_020/020_function_2.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: foxfriends/git-project path: /src/commands/hook/pre_commit.rs
use std::error::Error;
use std::fs::File;
use crate::PROJECT_TEMP_FILE;
pub fn pre_com<|fim_suffix|>le::create(PROJECT_TEMP_FILE)?;
Ok(())
}<|fim_middle|>mit() -> Result<(), Box<dyn Error>> {
Fi | code_fim | easy | {
"lang": "rust",
"repo": "foxfriends/git-project",
"path": "/src/commands/hook/pre_commit.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>mit() -> Result<(), Box<dyn Error>> {
File::create(PROJECT_TEMP_FILE)?;
Ok(())
}<|fim_prefix|>// repo: foxfriends/git-project path: /src/commands/hook/pre_commit.rs
use std::error::Error;
use std::fs::File;
u<|fim_middle|>se crate::PROJECT_TEMP_FILE;
pub fn pre_com | code_fim | easy | {
"lang": "rust",
"repo": "foxfriends/git-project",
"path": "/src/commands/hook/pre_commit.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[derive(Clone)]
pub struct Order {
pub symbol: String,
pub order_id: String,
pub kind: Option<OrderKind>,
pub side: Option<OrderSide>,
pub health: i8,
pub alive: bool,
}
impl Order {
pub fn lower_health(&mut self) {
self.health -= 1;
if self.health <= 0 {
... | code_fim | hard | {
"lang": "rust",
"repo": "bigbizze/buy_token_take_profit_kucoin",
"path": "/src/exchange/order.rs",
"mode": "spm",
"license": "LicenseRef-scancode-warranty-disclaimer",
"source": "the-stack-v2"
} |
<|fim_suffix|> write!(f, "{}", match self {
OrderSide::Buy => format!("buy"),
OrderSide::Sell => format!("sell")
})
}
}
#[derive(Clone)]
pub struct Order {
pub symbol: String,
pub order_id: String,
pub kind: Option<OrderKind>,
pub side: Option<OrderSide>,
... | code_fim | medium | {
"lang": "rust",
"repo": "bigbizze/buy_token_take_profit_kucoin",
"path": "/src/exchange/order.rs",
"mode": "spm",
"license": "LicenseRef-scancode-warranty-disclaimer",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: bigbizze/buy_token_take_profit_kucoin path: /src/exchange/order.rs
#[derive(Clone)]
pub enum OrderKind {
Market,
Limit,
}
impl std::fmt::Display for OrderKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
<|fim_suffix|>#[derive(Clone)]
pub struct Order {
... | code_fim | hard | {
"lang": "rust",
"repo": "bigbizze/buy_token_take_profit_kucoin",
"path": "/src/exchange/order.rs",
"mode": "psm",
"license": "LicenseRef-scancode-warranty-disclaimer",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Here we create an object that holds timeout-related configuration. We'll have to pass this
// config into two places. This is because different timeouts are handled at different
// "levels" of the AWS SDK Client networking stack. We'll note which timeouts are getting
// set each time we... | code_fim | hard | {
"lang": "rust",
"repo": "BAStriver/aws-doc-sdk-examples",
"path": "/rust_dev_preview/setting-timeouts/src/main.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> // You can define timeouts in your environment or your AWS profile, but in the following
// example, we overrule any previously set timeouts.
// NOTE: The two API call timeouts get set here.
let shared_config = aws_config::from_env()
.timeout_config(timeout_config.clone())
... | code_fim | hard | {
"lang": "rust",
"repo": "BAStriver/aws-doc-sdk-examples",
"path": "/rust_dev_preview/setting-timeouts/src/main.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: BAStriver/aws-doc-sdk-examples path: /rust_dev_preview/setting-timeouts/src/main.rs
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
use aws_smithy_client::{conns, erase::DynConnector, hyper_ext};
// Note: `TriState` is used to... | code_fim | hard | {
"lang": "rust",
"repo": "BAStriver/aws-doc-sdk-examples",
"path": "/rust_dev_preview/setting-timeouts/src/main.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mkanenobu/til path: /rust/voicevox_example/voicevox_api/src/query.rs
use reqwest::{Client, Response};
use serde::{Deserialize, Serialize};
<|fim_suffix|>pub async fn audio_query(
client: &Client,
query_params: &AudioQueryQuery,
) -> Result<Response, Box<dyn std::error::Error>> {
let... | code_fim | medium | {
"lang": "rust",
"repo": "mkanenobu/til",
"path": "/rust/voicevox_example/voicevox_api/src/query.rs",
"mode": "psm",
"license": "WTFPL",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub async fn audio_query(
client: &Client,
query_params: &AudioQueryQuery,
) -> Result<Response, Box<dyn std::error::Error>> {
let resp = client
.post("http://localhost:50021/audio_query")
.query(query_params)
.send()
.await?;
Ok(resp)
}<|fim_prefix|>// repo... | code_fim | medium | {
"lang": "rust",
"repo": "mkanenobu/til",
"path": "/rust/voicevox_example/voicevox_api/src/query.rs",
"mode": "spm",
"license": "WTFPL",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: acj/webots-rs path: /build.rs
use std::env;
use std::path::PathBuf;
static WEBOTS_LINUX_PATH: &'static str = "/usr/local/webots";
static WEBOTS_MACOS_PATH: &'static str = "/Applications/Webots.app";
static WEBOTS_WINDOWS_PATH: &'static str = "C:\\Program Files\\Webots";
<|fim_suffix|> let e... | code_fim | medium | {
"lang": "rust",
"repo": "acj/webots-rs",
"path": "/build.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let env_path = env::var("WEBOTS_PATH").ok();
let webots_path = if cfg!(target_os = "linux") {
WEBOTS_LINUX_PATH.to_string()
} else if cfg!(target_os = "macos") {
WEBOTS_MACOS_PATH.to_string()
} else if let Some(path) = env_path {
path
} else if cfg!(target_os = ... | code_fim | medium | {
"lang": "rust",
"repo": "acj/webots-rs",
"path": "/build.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: zhutony/stratovirt path: /machine_manager/src/config/network.rs
// Copyright (c) 2020 Huawei Technologies Co.,Ltd. All rights reserved.
//
// StratoVirt is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan
// PSL v2.
// You may obtain a ... | code_fim | hard | {
"lang": "rust",
"repo": "zhutony/stratovirt",
"path": "/machine_manager/src/config/network.rs",
"mode": "psm",
"license": "LicenseRef-scancode-mulanpsl-2.0-en",
"source": "the-stack-v2"
} |
<|fim_suffix|> if let Some(netcfg) = &vm_config.netdevs.remove(&netdev) {
netdevinterfacecfg.id = netid;
netdevinterfacecfg.host_dev_name = netcfg.ifname.clone();
netdevinterfacecfg.tap_fd = netcfg.tap_fd;
netdevinterfacecfg.vhost_fd = netcfg.vhost_fd;
netdevinterfacecfg.vhost... | code_fim | hard | {
"lang": "rust",
"repo": "zhutony/stratovirt",
"path": "/machine_manager/src/config/network.rs",
"mode": "spm",
"license": "LicenseRef-scancode-mulanpsl-2.0-en",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Ahimasjason/Rust-Reference path: /ch-1/clousure.rs
fn main() {
let doubler = |x| x * 2;
let value = 5;
let twice = doubler(value);
<|fim_suffix|> let some_num = big_closure(1, 2);
println!("Result from Clousure {}", some_num);
}<|fim_middle|> println!("{} double is {}", va... | code_fim | medium | {
"lang": "rust",
"repo": "Ahimasjason/Rust-Reference",
"path": "/ch-1/clousure.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let big_closure = |b, c| {
let z = b + c;
z * twice
};
let some_num = big_closure(1, 2);
println!("Result from Clousure {}", some_num);
}<|fim_prefix|>// repo: Ahimasjason/Rust-Reference path: /ch-1/clousure.rs
fn main() {
let doubler = |x| x * 2;
let value = 5;
... | code_fim | easy | {
"lang": "rust",
"repo": "Ahimasjason/Rust-Reference",
"path": "/ch-1/clousure.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Patryk27/bad-apple-avr path: /encoder-lib/src/frames.rs
mod dframe;
mod iframe;
mod pframe;
pub use self::{dframe::*, iframe::*, pframe::*};
fn compress(body: Vec<u8>) -> Vec<u8> {
enum State {
AwaitingFirstByte,
CompressingByte { prev: u8, run: u8 },
}
let mut out... | code_fim | hard | {
"lang": "rust",
"repo": "Patryk27/bad-apple-avr",
"path": "/encoder-lib/src/frames.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> out
}
fn serialize_bitset(data: impl IntoIterator<Item = bool>) -> Vec<u8> {
let data: Vec<_> = data.into_iter().collect();
data.chunks(8)
.map(|pixels| {
pixels.iter().enumerate().fold(
0u8,
|delta, (bit_idx, bit)| {
if... | code_fim | hard | {
"lang": "rust",
"repo": "Patryk27/bad-apple-avr",
"path": "/encoder-lib/src/frames.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: whichxjy/wdr path: /wdr/src/settings.rs
use gethostname::gethostname;
use std::collections::HashMap;
use std::fs;
use std::path::Path;
lazy_static! {
// settings
pub static ref SETTINGS_MAP: HashMap<String, String> = {
let mut settings = config::Config::default();
settin... | code_fim | hard | {
"lang": "rust",
"repo": "whichxjy/wdr",
"path": "/wdr/src/settings.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn init() {
let settings_map = &SETTINGS_MAP as &HashMap<String, String>;
fn_debug!("Settings: {:#?}", settings_map);
}
pub fn get_wdr_node_name() -> String {
format!("{}-{}", &HOST_NAME as &str, &IP_ADDR as &str)
}<|fim_prefix|>// repo: whichxjy/wdr path: /wdr/src/settings.rs
use gethos... | code_fim | hard | {
"lang": "rust",
"repo": "whichxjy/wdr",
"path": "/wdr/src/settings.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ju6ge/atsame70q21 path: /src/uart0/uart_cmpr.rs
#[doc = "Reader of register UART_CMPR"]
pub type R = crate::R<u32, super::UART_CMPR>;
#[doc = "Writer for register UART_CMPR"]
pub type W = crate::W<u32, super::UART_CMPR>;
#[doc = "Register UART_CMPR `reset()`'s with value 0"]
impl crate::ResetVal... | code_fim | hard | {
"lang": "rust",
"repo": "ju6ge/atsame70q21",
"path": "/src/uart0/uart_cmpr.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>6)) | (((value as u32) & 0xff) << 16);
self.w
}
}
impl R {
#[doc = "Bits 0:7 - First Comparison Value for Received Character"]
#[inline(always)]
pub fn val1(&self) -> VAL1_R {
VAL1_R::new((self.bits & 0xff) as u8)
}
#[doc = "Bit 12 - Comparison Mode"]
#[inline(a... | code_fim | hard | {
"lang": "rust",
"repo": "ju6ge/atsame70q21",
"path": "/src/uart0/uart_cmpr.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: warpforge/warpgrapher path: /src/engine/database/no_database.rs
//! Provides database interface types and functions when there is no database back-end. Mostly
//! throws errors.
use crate::engine::context::RequestContext;
use crate::engine::database::{
Comparison, DatabaseEndpoint, Database... | code_fim | hard | {
"lang": "rust",
"repo": "warpforge/warpgrapher",
"path": "/src/engine/database/no_database.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn rel_read_by_ids_fragment<RequestCtx: RequestContext>(
&mut self,
_rel_var: &RelQueryVar,
_rels: &[Rel<RequestCtx>],
) -> Result<QueryFragment, Error> {
Err(Error::DatabaseNotFound)
}
fn rel_read_fragment(
&mut self,
_src_fragment_opt: Opt... | code_fim | hard | {
"lang": "rust",
"repo": "warpforge/warpgrapher",
"path": "/src/engine/database/no_database.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let tmp_dir = tempfile::Builder::new()
.prefix("put_and_get")
.tempdir()
.unwrap();
let store = SledStore::new(tmp_dir.path().to_str().unwrap());
let mut batch = store.batch().unwrap();
batch.put(&[0, 0], &[0, 0, 0]).unwrap();
bat... | code_fim | hard | {
"lang": "rust",
"repo": "owencp/light-node",
"path": "/src/store/sled.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: owencp/light-node path: /src/store/sled.rs
use std::collections::HashMap;
use sled::{open, Db};
use std::sync::Arc;
use ckb_types::{
core::{BlockNumber, HeaderView, BlockView},
packed,
U256,
};
#[derive(Debug)]
pub enum Error {
DBError(String),
}
impl ToString for Error {
... | code_fim | hard | {
"lang": "rust",
"repo": "owencp/light-node",
"path": "/src/store/sled.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn delete() {
let tmp_dir = tempfile::Builder::new().prefix("delete").tempdir().unwrap();
let store = SledStore::new(tmp_dir.path().to_str().unwrap());
let mut batch = store.batch().unwrap();
batch.put(&[0, 0], &[0, 0, 0]).unwrap();
batch.commit().un... | code_fim | hard | {
"lang": "rust",
"repo": "owencp/light-node",
"path": "/src/store/sled.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> }
});
assert_eq!(expected, ser);
}
#[test]
fn serialise_document_for_custom_mapping() {
let ser = serde_json::to_string(&IndexDocumentMapping::from(CustomType::mapping())).unwrap();
let expected = json_str!({
"properties": {
... | code_fim | hard | {
"lang": "rust",
"repo": "elastic-rs/elastic-types",
"path": "/types/src/document/impls.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> use_document::<SimpleType>();
}
#[test]
fn get_type_name() {
assert_eq!("simpletype", SimpleTypeMapping::name());
}
#[test]
fn get_default_type_name() {
assert_eq!("simpletype", SimpleType::name());
}
#[test]
fn get_custom_type_name() {
... | code_fim | hard | {
"lang": "rust",
"repo": "elastic-rs/elastic-types",
"path": "/types/src/document/impls.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: elastic-rs/elastic-types path: /types/src/document/impls.rs
dexable Elasticsearch type.
This trait is implemented for the type being mapped, rather than the mapping
type itself.
*/
pub trait DocumentType {
/** The mapping type for this document. */
type Mapping: DocumentMapping;
/*... | code_fim | hard | {
"lang": "rust",
"repo": "elastic-rs/elastic-types",
"path": "/types/src/document/impls.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: JackHoeg/Sample-Code path: /Backgammon - Rust/src/tcp_handler.rs
use std::io::{BufRead, BufReader, BufWriter, Write};
use std::net::TcpStream;
use serde_json::Value;
const DEFAULT_BUF_SIZE: usize = 512;
/// Wraps a TcpStream and allows easy writing and reading of serde_json::Value
pub struct ... | code_fim | medium | {
"lang": "rust",
"repo": "JackHoeg/Sample-Code",
"path": "/Backgammon - Rust/src/tcp_handler.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn write(&mut self, val: &Value) {
//! write json to socket
let output_str = format!("{}\n", val);
self.writer.write(output_str.as_bytes()).ok();
self.writer.flush().ok();
}
}<|fim_prefix|>// repo: JackHoeg/Sample-Code path: /Backgammon - Rust/src/tcp_handler.r... | code_fim | hard | {
"lang": "rust",
"repo": "JackHoeg/Sample-Code",
"path": "/Backgammon - Rust/src/tcp_handler.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ehuss/cargo-index path: /reg-index/src/util.rs
use anyhow::{bail, Context, Error};
use semver::Version;
use sha2::Digest;
use std::{
env, fs, io,
path::{Path, PathBuf},
process::Command,
};
use walkdir::{DirEntry, WalkDir};
pub(crate) fn signature(repo: &git2::Repository) -> Result<... | code_fim | hard | {
"lang": "rust",
"repo": "ehuss/cargo-index",
"path": "/reg-index/src/util.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub(crate) fn extract_crate(crate_path: &Path) -> Result<(tempfile::TempDir, PathBuf), Error> {
let crate_file = fs::File::open(crate_path)
.with_context(|| format!("Failed to open `{}`.", crate_path.display()))?;
let tmp_dir = tempfile::tempdir().unwrap();
let gz = flate2::read::GzDec... | code_fim | hard | {
"lang": "rust",
"repo": "ehuss/cargo-index",
"path": "/reg-index/src/util.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> if let Err(e) = run(matches, _hope) {
println!("Application error: {}", e);
process::exit(1);
}
fn run(matches: ArgMatches, _hope: hopeScheme) -> Result<(), ReclaimPathError> {
match matches.subcommand() {
(CMD_SETUP, Some(matches)) => run_setup(matches, _h... | code_fim | hard | {
"lang": "rust",
"repo": "georgbramm/hope.rs",
"path": "/cli/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: georgbramm/hope.rs path: /cli/src/main.rs
#[macro_use]
extern crate clap;
use clap::{crate_version, App, ArgMatches};
use failure::{format_err, Fallible};
use std::env::set_var;
use std::error::Error;
use std::fmt;
use std::process;
use hope::config::Config;
use hope_library::scheme::hope as hop... | code_fim | hard | {
"lang": "rust",
"repo": "georgbramm/hope.rs",
"path": "/cli/src/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> WindowEvent::Key(Key::Q, _, Action::Press, _) => self.dezoom = true,
WindowEvent::Key(Key::Q, _, Action::Release, _) => self.dezoom = false,
WindowEvent::Key(Key::E, _, Action::Press, _) => self.zoom = true,
WindowEvent::Key(K... | code_fim | hard | {
"lang": "rust",
"repo": "Alikae/lumi-engine",
"path": "/src/controller.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> WindowEvent::Key(Key::Up, _, Action::Press, _) => self.camup = true,
WindowEvent::Key(Key::Up, _, Action::Release, _) => self.camup = false,
WindowEvent::Key(Key::Down, _, Action::Press, _) => self.camdown = true,
WindowEvent::Key(... | code_fim | hard | {
"lang": "rust",
"repo": "Alikae/lumi-engine",
"path": "/src/controller.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Alikae/lumi-engine path: /src/controller.rs
use luminance_glfw::GlfwSurface;
use glfw::{Action, Key, WindowEvent}; // Context as _,
use super::Game;
pub struct Controller {
pub quit: bool,
pub camleft: bool,
pub camright: bool,
pub camup: bool,
pub camdown: bool,... | code_fim | hard | {
"lang": "rust",
"repo": "Alikae/lumi-engine",
"path": "/src/controller.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: brian-dawn/jot path: /src/constants.rs
pub const TODO_NOT_DONE_PLACEHOLDER: &str = "not-done";
pub const TODO_HEADER: &str = TODO;
<|fim_suffix|>pub const NOTE: &str = "note";
pub const NOTES: &str = "notes";<|fim_middle|>pub const TODO: &str = "todo";
pub const TODOS: &str = "todos";
| code_fim | medium | {
"lang": "rust",
"repo": "brian-dawn/jot",
"path": "/src/constants.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub const NOTE: &str = "note";
pub const NOTES: &str = "notes";<|fim_prefix|>// repo: brian-dawn/jot path: /src/constants.rs
pub const TODO_NOT_DONE_PLACEHOLDER: &str = "not-done";
pub const TODO_HEADER: &str = TODO;
<|fim_middle|>pub const TODO: &str = "todo";
pub const TODOS: &str = "todos";
| code_fim | medium | {
"lang": "rust",
"repo": "brian-dawn/jot",
"path": "/src/constants.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> println!(
"{:?}",
Solution::spiral_order(vec![vec![1, 2, 3], vec![4, 5, 6], vec![7, 8, 9],])
); // 1, 2, 3, 6, 9, 8, 7, 4, 5
println!("{:?}", Solution::spiral_order(vec![])); // []
println!("{:?}", Solution::spiral_order(vec![vec![]])); // []
println!("{:?}", Solution::... | code_fim | hard | {
"lang": "rust",
"repo": "aiifabbf/leetcode-memo",
"path": "/54.rust/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>闭式解不知道怎么算。多元递推方程好像没有特别好的解决方法。
*/
struct Solution;
impl Solution {
pub fn spiral_order(matrix: Vec<Vec<i32>>) -> Vec<i32> {
let mut matrix = matrix;
if matrix.is_empty() {
return vec![];
}
if matrix[0].is_empty() {
return vec![];
}
... | code_fim | hard | {
"lang": "rust",
"repo": "aiifabbf/leetcode-memo",
"path": "/54.rust/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: aiifabbf/leetcode-memo path: /54.rust/src/main.rs
/*
.. default-role:: math
螺旋遍历矩阵。从左上角开始、顺时针一圈,像剥洋葱一样。
挺简单的,用递归。这一层函数只剥一层,里面的丢给下一层函数。
头条三面的时候被问了这道题,秒做。然而follow up问螺旋遍历的最后一个点的坐标是啥。搞了很久,也没有写出闭式解,只写出了递推式。
定义 `\vec{f}(m, n)` 是 `m \times n` 矩阵螺旋遍历的最后一个点的坐标。发现
.. math::
\vec{f}(m, n) = (1, ... | code_fim | hard | {
"lang": "rust",
"repo": "aiifabbf/leetcode-memo",
"path": "/54.rust/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> println!("The value of PI is : {}", PI);
println!("My Favorite number is : {}", FAV_NUMBER);
}<|fim_prefix|>// repo: sameem420/Learning-Rust path: /constants/src/main.rs
// always should keep upper-case name and constant has fixed value
const PI:f32 = 3.1416;
const FAV_NUMBER:u8 = 7;
<|fim_mid... | code_fim | easy | {
"lang": "rust",
"repo": "sameem420/Learning-Rust",
"path": "/constants/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: sameem420/Learning-Rust path: /constants/src/main.rs
// always should keep upper-case name and constant has fixed value
const PI:f32 = 3.1416;
const FAV_NUMBER:u8 = 7;
<|fim_suffix|> println!("The value of PI is : {}", PI);
println!("My Favorite number is : {}", FAV_NUMBER);
}<|fim_mid... | code_fim | easy | {
"lang": "rust",
"repo": "sameem420/Learning-Rust",
"path": "/constants/src/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut formatter = f.debug_struct("SendTaskFailureOutput");
formatter.finish()
}
}
/// See [`SendTaskFailureOutput`](crate::output::SendTaskFailureOutput)
pub mod send_task_failure_output {
/// A builder for [`SendTaskFailureOutput`](crate::output::SendTaskFailureOutput)
#[non... | code_fim | hard | {
"lang": "rust",
"repo": "mnts26/aws-sdk-rust",
"path": "/sdk/sfn/src/output.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mnts26/aws-sdk-rust path: /sdk/sfn/src/output.rs
{
let mut v = self.activities.unwrap_or_default();
v.push(input.into());
self.activities = Some(v);
self
}
pub fn set_activities(
mut self,
input: std::option... | code_fim | hard | {
"lang": "rust",
"repo": "mnts26/aws-sdk-rust",
"path": "/sdk/sfn/src/output.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mnts26/aws-sdk-rust path: /sdk/sfn/src/output.rs
}
}
impl DescribeStateMachineOutput {
/// Creates a new builder-style object to manufacture [`DescribeStateMachineOutput`](crate::output::DescribeStateMachineOutput)
pub fn builder() -> crate::output::describe_state_machine_output::Builder... | code_fim | hard | {
"lang": "rust",
"repo": "mnts26/aws-sdk-rust",
"path": "/sdk/sfn/src/output.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> conditional_function();
}<|fim_prefix|>// repo: jeroenpelgrims/rust-by-example path: /14/custom.rs
#[cfg(some_condition)]
fn conditional_function() {
println!("condition met");
}
<|fim_middle|>//compile using `rustc --cfg some_condition custom.rs`
fn main() {
| code_fim | medium | {
"lang": "rust",
"repo": "jeroenpelgrims/rust-by-example",
"path": "/14/custom.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>//compile using `rustc --cfg some_condition custom.rs`
fn main() {
conditional_function();
}<|fim_prefix|>// repo: jeroenpelgrims/rust-by-example path: /14/custom.rs
#[cfg(some_condition)]
fn conditional_function() {
<|fim_middle|> println!("condition met");
}
| code_fim | easy | {
"lang": "rust",
"repo": "jeroenpelgrims/rust-by-example",
"path": "/14/custom.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jeroenpelgrims/rust-by-example path: /14/custom.rs
#[cfg(some_condition)]
fn conditional_function() {
<|fim_suffix|> conditional_function();
}<|fim_middle|> println!("condition met");
}
//compile using `rustc --cfg some_condition custom.rs`
fn main() {
| code_fim | medium | {
"lang": "rust",
"repo": "jeroenpelgrims/rust-by-example",
"path": "/14/custom.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: terrierscript/raspi-sh1106-rust path: /canvas/src/lib.rs
// use embedded_graphics::pixelcolor::PixelColorU8;
use embedded_graphics::pixelcolor::BinaryColor;
use embedded_graphics::prelude::*;
use embedded_graphics::primitives::rectangle::Rectangle;
use embedded_graphics::{egrectangle, primitive_... | code_fim | hard | {
"lang": "rust",
"repo": "terrierscript/raspi-sh1106-rust",
"path": "/canvas/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // zz.draw(&mut drawable);
// z.draw(&mut drawable);
// ;
// .with_fill(Some(PixelColor(1u8)));
// let r =
// drawable.draw_iter(zz.into_iter());
// // .and(Ok(drawable))
// // ;
// drawable
}
pub fn draw_char<D>(&self,... | code_fim | hard | {
"lang": "rust",
"repo": "terrierscript/raspi-sh1106-rust",
"path": "/canvas/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[derive(Debug, Serialize, Deserialize)]
pub struct Record {
date: DateTime<Utc>,
recipient: Person,
sender: Person,
}
impl Record {
pub fn new(recipient: Person, sender: Person) -> Self {
Record {
date: Utc::now(),
recipient,
sender,
}
... | code_fim | medium | {
"lang": "rust",
"repo": "jack-greenberg/ledger",
"path": "/src/transaction.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jack-greenberg/ledger path: /src/transaction.rs
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::error::Error;
use crate::person::Person;
<|fim_suffix|>impl Record {
pub fn new(recipient: Person, sender: Person) -> Self {
Record {
date: Utc::no... | code_fim | medium | {
"lang": "rust",
"repo": "jack-greenberg/ledger",
"path": "/src/transaction.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn write_csv(self) -> Result<(), Box<dyn Error>> {
let file_path = std::path::Path::new("test.csv");
let mut writer = csv::Writer::from_path(file_path).unwrap();
writer.serialize(self)?;
Ok(())
}
}<|fim_prefix|>// repo: jack-greenberg/ledger path: /src/transac... | code_fim | hard | {
"lang": "rust",
"repo": "jack-greenberg/ledger",
"path": "/src/transaction.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: kaimast/iced path: /core/src/time.rs
//! Keep track of time, both in native and web platforms!
#[cfg(target_arch = "wasm32")]
pub use instant::Instant;
<|fim_suffix|>#[cfg(not(target_arch = "wasm32"))]
pub use std::time::Duration;<|fim_middle|>#[cfg(target_arch = "wasm32")]
pub use instant::Du... | code_fim | medium | {
"lang": "rust",
"repo": "kaimast/iced",
"path": "/core/src/time.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(not(target_arch = "wasm32"))]
pub use std::time::Duration;<|fim_prefix|>// repo: kaimast/iced path: /core/src/time.rs
//! Keep track of time, both in native and web platforms!
<|fim_middle|>#[cfg(target_arch = "wasm32")]
pub use instant::Instant;
#[cfg(target_arch = "wasm32")]
pub use instant::Du... | code_fim | medium | {
"lang": "rust",
"repo": "kaimast/iced",
"path": "/core/src/time.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(not(target_arch = "wasm32"))]
pub use std::time::Instant;
#[cfg(not(target_arch = "wasm32"))]
pub use std::time::Duration;<|fim_prefix|>// repo: kaimast/iced path: /core/src/time.rs
//! Keep track of time, both in native and web platforms!
#[cfg(target_arch = "wasm32")]
pub use instant::Instant;
... | code_fim | easy | {
"lang": "rust",
"repo": "kaimast/iced",
"path": "/core/src/time.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: brly/mrcl path: /src/follows.rs
use ::*;
pub fn post(c: &Config, uri: &str) -> APIResult<Account> {<|fim_suffix|>t body = form_body!("uri", Some(uri));
let mut response = c.post(url.as_ref(), body.as_ref())?;
Ok(Account::from(&mut response))
}<|fim_middle|>
let url = format!("https:... | code_fim | medium | {
"lang": "rust",
"repo": "brly/mrcl",
"path": "/src/follows.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>t body = form_body!("uri", Some(uri));
let mut response = c.post(url.as_ref(), body.as_ref())?;
Ok(Account::from(&mut response))
}<|fim_prefix|>// repo: brly/mrcl path: /src/follows.rs
use ::*;
pub fn post(c: &Config, uri: &str) -> APIResult<Account> {<|fim_middle|>
let url = format!("https:... | code_fim | medium | {
"lang": "rust",
"repo": "brly/mrcl",
"path": "/src/follows.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>et nps = (1000 * nodes) as f64 / time_elapsed as f64;
println!(
"Time: {}ms, Nodes: {}, KNPS: {}",
time_elapsed as f64 / 1000.,
nodes,
nps
);
for i in 1..=5 {
println!("{}: {}", i, state.perft(i));
}
let mut searcher = Searcher::with_tc(Timecontr... | code_fim | hard | {
"lang": "rust",
"repo": "imkgerC/rust-socha2020",
"path": "/demo/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: imkgerC/rust-socha2020 path: /demo/src/main.rs
use game_sdk::{Action, ClientListener, Color, GameState};
use player::mcts::MCTS;
use player::search::Searcher;
use player::timecontrol::Timecontrol;
use std::time::Instant;
fn main() {
// Do some perft testing
//FEN of midgame position:
... | code_fim | hard | {
"lang": "rust",
"repo": "imkgerC/rust-socha2020",
"path": "/demo/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let client = self.client.lock().await;
let identity = match client.update_module_identity(&self.module_id).await {
Ok(identity) => crate::identity::Identity::try_from(identity)?,
Err(err) => {
return Err(edgelet_http::error::server_error(err.to_stri... | code_fim | hard | {
"lang": "rust",
"repo": "Azure/iotedge",
"path": "/edgelet/edgelet-http-mgmt/src/identity/delete_or_update.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Azure/iotedge path: /edgelet/edgelet-http-mgmt/src/identity/delete_or_update.rs
// Copyright (c) Microsoft. All rights reserved.
use std::convert::TryFrom;
#[cfg(not(test))]
use aziot_identity_client_async::Client as IdentityClient;
#[cfg(test)]
use test_common::client::IdentityClient;
pub(c... | code_fim | hard | {
"lang": "rust",
"repo": "Azure/iotedge",
"path": "/edgelet/edgelet-http-mgmt/src/identity/delete_or_update.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> match self {
Error::Io(err) => Some(err),
_ => None,
}
}
}
impl From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Self {
Error::Io(err)
}
}
impl From<std::string::FromUtf8Error> for Error {
fn from(err: std::string::FromUtf8E... | code_fim | hard | {
"lang": "rust",
"repo": "adamransom/spyparty-rs",
"path": "/src/error.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: adamransom/spyparty-rs path: /src/error.rs
use std::fmt;
pub type Result<T> = std::result::Result<T, Error>;
/// The error type for errors that occur whilst reading the header.
///
/// # Notes
///
/// I've opted for specific error messages related to the format of the header so, for example, y... | code_fim | hard | {
"lang": "rust",
"repo": "adamransom/spyparty-rs",
"path": "/src/error.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// Simple macro to allow returning early with an error.
macro_rules! bail {
($e:expr) => {
return Err($e);
};
}
/// Simple macro to allow returning early with an error if a condition isn't satisfied.
macro_rules! ensure {
($cond:expr, $e:expr) => {
if !($cond) {
b... | code_fim | hard | {
"lang": "rust",
"repo": "adamransom/spyparty-rs",
"path": "/src/error.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: peterkinalex/just path: /tests/search.rs
extern crate brev;
extern crate executable_path;
extern crate tempdir;
use tempdir::TempDir;
use std::{path, str, fs, process};
use executable_path::executable_path;
fn search_test<P: AsRef<path::Path>>(path: P, args: &[&str]) {
let binary = executabl... | code_fim | hard | {
"lang": "rust",
"repo": "peterkinalex/just",
"path": "/tests/search.rs",
"mode": "psm",
"license": "CC0-1.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.