text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_prefix|>// repo: cyrilcoutelier/raytracer.rs path: /tests/matrix.rs
use raytracer::matrix::Matrix;
use raytracer::point::Point;
use raytracer::vector::Vector;
use std::f32::consts::PI;
// rotate_y
#[test]
fn rotate_y_positive_on_z() {
// Given
let origin = Point::new(0.0, 0.0, 1.0);
let matrix = Mat... | code_fim | hard | {
"lang": "rust",
"repo": "cyrilcoutelier/raytracer.rs",
"path": "/tests/matrix.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // When
let actual = matrix.dot_point(&origin);
// Then
let expected = Point::new(1.0, 0.0, 0.0);
assert_eq!(actual, expected);
}
#[test]
fn rotate_z_positive_on_z() {
// Given
let origin = Point::new(0.0, 0.0, 1.0);
let matrix = Matrix::new_rotation_z(PI / 2.0);
// ... | code_fim | hard | {
"lang": "rust",
"repo": "cyrilcoutelier/raytracer.rs",
"path": "/tests/matrix.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ju6ge/atsame70q21 path: /src/xdmac/xdmac_chid/xdmac_cid.rs
#[doc = "Writer for register XDMAC_CID"]
pub type W = crate::W<u32, super::XDMAC_CID>;
#[doc = "Register XDMAC_CID `reset()`'s with value 0"]
impl crate::ResetValue for super::XDMAC_CID {
type Type = u32;
#[inline(always)]
fn... | code_fim | hard | {
"lang": "rust",
"repo": "ju6ge/atsame70q21",
"path": "/src/xdmac/xdmac_chid/xdmac_cid.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>ts the field bit"]
#[inline(always)]
pub fn set_bit(self) -> &'a mut W {
self.bit(true)
}
#[doc = r"Clears the field bit"]
#[inline(always)]
pub fn clear_bit(self) -> &'a mut W {
self.bit(false)
}
#[doc = r"Writes raw bits to the field"]
#[inline(always)... | code_fim | hard | {
"lang": "rust",
"repo": "ju6ge/atsame70q21",
"path": "/src/xdmac/xdmac_chid/xdmac_cid.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn with<T: Clone + Send>(t: T) -> impl Filter<Extract = (T,), Error = Infallible> + Clone {
warp::any().map(move || t.clone())
}<|fim_prefix|>// repo: Herbstein/BurgerBackend path: /src/filters/helpers.rs
use std::convert::Infallible;
<|fim_middle|>use warp::Filter;
| code_fim | easy | {
"lang": "rust",
"repo": "Herbstein/BurgerBackend",
"path": "/src/filters/helpers.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Herbstein/BurgerBackend path: /src/filters/helpers.rs
use std::convert::Infallible;
<|fim_suffix|>pub fn with<T: Clone + Send>(t: T) -> impl Filter<Extract = (T,), Error = Infallible> + Clone {
warp::any().map(move || t.clone())
}<|fim_middle|>use warp::Filter;
| code_fim | easy | {
"lang": "rust",
"repo": "Herbstein/BurgerBackend",
"path": "/src/filters/helpers.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn to_refs<T>(mut list: Box<&mut List<T>>) -> Vec<&mut T> {
let mut result = vec![];
loop {
result.push(&mut list.value);
if let Some(n) = list.next.as_mut() {
*list = n;
} else {
return result;
}
}
}
fn main() {}<|fim_prefix|>// repo: I... | code_fim | medium | {
"lang": "rust",
"repo": "IThawk/rust-project",
"path": "/rust-master/src/test/ui/borrowck/issue-62007-assign-box.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut result = vec![];
loop {
result.push(&mut list.value);
if let Some(n) = list.next.as_mut() {
*list = n;
} else {
return result;
}
}
}
fn main() {}<|fim_prefix|>// repo: IThawk/rust-project path: /rust-master/src/test/ui/borrowck/... | code_fim | medium | {
"lang": "rust",
"repo": "IThawk/rust-project",
"path": "/rust-master/src/test/ui/borrowck/issue-62007-assign-box.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: IThawk/rust-project path: /rust-master/src/test/ui/borrowck/issue-62007-assign-box.rs
// run-pass
// Issue #62007: assigning over a deref projection of a box (in this
// case, `*list = n;`) should be able to kill all borrows of `*list`,
// so that `*list` can be borrowed on the next iteration t... | code_fim | medium | {
"lang": "rust",
"repo": "IThawk/rust-project",
"path": "/rust-master/src/test/ui/borrowck/issue-62007-assign-box.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(parse::<i32>(""), &[]);
assert_eq!(parse::<i32>("r"), &[]);
assert_eq!(parse::<i32>("1"), &[1]);
assert_eq!(parse::<i32>("12"), &[12]);
assert_eq!(parse::<i32>(" 12 3,4-5 -6 "), &[12, 3, 4, -5, -6]);
assert_eq!(parse::<i32>("0 <-> 2"), [0, 2]);
}
}<|fim_prefix|>// repo: DarthGandal... | code_fim | hard | {
"lang": "rust",
"repo": "DarthGandalf/advent-of-code",
"path": "/2017/days6-/src/numbers.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: DarthGandalf/advent-of-code path: /2017/days6-/src/numbers.rs
use pest::Parser;
#[derive(Parser)]
#[grammar = "numbers.pest"]
struct NumbersParser;
<|fim_suffix|> assert_eq!(parse::<i32>(""), &[]);
assert_eq!(parse::<i32>("r"), &[]);
assert_eq!(parse::<i32>("1"), &[1]);
assert_eq!(parse... | code_fim | hard | {
"lang": "rust",
"repo": "DarthGandalf/advent-of-code",
"path": "/2017/days6-/src/numbers.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: burrbull/vl6180x path: /src/pac/result_range_raw.rs
#[allow(missing_docs)]
pub struct RESULT_RANGE_RAW;
impl crate::Size for RESULT_RANGE_RAW {
typ<|fim_suffix|>= "`read()` method returns [R](R) reader structure"]
impl crate::Readable for RESULT_RANGE_RAW {}
#[doc = "Reader of register resul... | code_fim | medium | {
"lang": "rust",
"repo": "burrbull/vl6180x",
"path": "/src/pac/result_range_raw.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>= "`read()` method returns [R](R) reader structure"]
impl crate::Readable for RESULT_RANGE_RAW {}
#[doc = "Reader of register result_range_raw"]
pub type R = crate::R<u8, RESULT_RANGE_RAW>;
impl R {}<|fim_prefix|>// repo: burrbull/vl6180x path: /src/pac/result_range_raw.rs
#[allow(missing_docs)]
pub stru... | code_fim | medium | {
"lang": "rust",
"repo": "burrbull/vl6180x",
"path": "/src/pac/result_range_raw.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub mod collections {
pub use std::collections::btree_map;
pub use std::collections::btree_set;
pub use std::collections::vec_deque;
}
pub mod thread {
pub use std::thread::panicking;
}<|fim_prefix|>// repo: paritytech/substrate path: /primitives/std/with_std.rs
// This file is part of Substrate.
/... | code_fim | hard | {
"lang": "rust",
"repo": "paritytech/substrate",
"path": "/primitives/std/with_std.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: paritytech/substrate path: /primitives/std/with_std.rs
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance w... | code_fim | hard | {
"lang": "rust",
"repo": "paritytech/substrate",
"path": "/primitives/std/with_std.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: stearnsc/rust-stripe-client path: /src/errors/error.rs
use hyper;
use serde_json;
use std;
use super::stripe_error;
#[derive(Debug)]
pub enum Error {
HttpError(hyper::error::Error),
SerializationError(serde_json::error::Error),
IoError(std::io::Error),
StripeError(stripe_error::... | code_fim | medium | {
"lang": "rust",
"repo": "stearnsc/rust-stripe-client",
"path": "/src/errors/error.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> match *self {
HttpError(ref err) => write!(f, "Error::HyperError({})", err),
SerializationError(ref err) => write!(f, "Error::SerdeError({})", err),
IoError(ref err) => write!(f, "Error::IoError({})", err),
StripeError(ref err) ... | code_fim | hard | {
"lang": "rust",
"repo": "stearnsc/rust-stripe-client",
"path": "/src/errors/error.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: djg/unsafe-poke path: /tests/max_size.rs
#![allow(dead_code)]
use std::{marker::PhantomData, mem::size_of};
use unsafe_poke::UnsafePoke;
use unsafe_poke_derive::UnsafePoke;
#[test]
fn test_numbers() {
assert_eq!(u8::poke_max_size(), size_of::<u8>());
assert_eq!(u16::poke_max_size(), siz... | code_fim | hard | {
"lang": "rust",
"repo": "djg/unsafe-poke",
"path": "/tests/max_size.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[test]
fn test_enum() {
#[derive(UnsafePoke)]
enum TestEnum {
NoArg,
OneArg(usize),
Args(usize, usize),
AnotherNoArg,
StructLike { x: usize, y: f32 },
}
assert_eq!(
TestEnum::poke_max_size(),
size_of::<u32>() + 2 * size_of::<usize>()... | code_fim | hard | {
"lang": "rust",
"repo": "djg/unsafe-poke",
"path": "/tests/max_size.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert!(!is_balanced("}{"));
}
#[test]
fn wrong_closing_bracket() {
assert!(!is_balanced("{]"));
}
#[test]
fn paired_with_whitespace() {
assert!(is_balanced("{ }"));
}
#[test]
fn partially_paired_brackets() {
assert!(!is_balanced("{[])"))... | code_fim | hard | {
"lang": "rust",
"repo": "amscotti/rust_balanced_brackets",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert!(!is_balanced("[]]"));
}
#[test]
fn early_incomplete_brackets() {
assert!(!is_balanced(")()"));
}
#[test]
fn early_mismatched_brackets() {
assert!(!is_balanced("{)()"));
}
#[test]
fn math_expression() {
assert!(is_balanced("(((185 ... | code_fim | hard | {
"lang": "rust",
"repo": "amscotti/rust_balanced_brackets",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: amscotti/rust_balanced_brackets path: /src/lib.rs
use std::{convert::Infallible, str::FromStr};
#[derive(Debug, PartialEq)]
enum Bracket {
Round,
Square,
Curly,
}
#[derive(Debug, PartialEq)]
enum Type {
Open(Bracket),
Close(Bracket),
Other,
}
impl From<char> for Type {... | code_fim | hard | {
"lang": "rust",
"repo": "amscotti/rust_balanced_brackets",
"path": "/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> return Self {
symbol: value.symbol.clone(),
start_time: std_start
.map(|start| start.duration_since(UNIX_EPOCH).ok())
.flatten()
.map(|start| start.as_millis().to_string()),
end_time: std_end
.map(|std_end| std_end.duration_since(UNIX_EPOCH).ok())
... | code_fim | hard | {
"lang": "rust",
"repo": "hiroaki-yamamoto/midas",
"path": "/backend/libs/exchanges/history/src/binance/entities/query.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: hiroaki-yamamoto/midas path: /backend/libs/exchanges/history/src/binance/entities/query.rs
use ::std::convert::From;
use ::std::time::{SystemTime, UNIX_EPOCH};
use ::entities::HistoryFetchRequest;
use ::serde::Serialize;
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Query ... | code_fim | hard | {
"lang": "rust",
"repo": "hiroaki-yamamoto/midas",
"path": "/backend/libs/exchanges/history/src/binance/entities/query.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.as_mut_ptr() as *mut _
}
}<|fim_prefix|>// repo: EvanMerlock/sports_record path: /ffmpeg_common/src/unsafe_code/traits/as_raw.rs
use libc;
pub trait AsRawPtr<T> {
fn as_ptr(&self) -> *const T;
fn as_mut_ptr(&mut self) -> *mut T;
<|fim_middle|> fn as_void_ptr(&self) -> *const... | code_fim | medium | {
"lang": "rust",
"repo": "EvanMerlock/sports_record",
"path": "/ffmpeg_common/src/unsafe_code/traits/as_raw.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: EvanMerlock/sports_record path: /ffmpeg_common/src/unsafe_code/traits/as_raw.rs
use libc;
pub trait AsRawPtr<T> {
fn as_ptr(&self) -> *const T;
<|fim_suffix|> self.as_ptr() as *const _
}
fn as_mut_void_ptr(&mut self) -> *mut libc::c_void {
self.as_mut_ptr() as *mut _... | code_fim | medium | {
"lang": "rust",
"repo": "EvanMerlock/sports_record",
"path": "/ffmpeg_common/src/unsafe_code/traits/as_raw.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ThePerkinrex/TestLang path: /src/ast/types_old.rs
use super::expr::Expr;
use super::traits::Trait;
use super::Ident;
use crate::error::Error;
use crate::scope::Scope;
use crate::span::Span;
#[derive(Debug, Clone)]
pub enum Type {
Number,
String,
Array(Box<Span<Type>>),
Fn(Vec<(Span<Ident>, ... | code_fim | hard | {
"lang": "rust",
"repo": "ThePerkinrex/TestLang",
"path": "/src/ast/types_old.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> match self {
Self::Number => write!(f, "number"),
Self::String => write!(f, "string"),
Self::Array(typ) => write!(f, "[{}]", typ),
Self::Fn(args, ret) => write!(
f,
"fn({}) -> {}",
args.iter()
.map(|(name, x)| format!("{}: {}", name, x))
.collect::<Vec<String>>()
.... | code_fim | hard | {
"lang": "rust",
"repo": "ThePerkinrex/TestLang",
"path": "/src/ast/types_old.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn surface_lock_front_buffer(surface: &GBMSurface) -> Option<GBMBufferObject> {
assert!(*surface as usize != 0);
match unsafe {
ffi::gbm_surface_lock_front_buffer(*surface)
} as usize {
0 => None,
x => Some(x as GBMBufferObject)
}
}
pub fn surface_release_buffe... | code_fim | hard | {
"lang": "rust",
"repo": "willmtemple/rust-gbm",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn surface_create(gbm: &GBMDevice, width: u32, height: u32,
format: u32, flags: u32) -> Option<GBMSurface> {
assert!(*gbm as usize != 0);
match unsafe {
ffi::gbm_surface_create(*gbm, width, height, format, flags)
} as usize {
0 => None,
x => So... | code_fim | hard | {
"lang": "rust",
"repo": "willmtemple/rust-gbm",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: willmtemple/rust-gbm path: /src/lib.rs
extern crate libc;
use std::str;
use std::ffi::CStr;
mod ffi;
pub use ffi::formats::*;
pub type GBMDevice = *mut ffi::Struct_gbm_device;
pub type GBMBufferObject = *mut ffi::Struct_gbm_bo;
pub type GBMSurface = *mut ffi::Struct_gbm_surface;
pub use ffi... | code_fim | hard | {
"lang": "rust",
"repo": "willmtemple/rust-gbm",
"path": "/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: abhijeetbhagat/boa path: /boa/src/builtins/boolean/tests.rs
use super::*;
use crate::{builtins::value::same_value, exec::Interpreter, forward, forward_val, realm::Realm};
#[test]
fn check_boolean_constructor_is_function() {
let global = Value::new_object(None);
let boolean_constructor =... | code_fim | hard | {
"lang": "rust",
"repo": "abhijeetbhagat/boa",
"path": "/boa/src/builtins/boolean/tests.rs",
"mode": "psm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_suffix|> eprintln!("{}", forward(&mut engine, init));
let bool_instance = forward_val(&mut engine, "boolInstance").expect("value expected");
let bool_prototype = forward_val(&mut engine, "boolProto").expect("value expected");
assert!(same_value(
&bool_instance.get_internal_slot("__proto__"... | code_fim | medium | {
"lang": "rust",
"repo": "abhijeetbhagat/boa",
"path": "/boa/src/builtins/boolean/tests.rs",
"mode": "spm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[test]
fn constructor_gives_true_instance() {
let realm = Realm::create();
let mut engine = Interpreter::new(realm);
let init = r#"
var trueVal = new Boolean(true);
var trueNum = new Boolean(1);
var trueString = new Boolean("true");
var trueBool = new Boolean(t... | code_fim | hard | {
"lang": "rust",
"repo": "abhijeetbhagat/boa",
"path": "/boa/src/builtins/boolean/tests.rs",
"mode": "spm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_suffix|>X? ⇒ Debug with upper-case hexadecimal integers
//! - o ⇒ Octal
//! - x ⇒ LowerHex
//! - X ⇒ UpperHex
//! - p ⇒ Pointer
//! - b ⇒ Binary
//! - e ⇒ LowerExp
//! - E ⇒ UpperExp
//!
//! 详情查看:[https://doc.rust-lang.org/std/fmt/](https://doc.rust-lang.org/std/fmt/)<|fim_prefix|>// repo: ityy/rust_study path: ... | code_fim | hard | {
"lang": "rust",
"repo": "ityy/rust_study",
"path": "/src/book_study_notes/book01_the_tao_of_programming/src/c02_outline/t2_13_0_documentation_comments.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ityy/rust_study path: /src/book_study_notes/book01_the_tao_of_programming/src/c02_outline/t2_13_0_documentation_comments.rs
//! # 文档注释(documentation comments)
//! Rust文档的哲学是:代码即文档,文档即代码。<br/>
//!
//! **普通注释:**
//! - // 整行注释
//! - /* ... */ 整块注释
//!
//! **文档注释:支持Markdown语法,支持示例代码测试,使用r... | code_fim | hard | {
"lang": "rust",
"repo": "ityy/rust_study",
"path": "/src/book_study_notes/book01_the_tao_of_programming/src/c02_outline/t2_13_0_documentation_comments.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> Container::new(
Column::new()
.push(
Row::new()
.push(sound_col1)
.push(sound_col2)
.push(sound_col3)
.push(sound_col4),
)
... | code_fim | hard | {
"lang": "rust",
"repo": "geom3trik/tooro-editor",
"path": "/src/ui/sound/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: geom3trik/tooro-editor path: /src/ui/sound/mod.rs
//! Panel containing the sound (preset) parameters
mod amp;
mod arp;
mod enva;
mod envf;
mod extra;
mod filter;
mod lfo1;
mod lfo2;
mod misc;
mod modulation;
mod osc1;
mod osc2;
mod shaper;
use iced::{Column, Container, Element, Length, Row};
... | code_fim | hard | {
"lang": "rust",
"repo": "geom3trik/tooro-editor",
"path": "/src/ui/sound/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let sound_col3 = Column::new()
.padding(5)
.spacing(10)
.push(self.extra_section.view(params))
.push(self.shaper_section.view(params))
.push(self.envf_section.view(params))
.width(Length::FillPortion(4));
let sound_co... | code_fim | hard | {
"lang": "rust",
"repo": "geom3trik/tooro-editor",
"path": "/src/ui/sound/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: gilescope/MoonZoon path: /examples/time_tracker/shared/src/lib.rs
use serde::{Deserialize, Serialize};
use ulid::Ulid;
use chrono::{prelude::*, Duration};
use std::borrow::Cow;
mod clients_and_projects;
mod time_blocks;
mod time_tracker;
pub type ClientId = Ulid;
pub type ProjectId = Ulid;
pub... | code_fim | hard | {
"lang": "rust",
"repo": "gilescope/MoonZoon",
"path": "/examples/time_tracker/shared/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[derive(Serialize, Deserialize)]
pub enum DownMsg {
// ------ Auth ------
InvalidPassword,
LoggedIn(User),
LoggedOut,
AccessDenied,
// ------ Page data ------
ClientsAndProjectsClients(Vec<clients_and_projects::Client>),
TimeBlocksClients(Vec<time_blocks::Client>),
Tim... | code_fim | hard | {
"lang": "rust",
"repo": "gilescope/MoonZoon",
"path": "/examples/time_tracker/shared/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[derive(Serialize, Deserialize)]
pub enum UpMsg<'a> {
// ------ Auth ------
Login(Cow<'a, str>),
Logout,
// ------ Page data ------
GetClientsAndProjectsClients,
GetTimeBlocksClients,
GetTimeTrackerClients,
// ------ Client ------
AddClient(ClientId),
RemoveClient(... | code_fim | hard | {
"lang": "rust",
"repo": "gilescope/MoonZoon",
"path": "/examples/time_tracker/shared/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: graydon/rust-nbe-for-mltt path: /crates/mltt-test/src/lib.rs
//! Integration tests for the MLTT language.
macro_rules! run_test {
($name:ident, $path:literal) => {
#[test]
fn $name() {
use language_reporting::termcolor::{ColorChoice, StandardStream};
... | code_fim | hard | {
"lang": "rust",
"repo": "graydon/rust-nbe-for-mltt",
"path": "/crates/mltt-test/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut files = Files::new();
let writer = StandardStream::stdout(ColorChoice::Always);
let reporting_config = language_reporting::DefaultConfig;
let src = include_str!(concat!("../../../", $path));
let file_id = files.add($path, src);
... | code_fim | hard | {
"lang": "rust",
"repo": "graydon/rust-nbe-for-mltt",
"path": "/crates/mltt-test/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let iter = glib_sys::g_variant_iter_new(arr);
let mut child = glib_sys::g_variant_iter_next_value(iter);
while !child.is_null() {
let data = glib_sys::g_variant_get_data_as_bytes(child);
let ptr = glib_sys::g_bytes_ge... | code_fim | hard | {
"lang": "rust",
"repo": "manuels/wg-p2p-nm-plugin",
"path": "/src/gui/bulletinboard.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: manuels/wg-p2p-nm-plugin path: /src/gui/bulletinboard.rs
use std;
use glib;
use gdbus;
use glib_sys;
use gio_sys;
pub fn search_for_key<F>(v: &[u8], callback: F)
where F: Fn(Result<Vec<Vec<u8>>, glib::Error>) + 'static
{
println!("Searching...");
let connection = unsafe {
:... | code_fim | hard | {
"lang": "rust",
"repo": "manuels/wg-p2p-nm-plugin",
"path": "/src/gui/bulletinboard.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: inkhsutesou/pingbong path: /server/src/bot.rs
use crate::ball::{Ball, BALL_RADIUS_ANGLE, NO_TEAM};
use crate::player::{ClientId, Player, SeqNr};
use crate::protocol::ClientMoveUpdate;
use crate::room::{CIRCLE_RADIUS, FIELD_HEIGHT, FIELD_WIDTH, TPF, TPS};
use crate::util::positive_angle_wrap;
use... | code_fim | hard | {
"lang": "rust",
"repo": "inkhsutesou/pingbong",
"path": "/server/src/bot.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub struct BotTickResult {
pub ball_mask: BallMask,
pub move_update: ClientMoveUpdate,
}
impl Bot {
pub fn new(id: ClientId) -> Self {
Self {
id,
seq_nr: Cell::new(0),
previous_spin: Cell::new(0.0),
}
}
#[inline]
pub fn id(&self... | code_fim | hard | {
"lang": "rust",
"repo": "inkhsutesou/pingbong",
"path": "/server/src/bot.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: carbidegames/clockwork-server path: /src/worker.rs
use std::sync::mpsc::Sender;
use std::sync::Arc;
use crossbeam::sync::MsQueue;
use hyper::{Control, Next, RequestUri};
use webapp::{Application, Request, Responder, BodyResponder};
use webapp::header::Headers;
use webapp::status::StatusCode;
use... | code_fim | hard | {
"lang": "rust",
"repo": "carbidegames/clockwork-server",
"path": "/src/worker.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[derive(Debug)]
pub enum WorkerResponse {
Header(StatusCode, Headers),
Data(Vec<u8>),
Finish,
}
pub struct RequestToken {
method: Method,
uri: RequestUri,
body: Vec<u8>,
ctrl: Control,
sender: Sender<WorkerResponse>,
}
impl RequestToken {
pub fn new(method: Method, u... | code_fim | hard | {
"lang": "rust",
"repo": "carbidegames/clockwork-server",
"path": "/src/worker.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn finish(self) {
// TODO: See if we can eliminate the need for a write() and instead directly do an end()
self.sender.send(WorkerResponse::Finish).unwrap();
self.ctrl.ready(Next::write()).unwrap();
}
}
struct CwResponder {
token: RequestToken
}
impl Responder for CwR... | code_fim | hard | {
"lang": "rust",
"repo": "carbidegames/clockwork-server",
"path": "/src/worker.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: chenenjie/sample_rust path: /src/bin/channel4.rs
use std::sync::mpsc;
use std::thread;
fn main() {
let (tx, rx): (mpsc::Sender<i32>, mpsc::Receiver<i32>) = mpsc::channel();
let new_thread = thread::spawn(move || {
let mut i = 0;
loop {
i = i + 1;
<|fim_s... | code_fim | hard | {
"lang": "rust",
"repo": "chenenjie/sample_rust",
"path": "/src/bin/channel4.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> new_thread.join().unwrap();
println!("receive {}", rx.recv().unwrap());
}<|fim_prefix|>// repo: chenenjie/sample_rust path: /src/bin/channel4.rs
use std::sync::mpsc;
use std::thread;
fn main() {
let (tx, rx): (mpsc::Sender<i32>, mpsc::Receiver<i32>) = mpsc::channel();
let new_thread =... | code_fim | hard | {
"lang": "rust",
"repo": "chenenjie/sample_rust",
"path": "/src/bin/channel4.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: andoriyu/material-design-icons-rs path: /src/materialiconsround/notification/icon_wifi.rs
pub struct IconWifi {
props: crate::Props,
}
impl yew::Component for IconWifi {
type Properties = crate::Props;
type Message = ();
fn create(props: Self::Properties, _: yew::prelude::Component... | code_fim | medium | {
"lang": "rust",
"repo": "andoriyu/material-design-icons-rs",
"path": "/src/materialiconsround/notification/icon_wifi.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn lock(&mut self) -> IntrLockGuard {
let enabled = arch::intr_get();
arch::intr_off();
unsafe {
if *self.cnt.get() == 0 {
self.is_enabled_before = enabled;
self.hart_id = arch::hart_id();
} else {
if e... | code_fim | hard | {
"lang": "rust",
"repo": "orb1t-ua/core-os-riscv",
"path": "/kernel/src/process/cpu.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> if arch::intr_get() {
panic!("{} intr enabled", hart_id());
}
unsafe {
if hart_id() != self.lock.hart_id {
panic!("unlock on different hart");
}
let cnt = self.lock.cnt.get();
*cnt -= 1;
if *cnt... | code_fim | hard | {
"lang": "rust",
"repo": "orb1t-ua/core-os-riscv",
"path": "/kernel/src/process/cpu.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: orb1t-ua/core-os-riscv path: /kernel/src/process/cpu.rs
// Copyright (c) 2020 Alex Chi
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
use super::{Process, TrapFrame, Context};
use alloc::boxed::Box;
use core::mem::MaybeUninit;
use core::cell::Unsaf... | code_fim | hard | {
"lang": "rust",
"repo": "orb1t-ua/core-os-riscv",
"path": "/kernel/src/process/cpu.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: heathjay/RustStudy path: /project/chapter914pointer/src/main.rs
/*
//暂时不能编译,因为没有大小
enum List{
Cons(i32, Box<List>),
Nil,
}
*/
use std::rc::Rc;
enum List{
Cons(i32, Rc<List>),
Nil
}
use std::ops::Deref;
//创建一个智能指针
struct MyBox<T>(T);
impl<T> MyBox<T>{
fn new(x:T) -> MyBox<T>{
... | code_fim | hard | {
"lang": "rust",
"repo": "heathjay/RustStudy",
"path": "/project/chapter914pointer/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>
let a = Rc ::new(Cons(4, Rc::new(Cons(10,Rc::new(Nil)))));
println!("count a= {}",Rc::strong_count(&a));
let b = Cons(3, Rc::clone(&a));
println!("count b= {}",Rc::strong_count(&a));
let c = Cons(4,Rc::clone(&a));
println!("count c= {}",Rc::strong_count(&a));
}
fn hello(name : &st... | code_fim | hard | {
"lang": "rust",
"repo": "heathjay/RustStudy",
"path": "/project/chapter914pointer/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: LightningPeach/lnd-rust path: /src/bin/main.rs
#![forbid(unsafe_code)]
use lnd_rust::rpc_grpc::LightningClient;
use lnd_rust::rpc_grpc::Lightning;
use lnd_rust::tls_certificate::TLSCertificate;
use lnd_rust::macaroon_data::MacaroonData;
use lnd_rust::rpc;
use grpc::RequestOptions;
fn main() ... | code_fim | hard | {
"lang": "rust",
"repo": "LightningPeach/lnd-rust",
"path": "/src/bin/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> use std::{net::SocketAddr, sync::Arc};
use grpc::ClientStub;
println!("lnd-rust main");
if std::env::args().len() < 4 {
println!("Usage: cargo run -- %path_to_cert% %path_to_macaroon% %socket e.g. 127.0.0.1:100500%");
return
}
let certificate = {
let cert... | code_fim | medium | {
"lang": "rust",
"repo": "LightningPeach/lnd-rust",
"path": "/src/bin/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn chained_47_512() -> Result<()> {
let (mut tlc, array): (TLC5947<_, _>, BitVec) = test_configuration_random(512);
for (pos, val) in array.chunks(36).enumerate() {
let val: Vec<u16> = val
.chunks(12)
.map(|b| b.iter().fold(0, |a... | code_fim | hard | {
"lang": "rust",
"repo": "KyleCharters/tlc59xxx",
"path": "/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> Ok(())
}
#[test]
fn rgb_711() -> Result<()> {
let (mut tlc, array): (TLC59711<_, _>, BitVec) = test_configuration_random(1);
for (pos, val) in array.chunks(48).enumerate() {
let val: Vec<u16> = val
.chunks(16)
.map(|b| b.ite... | code_fim | hard | {
"lang": "rust",
"repo": "KyleCharters/tlc59xxx",
"path": "/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: KyleCharters/tlc59xxx path: /src/lib.rs
pub mod error;
use bitvec::prelude::{bitvec, BitVec, Bits, LittleEndian};
use embedded_hal::blocking::spi::Write;
use embedded_hal::digital::v2::OutputPin;
use error::{Error, Result};
use std::marker::PhantomData;
use typenum::{Unsigned, U12, U16, U24};
... | code_fim | hard | {
"lang": "rust",
"repo": "KyleCharters/tlc59xxx",
"path": "/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: gustavorobertux/celo-bls-snark-rs path: /crates/bls-crypto/src/hash_to_curve/try_and_increment.rs
use ark_std::{end_timer, start_timer};
use byteorder::WriteBytesExt;
use log::trace;
use std::marker::PhantomData;
use super::HashToCurve;
use crate::hashers::{
composite::{CompositeHasher, COM... | code_fim | hard | {
"lang": "rust",
"repo": "gustavorobertux/celo-bls-snark-rs",
"path": "/crates/bls-crypto/src/hash_to_curve/try_and_increment.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> if let Some(p) = super::from_random_bytes::<P>(&candidate_hash[..num_bytes]) {
trace!(
"succeeded hashing \"{}\" to curve in {} tries",
hex::encode(message),
c
);
end_timer!(hash_loop_ti... | code_fim | hard | {
"lang": "rust",
"repo": "gustavorobertux/celo-bls-snark-rs",
"path": "/crates/bls-crypto/src/hash_to_curve/try_and_increment.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> &self,
domain: &[u8],
message: &[u8],
extra_data: &[u8],
) -> Result<Self::Output, BLSError> {
self.hash_with_attempt(domain, message, extra_data)
.map(|res| res.0)
}
}
impl<'a, H, P> TryAndIncrement<'a, H, P>
where
H: Hasher<Error = BLSErro... | code_fim | hard | {
"lang": "rust",
"repo": "gustavorobertux/celo-bls-snark-rs",
"path": "/crates/bls-crypto/src/hash_to_curve/try_and_increment.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dem42/copper path: /src/post_processing/post_processing.rs
use super::generic_postprocess::GenericPostprocess;
use crate::display::{
Display,
framebuffers::FboMap,
framebuffers::FramebufferObject,
framebuffers::FboFlags,
};
use crate::gl;
use crate::models::{
RawMode... | code_fim | hard | {
"lang": "rust",
"repo": "dem42/copper",
"path": "/src/post_processing/post_processing.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // here we setup our chain of post processing steps
pub fn do_post_processing(&mut self, display: &Display) {
let camera_texture_fbo = self.post_processing_fbos.fbos.get_mut(FboMap::CAMERA_TEXTURE_FBO).expect("A camera texture must be present for postprocessing");
let camera_tex... | code_fim | hard | {
"lang": "rust",
"repo": "dem42/copper",
"path": "/src/post_processing/post_processing.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let camera_brightness_fbo = self.post_processing_fbos.fbos.get_mut(FboMap::CAMERA_BRIGHTNESS_FBO).expect("A camera brightness texture must be present for bloom effect");
let camera_brightness = camera_brightness_fbo.color_texture(0).expect("A camera texture must be present for postprocess... | code_fim | hard | {
"lang": "rust",
"repo": "dem42/copper",
"path": "/src/post_processing/post_processing.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut image = vec![
vec![0, 2, 3, 4, 5],
vec![6, 0, 8, 9, 10],
vec![11, 0, 0, 14, 15],
vec![16, 17, 18, 0, 20],
vec![21, 22, 23, 24, 25],
];
zero_matrix(&mut image);
let expected = vec![
vec![0, 0, 0,... | code_fim | hard | {
"lang": "rust",
"repo": "ghassanachi/ctci",
"path": "/src/problems/chp_1/problem_8.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ghassanachi/ctci path: /src/problems/chp_1/problem_8.rs
use std::collections::HashSet;
pub fn zero_matrix(matrix: &mut [Vec<u32>]) {
let mut col_set = HashSet::new();
let mut row_set = HashSet::new();
for (row_idx, row) in &mut matrix.iter().enumerate() {
for (col_idx, col) ... | code_fim | hard | {
"lang": "rust",
"repo": "ghassanachi/ctci",
"path": "/src/problems/chp_1/problem_8.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: sarus-tech/opendp path: /rust/opendp-ffi/src/trans/resize.rs
use std::convert::TryFrom;
use std::ops::Bound;
use std::os::raw::{c_char, c_uint, c_void};
use opendp::dom::{AllDomain, IntervalDomain};
use opendp::err;
use opendp::traits::{CheckNull, TotalOrd};
use opendp::trans::make_resize_const... | code_fim | hard | {
"lang": "rust",
"repo": "sarus-tech/opendp",
"path": "/rust/opendp-ffi/src/trans/resize.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> use super::*;
#[test]
fn test_make_resize() -> Fallible<()> {
let transformation = Result::from(opendp_trans__make_resize(
AnyObject::new_raw(0i32),
4 as c_uint,
"i32".to_char_p(),
))?;
let arg = AnyObject::new_raw(vec![1, 2, 3]);
... | code_fim | hard | {
"lang": "rust",
"repo": "sarus-tech/opendp",
"path": "/rust/opendp-ffi/src/trans/resize.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>
#[test]
fn test_make_resize_bounded() -> Fallible<()> {
let transformation = Result::from(opendp_trans__make_resize_bounded(
util::into_raw(0i32) as *const c_void,
4 as c_uint,
util::into_raw(0i32) as *const c_void,
util::into_raw(10i32) as ... | code_fim | hard | {
"lang": "rust",
"repo": "sarus-tech/opendp",
"path": "/rust/opendp-ffi/src/trans/resize.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let socket = format!("0.0.0.0:{}", port);
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
let sys = actix_rt::System::new("http-server");
let addr = HttpServer::new(||
App::new()
.route("/", actix_web::web::get().to(index))
.service(fs::Files::new("/.well-known/acme-challenge", "... | code_fim | hard | {
"lang": "rust",
"repo": "dvdsk/cert_manager",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dvdsk/cert_manager path: /src/lib.rs
use acme_lib::{Directory, DirectoryUrl};
use acme_lib::persist::FilePersist;
use acme_lib::create_p384_key;
use actix_web::{HttpServer, App, Responder, HttpResponse};
use actix_files as fs;
use actix_rt;
use log::{warn};
use std::env;
use std::sync::mpsc;
... | code_fim | hard | {
"lang": "rust",
"repo": "dvdsk/cert_manager",
"path": "/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let (tx, rx) = mpsc::channel();
thread::spawn(move || {
let sys = actix_rt::System::new("http-server");
let addr = HttpServer::new(||
App::new()
.route("/", actix_web::web::get().to(index))
.service(fs::Files::new("/.well-known/acme-challenge", "./.tmp/www/.well-known/acme-challenge"))
)... | code_fim | hard | {
"lang": "rust",
"repo": "dvdsk/cert_manager",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn get_vscode_keybindings_multi_os() -> String {
String::from(
r###"
[
{
"key": "ctrl+d",
"command": "workbench.action.closeActiveEditor"
},
{
"key": "ctrl+shift+y",
"command": "workbench.action.terminal.toggleTerminal",
"when": "!termina... | code_fim | hard | {
"lang": "rust",
"repo": "igncp/environment",
"path": "/src/os/multi_os_provision.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: igncp/environment path: /src/os/multi_os_provision.rs
pub fn get_vim_multi_os_provision() -> String {
String::from(
r###"
" Don't copy when using del
vnoremap <Del> "_d
nnoremap <Del> "_d
nnoremap r gt
nnoremap R gT
nnoremap <c-t> :tabnew<cr>:e <left><right>
nnoremap Q @q
" Replac... | code_fim | hard | {
"lang": "rust",
"repo": "igncp/environment",
"path": "/src/os/multi_os_provision.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl<'a> Config for Namespace<'a> {
fn clone_flags(&self) -> nix::sched::CloneFlags {
if self.path.is_none() {
self.kind.clone_flag()
} else {
0
}
}
fn prepare(&self) -> nix::Result<()> {
if let Some(ref path) = self.path {
l... | code_fim | hard | {
"lang": "rust",
"repo": "arcnmx/encage-runtime",
"path": "/src/namespace.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: arcnmx/encage-runtime path: /src/namespace.rs
use std::ffi::CStr;
use std::borrow::Cow;
use into_cow::IntoCow;
use config::Config;
use nix;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum NamespaceKind {
PID,
Network,
Mount,
IPC,
UTS,
User,
}
#[derive(Clone, Debug... | code_fim | hard | {
"lang": "rust",
"repo": "arcnmx/encage-runtime",
"path": "/src/namespace.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> if self.kind == NamespaceKind::PID {
match try!(nix::unistd::fork()) {
nix::unistd::Fork::Parent(pid) => {
use nix::sys::wait::{self, WaitStatus};
use nix::sys::ioctl::libc::_exit;
loop ... | code_fim | hard | {
"lang": "rust",
"repo": "arcnmx/encage-runtime",
"path": "/src/namespace.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut buffer = [0; 1024];
// 读取信息到固定长度的buffer中
stream.read(&mut buffer).unwrap();
// 构造响应
let response = format!(
"HTTP/1.1 200 OK\r\nContent-Length: {}\r\n\r\n{}",
"Hi~".len(),
"Hi~",
);
// 打印请求信息
// from_utf8_lossy() 只转换UTF-8编码,非UTF-8被当作无效序列,统... | code_fim | hard | {
"lang": "rust",
"repo": "captainlee1024/substrate-level1",
"path": "/chapter-three/three/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: captainlee1024/substrate-level1 path: /chapter-three/three/src/main.rs
use std::{
io::{Read, Write},
net::{TcpListener, TcpStream},
};
// cargo run and curl 127.0.0.1:8080 -d hello
fn main() {
let normal = "127.0.0.1:8080";
let err = "127.0.0.1:1";
start(&err);
start(&no... | code_fim | hard | {
"lang": "rust",
"repo": "captainlee1024/substrate-level1",
"path": "/chapter-three/three/src/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // 构造响应
let response = format!(
"HTTP/1.1 200 OK\r\nContent-Length: {}\r\n\r\n{}",
"Hi~".len(),
"Hi~",
);
// 打印请求信息
// from_utf8_lossy() 只转换UTF-8编码,非UTF-8被当作无效序列,统一使用�代替
println!("Request: {}", String::from_utf8_lossy(&buffer[..]));
// 回血请求到流
strea... | code_fim | medium | {
"lang": "rust",
"repo": "captainlee1024/substrate-level1",
"path": "/chapter-three/three/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: gba-rs/gba-emu path: /src/thumb_formats/long_branch_link.rs
use crate::operations::instruction::Instruction;
use crate::operations::{arm_arithmetic, bitutils::sign_extend_u32};
use crate::cpu::{cpu::CPU, cpu::THUMB_PC, cpu::THUMB_LR};
use std::fmt;
use crate::memory::memory_bus::MemoryBus;
pub ... | code_fim | hard | {
"lang": "rust",
"repo": "gba-rs/gba-emu",
"path": "/src/thumb_formats/long_branch_link.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> // LR should be PC + 2
assert_eq!(0x08000000 + 1, gba.cpu.get_register(THUMB_LR));
}
#[test]
fn branch_long_positive_offset() {
let mut gba: GBA = GBA::default();
gba.cpu.set_instruction_set(InstructionSet::Thumb);
// Offset: 00000000000 00000001010 0... | code_fim | hard | {
"lang": "rust",
"repo": "gba-rs/gba-emu",
"path": "/src/thumb_formats/long_branch_link.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> {
let mut dst = Vec::with_capacity(len);
dst.resize(len, 0);
let hex_string = hex_string(s.as_bytes());
hex_decode(hex_string.as_bytes(), &mut dst).unwrap();
hex_decode_with_case(hex_string.as_bytes(), &mut dst, CheckCase::Lower).unwrap... | code_fim | hard | {
"lang": "rust",
"repo": "nervosnetwork/faster-hex",
"path": "/src/lib.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: nervosnetwork/faster-hex path: /src/lib.rs
#![cfg_attr(not(any(test, feature = "std")), no_std)]
#[cfg(feature = "alloc")]
extern crate alloc;
mod decode;
mod encode;
mod error;
#[cfg(feature = "serde")]
mod serde;
pub use crate::decode::{
hex_check, hex_check_fallback, hex_check_with_ca... | code_fim | hard | {
"lang": "rust",
"repo": "nervosnetwork/faster-hex",
"path": "/src/lib.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>limits_impl! {
max_image_dimension_1d: u32 => max_image_dimension1_d,
max_image_dimension_2d: u32 => max_image_dimension2_d,
max_image_dimension_3d: u32 => max_image_dimension3_d,
max_image_dimension_cube: u32 => max_image_dimension_cube,
max_image_array_layers: u32 => max_image_array_... | code_fim | hard | {
"lang": "rust",
"repo": "i509VCB/vulkano",
"path": "/vulkano/src/instance/limits.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: i509VCB/vulkano path: /vulkano/src/instance/limits.rs
// Copyright (c) 2017 The vulkano developers
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>,
/... | code_fim | hard | {
"lang": "rust",
"repo": "i509VCB/vulkano",
"path": "/vulkano/src/instance/limits.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: nisarhassan12/materialize path: /src/expr/src/relation/func.rs
if offset.is_null() {
result.push((*offset, *original_row));
continue;
}
let idx = i64::try_from(idx).expect("Array index does not fit in i64");
let offset = i64::from(offset.unwr... | code_fim | hard | {
"lang": "rust",
"repo": "nisarhassan12/materialize",
"path": "/src/expr/src/relation/func.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: nisarhassan12/materialize path: /src/expr/src/relation/func.rs
| AggregateFunc::MaxInt32
| AggregateFunc::MaxInt64
| AggregateFunc::MaxUInt16
| AggregateFunc::MaxUInt32
| AggregateFunc::MaxUInt64
| AggregateFunc::MaxMzTimestamp
... | code_fim | hard | {
"lang": "rust",
"repo": "nisarhassan12/materialize",
"path": "/src/expr/src/relation/func.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Compute output type for ROW_NUMBER, RANK, DENSE_RANK
fn output_type_ranking_window_funcs(input_type: &ColumnType, col_name: &str) -> ScalarType {
match input_type.scalar_type {
ScalarType::Record { ref fields, .. } => ScalarType::List {
element_type: Box::ne... | code_fim | hard | {
"lang": "rust",
"repo": "nisarhassan12/materialize",
"path": "/src/expr/src/relation/func.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let addr = SocketAddr::new(Ipv4Addr::new(127, 0, 0, 1).into(), PORT);
let server = net::TcpListener::bind(&addr).unwrap();
println!("SERVER (sender): listening on 127.0.0.1:{}", PORT);
let (mut stream, _) = server.accept().unwrap();
println!("SERVER (sender): writing 'Hello'");
str... | code_fim | hard | {
"lang": "rust",
"repo": "rom1v/mio-sample",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> for event in &events {
println!("CLIENT (receiver): event={:?}", event);
if event.readiness().is_readable() {
match stream.read(&mut buf) {
Ok(0) => {
println!("CLIENT (receiver): eof");
ret... | code_fim | hard | {
"lang": "rust",
"repo": "rom1v/mio-sample",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rom1v/mio-sample path: /src/main.rs
extern crate mio;
use std::io::{ErrorKind, Read, Write};
use std::net::{self, Ipv4Addr, SocketAddr};
use std::time;
use std::thread;
use mio::{Events, Ready, Poll, PollOpt, Token};
const PORT: u16 = 1234;
fn client() {
let addr = SocketAddr::new(Ipv4Addr... | code_fim | hard | {
"lang": "rust",
"repo": "rom1v/mio-sample",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: DJAndries/cubik path: /examples/chat_server.rs
mod support;
use cubik::server::ServerContainer;
use support::msg::AppMessage;
use std::time::{Instant, Duration};
use std::thread::sleep;
const PORT: u16 = 27020;
fn main() {
<|fim_suffix|> loop {
server_container.update();
for pid in serve... | code_fim | medium | {
"lang": "rust",
"repo": "DJAndries/cubik",
"path": "/examples/chat_server.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> for pid in server_container.pids() {
if let Ok(msgs) = server_container.get_msgs(pid) {
for msg in msgs {
server_container.broadcast(msg);
}
}
}
if last_status_update.elapsed().as_secs_f32() > 5. {
last_status_update = Instant::now();
println!("peer status update:");
for... | code_fim | medium | {
"lang": "rust",
"repo": "DJAndries/cubik",
"path": "/examples/chat_server.rs",
"mode": "spm",
"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.