text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_suffix|>#[tonic::async_trait]
impl<M> write_service_server::WriteService for PBWriteService<M>
where
M: ConnectionManager + Send + Sync + Debug + 'static,
{
async fn write(
&self,
request: tonic::Request<WriteRequest>,
) -> Result<tonic::Response<WriteResponse>, tonic::Status> {
... | code_fim | medium | {
"lang": "rust",
"repo": "mtvu/influxdb_iox",
"path": "/influxdb_iox/src/influxdb_ioxd/server_type/database/rpc/write_pb.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mtvu/influxdb_iox path: /influxdb_iox/src/influxdb_ioxd/server_type/database/rpc/write_pb.rs
use generated_types::google::FieldViolation;
use generated_types::influxdata::pbdata::v1::*;
use server::{connection::ConnectionManager, Server};
use std::fmt::Debug;
use std::sync::Arc;
<|fim_suffix|>p... | code_fim | hard | {
"lang": "rust",
"repo": "mtvu/influxdb_iox",
"path": "/influxdb_iox/src/influxdb_ioxd/server_type/database/rpc/write_pb.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: charliejeynes/arc path: /src/sim/render/painter/test.rs
//! Test painter.
use crate::{
geom::Ray,
img::Shader,
phys::{laws::reflect_dir, Crossing},
sim::render::{lighting, shadowing, Grid, Scheme},
};
use nalgebra::{Point3, Unit};
// use palette::{Gradient, LinSrgba};
use palett... | code_fim | hard | {
"lang": "rust",
"repo": "charliejeynes/arc",
"path": "/src/sim/render/painter/test.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> weighting *= 1.0 - ref_prob;
*ray.dir_mut() = *trans_dir;
ray.travel(shader.bump_dist());
} else {
*ray.dir_mut() = reflect_dir(ray.dir(), hit.side().norm());
ray.travel(shader.bump_dist())... | code_fim | hard | {
"lang": "rust",
"repo": "charliejeynes/arc",
"path": "/src/sim/render/painter/test.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: opensource-assist/fuschia path: /src/connectivity/wlan/lib/rsn/src/crypto_utils/mod.rs
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
pub mod nonce;
// Used in PRF as specified ... | code_fim | hard | {
"lang": "rust",
"repo": "opensource-assist/fuschia",
"path": "/src/connectivity/wlan/lib/rsn/src/crypto_utils/mod.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> let key = Vec::from_hex("aaaa").unwrap();
let actual = prf(&key[..], "", "Lorem ipsum".as_bytes(), 256);
assert_eq!(actual.is_ok(), true);
let expected =
Vec::from_hex("1317523ae07f212fc4139ce9ebafe31ecf7c59cb07c7a7f04131afe7a59de60c")
.unwrap()... | code_fim | hard | {
"lang": "rust",
"repo": "opensource-assist/fuschia",
"path": "/src/connectivity/wlan/lib/rsn/src/crypto_utils/mod.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> let expected = Vec::from_hex("785e095774cfea480c267e74130cb86d1e3fc80095b66554").unwrap();
assert_eq!(actual.unwrap(), expected);
}
#[test]
fn test_prf_all_empty() {
let key: [u8; 0] = [];
let actual = prf(&key[..], "", "".as_bytes(), 128);
assert_eq!(a... | code_fim | hard | {
"lang": "rust",
"repo": "opensource-assist/fuschia",
"path": "/src/connectivity/wlan/lib/rsn/src/crypto_utils/mod.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> Self::storage()?
.remove_item(key.as_ref())
.map_err(WebStorageError::RemoveError)
}
/// Returns a deserialized value corresponding to the key.
///
/// # Errors
///
/// Returns error if we cannot get access to the storage
/// or find the key or ... | code_fim | hard | {
"lang": "rust",
"repo": "mh84/seed",
"path": "/src/browser/web_storage.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mh84/seed path: /src/browser/web_storage.rs
use crate::browser::util::window;
use serde::{de::DeserializeOwned, Serialize};
use wasm_bindgen::JsValue;
use web_sys::Storage;
/// Convenient type alias.
pub type Result<T> = std::result::Result<T, WebStorageError>;
// ------ WebStorageError ------... | code_fim | hard | {
"lang": "rust",
"repo": "mh84/seed",
"path": "/src/browser/web_storage.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> SessionStorage::clear().unwrap();
SessionStorage::insert("a_key", "a_value").unwrap();
assert_eq!("a_key", SessionStorage::key(0).unwrap());
}
#[wasm_bindgen_test]
fn local_storage_remove() {
SessionStorage::clear().unwrap();
SessionStorage::insert("a... | code_fim | hard | {
"lang": "rust",
"repo": "mh84/seed",
"path": "/src/browser/web_storage.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl FancyInt {
pub fn new(i: i32) -> FancyInt {
FancyInt {
internal: RefCell::new(i)
}
}
pub fn get(&self) -> i32 {
*self.internal.borrow()
}
pub fn set(&self, new: i32) {
*self.internal.borrow_mut() = new;
}
}<|fim_prefix|>// repo: ia... | code_fim | medium | {
"lang": "rust",
"repo": "iaroslav-ciupin/rust-playground",
"path": "/src/play_refcell.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: iaroslav-ciupin/rust-playground path: /src/play_refcell.rs
use std::cell::RefCell;
use std::fmt;
#[derive(Debug)]
pub struct FancyInt {
internal: RefCell<i32>
}
impl fmt::Display for FancyInt {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.inte... | code_fim | medium | {
"lang": "rust",
"repo": "iaroslav-ciupin/rust-playground",
"path": "/src/play_refcell.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub mod test_tooltip_01;
pub mod test_tooltip_mod;
pub mod test_tooltip_mod_use;
pub mod test_tooltip_std;<|fim_prefix|>// repo: rust-lang/rls path: /tests/fixtures/hover/src/lib.rs
#![allow(dead_code, unused_imports)]
<|fim_middle|>extern crate fnv;
| code_fim | easy | {
"lang": "rust",
"repo": "rust-lang/rls",
"path": "/tests/fixtures/hover/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rust-lang/rls path: /tests/fixtures/hover/src/lib.rs
#![allow(dead_code, unused_imports)]
<|fim_suffix|>pub mod test_tooltip_01;
pub mod test_tooltip_mod;
pub mod test_tooltip_mod_use;
pub mod test_tooltip_std;<|fim_middle|>extern crate fnv;
| code_fim | easy | {
"lang": "rust",
"repo": "rust-lang/rls",
"path": "/tests/fixtures/hover/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: knutin/libpq.rs path: /src/result/error_field.rs
// @see https://github.com/postgres/postgres/blob/REL_12_2/src/include/postgres_ext.h#L55
#[derive(Clone, Copy, Debug, PartialEq)]
#[repr(i32)]
pub enum ErrorField {
/** The severity. */
Severity = 'S' as i32,
/** The severity. */
... | code_fim | hard | {
"lang": "rust",
"repo": "knutin/libpq.rs",
"path": "/src/result/error_field.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> as i32,
/** If the error was associated with a specific constraint, the name of the constraint. */
ConstraintName = 'n' as i32,
/** The file name of the source-code location where the error was reported. */
SourceFile = 'F' as i32,
/** The line number of the source-code location where... | code_fim | hard | {
"lang": "rust",
"repo": "knutin/libpq.rs",
"path": "/src/result/error_field.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl<T> Deref for CachePadded<T> {
type Target = T;
fn deref(&self) -> &T {
unsafe { mem::transmute(&self.data) }
}
}
impl<T> DerefMut for CachePadded<T> {
fn deref_mut(&mut self) -> &mut T {
unsafe { mem::transmute(&mut self.data) }
}
}
#[cfg(test)]
mod test {
us... | code_fim | hard | {
"lang": "rust",
"repo": "alexcrichton/crossbeam",
"path": "/src/mem/cache_padded.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> unsafe { mem::transmute(&mut self.data) }
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn cache_padded_store_u64() {
let x: CachePadded<u64> = unsafe { CachePadded::new(17) };
assert_eq!(*x, 17);
}
#[test]
fn cache_padded_store_pair() {
l... | code_fim | medium | {
"lang": "rust",
"repo": "alexcrichton/crossbeam",
"path": "/src/mem/cache_padded.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: alexcrichton/crossbeam path: /src/mem/cache_padded.rs
use std::marker;
use std::cell::UnsafeCell;
use std::mem;
use std::ptr;
use std::ops::{Deref, DerefMut};
const CACHE_LINE: usize = 128;
// assume a cacheline size of CACHE_LINE bytes,
// and that T is smaller than a cacheline
pub struct Cac... | code_fim | hard | {
"lang": "rust",
"repo": "alexcrichton/crossbeam",
"path": "/src/mem/cache_padded.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Logicalshift/flowbetween path: /ui/src/control/keypress.rs
///
/// Represents a keypress
///
#[derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Hash, Debug, Serialize, Deserialize)]
pub enum KeyPress {
ModifierShift,
ModifierCtrl,
ModifierAlt,
ModifierMeta,
ModifierSuper,
... | code_fim | hard | {
"lang": "rust",
"repo": "Logicalshift/flowbetween",
"path": "/ui/src/control/keypress.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> KeyUp,
KeyDown,
KeyLeft,
KeyRight,
KeyBackslash,
KeyForwardslash,
KeyBacktick,
KeyComma,
KeyFullstop,
KeySemicolon,
KeyQuote,
KeyMinus,
KeyEquals,
KeyEscape,
KeyInsert,
KeyHome,
KeyPgUp,
KeyDelete,
KeyEnd,
KeyPgDown,
Key... | code_fim | hard | {
"lang": "rust",
"repo": "Logicalshift/flowbetween",
"path": "/ui/src/control/keypress.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> KeyF1,
KeyF2,
KeyF3,
KeyF4,
KeyF5,
KeyF6,
KeyF7,
KeyF8,
KeyF9,
KeyF10,
KeyF11,
KeyF12,
KeyF13,
KeyF14,
KeyF15,
KeyF16,
KeyNumpad0,
KeyNumpad1,
KeyNumpad2,
KeyNumpad3,
KeyNumpad4,
KeyNumpad5,
KeyNumpad6,
KeyNum... | code_fim | hard | {
"lang": "rust",
"repo": "Logicalshift/flowbetween",
"path": "/ui/src/control/keypress.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: JesseWright/aws-sdk-rust path: /sdk/lookoutvision/src/operation_ser.rs
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
pub fn serialize_operation_create_dataset(
input: &crate::input::CreateDatasetInput,
) -> Result<smithy_http::body::SdkBody, smithy_types::E... | code_fim | hard | {
"lang": "rust",
"repo": "JesseWright/aws-sdk-rust",
"path": "/sdk/lookoutvision/src/operation_ser.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn serialize_operation_start_model(
input: &crate::input::StartModelInput,
) -> Result<smithy_http::body::SdkBody, smithy_types::Error> {
let mut out = String::new();
let mut object = smithy_json::serialize::JsonObjectWriter::new(&mut out);
crate::json_ser::serialize_structure_start_mo... | code_fim | hard | {
"lang": "rust",
"repo": "JesseWright/aws-sdk-rust",
"path": "/sdk/lookoutvision/src/operation_ser.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: JoNil/loka-n64 path: /game/src/ecs/component.rs
use super::{entity::Entity, storage::Storage};
pub trait Component {
type Inner: Component + 'static;
type RefInner<'w>;
type Storage: Storage<Self::Inner> + Default;
fn convert(v: &mut Self::Inner) -> Self::RefInner<'_>;
fn e... | code_fim | hard | {
"lang": "rust",
"repo": "JoNil/loka-n64",
"path": "/game/src/ecs/component.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn convert(v: &mut Self::Inner) -> Self::RefInner<'_> {
Some(v)
}
fn empty<'w>() -> Self::RefInner<'w> {
None
}
fn get_from_storage(storage: &mut Self::Storage, entity: Entity) -> Option<Self::RefInner<'_>> {
match storage.lookup_mut(entity) {
Some... | code_fim | hard | {
"lang": "rust",
"repo": "JoNil/loka-n64",
"path": "/game/src/ecs/component.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Convert the message into the data payload.
pub fn into_bytes(self) -> Vec<u8> {
self.data
}
}<|fim_prefix|>// repo: RangerStation/alexandrie-run path: /.cargo/registry/src/github.com-1ecc6299db9ec823/async-sse-3.0.0/src/message.rs
/// An SSE event with a data payload.
#[derive(Deb... | code_fim | hard | {
"lang": "rust",
"repo": "RangerStation/alexandrie-run",
"path": "/.cargo/registry/src/github.com-1ecc6299db9ec823/async-sse-3.0.0/src/message.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl GeneratedPage for HomePage {
fn get_route(&self) -> String {
return "/".to_string();
}
}<|fim_prefix|>// repo: philip-peterson/yew-ssg path: /src/pages/home.rs
use crate::GeneratedPage;
<|fim_middle|>#[derive(Default)]
pub struct HomePage {}
| code_fim | easy | {
"lang": "rust",
"repo": "philip-peterson/yew-ssg",
"path": "/src/pages/home.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: philip-peterson/yew-ssg path: /src/pages/home.rs
use crate::GeneratedPage;
<|fim_suffix|>impl GeneratedPage for HomePage {
fn get_route(&self) -> String {
return "/".to_string();
}
}<|fim_middle|>#[derive(Default)]
pub struct HomePage {}
| code_fim | easy | {
"lang": "rust",
"repo": "philip-peterson/yew-ssg",
"path": "/src/pages/home.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> return "/".to_string();
}
}<|fim_prefix|>// repo: philip-peterson/yew-ssg path: /src/pages/home.rs
use crate::GeneratedPage;
<|fim_middle|>#[derive(Default)]
pub struct HomePage {}
impl GeneratedPage for HomePage {
fn get_route(&self) -> String {
| code_fim | medium | {
"lang": "rust",
"repo": "philip-peterson/yew-ssg",
"path": "/src/pages/home.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn read_test() {
// read should work fine in the case of a buffer whose length is within byte_limit
let inner: &[u8] = &[0u8, 1u8, 2u8, 3u8, 4u8];
let mut reader = LimitedBytesReader::new(3, inner);
let mut buf = [0u8; 3];
let output = reader.read(&m... | code_fim | hard | {
"lang": "rust",
"repo": "tari-project/tari",
"path": "/base_layer/core/src/common/limited_reader.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tari-project/tari path: /base_layer/core/src/common/limited_reader.rs
// Copyright 2022, The Tari Project
//
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
// following conditions are met:
//
// 1. Redistributions of source... | code_fim | hard | {
"lang": "rust",
"repo": "tari-project/tari",
"path": "/base_layer/core/src/common/limited_reader.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl<R: Read> Read for LimitedBytesReader<R> {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
let read = self.inner.read(buf)?;
self.num_read += read;
if self.num_read > self.byte_limit {
return Err(io::Error::new(
io::ErrorKind::Inva... | code_fim | medium | {
"lang": "rust",
"repo": "tari-project/tari",
"path": "/base_layer/core/src/common/limited_reader.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: verdantred/rogulit path: /src/game/map/mod.rs
extern crate rand;
use self::rand::distributions::{IndependentSample, Range};
use self::rand::ThreadRng;
use std::collections::HashMap;
use super::object;
#[derive(PartialEq, Debug)]
pub enum FloorType {
Lava,
Ground,
Pit,
Wall,
}
#[derive... | code_fim | hard | {
"lang": "rust",
"repo": "verdantred/rogulit",
"path": "/src/game/map/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> //self.populate_with_monsters();
//self.generate_items();
}
pub fn does_room_fit(&mut self, loc: object::Point<usize>, size: object::Point<usize>, dir: object::Direction) -> Option<(object::Point<usize>, object::Point<usize>)> {
let mut start = object::Point {x: 1, y: 1};
let mut en... | code_fim | hard | {
"lang": "rust",
"repo": "verdantred/rogulit",
"path": "/src/game/map/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: infinyon/k8-api path: /src/k8-client/k8-fixtures/src/lib.rs
mod test_fixtures;
pub use self::test_fix<|fim_suffix|>se self::test_fixtures::TestTopicWatchList;<|fim_middle|>tures::create_topic_stream_result;
pub use self::test_fixtures::TestTopicWatch;
pub u | code_fim | medium | {
"lang": "rust",
"repo": "infinyon/k8-api",
"path": "/src/k8-client/k8-fixtures/src/lib.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>se self::test_fixtures::TestTopicWatchList;<|fim_prefix|>// repo: infinyon/k8-api path: /src/k8-client/k8-fixtures/src/lib.rs
mod test_fixtures;
pub use self::test_fixtures::create_topic_stream_result;
pub use <|fim_middle|>self::test_fixtures::TestTopicWatch;
pub u | code_fim | easy | {
"lang": "rust",
"repo": "infinyon/k8-api",
"path": "/src/k8-client/k8-fixtures/src/lib.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: sierra-zero/rg3d path: /src/animation/mod.rs
isit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult {
visitor.enter_region(name)?;
self.id.visit("Id", visitor)?;
self.time.visit("Time", visitor)?;
self.enabled.visit("Enabled", visitor)?;
visit... | code_fim | hard | {
"lang": "rust",
"repo": "sierra-zero/rg3d",
"path": "/src/animation/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: sierra-zero/rg3d path: /src/animation/mod.rs
self.node,
position: k.position,
scale: k.scale,
rotation: k.rotation,
})
} else {
let left = &self.frames[right_index - 1];
let right = &self.frames[right_in... | code_fim | hard | {
"lang": "rust",
"repo": "sierra-zero/rg3d",
"path": "/src/animation/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Clone for Animation {
fn clone(&self) -> Self {
Self {
tracks: self.tracks.clone(),
speed: self.speed,
length: self.length,
time_position: self.time_position,
looped: self.looped,
enabled: self.enabled,
re... | code_fim | hard | {
"lang": "rust",
"repo": "sierra-zero/rg3d",
"path": "/src/animation/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut x: i32 = 1;
println!("{}", x);
x = 7;
println!("{}", x);
let x = x;
println!("{}", x);
let y = 4;
println!("{}", y);
let y = "I can also be bound to text!";
println!("{}", y);
}<|fim_prefix|>// repo: jfredrickson/rust_book path: /variables/src/main.rs
fn ma... | code_fim | hard | {
"lang": "rust",
"repo": "jfredrickson/rust_book",
"path": "/variables/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jfredrickson/rust_book path: /variables/src/main.rs
fn main() {
bindings();
patterns();
type_annotations();
mutability();
initializing_bindings();
scope_and_shadowing_1();
scope_and_shadowing_2();
scope_and_shadowing_3();
}
fn bindings() {
<|fim_suffix|>fn scope_... | code_fim | hard | {
"lang": "rust",
"repo": "jfredrickson/rust_book",
"path": "/variables/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: zhangkaizhao/repos path: /src/util.rs
use std::fs;
use std::path::Path;
use url::Url;
/// Validate repository url.
///
/// Notes:
/// * Relative URLs without base (scp-like syntax) are not supported.
///
/// e.g. `[user@]host.xz:path/to/repo.git` or `[user@]host.xz:~/path/to/repo.git`
pub fn... | code_fim | hard | {
"lang": "rust",
"repo": "zhangkaizhao/repos",
"path": "/src/util.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// Generate alternative url for vcs.
pub fn gen_alternative_url(vcs: &str, url: &str) -> Option<String> {
if vcs == "git" {
let alternative_url = if url.ends_with(".git") {
url.trim_right_matches(".git").to_string()
} else {
url.to_string() + ".git"
};
... | code_fim | hard | {
"lang": "rust",
"repo": "zhangkaizhao/repos",
"path": "/src/util.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tyrylu/feel-the-streets path: /server/src/error.rs
use axum::{
http::StatusCode,
response::{IntoResponse, Response},
};
use std::time::SystemTimeError;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("I/O error: {0}")]
IoError(#[from] std::io::Error),
#[error("Ru... | code_fim | hard | {
"lang": "rust",
"repo": "tyrylu/feel-the-streets",
"path": "/server/src/error.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> DoItLaterError(#[from] doitlater::Error),
#[error("Tera error: {0}")]
TeraError(#[from] tera::Error),
#[error("Failed to join a Tokio task: {0}")]
JoinError(#[from] tokio::task::JoinError),
}
impl IntoResponse for Error {
fn into_response(self) -> Response {
(
... | code_fim | hard | {
"lang": "rust",
"repo": "tyrylu/feel-the-streets",
"path": "/server/src/error.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: gauteh/ambiq-apollo3-pac path: /src/ctimer/mod.rs
: CMPRB2,
#[doc = "0x4c - Counter/Timer Control"]
pub ctrl2: CTRL2,
_reserved2: [u8; 4usize],
#[doc = "0x54 - Counter/Timer A2 Compare Registers"]
pub cmprauxa2: CMPRAUXA2,
#[doc = "0x58 - Counter/Timer B2 Compare Register... | code_fim | hard | {
"lang": "rust",
"repo": "gauteh/ambiq-apollo3-pac",
"path": "/src/ctimer/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>atileCell<u32>,
}
#[doc = "Counter/Timer Register"]
pub mod tmr3;
#[doc = "Counter/Timer A3 Compare Registers"]
pub struct CMPRA3 {
register: ::vcell::VolatileCell<u32>,
}
#[doc = "Counter/Timer A3 Compare Registers"]
pub mod cmpra3;
#[doc = "Counter/Timer B3 Compare Registers"]
pub struct CMPRB3 {
... | code_fim | hard | {
"lang": "rust",
"repo": "gauteh/ambiq-apollo3-pac",
"path": "/src/ctimer/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: gauteh/ambiq-apollo3-pac path: /src/ctimer/mod.rs
Config 3"]
pub outcfg3: OUTCFG3,
#[doc = "0x118 - Counter/Timer Input Config"]
pub incfg: INCFG,
_reserved9: [u8; 36usize],
#[doc = "0x140 - Configuration Register"]
pub stcfg: STCFG,
#[doc = "0x144 - System Timer Coun... | code_fim | hard | {
"lang": "rust",
"repo": "gauteh/ambiq-apollo3-pac",
"path": "/src/ctimer/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jac3km4/rustfu path: /renderer/src/frame_reader.rs
use crate::render::SpriteTransform;
use crate::types::{FrameData, TransformTable};
pub struct FrameReader<'a> {
data: &'a FrameData,
transform: &'a TransformTable,
position: usize,
}
impl<'a> FrameReader<'a> {
pub fn new(data: ... | code_fim | hard | {
"lang": "rust",
"repo": "jac3km4/rustfu",
"path": "/renderer/src/frame_reader.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let res = match &self.data {
FrameData::Ints(vec) => vec.get(self.position)?.clone(),
FrameData::Shorts(vec) => vec.get(self.position)?.clone().into(),
FrameData::Bytes(vec) => vec.get(self.position)?.clone().into(),
};
self.position += 1;
... | code_fim | hard | {
"lang": "rust",
"repo": "jac3km4/rustfu",
"path": "/renderer/src/frame_reader.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Map a value through an operation with an access level.
pub fn map<B, LL>(self, f: Mac<LL, impl Fn(A) -> B>) -> Mac<LL, B>
where
LL: AccessLevel + Above<L>,
{
let Mac { value: operation, level } = f;
Mac { value: operation(self.value), level }
}
}<|fim_prefix... | code_fim | hard | {
"lang": "rust",
"repo": "xurtis/mac",
"path": "/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: xurtis/mac path: /src/lib.rs
//! Manadtory Access Control Monad
use std::marker::PhantomData;
/// Trait for items that mark an access level.
pub trait AccessLevel: 'static {}
/// Trait for showing relations between access levels.
pub trait Above<T: AccessLevel> {}
<|fim_suffix|>/// An object... | code_fim | medium | {
"lang": "rust",
"repo": "xurtis/mac",
"path": "/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Map a value into a new access level.
pub fn and_then<B, LL>(self, f: impl Fn(A) -> Mac<LL, B>) -> Mac<LL, B>
where
LL: AccessLevel + Above<L>,
{
f(self.value)
}
/// Map a value through an operation with an access level.
pub fn map<B, LL>(self, f: Mac<LL, im... | code_fim | hard | {
"lang": "rust",
"repo": "xurtis/mac",
"path": "/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn test_deserialize() {
let test_string = r#"
{
"action": "opened",
"number": 123,
"pull_request": {
"merged": false,
"body": "honk",
"user": {
"login": "PJB3005"
}
},
"repository": {
"full_name": "PJB3005/MoMM... | code_fim | hard | {
"lang": "rust",
"repo": "PJB3005/MoMMI",
"path": "/WebMoMMI/src/github/data.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[derive(Deserialize, Debug, Clone)]
pub struct GitHubUser {
pub login: String,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_deserialize() {
let test_string = r#"
{
"action": "opened",
"number": 123,
"pull_request": {
"merged": false,
"body... | code_fim | hard | {
"lang": "rust",
"repo": "PJB3005/MoMMI",
"path": "/WebMoMMI/src/github/data.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: PJB3005/MoMMI path: /WebMoMMI/src/github/data.rs
#[derive(Deserialize, Debug, Clone)]
pub struct PullRequestEvent {
pub action: PullRequestAction,
pub number: u32,
pub pull_request: PullRequest,
pub repository: Repository,
}
#[derive(Deserialize, Debug, Clone)]
pub struct PushEv... | code_fim | hard | {
"lang": "rust",
"repo": "PJB3005/MoMMI",
"path": "/WebMoMMI/src/github/data.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: copterust/hitl-adapter path: /src/main.rs
use std::mem;
use std::net::UdpSocket;
use std::os::raw::{c_float, c_double};
#[repr(C)]
#[derive(Debug)]
pub struct FDMPacket {
// packet timestamp
timestamp: c_double,
// IMU angular velocity
angular: [c_double; 3],
// IMU linear acceleratio... | code_fim | medium | {
"lang": "rust",
"repo": "copterust/hitl-adapter",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut command: ServoPacket = [0.0; 16];
command[0] = 1.0;
command[1] = 1.0;
command[2] = 1.0;
command[3] = 1.0;
let buf_out: [u8; 64] = unsafe { mem::transmute(command) };
loop {
socket_out.send_to(&buf_out, "127.0.0.1:9002").expect("couldn't send data");
ma... | code_fim | hard | {
"lang": "rust",
"repo": "copterust/hitl-adapter",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let buf_out: [u8; 64] = unsafe { mem::transmute(command) };
loop {
socket_out.send_to(&buf_out, "127.0.0.1:9002").expect("couldn't send data");
match socket_in.recv_from(&mut buf_in) {
Ok(_) => {
let packet: FDMPacket = unsafe { mem::transmute(buf_in) }... | code_fim | medium | {
"lang": "rust",
"repo": "copterust/hitl-adapter",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pe TB2CCTL1 = crate::Reg<tb2cctl1::TB2CCTL1_SPEC>;
#[doc = "Timer_B Capture/Compare Control Register"]
pub mod tb2cctl1;
#[doc = "TB2CCTL2 (rw) register accessor: an alias for `Reg<TB2CCTL2_SPEC>`"]
pub type TB2CCTL2 = crate::Reg<tb2cctl2::TB2CCTL2_SPEC>;
#[doc = "Timer_B Capture/Compare Control Register"... | code_fim | hard | {
"lang": "rust",
"repo": "YuhanLiin/msp430fr2355",
"path": "/src/tb2.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>ccessor: an alias for `Reg<TB2CCR1_SPEC>`"]
pub type TB2CCR1 = crate::Reg<tb2ccr1::TB2CCR1_SPEC>;
#[doc = "Timer_B Capture/Compare Register"]
pub mod tb2ccr1;
#[doc = "TB2CCR2 (rw) register accessor: an alias for `Reg<TB2CCR2_SPEC>`"]
pub type TB2CCR2 = crate::Reg<tb2ccr2::TB2CCR2_SPEC>;
#[doc = "Timer_B ... | code_fim | hard | {
"lang": "rust",
"repo": "YuhanLiin/msp430fr2355",
"path": "/src/tb2.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: YuhanLiin/msp430fr2355 path: /src/tb2.rs
#[doc = r"Register block"]
#[repr(C)]
pub struct RegisterBlock {
#[doc = "0x00 - Timer_B Control Register"]
pub tb2ctl: TB2CTL,
#[doc = "0x02 - Timer_B Capture/Compare Control Register"]
pub tb2cctl0: TB2CCTL0,
#[doc = "0x04 - Timer_B ... | code_fim | hard | {
"lang": "rust",
"repo": "YuhanLiin/msp430fr2355",
"path": "/src/tb2.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[no_mangle]
pub unsafe extern "C" fn on_message(data: *mut c_void, msg_ptr: *mut u8, msg_len: usize) {
let cbs = &mut *(data as *mut RunningCbs);
(cbs.on_message)(&mut cbs.data, msg_ptr, msg_len);
}
unsafe fn on_message_<WebSocketId, EventType>(
data: &mut WebSocket,
msg_ptr: *mut u8,
... | code_fim | hard | {
"lang": "rust",
"repo": "mbirtwell/miniquad-websockets",
"path": "/src/wasm_imp.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mbirtwell/miniquad-websockets path: /src/wasm_imp.rs
use std::borrow::Cow;
use std::ffi::{c_void, CString};
use miniquad::CustomEventPostBox;
use crate::error::{Error, Result};
use crate::WebSocketEvent;
pub struct WebSocketContext<EventType> {
post_box: CustomEventPostBox<EventType>,
}
p... | code_fim | hard | {
"lang": "rust",
"repo": "mbirtwell/miniquad-websockets",
"path": "/src/wasm_imp.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: PacktPublishing/Rust-Quick-Start-Guide path: /chapter06/src/boxes.rs
use std::any::Any;
pub struct Person {
pub name: String,
pub validated: bool,
}
<|fim_suffix|> let jill: Box<dyn Any> = Box::new(Person { name: "Jill".to_string(), validated: false });
// println!("{}", jill.na... | code_fim | hard | {
"lang": "rust",
"repo": "PacktPublishing/Rust-Quick-Start-Guide",
"path": "/chapter06/src/boxes.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let real_jill = jill.downcast::<Person>().unwrap();
println!("{}", real_jill.name);
}<|fim_prefix|>// repo: PacktPublishing/Rust-Quick-Start-Guide path: /chapter06/src/boxes.rs
use std::any::Any;
pub struct Person {
pub name: String,
pub validated: bool,
}
pub struct TreeNode {
pub ... | code_fim | medium | {
"lang": "rust",
"repo": "PacktPublishing/Rust-Quick-Start-Guide",
"path": "/chapter06/src/boxes.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn longest<'a>(a: &'a str, b: &'a str) -> &'a str {
if a.len() >= b.len() {
a
} else {
b
}
}<|fim_prefix|>// repo: tomocy/rust-cookbook path: /longest/src/main.rs
fn main() {
let a = String::from("abcd");
let b = "xyz";
let longest = longest(&a, &b);
<|fim_middle|... | code_fim | medium | {
"lang": "rust",
"repo": "tomocy/rust-cookbook",
"path": "/longest/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> if a.len() >= b.len() {
a
} else {
b
}
}<|fim_prefix|>// repo: tomocy/rust-cookbook path: /longest/src/main.rs
fn main() {
let a = String::from("abcd");
let b = "xyz";
let longest = longest(&a, &b);
<|fim_middle|> println!("The two strings: {} and {}", a, b);
... | code_fim | medium | {
"lang": "rust",
"repo": "tomocy/rust-cookbook",
"path": "/longest/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tomocy/rust-cookbook path: /longest/src/main.rs
fn main() {
let a = String::from("abcd");
let b = "xyz";
let longest = longest(&a, &b);
<|fim_suffix|>fn longest<'a>(a: &'a str, b: &'a str) -> &'a str {
if a.len() >= b.len() {
a
} else {
b
}
}<|fim_middle|... | code_fim | medium | {
"lang": "rust",
"repo": "tomocy/rust-cookbook",
"path": "/longest/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl error::Error for Error {}
pub struct Shader(GLuint);
impl Shader {
pub fn from_source<P: AsRef<Path>>(path: P) -> Result<Self, Box<dyn error::Error>> {
let content = std::fs::read_to_string(&path)?;
let handle = glesv2::create_shader(match path.as_ref().extension().map(|s| s.to... | code_fim | hard | {
"lang": "rust",
"repo": "gustafla/particle-sim-thingy",
"path": "/src/glesv2_raii/shader.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: gustafla/particle-sim-thingy path: /src/glesv2_raii/shader.rs
use log::trace;
use opengles::glesv2::{self, constants::*, types::*};
use std::error;
use std::fmt;
use std::path::{Path, PathBuf};
#[derive(Debug)]
enum ErrorKind {
DetermineShaderStage,
Compile(Option<String>), // file path... | code_fim | hard | {
"lang": "rust",
"repo": "gustafla/particle-sim-thingy",
"path": "/src/glesv2_raii/shader.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> println!("Part1: {}", max);
}
fn part2(input: &[i32]) {
let mut max = 0;
let mut phases = vec![5, 6, 7, 8, 9];
loop {
let mut programs = Vec::with_capacity(5);
for phase in &phases {
programs.push(Program::new(input.to_vec(), *phase));
}
let mut... | code_fim | hard | {
"lang": "rust",
"repo": "daniel-buse/advent_of_code_2019",
"path": "/day07/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: daniel-buse/advent_of_code_2019 path: /day07/src/main.rs
// Update on day05
//
// - Store mem and ip in struct, since we now need to keep state over multiple runs
// - Init program with a phase input
// - Run returns Some(i32) on output and None on halt
#[derive(Debug, Copy, Clone, PartialEq, E... | code_fim | hard | {
"lang": "rust",
"repo": "daniel-buse/advent_of_code_2019",
"path": "/day07/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Pluriscient/Rust-Katas path: /src/probs/triplets_secret.rs
use std::collections::{HashMap, HashSet};
use std::iter::FromIterator;
fn recover_secret(triplets: Vec<[char; 3]>) -> String {
let all_letters: HashSet<char> = triplets.iter().flat_map(|x| x.iter()).cloned().collect();
let n = ... | code_fim | hard | {
"lang": "rust",
"repo": "Pluriscient/Rust-Katas",
"path": "/src/probs/triplets_secret.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> type G = HashMap<char, HashSet<char>>;
fn f(mut g: G, t: &[char; 3]) -> G {
g.entry(t[2]).or_insert_with(HashSet::new).insert(t[1]);
g.entry(t[1]).or_insert_with(HashSet::new).insert(t[0]);
g.entry(t[0]).or_insert_with(HashSet::new);
g
}
let mut graph = trip... | code_fim | hard | {
"lang": "rust",
"repo": "Pluriscient/Rust-Katas",
"path": "/src/probs/triplets_secret.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ThePuffin/rustudemy path: /eight part structure/rust47.rs
// la structure peut être créée à l'interieur de la fonction mais ne sera utilisable qu'à l'intérieur de la fonction
#[derive(Debug)]
struct User {
age: i32
}
<|fim_suffix|> if u1.age >u2.age {
println!("u1 is elder")
... | code_fim | hard | {
"lang": "rust",
"repo": "ThePuffin/rustudemy",
"path": "/eight part structure/rust47.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let u1= User {age: 25};
println!("{:?}", u1.age);
// on a une erreur
// let u2= User {age: 39};
// si on veut changer la valeur penser à ajouter mut
let mut u2= User {age: 39};
u2.age=40;
println!("{:?}", u2.age);
if u1.age >u2.age {
println!("u1 is elder")
... | code_fim | medium | {
"lang": "rust",
"repo": "ThePuffin/rustudemy",
"path": "/eight part structure/rust47.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> if u1.age >u2.age {
println!("u1 is elder")
} else if u1.age <u2.age {
println!("u2 is elder")
} else {
println!("same age");
}
}<|fim_prefix|>// repo: ThePuffin/rustudemy path: /eight part structure/rust47.rs
// la structure peut être créée à l'interieur de la f... | code_fim | hard | {
"lang": "rust",
"repo": "ThePuffin/rustudemy",
"path": "/eight part structure/rust47.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: eycorsican/leaf path: /leaf/src/proxy/http/inbound/stream.rs
use std::io;
use std::str;
use std::cmp;
use std::convert::TryFrom;
use std::{net::IpAddr, pin::Pin, task::Poll, task::Context};
use anyhow::Result;
use tokio::io::{AsyncWriteExt, AsyncReadExt, ReadBuf};
use bytes::BytesMut;
use async... | code_fim | hard | {
"lang": "rust",
"repo": "eycorsican/leaf",
"path": "/leaf/src/proxy/http/inbound/stream.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> match head.target_format {
TargetFormat::Absolute => {
let path_and_query = head.uri.path_and_query().map(|paq| paq.as_str()).unwrap_or("/");
head.uri = path_and_query.parse().unwrap();
head.set_header("host".to_string(), addr.to_string()... | code_fim | hard | {
"lang": "rust",
"repo": "eycorsican/leaf",
"path": "/leaf/src/proxy/http/inbound/stream.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>";
let s = &hello[0..3];
println!("&hello[0..4] = {}", s);
}<|fim_prefix|>// repo: dmgolembiowski/RustyKitchen path: /wat/slicing_strings.rs
fn main() {
// Have caution,
// it's generally a bad idea t<|fim_middle|>o try to slice strings
// and recover characters by index slice,
//... | code_fim | medium | {
"lang": "rust",
"repo": "dmgolembiowski/RustyKitchen",
"path": "/wat/slicing_strings.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dmgolembiowski/RustyKitchen path: /wat/slicing_strings.rs
fn main() {
// Have caution,
// it's generally a bad idea t<|fim_suffix|>";
let s = &hello[0..3];
println!("&hello[0..4] = {}", s);
}<|fim_middle|>o try to slice strings
// and recover characters by index slice,
//... | code_fim | medium | {
"lang": "rust",
"repo": "dmgolembiowski/RustyKitchen",
"path": "/wat/slicing_strings.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // println!("the secret number is {}", sec_num);/
match guess.cmp(&sec_num) {
Ordering::Less => println!("Oi that number is too weee"),
Ordering::Greater => println!("Thats 2 big 4 irl daddy-o"),
Ordering::Equal => {
println!("Shit you g... | code_fim | hard | {
"lang": "rust",
"repo": "k4m1/rust_projects",
"path": "/guessing_game/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: k4m1/rust_projects path: /guessing_game/src/main.rs
use std::io;
use std::cmp::Ordering;
use rand::Rng;
fn main() {
println!("Try and guess the number!");
let sec_num = rand::thread_rng().gen_range(1, 101);
loop {
println!("Please type a guess.");
let mut guess =... | code_fim | hard | {
"lang": "rust",
"repo": "k4m1/rust_projects",
"path": "/guessing_game/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rcore-os/zCore path: /kernel-hal/src/common/vm.rs
use crate::{addr::is_aligned, MMUFlags, PhysAddr, VirtAddr};
/// Errors may occur during address translation.
#[derive(Debug)]
pub enum PagingError {
NoMemory,
NotMapped,
AlreadyMapped,
}
/// Address translation result.
pub type Pag... | code_fim | hard | {
"lang": "rust",
"repo": "rcore-os/zCore",
"path": "/kernel-hal/src/common/vm.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> &mut self,
start_vaddr: VirtAddr,
size: usize,
start_paddr: PhysAddr,
flags: MMUFlags,
) -> PagingResult {
assert!(is_aligned(start_vaddr));
assert!(is_aligned(start_vaddr));
assert!(is_aligned(size));
debug!(
"map_con... | code_fim | hard | {
"lang": "rust",
"repo": "rcore-os/zCore",
"path": "/kernel-hal/src/common/vm.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>const RUST_LAYOUTS: &[(&str, Layout)] = &[
(
"ALSASeqClientInfo",
Layout {
size: size_of::<ALSASeqClientInfo>(),
alignment: align_of::<ALSASeqClientInfo>(),
},
),
(
"ALSASeqClientInfoClass",
Layout {
size: size_of::<AL... | code_fim | hard | {
"lang": "rust",
"repo": "alsa-project/alsa-gobject-rs",
"path": "/alsaseq-sys/tests/abi.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn get_c_output(name: &str) -> Result<String, Box<dyn Error>> {
let tmpdir = Builder::new().prefix("abi").tempdir()?;
let exe = tmpdir.path().join(name);
let c_file = Path::new("tests").join(name).with_extension("c");
let cc = Compiler::new().expect("configured compiler");
cc.compile(... | code_fim | hard | {
"lang": "rust",
"repo": "alsa-project/alsa-gobject-rs",
"path": "/alsaseq-sys/tests/abi.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: alsa-project/alsa-gobject-rs path: /alsaseq-sys/tests/abi.rs
, out: &Path) -> Result<(), Box<dyn Error>> {
let mut cmd = self.to_command();
cmd.arg(src);
cmd.arg("-o");
cmd.arg(out);
let status = cmd.spawn()?.wait()?;
if !status.success() {
... | code_fim | hard | {
"lang": "rust",
"repo": "alsa-project/alsa-gobject-rs",
"path": "/alsaseq-sys/tests/abi.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn get_next_message(&mut self, world: &PlayerWorld, scene: &Scene) -> Option<Message> {
if self.destination.is_none() {
debug!("PathFinder: destination is not set");
return None;
}
let dst_tile_pos = self.destination.unwrap();
let player_pos = wo... | code_fim | hard | {
"lang": "rust",
"repo": "elsid/hafen_bot",
"path": "/src/bot/tasks/path_finder.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> "PathFinder"
}
fn get_next_message(&mut self, world: &PlayerWorld, scene: &Scene) -> Option<Message> {
if self.destination.is_none() {
debug!("PathFinder: destination is not set");
return None;
}
let dst_tile_pos = self.destination.unwrap();... | code_fim | hard | {
"lang": "rust",
"repo": "elsid/hafen_bot",
"path": "/src/bot/tasks/path_finder.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: elsid/hafen_bot path: /src/bot/tasks/path_finder.rs
use std::collections::{BTreeMap, HashMap, VecDeque};
use std::sync::{Arc, Mutex};
use std::sync::atomic::AtomicBool;
use serde::Deserialize;
use crate::bot::map::{map_pos_to_tile_pos, pos_to_map_pos, pos_to_rel_tile_pos, pos_to_tile_pos, rel_... | code_fim | hard | {
"lang": "rust",
"repo": "elsid/hafen_bot",
"path": "/src/bot/tasks/path_finder.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn run(window: &window::Window) -> NResult<()> {
window.show();
let comp_host = window.create_composition_host()?;
let comp = comp_host.compositor;
let children = comp_host.root_visual.get_children()??;
for x in 0..5 {
for y in 0..5 {
let child_visual = comp.... | code_fim | hard | {
"lang": "rust",
"repo": "contextfree/rust-winui-experiments",
"path": "/src/main.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: contextfree/rust-winui-experiments path: /src/main.rs
#![feature(try_trait)]
extern crate winapi;
extern crate winrt;
#[macro_use]
extern crate bitflags;
extern crate libc;
mod DispatcherQueue;
mod nresult;
mod win32_composition;
mod window;
mod windows_ui_composition_interop;
use... | code_fim | hard | {
"lang": "rust",
"repo": "contextfree/rust-winui-experiments",
"path": "/src/main.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Thewessen/hello-world path: /Exercism/rust/armstrong-numbers/src/lib.rs
pub fn is_armstrong_number(num: u32) -> bool {
let s<|fim_suffix|>p(|c| c.to_digit(10).unwrap_or(0))
.map(|n| n.pow(string.len() as u32))
.sum::<u32>() == num
}<|fim_middle|>tring = num.to_string();
... | code_fim | easy | {
"lang": "rust",
"repo": "Thewessen/hello-world",
"path": "/Exercism/rust/armstrong-numbers/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>p(|c| c.to_digit(10).unwrap_or(0))
.map(|n| n.pow(string.len() as u32))
.sum::<u32>() == num
}<|fim_prefix|>// repo: Thewessen/hello-world path: /Exercism/rust/armstrong-numbers/src/lib.rs
pub fn is_armstrong_number(num: u32) -> bool {
let s<|fim_middle|>tring = num.to_string();
... | code_fim | easy | {
"lang": "rust",
"repo": "Thewessen/hello-world",
"path": "/Exercism/rust/armstrong-numbers/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: EinErste/sic-infit path: /src/main.rs
#![windows_subsystem = "windows"]
use amethyst::{
core::transform::TransformBundle,
prelude::*,
audio::AudioBundle,
renderer::{
plugins::{RenderFlat2D, RenderToWindow, RenderSkybox},
types::DefaultBackend,
RenderingBun... | code_fim | hard | {
"lang": "rust",
"repo": "EinErste/sic-infit",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let binding_path = app_root.join("config").join("bindings.ron");
let input_bundle = InputBundle::<StringBindings>::new().with_bindings_from_file(binding_path)?;
//main point where we basically construct the game from all the plugins and systems we have
let game_data = GameDataBuilder::defa... | code_fim | medium | {
"lang": "rust",
"repo": "EinErste/sic-infit",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>
let binding_path = app_root.join("config").join("bindings.ron");
let input_bundle = InputBundle::<StringBindings>::new().with_bindings_from_file(binding_path)?;
//main point where we basically construct the game from all the plugins and systems we have
let game_data = GameDataBuilder::def... | code_fim | medium | {
"lang": "rust",
"repo": "EinErste/sic-infit",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.