text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_prefix|>// repo: DavidVentura/Advent_of_code_2018 path: /src/aoc_1.rs
use std::collections::BTreeSet;
pub fn part_1(data: &Vec<i32>) {
let result: i32 = data.iter().sum();
println!("{}", result);
}
<|fim_suffix|>pub fn main() {
let body = super::get_challenge_data(1);
let data : Vec<i32> = body.... | code_fim | hard | {
"lang": "rust",
"repo": "DavidVentura/Advent_of_code_2018",
"path": "/src/aoc_1.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Reconstruct raw DTSTART line for use in RRULE
dtstart = Some(reconstruct_datetime(&event.start, get_tz(&prop.params)));
},
"DTEND" => {
let dt_str = prop.value.unwrap();
... | code_fim | hard | {
"lang": "rust",
"repo": "frnsys/agenda",
"path": "/src/ics.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: frnsys/agenda path: /src/ics.rs
use std::fs::File;
use std::path::Path;
use std::io::BufReader;
use ical::IcalParser;
use rrule::RRuleSet;
use thiserror::Error;
use chrono_tz::{Tz, UTC};
use chrono::{DateTime, TimeZone, Utc, Local};
use super::event::Event;
// Pull out the timezone, if any, fro... | code_fim | hard | {
"lang": "rust",
"repo": "frnsys/agenda",
"path": "/src/ics.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> return &s[start.. s.char_indices().nth(len).unwrap().0];
}<|fim_prefix|>// repo: driedtoast/rusties path: /src/hacker_rank/mod.rs
pub mod command;
mod cat_and_mouse;
mod repeated_string;
<|fim_middle|>
fn substring(s: &str, start: usize, len: usize) -> &str {
| code_fim | easy | {
"lang": "rust",
"repo": "driedtoast/rusties",
"path": "/src/hacker_rank/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: driedtoast/rusties path: /src/hacker_rank/mod.rs
pub mod command;
mod cat_and_mouse;
mod repeated_string;
<|fim_suffix|> return &s[start.. s.char_indices().nth(len).unwrap().0];
}<|fim_middle|>
fn substring(s: &str, start: usize, len: usize) -> &str {
| code_fim | easy | {
"lang": "rust",
"repo": "driedtoast/rusties",
"path": "/src/hacker_rank/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(test)]
mod tests {
use super::*;
#[test]
fn encode_works() {
let id = NodeId::generate(&mut rand::thread_rng()).unwrap();
let v = id.encode();
assert_eq!(v.len(), NODE_ID_LEN + 8);
assert_eq!(v[..8], (NODE_ID_LEN as u64).to_le_bytes());
}
}<|fim_prefi... | code_fim | hard | {
"lang": "rust",
"repo": "input-output-hk/chain-libs",
"path": "/chain-network/src/grpc/legacy.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: input-output-hk/chain-libs path: /chain-network/src/grpc/legacy.rs
//! Support for legacy features.
use rand_core::RngCore;
use std::array::TryFromSliceError;
use std::fmt;
const NODE_ID_LEN: usize = 24;
/// Represents a randomly generated node ID such as was present in subscription
/// reque... | code_fim | hard | {
"lang": "rust",
"repo": "input-output-hk/chain-libs",
"path": "/chain-network/src/grpc/legacy.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl<'a> fmt::Debug for HexWrap<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("0x")?;
for b in self.0 {
write!(f, "{:x}", *b)?;
}
Ok(())
}
}
impl fmt::Debug for NodeId {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result... | code_fim | hard | {
"lang": "rust",
"repo": "input-output-hk/chain-libs",
"path": "/chain-network/src/grpc/legacy.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl From<u8> for ErrorType {
fn from(byte: u8) -> Self {
match byte {
0x01 => Self::Other,
0x02 => Self::Unknown,
0x03 => Self::Ok,
0x04 => Self::BadRead,
0x05 => Self::ParityError,
0x06 => Self::SingleBitError,
... | code_fim | hard | {
"lang": "rust",
"repo": "jcreekmore/dmidecode",
"path": "/src/structures/018_memory_error_32.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jcreekmore/dmidecode path: /src/structures/018_memory_error_32.rs
//! 32-Bit Memory Error Information (Type 18)
//!
//! This structure identifies the specifics of an error that might be detected within a Physical Memory Array.
use core::fmt;
use crate::{
InfoType,
MalformedStructureErr... | code_fim | hard | {
"lang": "rust",
"repo": "jcreekmore/dmidecode",
"path": "/src/structures/018_memory_error_32.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let sample = &[
"Undefined: 0",
"Other",
"Unknown",
"OK",
"Bad read",
"Parity error",
"Single-bit error",
"Double-bit error",
"Multi-bit error",
"Nibble error",
"Chec... | code_fim | hard | {
"lang": "rust",
"repo": "jcreekmore/dmidecode",
"path": "/src/structures/018_memory_error_32.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mystor/dist-xprs-example path: /rt/nsIXPCScriptable.rs
//
// DO NOT EDIT. THIS FILE IS GENERATED FROM ../../../dist/idl/nsIXPCScriptable.idl
//
#[repr(C)]
pub struct nsIXPCScriptable {
vtable: *const nsIXPCScriptableVTable,
/// This field is a phantomdata to ensure that the VTable ty... | code_fim | hard | {
"lang": "rust",
"repo": "mystor/dist-xprs-example",
"path": "/rt/nsIXPCScriptable.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> /* boolean setProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in jsid id, in JSValPtr vp); */
/* boolean enumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
/* boolean newEnumerate (in nsIXPConnectWrappedNativ... | code_fim | hard | {
"lang": "rust",
"repo": "mystor/dist-xprs-example",
"path": "/rt/nsIXPCScriptable.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>
/* [nostdcall,notxpcom] JSClassPtr getJSClass (); */
/* void preCreate (in nsISupports nativeObj, in JSContextPtr cx, in JSObjectPtr globalObj, out JSObjectPtr parentObj); */
/* boolean getProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in jsid id, ... | code_fim | hard | {
"lang": "rust",
"repo": "mystor/dist-xprs-example",
"path": "/rt/nsIXPCScriptable.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> {
panic_on_errno!(rust_ibv_destroy_wq, self.pointer)
}
}
impl<'a, C: CompletionQueue> WorkQueue<'a, C>
{
#[inline(always)]
pub fn settings(&self) -> &SharedReceiveQueueSettings
{
&self.settings
}
}<|fim_prefix|>// repo: jisuanjidaqiang/rdma-core path: /workspace/rdma-core/src/verbs/model/share... | code_fim | medium | {
"lang": "rust",
"repo": "jisuanjidaqiang/rdma-core",
"path": "/workspace/rdma-core/src/verbs/model/sharedReceiveQueues/WorkQueue.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jisuanjidaqiang/rdma-core path: /workspace/rdma-core/src/verbs/model/sharedReceiveQueues/WorkQueue.rs
// This file is part of dpdk. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/dp... | code_fim | hard | {
"lang": "rust",
"repo": "jisuanjidaqiang/rdma-core",
"path": "/workspace/rdma-core/src/verbs/model/sharedReceiveQueues/WorkQueue.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl<'a, C: CompletionQueue> Drop for WorkQueue<'a, C>
{
#[inline(always)]
fn drop(&mut self)
{
panic_on_errno!(rust_ibv_destroy_wq, self.pointer)
}
}
impl<'a, C: CompletionQueue> WorkQueue<'a, C>
{
#[inline(always)]
pub fn settings(&self) -> &SharedReceiveQueueSettings
{
&self.settings
}
}<|... | code_fim | hard | {
"lang": "rust",
"repo": "jisuanjidaqiang/rdma-core",
"path": "/workspace/rdma-core/src/verbs/model/sharedReceiveQueues/WorkQueue.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: oddcoder/sickassembler path: /src/lib/pass_two/operand_translator.rs
use instruction::Instruction;
use basic_types::formats::Format;
use basic_types::operands::Value;
use basic_types::register::Register;
use symbol_tables::get_symbol;
use base_table::get_base_at;
use symbol::SymbolType;
use rege... | code_fim | hard | {
"lang": "rust",
"repo": "oddcoder/sickassembler",
"path": "/src/lib/pass_two/operand_translator.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>
fn panic_on_memory_limit(disp: i32, locctr: i32) {
if disp + locctr >= (1 << 20) {
panic!("Out of range address {}", disp + locctr)
}
}
lazy_static!{
// lazy_static regex to avoid recompilation on each function call -> read the docs
static ref HEX_REGEX:Regex = Regex::new(r"^(x|X... | code_fim | hard | {
"lang": "rust",
"repo": "oddcoder/sickassembler",
"path": "/src/lib/pass_two/operand_translator.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: FreddyWordingham/arctk-attr path: /src/save.rs
//! Implementation function of the save attribute macro.
<|fim_suffix|>/// Create the attribute macro save.
#[inline]
#[must_use]
pub fn implementation(_metadata: &TokenStream, input: TokenStream) -> TokenStream {
let input: proc_macro2::TokenS... | code_fim | easy | {
"lang": "rust",
"repo": "FreddyWordingham/arctk-attr",
"path": "/src/save.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// Create the attribute macro save.
#[inline]
#[must_use]
pub fn implementation(_metadata: &TokenStream, input: TokenStream) -> TokenStream {
let input: proc_macro2::TokenStream = input.into();
let output = quote::quote! {
#[derive(Debug, serde::Serialize, arctk_proc::Save)]
#inpu... | code_fim | easy | {
"lang": "rust",
"repo": "FreddyWordingham/arctk-attr",
"path": "/src/save.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: kaichaosun/play-substrate path: /pallets/coinflip/src/tests.rs
// Tests to be written here
use crate::{Error, mock::*};
use frame_support::{assert_ok, assert_noop};
use frame_support::traits::Currency;
use sp_runtime::traits::BadOrigin;
use super::*;
use pallet_balances::Error as BalancesError;... | code_fim | hard | {
"lang": "rust",
"repo": "kaichaosun/play-substrate",
"path": "/pallets/coinflip/src/tests.rs",
"mode": "psm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[test]
fn play_should_work_for_win() {
new_test_ext().execute_with(|| {
<Payment<Test>>::put(10);
<Pot<Test>>::put(30);
<Nonce<Test>>::put(0);
assert_ok!(CoinFlipModule::play(Origin::signed(2)));
assert_eq!(CoinFlipModule::payment(), Some(10));
assert_eq!(CoinFlipModule::pot(), 10);
asser... | code_fim | hard | {
"lang": "rust",
"repo": "kaichaosun/play-substrate",
"path": "/pallets/coinflip/src/tests.rs",
"mode": "spm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_suffix|> // set payment and pot, higher than the balances
<Payment<Test>>::put(30);
<Pot<Test>>::put(30);
assert_noop!(CoinFlipModule::play(Origin::signed(2)), BalancesError::<Test, _>::InsufficientBalance);
// set payment and pot, lower than the balances
<Payment<Test>>::put(10);
<Pot<Test>... | code_fim | hard | {
"lang": "rust",
"repo": "kaichaosun/play-substrate",
"path": "/pallets/coinflip/src/tests.rs",
"mode": "spm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn read(fp: &mut FilePool, mmu: &mut Mmu, fd: i64, p_buf: VirtAddr,
count: usize) -> Result<i64, VmExit> {
match fp.read(fd as usize, count) {
Some(data) => {
mmu.write_from(p_buf, data)?;
Ok(data.len() as i64)
},
None => Ok(-1)
... | code_fim | hard | {
"lang": "rust",
"repo": "Microsvuln/binexp-practice",
"path": "/fuzzing/emu-fuzzer/src/syscall.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Microsvuln/binexp-practice path: /fuzzing/emu-fuzzer/src/syscall.rs
/// Handle syscalls, in a way that is not super locked in to a specific arch.
///
/// Each arch we implement must do the number -> syscall transition, as well as the argument
/// parsing by itself.
// https://sourceware.org/n... | code_fim | hard | {
"lang": "rust",
"repo": "Microsvuln/binexp-practice",
"path": "/fuzzing/emu-fuzzer/src/syscall.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // If our current allocation suffices, just ret here.
if size <= mmu.cur_alloc.0 as i64 {
return Ok(mmu.cur_alloc.0 as i64);
}
let increment = size as usize - mmu.cur_alloc.0;
// If we managed to allocate something, return it.
match mmu.allocate(increment) {
Some(_... | code_fim | hard | {
"lang": "rust",
"repo": "Microsvuln/binexp-practice",
"path": "/fuzzing/emu-fuzzer/src/syscall.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ocboogie/boogie-bot path: /src/main.rs
#[macro_use]
extern crate log;
// #[macro_use]
// extern crate emoji_converter;
#[macro_use]
extern crate serde_derive;
extern crate dotenv;
extern crate env_logger;
extern crate failure;
extern crate serde_json;
extern crate serenity;
extern crate timeago;... | code_fim | hard | {
"lang": "rust",
"repo": "ocboogie/boogie-bot",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn main() {
dotenv().ok();
env_logger::init();
let mut client = Client::new(&env::var("DISCORD_TOKEN").expect("token"), Handler)
.expect("Error creating client");
{
let mut data = client.data.lock();
data.insert::<UsersInfo>(HashMap::default());
match store::UsersInfo::load() {
... | code_fim | hard | {
"lang": "rust",
"repo": "ocboogie/boogie-bot",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: PizzasBear/Bevy-Snake path: /src/main.rs
use bevy::prelude::*;
use rand::distributions::Uniform;
use rand::prelude::*;
use serde::{Deserialize, Serialize};
use std::collections::{HashSet, VecDeque};
use std::time::Duration;
use std::mem;
const BOARD_SIZE: u32 = 16;
const SIZE: f32 = 30.;
const ... | code_fim | hard | {
"lang": "rust",
"repo": "PizzasBear/Bevy-Snake",
"path": "/src/main.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut head_pos = *body_query.get::<Pos>(prev_head).unwrap();
if head_pos.update(dir)
|| (!state.body_pos_set.insert(head_pos)
&& *body_query.get::<Pos>(head).unwrap() != head_pos)
{
match state.snake_state {
SnakeState::Aliv... | code_fim | hard | {
"lang": "rust",
"repo": "PizzasBear/Bevy-Snake",
"path": "/src/main.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: CJTozer/rust-c-ares path: /src/nameinfo.rs
extern crate c_ares_sys;
extern crate libc;
use std::ffi::CStr;
use std::marker::PhantomData;
use std::mem;
use std::str;
use error::AresError;
use utils::ares_error;
/// The result of a successful name-info lookup.
pub struct NameInfoResult<'a> {
... | code_fim | medium | {
"lang": "rust",
"repo": "CJTozer/rust-c-ares",
"path": "/src/nameinfo.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub unsafe extern "C" fn get_name_info_callback<F>(
arg: *mut libc::c_void,
status: libc::c_int,
_timeouts: libc::c_int,
node: *mut libc::c_char,
service: *mut libc::c_char)
where F: FnOnce(Result<NameInfoResult, AresError>) + 'static {
let result = if status != c_ares_sys::ARE... | code_fim | hard | {
"lang": "rust",
"repo": "CJTozer/rust-c-ares",
"path": "/src/nameinfo.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: seanwallawalla-forks/nushell path: /crates/nu-command/src/commands/platform/sleep.rs
use crate::prelude::*;
use nu_engine::WholeStreamCommand;
use nu_errors::ShellError;
use nu_protocol::{Signature, SyntaxShape, UntaggedValue, Value};
use nu_source::Tagged;
use std::{
sync::atomic::Ordering,... | code_fim | hard | {
"lang": "rust",
"repo": "seanwallawalla-forks/nushell",
"path": "/crates/nu-command/src/commands/platform/sleep.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let start = Instant::now();
let results = test_examples(Sleep {});
let elapsed = start.elapsed();
println!("{:?}", elapsed);
// only examples with actual output are run
assert!(elapsed >= std::time::Duration::from_secs(1));
assert!(elapsed < std::tim... | code_fim | hard | {
"lang": "rust",
"repo": "seanwallawalla-forks/nushell",
"path": "/crates/nu-command/src/commands/platform/sleep.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl DigitalAudioPath {
pub fn new() -> Self {
DigitalAudioPath {
data: 0b0_0000_1000,
}
}
/// Enable or disable ADC high pass filter.
///
/// Under the hood, ADC high pass filter is enabled by setting the ADCHPD bit to zero.
pub fn adc_hpf(&mut sel... | code_fim | hard | {
"lang": "rust",
"repo": "eric-wood/wm8731",
"path": "/src/digital_audio_path.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> AdcHpf { index, bitmask }
}
pub fn enable(&mut self) {
self.bitmask.unset(self.index);
}
pub fn disable(&mut self) {
self.bitmask.set(self.index);
}
}
#[derive(Debug, Copy, Clone)]
pub struct DigitalAudioPath {
pub(crate) data: u16,
}
impl DigitalAudioPath... | code_fim | hard | {
"lang": "rust",
"repo": "eric-wood/wm8731",
"path": "/src/digital_audio_path.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: eric-wood/wm8731 path: /src/digital_audio_path.rs
//! Configuration for digital audio path
use crate::bitmask::BitMask;
use crate::EnableDisable;
pub struct Deemphasis<'a> {
index: u16,
bitmask: BitMask<'a>,
}
impl<'a> Deemphasis<'a> {
pub fn new(index: u16, data: &'a mut u16) -> ... | code_fim | hard | {
"lang": "rust",
"repo": "eric-wood/wm8731",
"path": "/src/digital_audio_path.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: asnelling/psst path: /psst-gui/src/ui/search.rs
use std::sync::Arc;
use druid::{
widget::{CrossAxisAlignment, Flex, Label, LabelText, List, TextBox},
Data, LensExt, Selector, Widget, WidgetExt,
};
use crate::{
cmd,
controller::InputController,
data::{AppState, Ctx, Nav, Sea... | code_fim | hard | {
"lang": "rust",
"repo": "asnelling/psst",
"path": "/psst-gui/src/ui/search.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> tracklist_widget(TrackDisplay {
title: true,
artist: true,
album: true,
..TrackDisplay::empty()
})
}
fn playlist_results_widget() -> impl Widget<WithCtx<SearchResults>> {
List::new(playlist_widget).lens(Ctx::data().then(SearchResults::playlists))
}
fn header_w... | code_fim | hard | {
"lang": "rust",
"repo": "asnelling/psst",
"path": "/psst-gui/src/ui/search.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: laldon/Pleco path: /pleco_engine/src/threadpool/mod.rs
//! Contains the ThreadPool and the individual Threads.
use std::heap::{Alloc, Layout, Heap};
use std::sync::atomic::{AtomicBool,Ordering};
use std::thread::{JoinHandle,self};
use std::sync::{Once, ONCE_INIT};
use std::ptr::NonNull;
use std... | code_fim | hard | {
"lang": "rust",
"repo": "laldon/Pleco",
"path": "/pleco_engine/src/threadpool/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert!(!root_moves.is_empty());
self.wait_for_finish();
self.stop.store(false, Ordering::Relaxed);
for thread_ptr in self.threads.iter_mut() {
let mut thread: &mut Searcher = unsafe {&mut **(*thread_ptr).get()};
thread.depth_completed = 0;
... | code_fim | hard | {
"lang": "rust",
"repo": "laldon/Pleco",
"path": "/pleco_engine/src/threadpool/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: AndikaRizary/juneau_wasm path: /packages/core/core/src/dump/implementations/primitive.rs
use crate::Dump;
macro_rules! implement_dump {
($($typ:ty),*) => {$(
impl Dump for $typ {
fn dump(&self) -> String {
<|fim_suffix|>
impl Dump for str {
fn dump(&self) -> String ... | code_fim | medium | {
"lang": "rust",
"repo": "AndikaRizary/juneau_wasm",
"path": "/packages/core/core/src/dump/implementations/primitive.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Dump for str {
fn dump(&self) -> String {
format!("\"{}\"", self)
}
}
impl Dump for String {
fn dump(&self) -> String {
format!("\"{}\"", self)
}
}<|fim_prefix|>// repo: AndikaRizary/juneau_wasm path: /packages/core/core/src/dump/implementations/primitive.rs
use crate... | code_fim | medium | {
"lang": "rust",
"repo": "AndikaRizary/juneau_wasm",
"path": "/packages/core/core/src/dump/implementations/primitive.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: bwestlin/advent-of-code-2018-rs path: /src/day01/day01.rs
extern crate utils;
use std::collections::HashSet;
use std::error::Error;
use std::io::{self, BufReader};
use std::io::prelude::*;
use std::fs::File;
use utils::*;
fn part1(freq_changes: Vec<i32>) -> i32 {
freq_changes.iter().sum()... | code_fim | hard | {
"lang": "rust",
"repo": "bwestlin/advent-of-code-2018-rs",
"path": "/src/day01/day01.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn test_part1() {
assert_eq!(part1(to_input("+1, -2, +3, +1")), 3);
assert_eq!(part1(to_input("+1, +1, +1")), 3);
assert_eq!(part1(to_input("+1, +1, -2")), 0);
assert_eq!(part1(to_input("-1, -2, -3")), -6);
}
#[test]
fn test_part2() {
as... | code_fim | medium | {
"lang": "rust",
"repo": "bwestlin/advent-of-code-2018-rs",
"path": "/src/day01/day01.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> if success == 0 || len_actual != len_required {
Err(Error::last_os_error())
} else {
Ok(())
}
}
pub fn read_buf(handle: ProcessHandle, address: usize, length: usize) -> Result<Vec<u8>, Error> {
let mut result: Vec<u8> = Vec::with_capacity(length);
unsafe { res... | code_fim | hard | {
"lang": "rust",
"repo": "heilhead/rust-fmi",
"path": "/crates/fmi/src/memory.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: heilhead/rust-fmi path: /crates/fmi/src/memory.rs
use super::process::ProcessHandle;
use std::io::Error;
use winapi::um::memoryapi::ReadProcessMemory;
pub fn read<T>(handle: ProcessHandle, address: usize) -> Result<T, Error>
where
T: Sized + Default,
{
let mut buf: T = Default::... | code_fim | hard | {
"lang": "rust",
"repo": "heilhead/rust-fmi",
"path": "/crates/fmi/src/memory.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(target_os = "linux")]
pub fn mkdev(major: u64, minor: u64) -> dev_t {
(major << MINORBITS) | minor
}
pub fn umask(mode: Mode) -> Mode {
let prev = unsafe { ffi::umask(mode.bits() as mode_t) };
Mode::from_bits(prev).expect("[BUG] umask returned invalid Mode")
}
pub fn stat<P: ?Sized + N... | code_fim | hard | {
"lang": "rust",
"repo": "hassoon1986/Vite_GrinWallet-android",
"path": "/rust/nix-0.7.0/src/sys/stat.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: hassoon1986/Vite_GrinWallet-android path: /rust/nix-0.7.0/src/sys/stat.rs
pub use libc::dev_t;
pub use libc::stat as FileStat;
use {Errno, Result, NixPath};
use libc::{self, mode_t};
use std::mem;
use std::os::unix::io::RawFd;
mod ffi {
use libc::{c_char, c_int, mode_t, dev_t};
pub use... | code_fim | hard | {
"lang": "rust",
"repo": "hassoon1986/Vite_GrinWallet-android",
"path": "/rust/nix-0.7.0/src/sys/stat.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> Ok(dst)
}
pub fn lstat<P: ?Sized + NixPath>(path: &P) -> Result<FileStat> {
let mut dst = unsafe { mem::uninitialized() };
let res = try!(path.with_nix_path(|cstr| {
unsafe {
ffi::lstat(cstr.as_ptr(), &mut dst as *mut FileStat)
}
}));
try!(Errno::result(re... | code_fim | hard | {
"lang": "rust",
"repo": "hassoon1986/Vite_GrinWallet-android",
"path": "/rust/nix-0.7.0/src/sys/stat.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: virattara/LocustDB path: /src/engine/data_types/byte_slices.rs
use std::cmp::min;
use std::fmt::Write;
use std::fmt;
use hex;
use itertools::Itertools;
use crate::engine::data_types::*;
use crate::ingest::raw_val::RawVal;
#[derive(Debug, Clone)]
pub struct ByteSlices<'a> {
pub row_len: u... | code_fim | hard | {
"lang": "rust",
"repo": "virattara/LocustDB",
"path": "/src/engine/data_types/byte_slices.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn get_type(&self) -> EncodingType { EncodingType::ByteSlices(self.row_len) }
fn append_all(&mut self, _other: &dyn Data<'a>, _count: usize) -> Option<BoxedData<'a>> {
panic!(self.type_error("append_all"))
}
fn slice_box<'b>(&'b self, _from: usize, _to: usize) -> BoxedData<'b> wh... | code_fim | hard | {
"lang": "rust",
"repo": "virattara/LocustDB",
"path": "/src/engine/data_types/byte_slices.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut result = String::new();
write!(result, "[").unwrap();
write!(result,
"{}",
slice[..max]
.iter()
.map(|x| format!("0x{}", hex::encode(x)))
.join(", ")
).unwrap();
if max < slice.len() {
write!(result, ", ... | code_fim | hard | {
"lang": "rust",
"repo": "virattara/LocustDB",
"path": "/src/engine/data_types/byte_slices.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: crimthy/crimthy-dragnit-schemes path: /src/lib.rs
extern crate dragnit;
use dragnit::*;
pub fn build_schemes() -> Vec<Schema> {
let point_schema: Sche<|fim_suffix|> Field {name: "x".to_owned(), type_id: TYPE_FLOAT, is_array: false, value: 0},
Field {name: "y".to_owned(), type_id... | code_fim | medium | {
"lang": "rust",
"repo": "crimthy/crimthy-dragnit-schemes",
"path": "/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>.to_owned(), type_id: TYPE_FLOAT, is_array: false, value: 0},
]),
]);
vec![
point_schema
]
}<|fim_prefix|>// repo: crimthy/crimthy-dragnit-schemes path: /src/lib.rs
extern crate dragnit;
use dragnit::*;
pub fn build_schemes() -> Vec<Schema> {
let point_schema: Schema = Schema::new("p... | code_fim | medium | {
"lang": "rust",
"repo": "crimthy/crimthy-dragnit-schemes",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[derive(Debug, Clone, Deserialize)]
pub struct Trade {
pub price: Decimal,
pub size: Decimal,
// side of the taker
pub side: model::OrderSide,
pub liquidation: bool,
pub time: DateTime<Utc>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct Orderbook {
pub bids: Vec<PriceQty>... | code_fim | hard | {
"lang": "rust",
"repo": "alveraboquet/ftx-rs",
"path": "/src/model/websocket.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: alveraboquet/ftx-rs path: /src/model/websocket.rs
use std::collections::HashMap;
use chrono::prelude::*;
use serde::{Deserialize, Serialize};
use crate::model::{self, PriceQty};
use rust_decimal::Decimal;
#[derive(Debug, Clone, Serialize)]
pub struct LoginArgs<'a> {
pub key: &'a str,
... | code_fim | hard | {
"lang": "rust",
"repo": "alveraboquet/ftx-rs",
"path": "/src/model/websocket.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: njust/druid-widget-nursery path: /examples/animated_value.rs
use druid::{
AppLauncher, BoxConstraints, Color, Env, Event, EventCtx, LayoutCtx, LifeCycle, LifeCycleCtx,
PaintCtx, RenderContext, Size, UnitPoint, UpdateCtx, Widget, WidgetExt, WindowDesc,
};
use druid_widget_nursery::animati... | code_fim | hard | {
"lang": "rust",
"repo": "njust/druid-widget-nursery",
"path": "/examples/animated_value.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn main_widget() -> impl Widget<()> {
AnimatedWidget::new().align_horizontal(UnitPoint::CENTER)
}
fn main() {
let main_window = WindowDesc::new(main_widget())
.title("Animated value")
.window_size((800.0, 600.0));
// start the application
AppLauncher::with_window(main_win... | code_fim | hard | {
"lang": "rust",
"repo": "njust/druid-widget-nursery",
"path": "/examples/animated_value.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Widget<()> for AnimatedWidget {
fn event(&mut self, ctx: &mut EventCtx, event: &Event, _: &mut (), _: &Env) {
match event {
Event::MouseDown(_) => {
ctx.set_active(true);
ctx.request_anim_frame();
self.set_insets(ctx.is_hot(), tr... | code_fim | hard | {
"lang": "rust",
"repo": "njust/druid-widget-nursery",
"path": "/examples/animated_value.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pe0.set_low();
pe1.set_low();
pe2.set_low();
loop {
// busy wait until the timer wraps around
while !syst.has_wrapped() {}
if pe0.is_set_low() {
pe0.set_high();
} else {
pe0.set_low();
}
// trigger the `EXTI0` interrup... | code_fim | hard | {
"lang": "rust",
"repo": "tatowicz/STM-rust",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tatowicz/STM-rust path: /src/main.rs
#![no_std]
#![no_main]
extern crate stm32f4;
extern crate panic_halt;
use cortex_m::peripheral::syst::SystClkSource;
use cortex_m_rt::{entry, exception, ExceptionFrame};
use cortex_m_semihosting::{hprint, hprintln};
use stm32f4::stm32f412::{interrupt, Inter... | code_fim | hard | {
"lang": "rust",
"repo": "tatowicz/STM-rust",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[interrupt]
fn EXTI0() {
hprint!(".").unwrap();
}
#[exception]
fn HardFault(ef: &ExceptionFrame) -> ! {
hprintln!("{:#?}", ef).unwrap();
loop {}
}<|fim_prefix|>// repo: tatowicz/STM-rust path: /src/main.rs
#![no_std]
#![no_main]
extern crate stm32f4;
extern crate panic_halt;
use cortex_m:... | code_fim | medium | {
"lang": "rust",
"repo": "tatowicz/STM-rust",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub mod avcodec;
pub mod avformat;
pub mod avutil;
pub mod util;<|fim_prefix|>// repo: yejinlei/ffmpeg-rs path: /src/lib.rs
#![feature(libc, std_misc, unsafe_destructor, core, old_io, collections)]
extern crate libc;
<|fim_middle|>#[allow(non_camel_case_types)]
#[macro_use]
pub mod ffi;
| code_fim | easy | {
"lang": "rust",
"repo": "yejinlei/ffmpeg-rs",
"path": "/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: yejinlei/ffmpeg-rs path: /src/lib.rs
#![feature(libc, std_misc, unsafe_destructor, core, old_io, collections)]
<|fim_suffix|>pub mod avcodec;
pub mod avformat;
pub mod avutil;
pub mod util;<|fim_middle|>extern crate libc;
#[allow(non_camel_case_types)]
#[macro_use]
pub mod ffi;
| code_fim | medium | {
"lang": "rust",
"repo": "yejinlei/ffmpeg-rs",
"path": "/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[allow(non_camel_case_types)]
#[macro_use]
pub mod ffi;
pub mod avcodec;
pub mod avformat;
pub mod avutil;
pub mod util;<|fim_prefix|>// repo: yejinlei/ffmpeg-rs path: /src/lib.rs
#![feature(libc, std_misc, unsafe_destructor, core, old_io, collections)]
<|fim_middle|>extern crate libc;
| code_fim | easy | {
"lang": "rust",
"repo": "yejinlei/ffmpeg-rs",
"path": "/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: kore-signet/carcinization path: /src/chron/v1.rs
use super::{CarcinizationResult, PaginatedRequest, PaginatedResponse, SortOrder};
use chrono::{DateTime, Utc};
use derive_builder::Builder;
use futures_core::Stream;
use serde::{Deserialize, Serialize};
use std::collections::VecDeque;
#[derive(De... | code_fim | hard | {
"lang": "rust",
"repo": "kore-signet/carcinization",
"path": "/src/chron/v1.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[derive(Serialize, Builder, Debug, Default)]
#[builder(setter(into, strip_option), default)]
pub struct GameUpdatesRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) count: Option<usize>,
#[serde(skip_serializing_if = "Option::is_none")]
game: Option<String>,
#[ser... | code_fim | medium | {
"lang": "rust",
"repo": "kore-signet/carcinization",
"path": "/src/chron/v1.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dustypomerleau/exercism path: /rust/clock/src/lib.rs
use chrono::{Duration, NaiveTime, Timelike};
use std::fmt;
#[derive(Debug, PartialEq)]
pub struct Clock {
time: NaiveTime,
}
<|fim_suffix|>impl fmt::Display for Clock {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
w... | code_fim | hard | {
"lang": "rust",
"repo": "dustypomerleau/exercism",
"path": "/rust/clock/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: eqlabs/pathfinder path: /crates/rpc/src/v02/method/get_class_at.rs
use crate::context::RpcContext;
use crate::v02::types::ContractClass;
use anyhow::Context;
use pathfinder_common::{BlockId, ClassHash, ContractAddress};
use starknet_gateway_types::pending::PendingData;
crate::error::generate_rp... | code_fim | hard | {
"lang": "rust",
"repo": "eqlabs/pathfinder",
"path": "/crates/rpc/src/v02/method/get_class_at.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Cairo v0.x class
// This class is declared in block 1.
let valid_v0 = contract_address_bytes!(b"contract 1");
let block1_hash = block_hash_bytes!(b"block 1");
super::get_class_at(
context.clone(),
GetClassAtInput {
block_id... | code_fim | hard | {
"lang": "rust",
"repo": "eqlabs/pathfinder",
"path": "/crates/rpc/src/v02/method/get_class_at.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> jh.await.context("Reading class from database")?
}
/// Returns the [ClassHash] of the given [ContractAddress] if any is defined in the pending data.
async fn get_pending_class_hash(
pending: Option<PendingData>,
address: ContractAddress,
) -> Option<ClassHash> {
pending?.state_update().aw... | code_fim | hard | {
"lang": "rust",
"repo": "eqlabs/pathfinder",
"path": "/crates/rpc/src/v02/method/get_class_at.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tathanhdinh/rustyvisor path: /src/serial_logger.rs
use log;
use core::fmt::{self, Write};
use spin::Mutex;
const PORT: u16 = 0x3f8;
#[derive(Default)]
pub struct SerialPort;
#[derive(Default)]
pub struct SerialLogger;
static SERIAL_PORT_MUTEX: Mutex<SerialPort> = Mutex::new(SerialPort);
fn... | code_fim | hard | {
"lang": "rust",
"repo": "tathanhdinh/rustyvisor",
"path": "/src/serial_logger.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let data: u8;
unsafe {
asm!("inb %dx, %al" : "={al}"(data) : "{dx}"(port as u16));
}
data
}
impl fmt::Write for SerialPort {
fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> {
for c in s.chars() {
while (inb(PORT + 5) & 0x20) == 0 {}
o... | code_fim | hard | {
"lang": "rust",
"repo": "tathanhdinh/rustyvisor",
"path": "/src/serial_logger.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>ktrace::Backtrace::new();
let res = BacktraceResponse {
text: format!("{:?}", bt),
..Default::default()
};
Box::new(res)
}<|fim_prefix|>// repo: BugenZhao/rust-swift-pb-interop path: /rust/src/async_handlers.rs
use crate::protos::DataModel::*;
use protobuf::Message;
pub async... | code_fim | hard | {
"lang": "rust",
"repo": "BugenZhao/rust-swift-pb-interop",
"path": "/rust/src/async_handlers.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: BugenZhao/rust-swift-pb-interop path: /rust/src/async_handlers.rs
use crate::protos::DataModel::*;
use protobuf::Message;
pub async fn handle_sleep(req: SleepRequest) -> Box<dyn Message> {
tokio::time::sleep(to<|fim_suffix|> ..Default::default()
};
Box::new(res)
}
pub async ... | code_fim | medium | {
"lang": "rust",
"repo": "BugenZhao/rust-swift-pb-interop",
"path": "/rust/src/async_handlers.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> ..Default::default()
};
Box::new(res)
}
pub async fn handle_backtrace(_req: BacktraceRequest) -> Box<dyn Message> {
let bt = backtrace::Backtrace::new();
let res = BacktraceResponse {
text: format!("{:?}", bt),
..Default::default()
};
Box::new(res)
}<|fim_p... | code_fim | medium | {
"lang": "rust",
"repo": "BugenZhao/rust-swift-pb-interop",
"path": "/rust/src/async_handlers.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn consumed_bytes(&self) -> usize {
self.consumed_bytes
}
}
impl<'a> std::io::Read for SliceReader<'a> {
fn read(&mut self, mut output: &mut [u8]) -> std::io::Result<usize> {
let mut total_read = 0;
while output.len() > 0 && self.index < self.slices.len() {
... | code_fim | medium | {
"lang": "rust",
"repo": "dennisss/dacha",
"path": "/pkg/compression/src/slice_reader.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dennisss/dacha path: /pkg/compression/src/slice_reader.rs
/// Enables reading from
pub struct SliceReader<'a> {
slices: [&'a [u8]; 2],
index: usize,
consumed_bytes: usize,
}
impl<'a> SliceReader<'a> {
pub fn new(slices: [&'a [u8]; 2]) -> Self {
Self {
slices,... | code_fim | hard | {
"lang": "rust",
"repo": "dennisss/dacha",
"path": "/pkg/compression/src/slice_reader.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> Ok(())
}
pub fn consumed_bytes(&self) -> usize {
self.consumed_bytes
}
}
impl<'a> std::io::Read for SliceReader<'a> {
fn read(&mut self, mut output: &mut [u8]) -> std::io::Result<usize> {
let mut total_read = 0;
while output.len() > 0 && self.index < self.... | code_fim | hard | {
"lang": "rust",
"repo": "dennisss/dacha",
"path": "/pkg/compression/src/slice_reader.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>lazy_static! {
pub static ref ETH_EVM_DICTIONARY_KEY: [u8; 32] = get_prefixed_db_key("eth-evm-dictionary");
}<|fim_prefix|>// repo: provable-things/ptokens-core path: /src/dictionaries/dictionary_constants.rs
pub use serde_json::{json, Value as JsonValue};
use crate::utils::get_prefixed_db_key;
<|f... | code_fim | hard | {
"lang": "rust",
"repo": "provable-things/ptokens-core",
"path": "/src/dictionaries/dictionary_constants.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>lazy_static! {
// NOTE: The actual string hashed remains as it was originally for backwards compatibility.
pub static ref EOS_ETH_DICTIONARY_KEY: [u8; 32] = get_prefixed_db_key("eos-erc20-dictionary");
}
lazy_static! {
pub static ref ETH_EVM_DICTIONARY_KEY: [u8; 32] = get_prefixed_db_key("eth... | code_fim | easy | {
"lang": "rust",
"repo": "provable-things/ptokens-core",
"path": "/src/dictionaries/dictionary_constants.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: provable-things/ptokens-core path: /src/dictionaries/dictionary_constants.rs
pub use serde_json::{json, Value as JsonValue};
<|fim_suffix|>lazy_static! {
pub static ref ETH_EVM_DICTIONARY_KEY: [u8; 32] = get_prefixed_db_key("eth-evm-dictionary");
}<|fim_middle|>use crate::utils::get_prefixe... | code_fim | hard | {
"lang": "rust",
"repo": "provable-things/ptokens-core",
"path": "/src/dictionaries/dictionary_constants.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: SCRTHodl/blockchain path: /dmbc-capi/src/capi/transfer.rs
use std::mem;
use std::ptr;
use messages::Message;
use libc::{c_char, size_t};
use assets::AssetBundle;
use capi::common::*;
use transactions::transfer::TransferWrapper;
use error::{Error, ErrorKind};
ffi_fn! {
fn dmbc_tx_transfer... | code_fim | hard | {
"lang": "rust",
"repo": "SCRTHodl/blockchain",
"path": "/dmbc-capi/src/capi/transfer.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>ffi_fn! {
fn dmbc_tx_transfer_free(wrapper: *const TransferWrapper) {
if !wrapper.is_null() {
unsafe { Box::from_raw(wrapper as *mut TransferWrapper); }
}
}
}
ffi_fn! {
fn dmbc_tx_transfer_add_asset(
wrapper: *mut TransferWrapper,
asset: *const Asse... | code_fim | hard | {
"lang": "rust",
"repo": "SCRTHodl/blockchain",
"path": "/dmbc-capi/src/capi/transfer.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: cloud-hypervisor/cloud-hypervisor path: /block/src/fixed_vhd_sync.rs
// Copyright © 2021 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
use crate::async_io::{
AsyncIo, AsyncIoError, AsyncIoResult, DiskFile, DiskFileError, DiskFileResult,
};
use crate::fixed_vhd::FixedVhd;
use c... | code_fim | hard | {
"lang": "rust",
"repo": "cloud-hypervisor/cloud-hypervisor",
"path": "/block/src/fixed_vhd_sync.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> use types::function::ArgType;
debug!("Checking acceptable range for arglist {}", arglist);
let mut iter = list::iter(arglist);
let mut min_args: i32 = 0;
let mut max_args: Option<i32> = Some(0);
let mut arg_type = ArgType::Mandatory;
loop {
... | code_fim | hard | {
"lang": "rust",
"repo": "gefjon/rlisp",
"path": "/src/evaluator/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn get_args_for_lisp_func(&mut self, arglist: &ConsCell, n_args: i32) -> Object {
use types::function::ArgType;
debug!("getting arglist {}", arglist);
// iterate through an arglist, pop()ing off the stack for each
// item and binding the arg to the pop()ed value.
... | code_fim | hard | {
"lang": "rust",
"repo": "gefjon/rlisp",
"path": "/src/evaluator/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: gefjon/rlisp path: /src/evaluator/mod.rs
/*
the `Evaluator` trait does the 'E' part of REPL. its forward-facing
operation is `evaluate`, which is passed an Object, evaluates it, and
returns it.
*/
use lisp;
use result::*;
use types::*;
use list;
use list::ConsIteratorResult;
use types::function... | code_fim | hard | {
"lang": "rust",
"repo": "gefjon/rlisp",
"path": "/src/evaluator/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>// Manipulates a gcode file so it gets compatible with the servo approach from the grbl fork
pub fn process(infile: String, outfile: Option<String>) {
let content = read_file(infile).expect("Input file not found");
let content_lines = content.lines();
let mut state = 0;
match outfile {
... | code_fim | hard | {
"lang": "rust",
"repo": "hargoniX/inkscape2servo",
"path": "/grbl-servo-client/src/process.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: hargoniX/inkscape2servo path: /grbl-servo-client/src/process.rs
use quicli::prelude::*;
use regex::Regex;
use std::fs::{File, OpenOptions};
use std::io::Write;
fn process_line(line: &str, state: u8, outfile: Option<&mut File>) -> u8 {
let mut new_state = state;
let mut new_line = line;
... | code_fim | hard | {
"lang": "rust",
"repo": "hargoniX/inkscape2servo",
"path": "/grbl-servo-client/src/process.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn secret(p: u64, b_pub: u64, a: u64) -> u64 {
modular_pow(b_pub as u128, a as u128, p as u128) as u64
}<|fim_prefix|>// repo: st3fan/exercism path: /rust/diffie-hellman/src/lib.rs
use rand::Rng;
fn modular_pow(mut base: u128, mut exponent: u128, modulus: u128) -> u128 {
if modulus == 1 {
... | code_fim | hard | {
"lang": "rust",
"repo": "st3fan/exercism",
"path": "/rust/diffie-hellman/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> while exponent > 0 {
if exponent % 2 == 1 {
result = (result * base) % modulus
}
exponent >>= 1;
base = (base * base) % modulus;
}
result
}
pub fn private_key(p: u64) -> u64 {
let mut rng = rand::thread_rng();
rng.gen_range(2..p)
}
pub fn ... | code_fim | medium | {
"lang": "rust",
"repo": "st3fan/exercism",
"path": "/rust/diffie-hellman/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: st3fan/exercism path: /rust/diffie-hellman/src/lib.rs
use rand::Rng;
fn modular_pow(mut base: u128, mut exponent: u128, modulus: u128) -> u128 {
if modulus == 1 {
return 0;
}
let mut result = 1;
while exponent > 0 {
if exponent % 2 == 1 {
result = (... | code_fim | hard | {
"lang": "rust",
"repo": "st3fan/exercism",
"path": "/rust/diffie-hellman/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: shifteight/rust path: /byexample/closure_capturing.rs
fn main() {
use std::mem;
let color = "green";
// A closure to print `color` which immediately borrows (`&`)
// `color` and stores the borrow and closure in the `print`
// variable. It will remain borrowed until `print` goes out ... | code_fim | hard | {
"lang": "rust",
"repo": "shifteight/rust",
"path": "/byexample/closure_capturing.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> println!("{}", contains(&1));
println!("{}", contains(&4));
// println!("There're {} elements in vec", haystack.len());
// ^ Uncommenting above line will result in compile-time error
// because borrow checker doesn't allow re-using variable after it
// has been moved.
// ... | code_fim | medium | {
"lang": "rust",
"repo": "shifteight/rust",
"path": "/byexample/closure_capturing.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // `consume` consumes the variable so this can only be called once.
consume();
// consume();
// `Vec` has non-copy semantics.
let haystack = vec![1, 2, 3];
let contains = move |needle| haystack.contains(needle);
println!("{}", contains(&1));
println!("{}", contains(&4))... | code_fim | hard | {
"lang": "rust",
"repo": "shifteight/rust",
"path": "/byexample/closure_capturing.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> match e {
AuthorizationError::CertType => RusticaServerError::BadCertOptions,
AuthorizationError::NotAuthorized => RusticaServerError::NotAuthorized,
AuthorizationError::AuthorizerError => RusticaServerError::Unknown,
}
}
}<|fim_prefix|>// repo: dhav... | code_fim | medium | {
"lang": "rust",
"repo": "dhaveed/rustica",
"path": "/rustica/src/error.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dhaveed/rustica path: /rustica/src/error.rs
use crate::auth::AuthorizationError;
#[derive(Debug)]
pub enum RusticaServerError {
Success = 0,
TimeExpired = 1,
BadChallenge = 2,
InvalidKey = 3,
UnsupportedKeyType = 4,
BadCertOptions = 5,
NotAuthorized = 6,
BadReque... | code_fim | medium | {
"lang": "rust",
"repo": "dhaveed/rustica",
"path": "/rustica/src/error.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.