text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_suffix|> for i in 0..haystack_bytes.len() {
let mut found = true;
for j in 0..needle_bytes.len() {
if haystack_bytes.get(i+j) != needle_bytes.get(j) {
found = false;
break
}
}
if found {
... | code_fim | hard | {
"lang": "rust",
"repo": "jack-davies/leetcode",
"path": "/28.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jack-davies/leetcode path: /28.rs
impl Solution {
pub fn str_str(haystack: String, needle: String) -> i32 {
if haystack == needle {
// catches edge case haystack == needle == ""
return 0
}
<|fim_suffix|> for i in 0..haystack_bytes.len() {
... | code_fim | hard | {
"lang": "rust",
"repo": "jack-davies/leetcode",
"path": "/28.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: copperinc/usbg.rs path: /examples/hidrndis.rs
extern crate usbg;
use std::path::PathBuf;
use std::fs;
use usbg::UsbGadget;
use usbg::UsbGadgetState;
use usbg::UsbGadgetFunction;
use usbg::UsbGadgetConfig;
use usbg::hid;
use usbg::rndis;
fn main() {
// general setup
let mut g1 = UsbGad... | code_fim | hard | {
"lang": "rust",
"repo": "copperinc/usbg.rs",
"path": "/examples/hidrndis.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // if you want test against a temp directory you can uncomment this
// let tmp_configfs = PathBuf::from("/tmp/configfs/usb_gadget");
// let _ = fs::create_dir_all(tmp_configfs.as_path());
// usb_state.configfs_path(tmp_configfs);
match usb_state.enable(g1) {
Ok(_) => println!(... | code_fim | hard | {
"lang": "rust",
"repo": "copperinc/usbg.rs",
"path": "/examples/hidrndis.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: fghzxm/windows-rs path: /src/result/error.rs
use crate::*;
/// A WinRT error object consists of both an error code as well as detailed error information for debugging.
#[derive(Clone, PartialEq)]
pub struct Error {
code: ErrorCode,
info: Option<IRestrictedErrorInfo>,
}
impl Error {
... | code_fim | hard | {
"lang": "rust",
"repo": "fghzxm/windows-rs",
"path": "/src/result/error.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl std::error::Error for Error {}
pub struct HeapString(RawPtr);
impl Drop for HeapString {
fn drop(&mut self) {
if !self.0.is_null() {
unsafe {
heap_free(self.0);
}
}
}
}
#[link(name = "kernel32")]
extern "system" {
fn FormatMessage... | code_fim | hard | {
"lang": "rust",
"repo": "fghzxm/windows-rs",
"path": "/src/result/error.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> if let &Some(ref object) = object_option {
object.show_message();
}
}<|fim_prefix|>// repo: evaporei/design-patterns path: /creational/singleton/rust/src/main.rs
extern crate singleton;
use singleton::SingletonObject;
fn main() {
<|fim_middle|> let object_option = SingletonObject::ge... | code_fim | easy | {
"lang": "rust",
"repo": "evaporei/design-patterns",
"path": "/creational/singleton/rust/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let object_option = SingletonObject::get_instance();
if let &Some(ref object) = object_option {
object.show_message();
}
}<|fim_prefix|>// repo: evaporei/design-patterns path: /creational/singleton/rust/src/main.rs
extern crate singleton;
<|fim_middle|>use singleton::SingletonObject... | code_fim | easy | {
"lang": "rust",
"repo": "evaporei/design-patterns",
"path": "/creational/singleton/rust/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: evaporei/design-patterns path: /creational/singleton/rust/src/main.rs
extern crate singleton;
<|fim_suffix|> let object_option = SingletonObject::get_instance();
if let &Some(ref object) = object_option {
object.show_message();
}
}<|fim_middle|>use singleton::SingletonObject... | code_fim | easy | {
"lang": "rust",
"repo": "evaporei/design-patterns",
"path": "/creational/singleton/rust/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: comfortablynick/todors path: /src/file.rs
use crate::{
config::AppContext,
prelude::*,
task::{Task, Tasks},
};
use std::{
fs::OpenOptions,
io::{Read, Write},
path::Path,
};
// TODO: combine get_tasks and get_done since they are 90% the same
/// Load todo.txt file and par... | code_fim | hard | {
"lang": "rust",
"repo": "comfortablynick/todors",
"path": "/src/file.rs",
"mode": "psm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// Read file to string
pub fn read_file_to_string<P>(file_path: P) -> Result<String>
where
P: AsRef<Path> + std::fmt::Debug,
{
OpenOptions::new()
.read(true)
.open(&file_path)
.and_then(|mut file| {
let mut buf = String::new();
file.read_to_string(&... | code_fim | hard | {
"lang": "rust",
"repo": "comfortablynick/todors",
"path": "/src/file.rs",
"mode": "spm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: GabrielAtenciaGomez/reto_rust path: /src/logica/operaciones_json.rs
extern crate reqwest;
use anyhow::Result;
use isahc::{ResponseExt};
use serde_json::Value;
pub fn configuracion(json: &Value, configuracion: &str) -> String {
let mut json_copia: Value = json.clone();
let mut operacion... | code_fim | hard | {
"lang": "rust",
"repo": "GabrielAtenciaGomez/reto_rust",
"path": "/src/logica/operaciones_json.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> resultado = ((a as f64) * b).to_string();
} else if num1.matches(".").count() == 0 && num2.matches(".").count() == 0 {
let a = num1.parse::<isize>().unwrap_or(0);
let b = num2.parse::<isize>().unwrap_or(0);
resultado = (a * b).to_string();
}
resultado
}
pub fn... | code_fim | hard | {
"lang": "rust",
"repo": "GabrielAtenciaGomez/reto_rust",
"path": "/src/logica/operaciones_json.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: morganfogg/zanthe path: /src/interface/terminal.rs
pub mod window;
use std::{
error::Error,
io,
time::{Duration, Instant},
};
use crossterm::{
self,
cursor::{position as cursor_pos, MoveLeft, MoveTo},
event::{self, read, Event, KeyCode, KeyEvent},
execute, queue,
... | code_fim | hard | {
"lang": "rust",
"repo": "morganfogg/zanthe",
"path": "/src/interface/terminal.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Set the text style to fixed-width
fn text_style_fixed(&mut self) -> Result<()> {
// todo!();
Ok(())
}
/// Remove all text styles
fn text_style_clear(&mut self) -> Result<()> {
// todo!();
Ok(())
}
fn set_z_machine_version(&mut self, version... | code_fim | hard | {
"lang": "rust",
"repo": "morganfogg/zanthe",
"path": "/src/interface/terminal.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl SolverLogger for StdoutLogger {
fn log(&mut self, context: &OptContext, ignore_frequency: bool) {
match self.frequency {
EveryNthIteration(freq) => {
if (context.iteration % freq == 0 && !ignore_frequency)
|| (ignore_frequency && self.last_o... | code_fim | hard | {
"lang": "rust",
"repo": "hheld/runolinop",
"path": "/src/output.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: hheld/runolinop path: /src/output.rs
use crate::optimizer::OptContext;
use crate::output::Frequency::EveryNthIteration;
#[allow(dead_code)]
pub enum Frequency {
EveryNthIteration(u32),
}
pub trait SolverLogger {
fn log(&mut self, context: &OptContext, ignore_frequency: bool);
<|fim_suf... | code_fim | hard | {
"lang": "rust",
"repo": "hheld/runolinop",
"path": "/src/output.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let delta: f32 = data.world.read_resource::<Time>().delta_seconds();
if let Some(mut exit_opt) = data.world.try_fetch_mut::<Option<ExitCombat>>() {
let mut exit_idx: Option<(usize, Option<Team>)> = None;
if let Some(exit) = exit_opt.as_mut() {
exit.t... | code_fim | hard | {
"lang": "rust",
"repo": "Merlotec/gravity",
"path": "/src/state/combat_state.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Merlotec/gravity path: /src/state/combat_state.rs
use amethyst::{
assets::{
Handle,
Prefab,
PrefabLoader,
PrefabLoaderSystemDesc,
RonFormat,
},
core::{
math::Vector3,
Parent,
Transform,
Time,
},
ecs::prel... | code_fim | hard | {
"lang": "rust",
"repo": "Merlotec/gravity",
"path": "/src/state/combat_state.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: planet0104/android_sdl2_test path: /pbrain/src/ga.rs
use rand::rngs::ThreadRng;
use std::sync::mpsc::channel;
use std::thread;
use std::sync::{Arc, Mutex};
use rand::{thread_rng, Rng};
use ::INSTRUCTION_SET;
pub trait CalcFitnessClone: Send {
fn clone_box(&self) -> Box<CalcFitness>;
}
impl... | code_fim | hard | {
"lang": "rust",
"repo": "planet0104/android_sdl2_test",
"path": "/pbrain/src/ga.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub struct GA {
params: Params,
pop: Vec<Genome>,
total_fitness: f64,
generations: usize,
rng: ThreadRng,
}
impl GA {
pub fn new(params:Params) -> GA {
let mut pop = vec![];
for _ in 0..params.pop_size{
pop.push(Genome::new(params.num_copies_elite));
... | code_fim | hard | {
"lang": "rust",
"repo": "planet0104/android_sdl2_test",
"path": "/pbrain/src/ga.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: BusyJay/alloc-tcmalloc path: /build.rs
extern crate gcc;
use std::env;
use std::fs;
use std::path::{Path, PathBuf};
use std::process::Command;
fn main() {
let target = env::var("TARGET").unwrap();
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
let build_dir = out_dir... | code_fim | hard | {
"lang": "rust",
"repo": "BusyJay/alloc-tcmalloc",
"path": "/build.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn run(cmd: &mut Command) -> &mut Command {
println!("running: {:?}", cmd);
let status = match cmd.status() {
Ok(status) => status,
Err(e) => panic!("failed to execute command: {}", e),
};
if !status.success() {
panic!("command did not execute successfully: {:?}\n\
... | code_fim | hard | {
"lang": "rust",
"repo": "BusyJay/alloc-tcmalloc",
"path": "/build.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rcore-os/virtio-drivers path: /examples/aarch64/src/main.rs
#![no_std]
#![no_main]
extern crate alloc;
mod exceptions;
mod hal;
mod logger;
#[cfg(platform = "qemu")]
mod pl011;
#[cfg(platform = "qemu")]
use pl011 as uart;
#[cfg(platform = "crosvm")]
mod uart8250;
#[cfg(platform = "crosvm")]
us... | code_fim | hard | {
"lang": "rust",
"repo": "rcore-os/virtio-drivers",
"path": "/examples/aarch64/src/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn virtio_blk<T: Transport>(transport: T) {
let mut blk = VirtIOBlk::<HalImpl, T>::new(transport).expect("failed to create blk driver");
assert!(!blk.readonly());
let mut input = [0xffu8; 512];
let mut output = [0; 512];
for i in 0..32 {
for x in input.iter_mut() {
... | code_fim | hard | {
"lang": "rust",
"repo": "rcore-os/virtio-drivers",
"path": "/examples/aarch64/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let partial_ticket_fr = bytes_into_fr::<Bls12>(&partial_ticket)?;
Ok(Candidate {
sector_id: sector_id.into(),
partial_ticket: partial_ticket_fr,
ticket,
sector_challenge_index,
})
}
}
#[repr(C)]
#[derive(DropStructMacro)]
pub str... | code_fim | hard | {
"lang": "rust",
"repo": "finalitylabs/rust-fil-proofs-ffi",
"path": "/src/types.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: finalitylabs/rust-fil-proofs-ffi path: /src/types.rs
use std::io::{Error, SeekFrom};
use std::ptr;
use drop_struct_macro_derive::DropStructMacro;
use paired::bls12_381::Bls12;
// `CodeAndMessage` is the trait implemented by `code_and_message_impl`
use ffi_toolkit::{code_and_message_impl, free_c... | code_fim | hard | {
"lang": "rust",
"repo": "finalitylabs/rust-fil-proofs-ffi",
"path": "/src/types.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Davier/bevy_prototype_widgets path: /src/focus.rs
use bevy::{
input::{keyboard::KeyboardInput, ElementState},
prelude::*,
};
use serde::{Deserialize, Serialize};
/*
- UI entities can be Focusable
- at most one entity can be focused, only it is allowed to process keyboard events
- the foc... | code_fim | hard | {
"lang": "rust",
"repo": "Davier/bevy_prototype_widgets",
"path": "/src/focus.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn tab_navigation(
mut keyboard_input_events: EventReader<KeyboardInput>,
keyboard_state: Res<Input<KeyCode>>,
mut current_focus: ResMut<CurrentFocus>,
mut query_focusable: Query<&mut Focusable>,
) {
for event in keyboard_input_events.iter() {
if let Some(key_code) = event.... | code_fim | hard | {
"lang": "rust",
"repo": "Davier/bevy_prototype_widgets",
"path": "/src/focus.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let data = DataSet::UnstructuredGrid {
points: pos.into(),
cells: Cells {
num_cells: 0,
vertices: vec![],
},
cell_types: vec![],
data: attributes,
};
let vtk = Vtk {
version: Version::new((4, 1)),
title: String::f... | code_fim | hard | {
"lang": "rust",
"repo": "dineshadepu/simple_shapes",
"path": "/examples/hollow_box_2d.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let spacing = 0.03;
let (x1, y1) = hollow_box_2d(0., 1.0, spacing, 0., 1.0, spacing, 2, false);
let filename = format!("hollow_box_2d_inside.vtk");
let mut pos = vec![];
let mut radius = vec![];
for i in 0..x1.len() {
pos.push(x1[i]);
pos.push(y1[i]);
pos.p... | code_fim | hard | {
"lang": "rust",
"repo": "dineshadepu/simple_shapes",
"path": "/examples/hollow_box_2d.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dineshadepu/simple_shapes path: /examples/hollow_box_2d.rs
extern crate simple_shapes;
extern crate vtkio;
use simple_shapes::hollow_box_2d;
use std::path::PathBuf;
use vtkio::export_ascii;
use vtkio::model::*;
fn main() {
// dimension
let spacing = 0.03;
let (x1, y1) = hollow_box_2... | code_fim | hard | {
"lang": "rust",
"repo": "dineshadepu/simple_shapes",
"path": "/examples/hollow_box_2d.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: niuez/toptree-rust path: /src/cut.rs
use std::ptr::NonNull;
use crate::node::*;
use crate::expose::*;
use crate::splay::*;
fn bring<T: Cluster>(mut root: NonNull<Compress<T>>) {
unsafe {
match root.as_ref().rake() {
None => {
let mut left = root.as_ref().... | code_fim | hard | {
"lang": "rust",
"repo": "niuez/toptree-rust",
"path": "/src/cut.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> *root.as_mut().child_mut(1) = new_right;
*new_right.parent_mut() = Some(ParentNode::Compress(root));
*root.as_mut().rake_mut() = Some(new_rake);
*new_rake.parent_mut() = Some(ParentNode::Compress(root));
new_rake.fix();
... | code_fim | hard | {
"lang": "rust",
"repo": "niuez/toptree-rust",
"path": "/src/cut.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: marcinioski/nes_rust_emulator path: /hal/src/interface/mod.rs
use std::sync::Arc;
pub type RawPtr = Arc<Box<[u8]>>;
pub trait Memory {
fn ctrlmalloc(&mut self, size: usize) -> Option<RawPtr>;
fn ctrlfree(&mut self, ptr: RawPtr);
fn ctrl_from_ptr(&mut self, ptr: *const u8, size: usiz... | code_fim | hard | {
"lang": "rust",
"repo": "marcinioski/nes_rust_emulator",
"path": "/hal/src/interface/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.controller.ctrlfree(ptr);
}
fn ctrl_from_ptr(&mut self, ptr: *const u8, size: usize) -> Option<RawPtr> {
self.controller.ctrl_from_ptr(ptr, size)
}
fn ctrl_ptr_from_slice(&mut self, ptr: &mut RawPtr, len: usize, shift: usize) -> Option<RawPtr> {
self.controll... | code_fim | hard | {
"lang": "rust",
"repo": "marcinioski/nes_rust_emulator",
"path": "/hal/src/interface/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: yred/euler path: /rust/problem_022.rs
// Problem 22 - Names scores
//
// Using "../resources/p022_names.txt", a 46K text file containing over
// five-thousand first names, begin by sorting it into alphabetical order.
// Then working out the alphabetical value for each name, multiply this value b... | code_fim | hard | {
"lang": "rust",
"repo": "yred/euler",
"path": "/rust/problem_022.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut names = file.split(b',')
.map(|res| get_name(res.unwrap()))
.collect::<Vec<_>>();
names.sort();
names.iter()
.enumerate()
.map(|(ix, name)| (ix as u32 + 1)*value(name))
.fold(0, |sum, score| sum + score)
}
fn... | code_fim | medium | {
"lang": "rust",
"repo": "yred/euler",
"path": "/rust/problem_022.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: kenoss/frum path: /src/cli.rs
use clap::{App, AppSettings, Arg, SubCommand};
pub fn build_cli() -> App<'static, 'static> {
App::new("frum")
.setting(AppSettings::ArgRequiredElseHelp)
.version("0.1.1")
.about("A little bit fast and modern Ruby version manager written ... | code_fim | hard | {
"lang": "rust",
"repo": "kenoss/frum",
"path": "/src/cli.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>ith_name("version").index(1))
.arg(
Arg::with_name("configure_opts")
.multiple(true)
.help("Options passed to ./configure"),
),
)
.subcommand(
SubCommand::with_name("uninstall")
... | code_fim | hard | {
"lang": "rust",
"repo": "kenoss/frum",
"path": "/src/cli.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn get_prev_mut(&mut self) -> &mut BufferNode {
assert!(self.left_list.len() >= 2);
let idx = self.left_list.len() - 2;
self.left_list.get_mut(idx).unwrap()
}
pub fn insert_curr(&mut self, node: BufferNode) {
self.left_list.push_back(node);
}
... | code_fim | hard | {
"lang": "rust",
"repo": "eldon-chung/raccoon-editor",
"path": "/src/model/nodelist.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn iter_until_curr(&self) -> impl Iterator<Item = &BufferNode> {
self.left_list.iter()
}
pub fn iter_from_after_curr(&self) -> impl Iterator<Item = &BufferNode> {
self.right_list.iter()
}
pub fn move_to_prev_newline(&mut self) {
self.move_left();
... | code_fim | hard | {
"lang": "rust",
"repo": "eldon-chung/raccoon-editor",
"path": "/src/model/nodelist.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: eldon-chung/raccoon-editor path: /src/model/nodelist.rs
use std::collections::VecDeque;
#[allow(dead_code)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum BufferType {
Original,
Added,
}
#[derive(Clone, PartialEq, Debug)]
pub struct BufferNode {
from: BufferType,
... | code_fim | hard | {
"lang": "rust",
"repo": "eldon-chung/raccoon-editor",
"path": "/src/model/nodelist.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rust-lang/rust-log-analyzer path: /src/bin/server/worker.rs
use super::QueueItem;
use crate::rla;
use crate::rla::ci::{self, BuildCommit, CiPlatform};
use anyhow::bail;
use rla::index::IndexStorage;
use std::collections::{HashSet, VecDeque};
use std::hash::Hash;
use std::str;
use std::time::{Du... | code_fim | hard | {
"lang": "rust",
"repo": "rust-lang/rust-log-analyzer",
"path": "/src/bin/server/worker.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn process(&mut self, item: QueueItem, span: &tracing::Span) -> rla::Result<ProcessOutcome> {
let (repo, build_id, outcome) = match &item {
QueueItem::GitHubStatus { payload, .. } => {
match self.ci.build_id_from_github_status(&payload) {
Some(id... | code_fim | hard | {
"lang": "rust",
"repo": "rust-lang/rust-log-analyzer",
"path": "/src/bin/server/worker.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Nnubes256/IDIoT path: /dht11-test/src/main.rs
#[cfg(arch = "arm")]
use adafruit_dht11_sys::pi_2_dht_read;
/*use hal_sensor_dht::SensorType;
use libc::sched_param;
use libc::sched_setscheduler;
use libc::SCHED_FIFO;
use libc::SCHED_OTHER;*/
/*struct MyInterruptCtrl;
impl hal_sensor_dht::Interru... | code_fim | hard | {
"lang": "rust",
"repo": "Nnubes256/IDIoT",
"path": "/dht11-test/src/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(target_arch = "arm")]
fn dht_read(pin: i32) -> Result<Measurement, i32> {
let mut temperature = 0.0;
let mut humidity = 0.0;
let result = unsafe { pi_2_dht_read(11, pin, &mut humidity, &mut temperature) };
match result {
0 => Ok(Measurement {
temperature,
... | code_fim | hard | {
"lang": "rust",
"repo": "Nnubes256/IDIoT",
"path": "/dht11-test/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>struct Measurement {
temperature: f32,
humidity: f32,
}
#[cfg(not(target_arch = "arm"))]
fn dht_read(_pin: i32) -> Result<Measurement, i32> {
Ok(Measurement {
temperature: 0.0,
humidity: 0.0,
})
}
#[cfg(target_arch = "arm")]
fn dht_read(pin: i32) -> Result<Measurement, i3... | code_fim | hard | {
"lang": "rust",
"repo": "Nnubes256/IDIoT",
"path": "/dht11-test/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: davethecanuck/rust-bitfoo path: /examples/addr.rs
use std::time::{Instant,Duration};
use bitfoo::{Addr};
fn main() {
let max = 10_000_000;
let start = Instant::now();
<|fim_suffix|>fn get_rate(elapsed: Duration, count: u64) -> u64 {
(count as f64 / elapsed.as_secs_f64()) as u64
}<|... | code_fim | hard | {
"lang": "rust",
"repo": "davethecanuck/rust-bitfoo",
"path": "/examples/addr.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn get_rate(elapsed: Duration, count: u64) -> u64 {
(count as f64 / elapsed.as_secs_f64()) as u64
}<|fim_prefix|>// repo: davethecanuck/rust-bitfoo path: /examples/addr.rs
use std::time::{Instant,Duration};
use bitfoo::{Addr};
fn main() {
let max = 10_000_000;
let start = Instant::now();
... | code_fim | medium | {
"lang": "rust",
"repo": "davethecanuck/rust-bitfoo",
"path": "/examples/addr.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut request_bytes = Vec::new();
let (parts, _body) = self.into_parts();
request_bytes.extend_from_slice(parts.method.as_str().as_bytes());
request_bytes.extend_from_slice(b" / HTTP/1.1\r\n");
request_bytes.extend_from_slice(b"\r\nHost: ");
request_bytes... | code_fim | medium | {
"lang": "rust",
"repo": "glenmerry/rs-TAPS",
"path": "/src/framer.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Decode for Response<()> {
fn decode(data: Vec<u8>) -> Self {
let response_str = std::str::from_utf8(&data).unwrap();
let mut response_lines = response_str.lines();
let mut status_line = response_lines.next().unwrap().split_whitespace();
let version = match status_l... | code_fim | hard | {
"lang": "rust",
"repo": "glenmerry/rs-TAPS",
"path": "/src/framer.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: glenmerry/rs-TAPS path: /src/framer.rs
use crate::message::Message;
use http::{Request, Response, StatusCode, Version};
pub trait Framer<T, U> {
fn new_sent_message(&self, message: Message<T>) -> Vec<u8>;
fn handle_received_data(&self, received_data: Vec<u8>) -> U;
}
pub struct HttpCl... | code_fim | medium | {
"lang": "rust",
"repo": "glenmerry/rs-TAPS",
"path": "/src/framer.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: kpinter3-14/phone-game-rust path: /game-lib/src/key_status.rs
use std::collections::HashSet;
pub struct KeyStatus {
key_status: HashSet<sdl2::keyboard::Keycode>,
}
<|fim_suffix|> pub fn is_key_pressed(&self, keycode: sdl2::keyboard::Keycode) -> bool {
self.key_status.contains(&keycode)
... | code_fim | hard | {
"lang": "rust",
"repo": "kpinter3-14/phone-game-rust",
"path": "/game-lib/src/key_status.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn is_key_pressed(&self, keycode: sdl2::keyboard::Keycode) -> bool {
self.key_status.contains(&keycode)
}
}<|fim_prefix|>// repo: kpinter3-14/phone-game-rust path: /game-lib/src/key_status.rs
use std::collections::HashSet;
pub struct KeyStatus {
key_status: HashSet<sdl2::keyboard::Keycode>... | code_fim | hard | {
"lang": "rust",
"repo": "kpinter3-14/phone-game-rust",
"path": "/game-lib/src/key_status.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: lnicola/serde_fix path: /fix50sp2/src/leg_pricing_date_time.rs
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
pub struct LegPricingDateTime {
/// LegPricingDateUnadjusted
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rena... | code_fim | hard | {
"lang": "rust",
"repo": "lnicola/serde_fix",
"path": "/fix50sp2/src/leg_pricing_date_time.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> "41612")]
pub leg_pricing_time: Option<String>,
/// LegPricingTimeBusinessCenter
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "41613")]
pub leg_pricing_time_business_center: Option<String>,
}
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq)]
pub enum LegPricingD... | code_fim | hard | {
"lang": "rust",
"repo": "lnicola/serde_fix",
"path": "/fix50sp2/src/leg_pricing_date_time.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> Nr::try_from(src as u16).unwrap()
}
}
#[allow(unused)]
pub type PLIC = Plic<PLIC_BASE, 3>;
/// 通过 plic 库来初始化 PLIC,目前有问题,原因未知
#[allow(unused)]
pub unsafe fn init() {
// set desired IRQ priorities non-zero (otherwise disabled).
PLIC::set_priority(ExternInterrupt::VIRTIO0, Priority::low... | code_fim | hard | {
"lang": "rust",
"repo": "dumpmemory/tornado-os",
"path": "/tornado-kernel/src/plic.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dumpmemory/tornado-os path: /tornado-kernel/src/plic.rs
//! RISC-V 平台级中断控制器逻辑
//!
//! [关于plic](https://github.com/riscv/riscv-plic-spec)
//!
//! [关于context](https://github.com/riscv/riscv-plic-spec/pull/18)
use crate::hart;
use crate::memory::{PLIC_BASE, VIRTIO0_IRQ};
use core::convert::TryFrom;... | code_fim | hard | {
"lang": "rust",
"repo": "dumpmemory/tornado-os",
"path": "/tornado-kernel/src/plic.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: huonw/ieee754 path: /examples/all_ints.rs
extern crate criterion;
// base line comparison for the all example.
fn main() {
<|fim_suffix|> println!("count {}", (0..expected as u32).map(criterion::black_box).count());
}<|fim_middle|> let expected =
/* bits */ (1u64 << 32)
- ... | code_fim | medium | {
"lang": "rust",
"repo": "huonw/ieee754",
"path": "/examples/all_ints.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> println!("count {}", (0..expected as u32).map(criterion::black_box).count());
}<|fim_prefix|>// repo: huonw/ieee754 path: /examples/all_ints.rs
extern crate criterion;
// base line comparison for the all example.
fn main() {
<|fim_middle|> let expected =
/* bits */ (1u64 << 32)
- ... | code_fim | medium | {
"lang": "rust",
"repo": "huonw/ieee754",
"path": "/examples/all_ints.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> right_index = left_index + token_size;
let token = &bytes[left_index..right_index];
let g = Group::from_bytes(&token);
group_list.push(g);
}
group_list
}
}<|fim_prefix|>// repo: myg133/cqpsdk-rust path: /src/cqpapi/base_struct/group.rs
use bas... | code_fim | hard | {
"lang": "rust",
"repo": "myg133/cqpsdk-rust",
"path": "/src/cqpapi/base_struct/group.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: myg133/cqpsdk-rust path: /src/cqpapi/base_struct/group.rs
use base64;
use super::utils;
#[derive(Serialize, Deserialize, Debug)]
pub struct Group{
id :i64,
name :String
}
<|fim_suffix|> for _ in 0..count{
left_index = right_index;
let (token_size,left_index) = ut... | code_fim | hard | {
"lang": "rust",
"repo": "myg133/cqpsdk-rust",
"path": "/src/cqpapi/base_struct/group.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: lemonrock/simple-http-server path: /workspace/simple-http-server-epoll/src/terminal/WhenToChangeTerminalAttributes.rs
// This file is part of simple-http-server. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.gith... | code_fim | hard | {
"lang": "rust",
"repo": "lemonrock/simple-http-server",
"path": "/workspace/simple-http-server-epoll/src/terminal/WhenToChangeTerminalAttributes.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Change after waiting until all queued output has been written and after discarding all queued input.
Flush = TCSAFLUSH,
}
impl WhenToChangeTerminalAttributes
{
#[inline(always)]
pub(crate) fn flags(self, ignore_control_flags: bool) -> c_int
{
let flags = self as c_int;
if unlikely!(ignore_co... | code_fim | hard | {
"lang": "rust",
"repo": "lemonrock/simple-http-server",
"path": "/workspace/simple-http-server-epoll/src/terminal/WhenToChangeTerminalAttributes.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> gen_bool(self.single_vertex_dispatch, 31) |
gen_bool(self.vector_mask_enable, 30) |
gen_uint(self.sampler_count, 27, 29) |
gen_uint(self.binding_table_entry_count, 18, 25) |
gen_uint(self.thread_dispatch_priority, 17, 17) |
gen_uint(s... | code_fim | medium | {
"lang": "rust",
"repo": "krh/rust-drm",
"path": "/src/gen9.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: krh/rust-drm path: /src/gen9.rs
fn gen_uint(value: u32, start: u32, end: u32) -> u32 {
let width = end - start + 1;
debug_assert!(width == 64 || value < (1 << width));
value << start
}
fn gen_bool(value: bool, start: u32) -> u32 {
if value { 1 << start } else { 0 }
}
#[allow(... | code_fim | hard | {
"lang": "rust",
"repo": "krh/rust-drm",
"path": "/src/gen9.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let owner_addr = accounts[0].owner as *const Pubkey;
unsafe {
std::ptr::write_volatile(owner_addr as *mut [u8; 32], tmp_native_owner);
}
Ok(())
}<|fim_prefix|>// repo: solana-labs/solana path: /programs/sbf/rust/spoof1/src/lib.rs
use solana_program::{
account_info::AccountInf... | code_fim | hard | {
"lang": "rust",
"repo": "solana-labs/solana",
"path": "/programs/sbf/rust/spoof1/src/lib.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: solana-labs/solana path: /programs/sbf/rust/spoof1/src/lib.rs
use solana_program::{
account_info::AccountInfo,
entrypoint::ProgramResult,
instruction::{AccountMeta, Instruction},
msg,
program::invoke,
pubkey::Pubkey,
system_instruction::SystemInstruction,
system_p... | code_fim | medium | {
"lang": "rust",
"repo": "solana-labs/solana",
"path": "/programs/sbf/rust/spoof1/src/lib.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Liby99/saemanga-rust path: /src/routes/pages/admin/index.rs
use rocket::response::Redirect;
use rocket_contrib::templates::Template;
use super::AdminUser;
use crate::app::user::User;
use crate::util::Database;
<|fim_suffix|>impl From<&User> for RegisteredUser {
fn from(user: &User) -> Self {... | code_fim | medium | {
"lang": "rust",
"repo": "Liby99/saemanga-rust",
"path": "/src/routes/pages/admin/index.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl From<&User> for RegisteredUser {
fn from(user: &User) -> Self {
RegisteredUser {
id: user.id().to_hex(),
username: user.username().clone(),
last_visit_date_time: user.last_visit_date_time().to_rfc3339(),
visit_count: user.visit_count(),
}
}
}
#[derive(Serialize)]
... | code_fim | medium | {
"lang": "rust",
"repo": "Liby99/saemanga-rust",
"path": "/src/routes/pages/admin/index.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Nercury/metafactory-rs path: /src/lib.rs
/*!
<a href="https://github.com/Nercury/metafactory-rs">
<img style="position: absolute; top: 0; left: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_left_red_aa0000.png" alt="Fork me on GitHub">
</a>
<style>.sidebar { margin-top: ... | code_fim | hard | {
"lang": "rust",
"repo": "Nercury/metafactory-rs",
"path": "/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// Gettable value trait.
#[experimental]
pub trait Getter<T> {
/// Produce a new value.
fn take(&self) -> T;
/// Create a clone for this getter.
///
/// This is kind of experimental solution - can not return plain traits
/// as function result.
fn boxed_clone(&self) -> Box<Ge... | code_fim | hard | {
"lang": "rust",
"repo": "Nercury/metafactory-rs",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Downcast to factory by creating factory clone.
fn as_factory_clone_of<T>(&self) -> Option<Factory<T>>;
}
impl AsFactoryExt for Box<Any> {
fn as_factory_of<'a, T: 'static>(self) -> Option<Factory<T>> {
match self.downcast::<Factory<T>>().ok() {
Some(val) => Some(*val),
... | code_fim | hard | {
"lang": "rust",
"repo": "Nercury/metafactory-rs",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>{
match OpenOptions::new()
.create(false)
.read(false)
.write(true)
.open(defs::BRIGHTNESSFILE)
{
Ok(ref mut file) => {
write!(file, "{}", value).expect("Failed to change brightness");
},
Err(err) => { panic!("Failed to open brigh... | code_fim | hard | {
"lang": "rust",
"repo": "einzigartigerName/illuminate",
"path": "/illuminate.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: einzigartigerName/illuminate path: /illuminate.rs
use std::env;
use std::process;
use std::io::{Write, Read};
use std::fs::OpenOptions;
mod defs;
fn main()
{
let mut args: Vec<String> = env::args().collect();
let mut bright_up: bool = false;
let mut offset = 0;
if args.len(... | code_fim | hard | {
"lang": "rust",
"repo": "einzigartigerName/illuminate",
"path": "/illuminate.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn up(current: i32, offset: i32)
{
let write_value = current + offset;
if write_value < defs::MAX { write_brightness(write_value); }
else { write_brightness(defs::MAX); }
}
fn down(current: i32, offset: i32)
{
let write_value = current - offset;
if write_value > 0 { write_brightness(w... | code_fim | hard | {
"lang": "rust",
"repo": "einzigartigerName/illuminate",
"path": "/illuminate.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let e = Election {
parameters: Parameters {
location: "right here".to_owned(),
date: "right now".to_owned(),
num_trustees: BigUint::from(5_u32),
threshold: BigUint::from(3_u32),
prime: prime().clone(),
generator: generator... | code_fim | hard | {
"lang": "rust",
"repo": "danwallach/electionguard-verifier",
"path": "/src/test_gen_check.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: danwallach/electionguard-verifier path: /src/test_gen_check.rs
use crate::check;
use crate::crypto::group::{generator, prime};
use crate::generate::{self, Ballot, Contest, Election};
use crate::schema::{BallotInfo, Parameters};
use num::BigUint;
use rand;
#[test]
fn test_normal() {
let dumm... | code_fim | hard | {
"lang": "rust",
"repo": "danwallach/electionguard-verifier",
"path": "/src/test_gen_check.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: kirikaza/postgread path: /src/convey/tests/fake_tls.rs
use crate::tls::interface::*;
use ::async_trait::async_trait;
use ::std::fmt::{self, Display, Formatter};
use ::std::error;
pub struct FakeTlsClient();
<|fim_suffix|>#[derive(Debug)]
pub struct FakeTlsError();
impl<Plain> TlsProvider<Pla... | code_fim | medium | {
"lang": "rust",
"repo": "kirikaza/postgread",
"path": "/src/convey/tests/fake_tls.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[async_trait]
impl<Plain> TlsServer<Plain> for FakeTlsServer
where Plain: Send + Unpin {
async fn accept(&self, plain: Plain) -> Result<FakeTlsStream<Plain>, FakeTlsError>
where Plain: 'async_trait {
Ok(FakeTlsStream { plain })
}
}
impl Display for FakeTlsError {
fn fmt(&self, f:... | code_fim | hard | {
"lang": "rust",
"repo": "kirikaza/postgread",
"path": "/src/convey/tests/fake_tls.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: sanbox-irl/advent-of-code-2019 path: /src/day4/main.rs
const START: usize = 156218;
const END: usize = 652527;
fn main() {
println!(
"Number of valid combinations is {:?}",
(START..END).filter(|n| check_is_valid(*n)).count()
);
}
<|fim_suffix|> let digit_array: [usiz... | code_fim | medium | {
"lang": "rust",
"repo": "sanbox-irl/advent-of-code-2019",
"path": "/src/day4/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> array
};
// Digits do not decrease
let mut max_numb = digit_array[0];
for digit in digit_array.iter() {
if digit < &max_numb {
return false;
} else {
max_numb = *digit;
}
}
// Duplicate Digit!
let mut digit_counter = [0u... | code_fim | hard | {
"lang": "rust",
"repo": "sanbox-irl/advent-of-code-2019",
"path": "/src/day4/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: FenrirWolf/ctr-std path: /src/rt.rs
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/... | code_fim | hard | {
"lang": "rust",
"repo": "FenrirWolf/ctr-std",
"path": "/src/rt.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>// Reexport some of our utilities which are expected by other crates.
pub use panicking::{begin_panic, begin_panic_fmt};
//TODO: Handle argc/argv arguments
#[lang = "start"]
#[allow(unused_variables)]
fn lang_start(main: *const u8, argc: isize, argv: *const *const u8) -> isize {
unsafe { mem::transmu... | code_fim | hard | {
"lang": "rust",
"repo": "FenrirWolf/ctr-std",
"path": "/src/rt.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>use mem;
// Reexport some of our utilities which are expected by other crates.
pub use panicking::{begin_panic, begin_panic_fmt};
//TODO: Handle argc/argv arguments
#[lang = "start"]
#[allow(unused_variables)]
fn lang_start(main: *const u8, argc: isize, argv: *const *const u8) -> isize {
unsafe { me... | code_fim | hard | {
"lang": "rust",
"repo": "FenrirWolf/ctr-std",
"path": "/src/rt.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>d offsets;
pub mod send;
pub mod encoding;
mod messages;
pub use self::messages::*;<|fim_prefix|>// repo: KodrAus/kafka-rs path: /src/protocol/mod.rs
pub mod fetch;
pub mod metadata;
pub mod o<|fim_middle|>ffset_commit;
pub mod offset_fetch;
pub mo | code_fim | easy | {
"lang": "rust",
"repo": "KodrAus/kafka-rs",
"path": "/src/protocol/mod.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: KodrAus/kafka-rs path: /src/protocol/mod.rs
pub mod fetch;
pub mod metadata;
pub mod o<|fim_suffix|>
mod messages;
pub use self::messages::*;<|fim_middle|>ffset_commit;
pub mod offset_fetch;
pub mod offsets;
pub mod send;
pub mod encoding; | code_fim | medium | {
"lang": "rust",
"repo": "KodrAus/kafka-rs",
"path": "/src/protocol/mod.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let payload = jwt.payload()?.clone();
Ok(AuthUser {
subject: payload
.registered
.subject
.as_ref()
.ok_or(ServiceError::bad_request(failure::err_msg("no subject")))?
.to_string(),
roles... | code_fim | hard | {
"lang": "rust",
"repo": "myuon/jitome-kingdom-api",
"path": "/src/infra/jwt_handler.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn authorize(&self, auth_token: &str) -> Result<AuthUser, ServiceError> {
let token = auth_token.split("Bearer ").collect::<Vec<&str>>();
if token.len() != 2 {
return Err(ServiceError::unauthorized(failure::err_msg(
"access denied",
)));
... | code_fim | hard | {
"lang": "rust",
"repo": "myuon/jitome-kingdom-api",
"path": "/src/infra/jwt_handler.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: myuon/jitome-kingdom-api path: /src/infra/jwt_handler.rs
use crate::domain::model::{AuthUser, Role};
use crate::wrapper::error::ServiceError;
use biscuit::errors::Error;
use serde::*;
use std::sync::Arc;
impl From<biscuit::errors::Error> for ServiceError {
fn from(err: Error) -> Self {
... | code_fim | hard | {
"lang": "rust",
"repo": "myuon/jitome-kingdom-api",
"path": "/src/infra/jwt_handler.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let query = "rUsT";
let content = "Rust:
Safe,Fast,Productive.
Pick three.
Trust me.";
assert_eq!(vec!["Rust:","Trust me."],search_insensitive(query,content));
}<|fim_prefix|>// repo: yaozijian/RustProgramming path: /chap12/src/tests.rs
use super::*;
#[test]
fn one_result(){
<|fim_... | code_fim | medium | {
"lang": "rust",
"repo": "yaozijian/RustProgramming",
"path": "/chap12/src/tests.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: yaozijian/RustProgramming path: /chap12/src/tests.rs
use super::*;
#[test]
fn one_result(){
<|fim_suffix|> let query = "rUsT";
let content = "Rust:
Safe,Fast,Productive.
Pick three.
Trust me.";
assert_eq!(vec!["Rust:","Trust me."],search_insensitive(query,content));
}<|fim_... | code_fim | medium | {
"lang": "rust",
"repo": "yaozijian/RustProgramming",
"path": "/chap12/src/tests.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> filtered_records.sort_unstable_by_key(|pair| pair.0);
// aggregate traits
let mut output = Map::new();
for mut mapping in filtered_records {
let (ref mut _trait, ref mut occurrences) = mapping;
occurrences.sort_unstable();
occurrences.dedup();
output.insert... | code_fim | hard | {
"lang": "rust",
"repo": "minhducsun2002/fgo-trait-aggregator",
"path": "/src/main.rs",
"mode": "spm",
"license": "CC0-1.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: minhducsun2002/fgo-trait-aggregator path: /src/main.rs
use std::{env, collections::HashSet, fs::read_to_string};
use std::fs;
use std::path::Path;
use multimap::MultiMap;
use serde_json::{Map, Value, from_str, to_string, to_value};
fn main() {
let array: [&'static str; 5] = ["mstBuff", "mst... | code_fim | hard | {
"lang": "rust",
"repo": "minhducsun2002/fgo-trait-aggregator",
"path": "/src/main.rs",
"mode": "psm",
"license": "CC0-1.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: sonald/lxxtcode-rs path: /src/construct_binary_tree_from_preorder_and_inorder_traversal.rs
use super::utils::*;
use std::cell::RefCell;
use std::rc::Rc;
pub struct Solution;
impl Solution {
pub fn build_tree(preorder: Vec<i32>, inorder: Vec<i32>) -> Option<Rc<RefCell<TreeNode>>> {
f... | code_fim | hard | {
"lang": "rust",
"repo": "sonald/lxxtcode-rs",
"path": "/src/construct_binary_tree_from_preorder_and_inorder_traversal.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let root = Solution::build_tree(vec![3,9,20,15,7], vec![9,3,15,20,7]);
eprintln!("{}", root.unwrap().borrow())
}
}<|fim_prefix|>// repo: sonald/lxxtcode-rs path: /src/construct_binary_tree_from_preorder_and_inorder_traversal.rs
use super::utils::*;
use std::cell::RefCell;
use std::rc:... | code_fim | hard | {
"lang": "rust",
"repo": "sonald/lxxtcode-rs",
"path": "/src/construct_binary_tree_from_preorder_and_inorder_traversal.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: JanneRemes/rust_cards path: /src/client/mod.rs
mod request_builder;
use client::request_builder::RequestBuilder;
use std::net::UdpSocket;
use std::str;
use std::thread;
use std::thread::JoinHandle;
use std::sync::mpsc;
use std::sync::mpsc::Receiver;
use std::time::Duration;
use std::sync::{Arc... | code_fim | hard | {
"lang": "rust",
"repo": "JanneRemes/rust_cards",
"path": "/src/client/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let hidden = {
if let Some(hide) = message_chunks.pop() {
if hide == "private" {
true
} else {
false
}
} else {
... | code_fim | hard | {
"lang": "rust",
"repo": "JanneRemes/rust_cards",
"path": "/src/client/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: twicepipes/rust-effects path: /src/option.rs
/// Option Typeclass Behaviors
///
/// Semigroup (result-type must be a monoid for identity and parameters must be semigroup
/// for combination)
/// `combine(Some(X), Some(Y)) => Some(combine(X, Y))`
/// `combine(Some(X), None) => Some(X)`
//... | code_fim | hard | {
"lang": "rust",
"repo": "twicepipes/rust-effects",
"path": "/src/option.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.