text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_prefix|>// repo: strogo/actix-web-validator path: /tests/test_error_transformation.rs
use actix_web_validator::{Error, error::DeserializeErrors};
use serde::Deserialize;
#[derive(Deserialize)]
struct Query {
pub test: i32,
pub value: i32,
}
<|fim_suffix|>#[test]
fn test_serde_json_error_transformation(... | code_fim | hard | {
"lang": "rust",
"repo": "strogo/actix-web-validator",
"path": "/tests/test_error_transformation.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[test]
fn test_serde_json_error_transformation() {
let error = serde_json::from_str::<Query>("{\"test\": 42, \"value\": null}")
.map_err(Error::from);
assert!(matches!(error, Err(Error::Deserialize(DeserializeErrors::DeserializeJson(_)))));
}<|fim_prefix|>// repo: strogo/actix-web-validat... | code_fim | hard | {
"lang": "rust",
"repo": "strogo/actix-web-validator",
"path": "/tests/test_error_transformation.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: fabien-h/learn-to-program-with-rust path: /comments_and_documentation/src/main.rs
/// Documentation pour le module
/// Description du module
fn main() {
//! # fonction main
//!
//! ```
//! fn main()
//! ```
//!
//! Description de la fonction
//!
println!("He... | code_fim | hard | {
"lang": "rust",
"repo": "fabien-h/learn-to-program-with-rust",
"path": "/comments_and_documentation/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let n1: u8 = 5u8;
let n2: u16 = 0b0000000000000101;
let n3: f64 = 5f64;
println!("{n1:b} {n2} {n3:b}", n1 = n1, n2 = n2, n3 = n3.to_bits());
let (_a, _b, _c): (usize, usize, usize) = (1, 2, 3);
}<|fim_prefix|>// repo: fabien-h/learn-to-program-with-rust path: /comments_and_documenta... | code_fim | medium | {
"lang": "rust",
"repo": "fabien-h/learn-to-program-with-rust",
"path": "/comments_and_documentation/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: FlorianWilhelm/polars path: /polars/polars-core/src/chunked_array/ops/fill_none.rs
use crate::prelude::*;
use num::{Bounded, Num, NumCast, One, Zero};
use std::ops::{Add, Div};
fn fill_forward<T>(ca: &ChunkedArray<T>) -> ChunkedArray<T>
where
T: PolarsNumericType,
{
ca.into_iter()
... | code_fim | hard | {
"lang": "rust",
"repo": "FlorianWilhelm/polars",
"path": "/polars/polars-core/src/chunked_array/ops/fill_none.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> Err(PolarsError::InvalidOperation(
"fill_none not supported for List type".into(),
))
}
}
impl ChunkFillNone for CategoricalChunked {
fn fill_none(&self, _strategy: FillNoneStrategy) -> Result<Self> {
Err(PolarsError::InvalidOperation(
"fill_none no... | code_fim | hard | {
"lang": "rust",
"repo": "FlorianWilhelm/polars",
"path": "/polars/polars-core/src/chunked_array/ops/fill_none.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(test)]
mod test {
use crate::prelude::*;
#[test]
fn test_fill_none() {
let ca =
Int32Chunked::new_from_opt_slice("", &[None, Some(2), Some(3), None, Some(4), None]);
let filled = ca.fill_none(FillNoneStrategy::Forward).unwrap();
assert_eq!(
... | code_fim | hard | {
"lang": "rust",
"repo": "FlorianWilhelm/polars",
"path": "/polars/polars-core/src/chunked_array/ops/fill_none.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>/ at compile time but not a vector. Makes sense.<|fim_prefix|>// repo: tarquin-the-brave/rust-book path: /chapter9/panic_test_2/src/main.rs
fn main() {
let a: [usize; 5] = [1,2,3,4,5]<|fim_middle|>;
a[99];
}
// this fails to build
// so rust will stop you indexing an array out of range
/ | code_fim | medium | {
"lang": "rust",
"repo": "tarquin-the-brave/rust-book",
"path": "/chapter9/panic_test_2/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tarquin-the-brave/rust-book path: /chapter9/panic_test_2/src/main.rs
fn main() {
let a: [usize; 5] = [1,2,3,4,5];
a[99];
}
// this fails to build
// so rus<|fim_suffix|>/ at compile time but not a vector. Makes sense.<|fim_middle|>t will stop you indexing an array out of range
/ | code_fim | easy | {
"lang": "rust",
"repo": "tarquin-the-brave/rust-book",
"path": "/chapter9/panic_test_2/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: blm768/warp path: /src/server.rs
use std::net::SocketAddr;
use std::sync::Arc;
use futures::{Async, Future, Poll};
use hyper::{rt, Server as HyperServer};
use hyper::service::{service_fn};
use ::never::Never;
use ::reject::Reject;
use ::reply::{ReplySealed, Reply};
use ::Request;
/// Create a... | code_fim | hard | {
"lang": "rust",
"repo": "blm768/warp",
"path": "/src/server.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl<F> Future for ReplyFuture<F>
where
F: Future,
F::Item: Reply,
F::Error: Reject,
{
type Item = ::reply::Response;
type Error = Never;
#[inline]
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
match self.inner.poll() {
Ok(Async::Ready(ok)) => Ok(As... | code_fim | hard | {
"lang": "rust",
"repo": "blm768/warp",
"path": "/src/server.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // {} is a placeholder, for multiple values use multiple {} like
// println!("Hello I am {} years old, I was {} years old", 22, 21);
println!("You guessed: {}", guess);
// match statement:
// match x { value1 => do something, ..., _ => default}
// Ordering :... | code_fim | hard | {
"lang": "rust",
"repo": "7flying/code-n-fun",
"path": "/rusty-rust/300_learn/guessing_game/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: 7flying/code-n-fun path: /rusty-rust/300_learn/guessing_game/src/main.rs
// rand is declared on the dependencies
extern crate rand;
// Use the io library from the standard (std) lib
// Rust imports some things to every program, this is the 'prelude'
// TODO see which things are imported in the ... | code_fim | hard | {
"lang": "rust",
"repo": "7flying/code-n-fun",
"path": "/rusty-rust/300_learn/guessing_game/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: suspend0/aws-sdk-rust path: /sdk/wellarchitected/src/client.rs
y behavior
/// is configurable with the [RetryConfig](aws_smithy_types::retry::RetryConfig), which can be
/// set when configuring the client.
pub async fn send(
self,
) -> std::result::Res... | code_fim | hard | {
"lang": "rust",
"repo": "suspend0/aws-sdk-rust",
"path": "/sdk/wellarchitected/src/client.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>ers::UpdateShareInvitation<C, M, R> {
fluent_builders::UpdateShareInvitation::new(self.handle.clone())
}
/// Constructs a fluent builder for the `UpdateWorkload` operation.
///
/// See [`UpdateWorkload`](crate::client::fluent_builders::UpdateWorkload) for more information about the... | code_fim | hard | {
"lang": "rust",
"repo": "suspend0/aws-sdk-rust",
"path": "/sdk/wellarchitected/src/client.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(
::std::mem::size_of::<A_D<::std::os::raw::c_int>>(),
4usize,
concat!(
"Size of template specialization: ",
stringify!(A_D < ::std::os::raw::c_int >),
),
);
assert_eq!(
::std::mem::align_of::<A_D<::std::os::raw::c_int>>... | code_fim | hard | {
"lang": "rust",
"repo": "rust-lang/rust-bindgen",
"path": "/bindgen-tests/tests/expectations/tests/class_nested.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rust-lang/rust-bindgen path: /bindgen-tests/tests/expectations/tests/class_nested.rs
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct A {
pub member_a: ::std::os::raw::c_int,
}... | code_fim | hard | {
"lang": "rust",
"repo": "rust-lang/rust-bindgen",
"path": "/bindgen-tests/tests/expectations/tests/class_nested.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.status
}
}
impl StatusAction for Drink {
fn enter(&self, cter: &Miner) {
if cter.location_type.load() != LocationType::Bar {
cter.change_location(LocationType::Bar);
}
self.execute(cter);
}
fn execute(&self, cter: &Miner) {
println... | code_fim | hard | {
"lang": "rust",
"repo": "lineCode/GameServer_Rust",
"path": "/robotserver/src/fsm/status.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: lineCode/GameServer_Rust path: /robotserver/src/fsm/status.rs
use crate::fsm::miner::{Miner, Robot};
use num_enum::IntoPrimitive;
use num_enum::TryFromPrimitive;
use std::borrow::BorrowMut;
use std::time::Duration;
///pos操作类型
#[derive(Debug, Clone, Copy, Eq, PartialEq, TryFromPrimitive, IntoPri... | code_fim | hard | {
"lang": "rust",
"repo": "lineCode/GameServer_Rust",
"path": "/robotserver/src/fsm/status.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn exit(&self, miner: &Miner) {
println!("矿工休息结束!");
}
fn get_status(&self) -> Status {
self.status
}
}
impl StatusAction for EnterMineAndDigForNugget {
fn enter(&self, cter: &Miner) {
if cter.location_type.load() != LocationType::KuangChang {
cter... | code_fim | hard | {
"lang": "rust",
"repo": "lineCode/GameServer_Rust",
"path": "/robotserver/src/fsm/status.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>2,i32) = (3,2,1);
println!("tamanho:{:?}",t);
}<|fim_prefix|>// repo: alanwalter45/rust path: /rs01/main4.rs
fn main(){
let (v1,v2,v3) = (3,2,1);
println!("tamanho:{}{}{}",v1,v2,v3);
let t = (3,2,1)<|fim_middle|>;
println!("tamanho:{:?}",t);
let t:(i32,i3 | code_fim | easy | {
"lang": "rust",
"repo": "alanwalter45/rust",
"path": "/rs01/main4.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: alanwalter45/rust path: /rs01/main4.rs
fn main(){
let (v1,v2,v3) = (3,2,1);
print<|fim_suffix|>2,i32) = (3,2,1);
println!("tamanho:{:?}",t);
}<|fim_middle|>ln!("tamanho:{}{}{}",v1,v2,v3);
let t = (3,2,1);
println!("tamanho:{:?}",t);
let t:(i32,i3 | code_fim | medium | {
"lang": "rust",
"repo": "alanwalter45/rust",
"path": "/rs01/main4.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>R Non-compliant - no terminating `else`
}<|fim_prefix|>// repo: mtthw-meyer/misra-rust path: /tests/compile-fail/Rule_15_7.rs
fn main() {
let x = 1;
if x == 2 {
let _ = 1;
} else if x == 3<|fim_middle|> {
let _ = 2;
}
//~^ ERRO | code_fim | easy | {
"lang": "rust",
"repo": "mtthw-meyer/misra-rust",
"path": "/tests/compile-fail/Rule_15_7.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mtthw-meyer/misra-rust path: /tests/compile-fail/Rule_15_7.rs
fn main() {
let x = 1;
if x == 2 {
let _ = 1;
} else if x == 3<|fim_suffix|>R Non-compliant - no terminating `else`
}<|fim_middle|> {
let _ = 2;
}
//~^ ERRO | code_fim | easy | {
"lang": "rust",
"repo": "mtthw-meyer/misra-rust",
"path": "/tests/compile-fail/Rule_15_7.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: DennisVanEe/rust_prism path: /rust_prism/src/filter.rs
// This file stores all of the different filters that PRISM
// supports.
use pmath::vector::Vec2;
use std::hint;
pub trait Filter {
fn eval(&self, p: Vec2<f64>) -> f64;
fn get_radius(&self) -> Vec2<f64>;
}
//
// Box Filter
//
#[d... | code_fim | hard | {
"lang": "rust",
"repo": "DennisVanEe/rust_prism",
"path": "/rust_prism/src/filter.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn gaussian(&self, d: f64, expv: f64) -> f64 {
((-self.alpha * d * d).exp() - expv).max(0.)
}
}
impl Filter for GaussianFilter {
fn eval(&self, p: Vec2<f64>) -> f64 {
self.gaussian(p.x, self.exp.x) * self.gaussian(p.y, self.exp.y)
}
fn get_radius(&self) -> Vec2<f64> {... | code_fim | hard | {
"lang": "rust",
"repo": "DennisVanEe/rust_prism",
"path": "/rust_prism/src/filter.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn sample_pos(self, r: Vec2<f64>) -> Vec2<f64> {
// First, we sample the x-value:
let x = match self.cdf_x.iter().position(|&cdf| cdf > r.x) {
Some(x) => x,
_ => FILTER_TABLE_WIDTH / 2,
};
// Using this x-value, we can now find the y-value:
... | code_fim | hard | {
"lang": "rust",
"repo": "DennisVanEe/rust_prism",
"path": "/rust_prism/src/filter.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: technetos/rustbridge.io path: /src/error.rs
use std;
use rocket;
pub enum Error {
Io(std::io::Error),
Status(rocket::http::Status),
}
<|fim_suffix|>impl From<rocket::http::Status> for Error {
fn from(err: rocket::http::Status) -> Error {
Error::Status(err)
}
}<|fim_midd... | code_fim | medium | {
"lang": "rust",
"repo": "technetos/rustbridge.io",
"path": "/src/error.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl From<rocket::http::Status> for Error {
fn from(err: rocket::http::Status) -> Error {
Error::Status(err)
}
}<|fim_prefix|>// repo: technetos/rustbridge.io path: /src/error.rs
use std;
use rocket;
pub enum Error {
Io(std::io::Error),
Status(rocket::http::Status),
}
<|fim_midd... | code_fim | medium | {
"lang": "rust",
"repo": "technetos/rustbridge.io",
"path": "/src/error.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]
pub struct Document {
pub text: Text,
}
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct Editor {
pub document_index: Index,
pub cursors: CursorSet,
pub selections: RangeSet,
pub carets: PositionSet,
}
impl Editor {
pub... | code_fim | hard | {
"lang": "rust",
"repo": "zeroexcuses/makepad",
"path": "/codeeditor/src/state.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: zeroexcuses/makepad path: /codeeditor/src/state.rs
use {
crate::{
components::{code_editor, root},
core::{
delta,
generational::{Arena, Index, IndexAllocator},
position_set, range_set, Position, PositionSet, Range, RangeSet, Text,
}... | code_fim | hard | {
"lang": "rust",
"repo": "zeroexcuses/makepad",
"path": "/codeeditor/src/state.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub use socket_descr::{New, Listen, Accept, SocketDescr};
pub use kqueue_descr::{KQueueDescr, Token};
pub use ffi::keventfn;<|fim_prefix|>// repo: davidpeklak/rust-ffi-explore path: /src/lib.rs
extern crate libc;
<|fim_middle|>mod ffi;
mod socket_descr;
mod kqueue_descr;
| code_fim | easy | {
"lang": "rust",
"repo": "davidpeklak/rust-ffi-explore",
"path": "/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: davidpeklak/rust-ffi-explore path: /src/lib.rs
extern crate libc;
<|fim_suffix|>pub use socket_descr::{New, Listen, Accept, SocketDescr};
pub use kqueue_descr::{KQueueDescr, Token};
pub use ffi::keventfn;<|fim_middle|>
mod ffi;
mod socket_descr;
mod kqueue_descr;
| code_fim | easy | {
"lang": "rust",
"repo": "davidpeklak/rust-ffi-explore",
"path": "/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: perlindgren/lm3s6965 path: /src/i2c0/mcs.rs
#[doc = "Reader of register MCS"]
pub type R = crate::R<u32, super::MCS>;
#[doc = "Writer for register MCS"]
pub type W = crate::W<u32, super::MCS>;
#[doc = "Register MCS `reset()`'s with value 0"]
impl crate::ResetValue for super::MCS {
type Type ... | code_fim | hard | {
"lang": "rust",
"repo": "perlindgren/lm3s6965",
"path": "/src/i2c0/mcs.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn parse_solium_response(o: &str) -> Vec<tool_output::SoliumIssue> {
o.lines()
.map(|s| {
s.splitn(5, ':')
.map(|s| s.to_owned())
.collect::<Vec<String>>()
})
.filter(|l| l.len() == 5)
.map(|components| tool_output::SoliumIssu... | code_fim | hard | {
"lang": "rust",
"repo": "enhancedsociety/solsa",
"path": "/src/tools.rs",
"mode": "spm",
"license": "ISC",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: enhancedsociety/solsa path: /src/tools.rs
use std::env;
use std::process::Command;
use serde_json;
use tool_output;
#[derive(Debug)]
pub enum SolcResponse {
Success(tool_output::SolcOutput),
Failure(String),
}
#[derive(Debug)]
pub enum MythrilResponse {
Success(tool_output::Mythr... | code_fim | hard | {
"lang": "rust",
"repo": "enhancedsociety/solsa",
"path": "/src/tools.rs",
"mode": "psm",
"license": "ISC",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: owen8877/leetcode-rs path: /src/problem_334.rs
pub fn increasing_triplet(nums: Vec<i32>) -> bool {
if nums.len() < 3 {
return false;
}
let mut a = None;
let mut b = None;
let mut aa = None;
let mut bb = None;
for num in nums {
match (a, b) {
... | code_fim | hard | {
"lang": "rust",
"repo": "owen8877/leetcode-rs",
"path": "/src/problem_334.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> if aa.unwrap() >= na && bb.unwrap() > nb {
aa = Some(na);
bb = Some(nb);
}
} else {
aa = Some(na);
bb = Some(nb);
}
}
}
if aa... | code_fim | hard | {
"lang": "rust",
"repo": "owen8877/leetcode-rs",
"path": "/src/problem_334.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> {
a = Some(na);
b = Some(num);
} else if num > nb {
return true;
} else {
a = Some(na);
b = Some(nb);
}
}
_ => {}
}
... | code_fim | hard | {
"lang": "rust",
"repo": "owen8877/leetcode-rs",
"path": "/src/problem_334.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: aethertap/audio path: /audio-device/src/runtime/poll.rs
use crate::libc as c;
use crate::loom::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use crate::loom::sync::{Arc, Mutex};
use crate::loom::thread;
use crate::runtime::atomic_waker::AtomicWaker;
use crate::unix::errno::Errno;
use crate:... | code_fim | hard | {
"lang": "rust",
"repo": "aethertap/audio",
"path": "/audio-device/src/runtime/poll.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// Wrap a panic guard around self which will release any resources it
/// has allocated when dropped and mark itself as panicked.
struct PanicGuard {
shared: Arc<Shared>,
wakers: Vec<Arc<Waker>>,
}
impl Drop for PanicGuard {
fn drop(&mut self) {
self.shared.running.store(false, Order... | code_fim | hard | {
"lang": "rust",
"repo": "aethertap/audio",
"path": "/audio-device/src/runtime/poll.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: phial3/Erics-OS path: /src/memory/heap.rs
use super::config::KERNEL_HEAP_SIZE;
use buddy_system_allocator::LockedHeap;
<|fim_suffix|>/// 堆内存分配器
///
/// ### `#[global_allocator]`
/// [`LockedHeap`] 实现了 [`alloc::alloc::GlobalAlloc`] trait,
/// 可以为全局需要用到堆的地方分配空间。例如 `Box` `Arc` 等
#[global_allocato... | code_fim | medium | {
"lang": "rust",
"repo": "phial3/Erics-OS",
"path": "/src/memory/heap.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// 空间分配错误回调函数
#[alloc_error_handler]
fn alloc_error_handler(_: alloc::alloc::Layout) -> ! {
panic!("alloc error")
}<|fim_prefix|>// repo: phial3/Erics-OS path: /src/memory/heap.rs
use super::config::KERNEL_HEAP_SIZE;
use buddy_system_allocator::LockedHeap;
/// 动态内存分配堆空间
///
/// 内存大小为 ['KERNEL_HEAP... | code_fim | hard | {
"lang": "rust",
"repo": "phial3/Erics-OS",
"path": "/src/memory/heap.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ndarilek/synthizer-rs path: /synthizer/examples/linger.rs
//! test linger behavior.
use synthizer as syz;
fn main() -> syz::Result<()> {
let args = std::env::args().collect::<Vec<_>>();
if args.len() != 2 {
panic!("Usage: example <file>");
}
<|fim_suffix|> println!("Pres... | code_fim | hard | {
"lang": "rust",
"repo": "ndarilek/synthizer-rs",
"path": "/synthizer/examples/linger.rs",
"mode": "psm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_suffix|> {
let del_cfg = syz::DeleteBehaviorConfigBuilder::new()
.linger(true)
.linger_timeout(5.0)
.build();
let src = syz::DirectSource::new(&context)?;
let generator = syz::BufferGenerator::new(&context)?;
generator.buffer().set(&buffer)?;
... | code_fim | medium | {
"lang": "rust",
"repo": "ndarilek/synthizer-rs",
"path": "/synthizer/examples/linger.rs",
"mode": "spm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: International/rust-play path: /src/io_and_hashmap/main.rs
use std::collections::HashMap;
use std::io::{BufRead, BufReader};
use std::env;
use std::fs::File;
use std::collections::hash_map::Entry::{Occupied, Vacant};
<|fim_suffix|> let first_arg:Vec<String> = env::args().collect();
let fi... | code_fim | medium | {
"lang": "rust",
"repo": "International/rust-play",
"path": "/src/io_and_hashmap/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> for (entry, count) in map.iter() {
println!("line: {} appears: {}", entry, count);
}
}<|fim_prefix|>// repo: International/rust-play path: /src/io_and_hashmap/main.rs
use std::collections::HashMap;
use std::io::{BufRead, BufReader};
use std::env;
use std::fs::File;
use std::collections::h... | code_fim | hard | {
"lang": "rust",
"repo": "International/rust-play",
"path": "/src/io_and_hashmap/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> Some((min, max))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_minmax() {
let data: &[i32] = &[];
assert_eq!(minmax(data), None);
assert_eq!(minmax(&[1, 2, 3]), Some((&1, &3)));
assert_eq!(minmax(&[1]), Some((&1, &1)));
assert_eq!(minma... | code_fim | hard | {
"lang": "rust",
"repo": "utterstep/advent-2019",
"path": "/day-11/src/utils.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: utterstep/advent-2019 path: /day-11/src/utils.rs
pub fn minmax<T: Ord + Copy>(iter: impl IntoIterator<Item = T>) -> Option<(T, T)> {
let mut iter = iter.into_iter();
let mut min = match iter.next() {
None => return None,
Some(value) => value,
};
let mut max = min... | code_fim | medium | {
"lang": "rust",
"repo": "utterstep/advent-2019",
"path": "/day-11/src/utils.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(minmax(&[1, 2, 3]), Some((&1, &3)));
assert_eq!(minmax(&[1]), Some((&1, &1)));
assert_eq!(minmax(&[543, 23434, 3]), Some((&3, &23434)));
assert_eq!(minmax(&[2, 2, 2]), Some((&2, &2)));
}
}<|fim_prefix|>// repo: utterstep/advent-2019 path: /day-11/src/utils.r... | code_fim | medium | {
"lang": "rust",
"repo": "utterstep/advent-2019",
"path": "/day-11/src/utils.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert!(frame.vector_elements().is_some());
assert!(frame.vector_elements().unwrap().count() > 0);
assert!(frame.vector_elements().unwrap().count() == 2);
}<|fim_prefix|>// repo: Logicalshift/flowbetween path: /animation/src/storage/tests/shape.rs
use super::*;
use std::time::Duration;
#[te... | code_fim | medium | {
"lang": "rust",
"repo": "Logicalshift/flowbetween",
"path": "/animation/src/storage/tests/shape.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Logicalshift/flowbetween path: /animation/src/storage/tests/shape.rs
use super::*;
use std::time::Duration;
#[test]
fn draw_shape() {
let anim = create_animation();
anim.perform_edits(vec![
AnimationEdit::AddNewLayer(2),
AnimationEdit::Layer(2, LayerEdit::AddKeyFrame(D... | code_fim | medium | {
"lang": "rust",
"repo": "Logicalshift/flowbetween",
"path": "/animation/src/storage/tests/shape.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> VerTam::obter_dados().comparar().responder();
}
#[cfg(test)]
mod teste {
use VerTam;
#[test]
fn teste() {
let mut vertam = VerTam {
foto: "Foto_A308.jpg".into(),
dimensoes: (1200, 1680),
resposta: "",
};
vertam.comparar().respond... | code_fim | hard | {
"lang": "rust",
"repo": "eliasdilem/od_ver_tamanho_com_cx_msg",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: eliasdilem/od_ver_tamanho_com_cx_msg path: /src/main.rs
#![windows_subsystem = "windows"]
extern crate imagesize;
extern crate winapi;
mod mensagem;
pub use self::mensagem::cx_msg;
use imagesize::size;
use std::cmp::Ordering::*;
use std::env;
const ROTULO: &str = "Verificar o tamanho da foto..... | code_fim | hard | {
"lang": "rust",
"repo": "eliasdilem/od_ver_tamanho_com_cx_msg",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn parse(data: &[u8]) -> Result<EthernetPacket<EthernetKind>, ParseError> {
EthernetPacket::parse(data)
}<|fim_prefix|>// repo: embed-rs/net path: /src/parse.rs
use ethernet::{EthernetPacket, EthernetKind};
<|fim_middle|>pub trait Parse<'a>: Sized {
fn parse(data: &'a [u8]) -> Result<Self, P... | code_fim | hard | {
"lang": "rust",
"repo": "embed-rs/net",
"path": "/src/parse.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: embed-rs/net path: /src/parse.rs
use ethernet::{EthernetPacket, EthernetKind};
<|fim_suffix|>}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ParseError {
Unimplemented(&'static str),
Malformed(&'static str),
Truncated(usize),
}
pub fn parse(data: &[u8]) -> Result<EthernetP... | code_fim | medium | {
"lang": "rust",
"repo": "embed-rs/net",
"path": "/src/parse.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: impakt73/forge-rs path: /src/bin/server.rs
use failure::Error;
use forge::server::run_server;
use std::ptr;
use std::thread;
use std::time::Duration;
<|fim_suffix|> let context = run_server("127.0.0.1", 8005, &forge::server::PacketCallback {userdata: ptr::null_mut(), func: None })?;
th... | code_fim | easy | {
"lang": "rust",
"repo": "impakt73/forge-rs",
"path": "/src/bin/server.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let context = run_server("127.0.0.1", 8005, &forge::server::PacketCallback {userdata: ptr::null_mut(), func: None })?;
thread::sleep(Duration::from_secs(30));
context.shutdown()?;
Ok(())
}<|fim_prefix|>// repo: impakt73/forge-rs path: /src/bin/server.rs
use failure::Error;
use forge::ser... | code_fim | easy | {
"lang": "rust",
"repo": "impakt73/forge-rs",
"path": "/src/bin/server.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> for e in &content.enums {
match e {
EnumTest::Unnamed(attr, text, node, flatten) => {
assert_eq!(attr.as_str(), "value");
assert_eq!(text.as_str(), "node");
assert_eq!(node.as_str(), "node");
... | code_fim | hard | {
"lang": "rust",
"repo": "QAQtutu/easy-xml",
"path": "/easy-xml/tests/enum.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(node, de::from_str::<Node>(xml.as_str()).unwrap());
}
#[test]
fn test_enum_with_rename() {
#[derive(PartialEq, Debug, XmlDeserialize, XmlSerialize)]
enum Type {
#[easy_xml(rename = "TTT1")]
T1,
#[easy_xml(rename = "TTT2")]
T2,
#[easy_xml(rena... | code_fim | hard | {
"lang": "rust",
"repo": "QAQtutu/easy-xml",
"path": "/easy-xml/tests/enum.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: QAQtutu/easy-xml path: /easy-xml/tests/enum.rs
use easy_xml::{de, se};
#[macro_use]
extern crate easy_xml_derive;
#[test]
fn test() {
{
#[derive(Debug, XmlDeserialize, XmlSerialize)]
#[easy_xml(root)]
struct Content {
#[easy_xml(rename = "Unnamed|Named|U... | code_fim | hard | {
"lang": "rust",
"repo": "QAQtutu/easy-xml",
"path": "/easy-xml/tests/enum.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: farcaller/rustedirc path: /src/server/mod.rs
use std::collections::HashMap;
use std::io::Write;
use std::cell::{Cell, RefCell};
use core;
use uidgen::TS6UIDGenerator;
use message::Message;
mod command;
pub type Token = usize;
pub struct Client {
token: Token,
nickname: RefCell<Option... | code_fim | hard | {
"lang": "rust",
"repo": "farcaller/rustedirc",
"path": "/src/server/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.buf.borrow_mut().write(buf)
}
fn flush(&mut self) -> io::Result<()> {
self.buf.borrow_mut().flush()
}
}
impl Clone for TestSock {
fn clone(&self) -> Self {
TestSock {
buf: self.buf.clone()
}
... | code_fim | hard | {
"lang": "rust",
"repo": "farcaller/rustedirc",
"path": "/src/server/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> &self.0
}
}
#[doc = "Field `TX_DEPTH_IRQ` writer - Set the FIFO level on which to create an irq request."]
pub struct TX_DEPTH_IRQ_W<'a> {
w: &'a mut W,
}
impl<'a> TX_DEPTH_IRQ_W<'a> {
#[doc = r"Writes raw bits to the field"]
#[inline(always)]
pub unsafe fn bits(self, value: u8... | code_fim | hard | {
"lang": "rust",
"repo": "rcls/svd2rust-example",
"path": "/lpc408x/src/i2s/irq.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rcls/svd2rust-example path: /lpc408x/src/i2s/irq.rs
#[doc = "Register `IRQ` reader"]
pub struct R(crate::R<IRQ_SPEC>);
impl core::ops::Deref for R {
type Target = crate::R<IRQ_SPEC>;
#[inline(always)]
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl From<crate::R<IRQ_S... | code_fim | hard | {
"lang": "rust",
"repo": "rcls/svd2rust-example",
"path": "/lpc408x/src/i2s/irq.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> &self.0
}
}
#[doc = "Field `RX_IRQ_ENABLE` writer - When 1, enables I2S receive interrupt."]
pub struct RX_IRQ_ENABLE_W<'a> {
w: &'a mut W,
}
impl<'a> RX_IRQ_ENABLE_W<'a> {
#[doc = r"Sets the field bit"]
#[inline(always)]
pub fn set_bit(self) -> &'a mut W {
self.bit(tru... | code_fim | hard | {
"lang": "rust",
"repo": "rcls/svd2rust-example",
"path": "/lpc408x/src/i2s/irq.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub enum Permission {
Owner,
Member,
Admin,
}
pub enum Platform {
Mobile,
}
pub mod recive {
use self::sender::FromMap;
use crate::rev::MessageRevMid;
use serde_json::Value;
use std::collections::HashMap;
pub use super::Sender;
pub use crate::MessageRev;
pub ... | code_fim | hard | {
"lang": "rust",
"repo": "Goodjooy/msg_proc",
"path": "/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Goodjooy/msg_proc path: /src/lib.rs
use msg_chain::MessageChain;
mod impls;
mod rev;
mod sd;
pub trait Sender:Send {
fn get_sender_id(&self) -> &u64;
fn get_sender_permission(&self) -> Option<&Permission> {
None
}
fn get_sender_name(&self) -> Option<&String> {
N... | code_fim | hard | {
"lang": "rust",
"repo": "Goodjooy/msg_proc",
"path": "/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: alexcrichton/tar-rs path: /src/lib.rs
//! A library for reading and writing TAR archives
//!
//! This library provides utilities necessary to manage [TAR archives][1]
//! abstracted over a reader or writer. Great strides are taken to ensure that
//! an archive is never required to be fully resid... | code_fim | hard | {
"lang": "rust",
"repo": "alexcrichton/tar-rs",
"path": "/src/lib.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub use crate::archive::{Archive, Entries};
pub use crate::builder::Builder;
pub use crate::entry::{Entry, Unpacked};
pub use crate::entry_type::EntryType;
pub use crate::header::GnuExtSparseHeader;
pub use crate::header::{GnuHeader, GnuSparseHeader, Header, HeaderMode, OldHeader, UstarHeader};
pub use cr... | code_fim | medium | {
"lang": "rust",
"repo": "alexcrichton/tar-rs",
"path": "/src/lib.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: VersBinarii/spike path: /src/controllers/subscriber.rs
use actix_web::{web, Error as ActixErr, HttpResponse};
use futures::Future;
use std::error::Error;
use crate::db;
use crate::models::NewSubscriber;
use crate::AppState;
pub fn show_subscriber(
subscriber_id: web::Path<i32>,
state:... | code_fim | hard | {
"lang": "rust",
"repo": "VersBinarii/spike",
"path": "/src/controllers/subscriber.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn create_new_subscriber(
req: web::Json<NewSubscriber>,
state: web::Data<AppState>,
) -> impl Future<Item = HttpResponse, Error = ActixErr> {
state
.db
.send(db::subscriber::InsertSubscriber(req.into_inner()))
.from_err()
.and_then(move |res| match res {
... | code_fim | hard | {
"lang": "rust",
"repo": "VersBinarii/spike",
"path": "/src/controllers/subscriber.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: cedric-h/sqlx path: /sqlx-core/src/sqlite/connection/executor.rs
use std::sync::Arc;
use either::Either;
use futures_core::future::BoxFuture;
use futures_core::stream::BoxStream;
use futures_util::{FutureExt, TryStreamExt};
use hashbrown::HashMap;
use libsqlite3_sys::sqlite3_last_insert_rowid;
... | code_fim | hard | {
"lang": "rust",
"repo": "cedric-h/sqlx",
"path": "/sqlx-core/src/sqlite/connection/executor.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn fetch_many<'e, 'q: 'e, E: 'q>(
self,
mut query: E,
) -> BoxStream<'e, Result<Either<SqliteDone, SqliteRow>, Error>>
where
'c: 'e,
E: Execute<'q, Self::Database>,
{
let s = query.query();
let arguments = query.take_arguments();
Box... | code_fim | hard | {
"lang": "rust",
"repo": "cedric-h/sqlx",
"path": "/sqlx-core/src/sqlite/connection/executor.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: yiyuanliu/async-learning path: /src/main.rs
mod aio;
use std::rc::Rc;
use std::task::*;
use std::future::*;
use aio::*;
use std::os::unix::io::AsRawFd;
use std::{fs::OpenOptions, os::unix::fs::OpenOptionsExt};
struct AioFuture {
rc: Option<i64>,
waker: Option<Waker>,
}
impl AioFuture ... | code_fim | hard | {
"lang": "rust",
"repo": "yiyuanliu/async-learning",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> future.await
}
async fn async_copy(src_path: &str, dst_path: &str) {
const O_DIRECT: i32 = 0o0040000;
let src = OpenOptions::new().read(true).custom_flags(O_DIRECT).open(src_path).unwrap();
let dst = OpenOptions::new().create(true).write(true).custom_flags(O_DIRECT).open(dst_path).unwrap(... | code_fim | hard | {
"lang": "rust",
"repo": "yiyuanliu/async-learning",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: lindzey/AdventOfCode path: /2017/day03/src/main.rs
use std::collections::HashMap;
#[cfg(test)]
mod test {
use super::*;
use pretty_assertions::assert_eq;
#[test]
fn test_get_ring() {
assert_eq!(0, get_ring(1));
assert_eq!(1, get_ring(2));
assert_eq!(1, g... | code_fim | hard | {
"lang": "rust",
"repo": "lindzey/AdventOfCode",
"path": "/2017/day03/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // (n, -n) Bottom-right corner will be (2n+1) ^2
// let bottom_right = (2*ring+1).pow(2);
let xx: i32;
let yy: i32;
if val < top_right {
xx = ring;
yy = val - center_right;
} else if val < top_left {
xx = center_top - val;
yy = ring;
} els... | code_fim | hard | {
"lang": "rust",
"repo": "lindzey/AdventOfCode",
"path": "/2017/day03/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn get_coords(val: i32, ring: i32) -> Point2 {
// (n, 0) Center of right side will be: (2n-1)^2 + n
let center_right = (2*ring-1).pow(2) + ring;
// (n, n) Top-right corner will be: (2n-1)^2 + 2n
let top_right = (2*ring-1).pow(2) + 2*ring;
// (0, n) Center of top will be: (2n-1)^2 + 3n... | code_fim | hard | {
"lang": "rust",
"repo": "lindzey/AdventOfCode",
"path": "/2017/day03/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dhruvasagar/comp path: /adventofcode/2022/day02/src/main.rs
use std::io;
use std::str::FromStr;
use std::time::Instant;
#[derive(Clone, Debug)]
pub enum Move {
Rock, // A, X
Paper, // B, Y
Scissor, // C, Z
}
impl FromStr for Move {
type Err = ();
fn from_str(s: &str) ... | code_fim | hard | {
"lang": "rust",
"repo": "dhruvasagar/comp",
"path": "/adventofcode/2022/day02/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> match mv1 {
Move::Rock => match mv2 {
Move::Rock => Outcome::Draw,
Move::Scissor => Outcome::Lose,
Move::Paper => Outcome::Win,
},
Move::Paper => match mv2 {
Move::Paper => Outcome::Draw,
Move::Rock => Outcome::Lose,
... | code_fim | hard | {
"lang": "rust",
"repo": "dhruvasagar/comp",
"path": "/adventofcode/2022/day02/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: wmeph/updown-rust path: /src/main.rs
#[macro_use]
extern crate quick_error;
use client::Client;
use command::Updown;
use config::Config;
use crate::messages::check::CheckParams;
use confy::ConfyError;
use std::process::exit;
use structopt::StructOpt;
use validator::ValidationErrors;
extern cr... | code_fim | hard | {
"lang": "rust",
"repo": "wmeph/updown-rust",
"path": "/src/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> None => {
println!("No api key provided. Exiting.");
exit(exitcode::CONFIG);
}
}
match subcommand_matches.value_of("private-api-key") {
Some(k) => {
private_api_key = k;
}
None => ... | code_fim | hard | {
"lang": "rust",
"repo": "wmeph/updown-rust",
"path": "/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>}
/// A simple Debugger trait that abstracts the debug information
/// to allow for more general handling of debug related stuff
pub trait Debugger {
/// Prints the given String to the given Debug
fn print(&self, content: &str);
/// Prints the given Instruction to the Debug output
fn pri... | code_fim | hard | {
"lang": "rust",
"repo": "Lol3rrr/rizm",
"path": "/emulator/src/traits.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// A simple Debugger trait that abstracts the debug information
/// to allow for more general handling of debug related stuff
pub trait Debugger {
/// Prints the given String to the given Debug
fn print(&self, content: &str);
/// Prints the given Instruction to the Debug output
fn print_... | code_fim | hard | {
"lang": "rust",
"repo": "Lol3rrr/rizm",
"path": "/emulator/src/traits.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Lol3rrr/rizm path: /emulator/src/traits.rs
use std::future::Future;
use sh::asm::Instruction;
use crate::{Key, Memory, Modifier};
/// A generic Trait that allows for different
/// Input-Methods to be used with the emulator
pub trait Input {
type Fut: Future<Output = (Key, Modifier)>;
... | code_fim | hard | {
"lang": "rust",
"repo": "Lol3rrr/rizm",
"path": "/emulator/src/traits.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Samoxive/SafetyJim path: /src/discord/slash_commands/invite.rs
use async_trait::async_trait;
use serenity::all::{CommandInteraction, CommandType};
use serenity::builder::{
CreateActionRow, CreateButton, CreateCommand, CreateInteractionResponse,
CreateInteractionResponseMessage,
};
use se... | code_fim | hard | {
"lang": "rust",
"repo": "Samoxive/SafetyJim",
"path": "/src/discord/slash_commands/invite.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> async fn handle_command(
&self,
context: &Context,
interaction: &CommandInteraction,
_config: &Config,
_services: &Services,
) -> anyhow::Result<()> {
let components = vec![CreateActionRow::Buttons(vec![
CreateButton::new_link("Invite Jim... | code_fim | hard | {
"lang": "rust",
"repo": "Samoxive/SafetyJim",
"path": "/src/discord/slash_commands/invite.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub struct InviteCommand;
#[async_trait]
impl SlashCommand for InviteCommand {
fn command_name(&self) -> &'static str {
"invite"
}
fn create_command(&self) -> CreateCommand {
CreateCommand::new("invite")
.kind(CommandType::ChatInput)
.description("disp... | code_fim | hard | {
"lang": "rust",
"repo": "Samoxive/SafetyJim",
"path": "/src/discord/slash_commands/invite.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> input
.into_iter()
.flat_map(|el| el.chars())
.filter(|c| c.is_alphabetic())
.fold(HashMap::new(), |mut map, c| {
*map.entry(c.to_ascii_lowercase()).or_insert(0 as usize) += 1 as usize;
map
})
}<|fim_prefix|>// repo: koboriakira/exercism-... | code_fim | medium | {
"lang": "rust",
"repo": "koboriakira/exercism-rust",
"path": "/rust/parallel-letter-frequency/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: koboriakira/exercism-rust path: /rust/parallel-letter-frequency/src/lib.rs
use std::collections::HashMap;
pub fn frequency(input: &[&str], worker_count: usize) -> HashMap<char, usize> {
input
.chunks(worker_count)
.map(|input| crossbeam::scope(|_| analyse(input)))
.f... | code_fim | medium | {
"lang": "rust",
"repo": "koboriakira/exercism-rust",
"path": "/rust/parallel-letter-frequency/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: sandialabs/Polymers path: /src/physics/single_chain/swfjc/thermodynamics/isotensional/ex.rs
#[no_mangle]
pub extern fn physics_single_chain_swfjc_thermodynamics_isotensional_end_to_end_length(number_of_links: u8, link_length: f64, well_width: f64, force: f64, temperature: f64) -> f64
{
su... | code_fim | hard | {
"lang": "rust",
"repo": "sandialabs/Polymers",
"path": "/src/physics/single_chain/swfjc/thermodynamics/isotensional/ex.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|>amics_isotensional_nondimensional_gibbs_free_energy_per_link(link_length: f64, hinge_mass: f64, well_width: f64, nondimensional_force: f64, temperature: f64) -> f64
{
super::nondimensional_gibbs_free_energy_per_link(&link_length, &hinge_mass, &well_width, &nondimensional_force, &temperature)
}
#[n... | code_fim | hard | {
"lang": "rust",
"repo": "sandialabs/Polymers",
"path": "/src/physics/single_chain/swfjc/thermodynamics/isotensional/ex.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn tick_times(&mut self, times: u32) {
for _ in 0..times { self.tick() }
}
pub fn loop_times(&mut self, times: u32) {
for _ in 0..times {
self.tick();
self.render();
}
}
pub fn tick(&mut self) {
self.game.tick();
}
... | code_fim | hard | {
"lang": "rust",
"repo": "wolfgang/sa",
"path": "/src/_tests/helpers/testable_game.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: wolfgang/sa path: /src/_tests/helpers/testable_game.rs
use crate::_tests::helpers::input_stub::{InputStub, InputStubRef};
use crate::_tests::helpers::string_renderer::StringRenderer;
use crate::game::builder::GameBuilder;
use crate::game::Game;
const DEFAULT_SHIP_WIDTH: u32 = 4;
const DEFAULT_S... | code_fim | hard | {
"lang": "rust",
"repo": "wolfgang/sa",
"path": "/src/_tests/helpers/testable_game.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: google/flatbuffers path: /tests/more_defaults/mod.rs
// Automatically generated by the Flatbuffers compiler. Do not modify.
// @generated
mod abc_generated;<|fim_suffix|>generated;
pub use self::more_defaults_generated::*;<|fim_middle|>
pub use self::abc_generated::*;
mod more_defaults_ | code_fim | easy | {
"lang": "rust",
"repo": "google/flatbuffers",
"path": "/tests/more_defaults/mod.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>generated;
pub use self::more_defaults_generated::*;<|fim_prefix|>// repo: google/flatbuffers path: /tests/more_defaults/mod.rs
// Automatically generated by the Flatbuffers compiler. Do not modify.
// @generated
mod abc_generated;<|fim_middle|>
pub use self::abc_generated::*;
mod more_defaults_ | code_fim | easy | {
"lang": "rust",
"repo": "google/flatbuffers",
"path": "/tests/more_defaults/mod.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> PortV(_) => write!(f, "#<port>"),
Closure(_) => write!(f, "#<bytecode-closure>"),
HashMapV(hm) => write!(f, "#<hashmap {:#?}>", hm.as_ref()),
IterV(_) => write!(f, "#<iterator>"),
HashSetV(hs) => write!(f, "#<hashset {hs:?}>"),
Future... | code_fim | hard | {
"lang": "rust",
"repo": "mattwparas/steel",
"path": "/crates/steel-core/src/rvals/cycles.rs",
"mode": "spm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mattwparas/steel path: /crates/steel-core/src/rvals/cycles.rs
use crate::steel_vm::builtin::get_function_name;
use super::*;
#[derive(Default)]
// Keep track of any reference counted values that are visited, in a pointer
pub(super) struct CycleDetector {
// Keep a mapping of the pointer ->... | code_fim | hard | {
"lang": "rust",
"repo": "mattwparas/steel",
"path": "/crates/steel-core/src/rvals/cycles.rs",
"mode": "psm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_suffix|> // If we've already seen this, its fine, we can just move on
if let std::collections::hash_map::Entry::Vacant(e) = self.cycles.entry(val) {
e.insert(id);
// Keep track of the actual values that are being captured
self.values.push(stee... | code_fim | hard | {
"lang": "rust",
"repo": "mattwparas/steel",
"path": "/crates/steel-core/src/rvals/cycles.rs",
"mode": "spm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.