text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_suffix|> Self {
retrievable_request,
authorization,
phantom: PhantomData,
}
}
}
impl<'a, T> Retrievable<'a> for Retriever<T>
where
T: DeserializeOwned,
{
type Item = T;
fn deserialize(s: &'a str) -> Result<Self::Item, serde_json::Error>
whe... | code_fim | medium | {
"lang": "rust",
"repo": "lperson/spotifytops",
"path": "/src/lib/spotify/retriever.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>mod withf {
use super::*;
#[test]
#[should_panic(expected = "MockFoo::foo([1, 2, 3, 4]): No matching expectation found")]
fn fail() {
let mut mock = MockFoo::new();
mock.expect_foo()
.withf(|sl| sl == [1, 2, 3])
.returning(|_| ());
let x = v... | code_fim | medium | {
"lang": "rust",
"repo": "asomers/mockall",
"path": "/mockall/tests/automock_slice_arguments.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut mock = MockFoo::new();
mock.expect_foo()
.withf(|sl| sl == [1, 2, 3])
.returning(|_| ());
let x = vec![1, 2, 3];
mock.foo(&x);
}
}<|fim_prefix|>// repo: asomers/mockall path: /mockall/tests/automock_slice_arguments.rs
// vim: tw=80
//! a... | code_fim | hard | {
"lang": "rust",
"repo": "asomers/mockall",
"path": "/mockall/tests/automock_slice_arguments.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: asomers/mockall path: /mockall/tests/automock_slice_arguments.rs
// vim: tw=80
//! a method with slice arguments
#![deny(warnings)]
use mockall::*;
<|fim_suffix|> let mut mock = MockFoo::new();
mock.expect_foo()
.withf(|sl| sl == [1, 2, 3])
.returning(|_|... | code_fim | hard | {
"lang": "rust",
"repo": "asomers/mockall",
"path": "/mockall/tests/automock_slice_arguments.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: johnterickson/adventofcode path: /2021/src/day5.rs
use std::cmp;
use aoc_runner_derive::{aoc, aoc_generator};
#[derive(Debug)]
struct Point { x: isize, y: isize }
impl Point {
fn parse(s: &str) -> Point {
let mut xy = s.split(',');
Point {
x: isize::from_str_r... | code_fim | hard | {
"lang": "rust",
"repo": "johnterickson/adventofcode",
"path": "/2021/src/day5.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let input =
r#"0,9 -> 5,9
8,0 -> 0,8
9,4 -> 3,4
2,2 -> 2,1
7,0 -> 7,4
6,4 -> 2,0
0,9 -> 2,9
3,4 -> 1,4
0,0 -> 8,8
5,5 -> 8,2"#;
let input = parse_input(input);
assert_eq!(part1(&input), 5);
}
#[test]
fn part2_example() {
... | code_fim | hard | {
"lang": "rust",
"repo": "johnterickson/adventofcode",
"path": "/2021/src/day5.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: sndnv/rowe path: /tests/setup/production/mod.rs
use owe::entities::doodad;
use owe::entities::Entity;
use owe::entities::resource;
use owe::entities::structure;
use owe::entities::walker;
use owe::production::Commodity;
use owe::production::exchange::CommodityExchange;
use std::collections::Hash... | code_fim | hard | {
"lang": "rust",
"repo": "sndnv/rowe",
"path": "/tests/setup/production/mod.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let e0 = Rc::new(Entity::Structure { props: s0, state: s0_state, producer: None });
let e1 = Rc::new(Entity::Structure { props: s1, state: s1_state, producer: None });
let e2 = Rc::new(Entity::Walker { props: w0, state: w0_state });
let e3 = Rc::new(Entity::Walker { props: w1, state: w1_st... | code_fim | hard | {
"lang": "rust",
"repo": "sndnv/rowe",
"path": "/tests/setup/production/mod.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let r0 = resource::ResourceProperties {
name: "r0".to_owned(),
max_amount: 10,
replenish_amount: Some(15),
};
let r1 = resource::ResourceProperties {
name: "r1".to_owned(),
max_amount: 10,
replenish_amount: None,
};
let r0_state = resou... | code_fim | hard | {
"lang": "rust",
"repo": "sndnv/rowe",
"path": "/tests/setup/production/mod.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: sagiegurari/cargo-make path: /src/lib/plugin/runner_test.rs
es = IndexMap::new();
let output = get_plugin_name_recursive(&aliases, "test", &mut vec![]);
assert_eq!(output, "test");
}
#[test]
fn get_plugin_name_recursive_not_found() {
let mut aliases = IndexMap::new();
aliases.... | code_fim | hard | {
"lang": "rust",
"repo": "sagiegurari/cargo-make",
"path": "/src/lib/plugin/runner_test.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut plugins = IndexMap::new();
plugins.insert(
"test2".to_string(),
Plugin {
script: "assert_eq ${task.plugin.name} wrongvalue".to_string(),
},
);
let mut aliases = IndexMap::new();
aliases.insert("test_plugin".to_string(), "test2".to_string());
... | code_fim | hard | {
"lang": "rust",
"repo": "sagiegurari/cargo-make",
"path": "/src/lib/plugin/runner_test.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> set_env PLUGIN_RUNNER_RUN_TASK_INVOKED done
"#
.to_string(),
},
);
plugins.insert(
"empty".to_string(),
Plugin {
script: r#"
assert_eq ${flow.task.name} test
empty = array_is_empty ${flow.cl... | code_fim | hard | {
"lang": "rust",
"repo": "sagiegurari/cargo-make",
"path": "/src/lib/plugin/runner_test.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn secret_key() -> String {
match env::var("secret_key") {
Ok(env_secret_key) => env_secret_key,
Err(_) => JWT_BACKUP.to_owned()
}
}<|fim_prefix|>// repo: gouthamkrishnakv/plastic_lace path: /src/config.rs
// Library for environment variables
use std::env;
// Token Issuer, in... | code_fim | hard | {
"lang": "rust",
"repo": "gouthamkrishnakv/plastic_lace",
"path": "/src/config.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: gouthamkrishnakv/plastic_lace path: /src/config.rs
// Library for environment variables
use std::env;
// Token Issuer, in this case, me.
pub const TOKEN_ISSUER = "Plastic Lace by Goutham Krishna K V";
<|fim_suffix|>pub fn secret_key() -> String {
match env::var("secret_key") {
Ok(e... | code_fim | hard | {
"lang": "rust",
"repo": "gouthamkrishnakv/plastic_lace",
"path": "/src/config.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rikkaneko/algorithm path: /src/sorting/quicksort.rs
use rand::Rng;
/// Partition using Lomuto's Method
pub fn partition<T: Ord>(arr: &mut [T], lo: usize, hi: usize) -> usize {
let mut i = lo;
let mut rng = rand::thread_rng();
// Select a random element as pivot
arr.swap(rng.gen_range(lo..=hi... | code_fim | hard | {
"lang": "rust",
"repo": "rikkaneko/algorithm",
"path": "/src/sorting/quicksort.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn test_sort() {
let mut arrx = [
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
[4, 9, 10, 8, 9, 5, 1, 2, 3, 7],
[0, 0, 1, 0, 1, 1, 0, 1, 0, 1]
];
for arr in arrx.iter_mut() {
shuffle(arr);
sort(arr);
}
assert_eq!(arrx[0], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
assert_eq!(arrx[1], [1, 2... | code_fim | medium | {
"lang": "rust",
"repo": "rikkaneko/algorithm",
"path": "/src/sorting/quicksort.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: 0e4ef622/aoc path: /2020/day20/src/solution.rs
use std::collections::*;
#[derive(Debug)]
struct Tile {
top: Vec<u8>,
bottom: Vec<u8>,
left: Vec<u8>,
right: Vec<u8>,
inner: Vec<Vec<u8>>,
used: bool,
}
impl Tile {
fn rotate(&mut self) {
std::mem::swap(&mut sel... | code_fim | hard | {
"lang": "rust",
"repo": "0e4ef622/aoc",
"path": "/2020/day20/src/solution.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn part2(input: &str) -> impl std::fmt::Display {
let mut tiles = HashMap::new();
for section in input.split("\n\n") {
let mut s = section.splitn(2, "\n");
let tile_id = s.next().unwrap();
let tile_id = tile_id[5..tile_id.len()-1].parse::<usize>().unwrap();
let ... | code_fim | hard | {
"lang": "rust",
"repo": "0e4ef622/aoc",
"path": "/2020/day20/src/solution.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> spawner => {
"hello there".to_owned()
}
}<|fim_prefix|>// repo: noocene/vessels-web path: /examples/test-vessel/src/lib.rs
use protocol_mve_transport::ProtocolMveTransport;
use vessels::{runtime::RawAdapter, vessel};
vessel! {
<|fim_middle|>using RawAdapter<_, _, _, _, ProtocolMveTrans... | code_fim | easy | {
"lang": "rust",
"repo": "noocene/vessels-web",
"path": "/examples/test-vessel/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: noocene/vessels-web path: /examples/test-vessel/src/lib.rs
use protocol_mve_transport::ProtocolMveTransport;
use <|fim_suffix|> spawner => {
"hello there".to_owned()
}
}<|fim_middle|>vessels::{runtime::RawAdapter, vessel};
vessel! {
using RawAdapter<_, _, _, _, ProtocolMveTrans... | code_fim | medium | {
"lang": "rust",
"repo": "noocene/vessels-web",
"path": "/examples/test-vessel/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: stormtracks/rust-examples path: /vec/examples/ex0.rs
/*
* Check to see if any of the columns inside the input
* does not exist in a vec of columns
*/
pub fn do_vecs_match<T: PartialEq>(a: &Vec<T>, b: &Vec<T>) -> bool {
let matching = a.iter().zip(b.iter()).filter(|&(a, b)| a == b).count()... | code_fim | hard | {
"lang": "rust",
"repo": "stormtracks/rust-examples",
"path": "/vec/examples/ex0.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let input2 = vec!["orange".to_string(), "white".to_string()];
let columns2 = vec!["green".to_string(), "blue".to_string()];
let result = column_does_not_exist(input2, columns2);
println!("Does not exist = {:?}", result);
}<|fim_prefix|>// repo: stormtracks/rust-examples path: /vec/example... | code_fim | hard | {
"lang": "rust",
"repo": "stormtracks/rust-examples",
"path": "/vec/examples/ex0.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> match chars.next() {
Some(next) if next.is_alphabetic() => matched.push(next),
_ => return Err(input),
}
while let Some(next) = chars.next() {
if next.is_alphanumeric() || next == '-' {
matched.push(next);
} else {
... | code_fim | medium | {
"lang": "rust",
"repo": "95th/xml",
"path": "/src/ident.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: 95th/xml path: /src/ident.rs
use crate::parser::{ParseResult, Parser};
pub struct Identifier {
_priv: (),
}
pub fn identifier() -> Identifier {
Identifier { _priv: () }
}
<|fim_suffix|> fn parse<'a>(&self, input: &'a str) -> ParseResult<'a, String> {
let mut matched = Strin... | code_fim | medium | {
"lang": "rust",
"repo": "95th/xml",
"path": "/src/ident.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl ControlInner for CocoaFrame {
fn on_added_to_container(&mut self, member: &mut MemberBase, control: &mut ControlBase, _parent: &dyn controls::Container, _x: i32, _y: i32, pw: u16, ph: u16) {
self.measure(member, control, pw, ph);
if let Some(ref mut child) = self.child {
... | code_fim | hard | {
"lang": "rust",
"repo": "plyhun/plygui-cocoa",
"path": "/src/frame.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.base.parent()
}
fn parent_mut(&mut self) -> Option<&mut dyn controls::Member> {
self.base.parent_mut()
}
fn root(&self) -> Option<&dyn controls::Member> {
self.base.root()
}
fn root_mut(&mut self) -> Option<&mut dyn controls::Member> {
self.base... | code_fim | hard | {
"lang": "rust",
"repo": "plyhun/plygui-cocoa",
"path": "/src/frame.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: plyhun/plygui-cocoa path: /src/frame.rs
use crate::common::{self, *};
pub use std::os::raw::c_char;
const INNER_PADDING_H: i32 = 8; // TODO: WHY???
const INNER_PADDING_V: i32 = 8; // TODO: WHY???
lazy_static! {
static ref WINDOW_CLASS: common::RefClass = unsafe {
register_window_c... | code_fim | hard | {
"lang": "rust",
"repo": "plyhun/plygui-cocoa",
"path": "/src/frame.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// Print the help message
pub async fn help(args: Arc<Args>) -> Result<(), Error> {
let help_string = "search for a crate on crates.io
```
?crate query...
```";
api::send_reply(args.clone(), &help_string).await?;
Ok(())
}
/// Print the help message
pub async fn doc_help(args: Arc<Args>) -> R... | code_fim | hard | {
"lang": "rust",
"repo": "rust-lang/discord-mods-bot",
"path": "/src/crates.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rust-lang/discord-mods-bot path: /src/crates.rs
use crate::{api, commands::Args, Error};
use reqwest::header;
use serde::Deserialize;
use std::sync::Arc;
use tracing::info;
const USER_AGENT: &str = "rust-lang/discord-mods-bot";
#[derive(Debug, Deserialize)]
struct Crates {
crates: Vec<Crat... | code_fim | hard | {
"lang": "rust",
"repo": "rust-lang/discord-mods-bot",
"path": "/src/crates.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn successful_upgrade() {
let root = Root::new();
let strong = RootedRc::new(&root, 42);
let weak = RootedRc::downgrade(&strong, &root);
let upgraded = weak.upgrade(&root).unwrap();
assert_eq!(*upgraded, *strong);
upgraded.explicit_drop(&r... | code_fim | hard | {
"lang": "rust",
"repo": "shadow/shadow",
"path": "/src/lib/shadow-shim-helper-rs/src/rootedcell/rc.rs",
"mode": "spm",
"license": "LicenseRef-scancode-public-domain",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: shadow/shadow path: /src/lib/shadow-shim-helper-rs/src/rootedcell/rc.rs
otedRcInternal<T> {
val: UnsafeCell<Option<T>>,
strong_count: Cell<u32>,
weak_count: Cell<u32>,
}
impl<T> RootedRcInternal<T> {
pub fn new(val: T) -> Self {
Self {
val: UnsafeCell::new(So... | code_fim | hard | {
"lang": "rust",
"repo": "shadow/shadow",
"path": "/src/lib/shadow-shim-helper-rs/src/rootedcell/rc.rs",
"mode": "psm",
"license": "LicenseRef-scancode-public-domain",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: shadow/shadow path: /src/lib/shadow-shim-helper-rs/src/rootedcell/rc.rs
Self {
Self {
val: UnsafeCell::new(Some(val)),
strong_count: Cell::new(1),
weak_count: Cell::new(0),
}
}
pub fn inc_strong(&self) {
self.strong_count.set(... | code_fim | hard | {
"lang": "rust",
"repo": "shadow/shadow",
"path": "/src/lib/shadow-shim-helper-rs/src/rootedcell/rc.rs",
"mode": "psm",
"license": "LicenseRef-scancode-public-domain",
"source": "the-stack-v2"
} |
<|fim_suffix|>s_no_extra_traits! {
pub struct pthread_attr_t {
__sig: c_long,
__opaque: [::c_char; 56]
}
}
cfg_if! {
if #[cfg(feature = "extra_traits")] {
impl PartialEq for pthread_attr_t {
fn eq(&self, other: &pthread_attr_t) -> bool {
self.__sig == oth... | code_fim | hard | {
"lang": "rust",
"repo": "oshunter/fuchsia",
"path": "/third_party/rust_crates/vendor/libc/src/unix/bsd/apple/b64/mod.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|>cfg_if! {
if #[cfg(feature = "extra_traits")] {
impl PartialEq for pthread_attr_t {
fn eq(&self, other: &pthread_attr_t) -> bool {
self.__sig == other.__sig
&& self.__opaque
.iter()
.zip(other.__opaque.iter... | code_fim | hard | {
"lang": "rust",
"repo": "oshunter/fuchsia",
"path": "/third_party/rust_crates/vendor/libc/src/unix/bsd/apple/b64/mod.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: oshunter/fuchsia path: /third_party/rust_crates/vendor/libc/src/unix/bsd/apple/b64/mod.rs
//! 64-bit specific Apple (ios/darwin) definitions
pub type c_long = i64;
pub type c_ulong = u64;
pub type boolean_t = ::c_uint;
pub type mcontext_t = *mut __darwin_mcontext64;
s! {
pub struct timeval... | code_fim | hard | {
"lang": "rust",
"repo": "oshunter/fuchsia",
"path": "/third_party/rust_crates/vendor/libc/src/unix/bsd/apple/b64/mod.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: input-output-hk/jormungandr path: /testing/jormungandr-automation/src/jcli/command/genesis/decode.rs
use std::{path::Path, process::Command};
pub struct GenesisDecodeCommand {
command: Command,
}
<|fim_suffix|> pub fn build(self) -> Command {
self.command
}
}<|fim_middle|>imp... | code_fim | hard | {
"lang": "rust",
"repo": "input-output-hk/jormungandr",
"path": "/testing/jormungandr-automation/src/jcli/command/genesis/decode.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ebottabi/datafuse path: /fusecli/cli/src/cmds/status.rs
// Copyright 2020-2021 The Datafuse Authors.
//
// SPDX-License-Identifier: Apache-2.0.
use std::fs::File;
use std::fs::OpenOptions;
use std::io::BufReader;
use std::path::Path;
use crate::cmds::Config;
use crate::error::Result;
#[derive... | code_fim | medium | {
"lang": "rust",
"repo": "ebottabi/datafuse",
"path": "/fusecli/cli/src/cmds/status.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[derive(serde::Serialize, serde::Deserialize, Debug)]
pub struct Status {
path: String,
pub latest: String,
}
impl Status {
pub fn read(conf: Config) -> Result<Self> {
let status_path = format!("{}/.status.json", conf.datafuse_dir);
if !Path::new(status_path.as_str()).exists... | code_fim | medium | {
"lang": "rust",
"repo": "ebottabi/datafuse",
"path": "/fusecli/cli/src/cmds/status.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: kvsari/dicey-dice path: /src/game/model.rs
//! Game data structures
use std::collections::HashMap;
use std::cell::Cell;
use std::{fmt, ops, cmp};
use derive_getters::Getters;
use crate::hexagon::{Cube, Grid};
use super::{Player, Players, player};
pub type FromHex = Cube;
pub type ToHex = Cube... | code_fim | hard | {
"lang": "rust",
"repo": "kvsari/dicey-dice",
"path": "/src/game/model.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn action(&self) -> &Action {
&self.action
}
pub fn consequence(&self) -> &Consequence {
&self.consequence
}
pub fn score(&self) -> Option<Score> {
self.score.get()
}
pub fn set_score(&self, score: Score) {
self.score.set(Some(score));
... | code_fim | hard | {
"lang": "rust",
"repo": "kvsari/dicey-dice",
"path": "/src/game/model.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: bertptrs/adventofcode path: /2020/src/day16.rs
use std::collections::HashMap;
use std::io::Read;
use std::ops::RangeInclusive;
use crate::common::Lines;
use crate::Solution;
fn split_nums<'a>(s: &'a str) -> impl Iterator<Item = u32> + 'a {
s.split(|c: char| !c.is_ascii_digit()).filter_map(... | code_fim | hard | {
"lang": "rust",
"repo": "bertptrs/adventofcode",
"path": "/2020/src/day16.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> for (field, &pos) in can_fit
.iter()
.enumerate()
.filter(|(_, v)| v.count_ones() == 1)
{
let pos = pos.trailing_zeros() as usize;
let field = fields[field];
assert!(!fixed_fields.contai... | code_fim | hard | {
"lang": "rust",
"repo": "bertptrs/adventofcode",
"path": "/2020/src/day16.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Pt {
pub fn new(x: i32, y: i32) -> Pt {
Pt{x: x, y: y}
}
pub fn add(a: &Pt, b: &Pt) -> Pt {
Pt{x: a.x + b.x, y: a.y + b.y}
}
}
impl fmt::Display for Pt {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "({}, {})", self.x, self.y)
... | code_fim | hard | {
"lang": "rust",
"repo": "eZanmoto/advent_of_code",
"path": "/src/day_3_1.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub struct Ln {
pub src: Pt,
pub tgt: Pt,
}
impl Ln {
pub fn new(src: Pt, tgt: Pt) -> Ln {
Ln{src: src, tgt: tgt}
}
pub fn man_poi(a: &Ln, b: &Ln) -> Option<Pt> {
let (vert, horz) =
if a.src.x == a.tgt.x {
(a, b)
} else {
... | code_fim | hard | {
"lang": "rust",
"repo": "eZanmoto/advent_of_code",
"path": "/src/day_3_1.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: eZanmoto/advent_of_code path: /src/day_3_1.rs
use std::cmp;
use std::fmt;
use std::fs::File;
use std::io;
use std::io::prelude::*;
pub fn run() -> Result<Option<i32>, Error> {
run_on_parsed_file("inputs/day_3_1.txt", closest_intersection)
}
pub fn run_on_parsed_file(path: &str, f: fn(&str,... | code_fim | hard | {
"lang": "rust",
"repo": "eZanmoto/advent_of_code",
"path": "/src/day_3_1.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: sugyan/atcoder path: /sumitrust2019/src/bin/e.rs
use proconio::{fastout, input};
const DIV: u64 = 1_000_000_007;
<|fim_suffix|> input! {
n: usize,
a: [u32; n],
}
let mut answer = 1;
let mut rgb = [0, 0, 0];
for &a in &a {
let c = (0..3).filter(|&i| rg... | code_fim | easy | {
"lang": "rust",
"repo": "sugyan/atcoder",
"path": "/sumitrust2019/src/bin/e.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> input! {
n: usize,
a: [u32; n],
}
let mut answer = 1;
let mut rgb = [0, 0, 0];
for &a in &a {
let c = (0..3).filter(|&i| rgb[i] == a).collect::<Vec<_>>();
answer = (answer * c.len() as u64) % DIV;
if !c.is_empty() {
rgb[c[0]] += 1;
... | code_fim | easy | {
"lang": "rust",
"repo": "sugyan/atcoder",
"path": "/sumitrust2019/src/bin/e.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: datachand/nettu-scheduler path: /scheduler/crates/infra/src/repos/event/event/postgres.rs
use super::{IEventRepo, MostRecentCreatedServiceEvents};
use crate::repos::{shared::query_structs::MetadataFindQuery, user};
use nettu_scheduler_domain::{CalendarEvent, CalendarEventReminder, Metadata, RRul... | code_fim | hard | {
"lang": "rust",
"repo": "datachand/nettu-scheduler",
"path": "/scheduler/crates/infra/src/repos/event/event/postgres.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> async fn find_by_calendar(
&self,
calendar_id: &ID,
timespan: Option<&nettu_scheduler_domain::TimeSpan>,
) -> anyhow::Result<Vec<CalendarEvent>> {
let events: Vec<EventRaw> = match timespan {
Some(timespan) => {
sqlx::query_as!(
... | code_fim | hard | {
"lang": "rust",
"repo": "datachand/nettu-scheduler",
"path": "/scheduler/crates/infra/src/repos/event/event/postgres.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> async fn find_by_service(
&self,
service_id: &ID,
user_ids: &[ID],
min_ts: i64,
max_ts: i64,
) -> Vec<CalendarEvent> {
let user_ids = user_ids
.iter()
.map(|id| id.inner_ref().clone())
.collect::<Vec<_>>();
... | code_fim | hard | {
"lang": "rust",
"repo": "datachand/nettu-scheduler",
"path": "/scheduler/crates/infra/src/repos/event/event/postgres.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> *reg &= !(0b11 << (port * 2));
*reg |= mask << (port * 2);
}
}
pub fn get_pull(&self, port: u8) -> Pull {
if port > 15 {
panic!("PUPDR::get_pull - specified port must be between [0..15]!");
}
let mask = unsafe {
let reg = self.addr();
(*reg & (0b11 << (... | code_fim | hard | {
"lang": "rust",
"repo": "dnseitz/CortexM0Rust",
"path": "/port/cortex-m0/src/peripheral/gpio/pupdr.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dnseitz/CortexM0Rust path: /port/cortex-m0/src/peripheral/gpio/pupdr.rs
// peripheral/gpio/pupdr.rs
// AltOSRust
//
// Created by Daniel Seitz on 11/30/16
use super::super::{Register, Field};
#[derive(Copy, Clone)]
pub enum Pull {
Neither,
Up,
Down,
}
impl Field for Pull {
fn mask(&se... | code_fim | hard | {
"lang": "rust",
"repo": "dnseitz/CortexM0Rust",
"path": "/port/cortex-m0/src/peripheral/gpio/pupdr.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ssing2/zksync path: /core/bin/zksync_event_listener/src/messages.rs
// Built-in uses
use std::sync::Arc;
// External uses
use actix::prelude::*;
// Workspace uses
use zksync_storage::listener::notification::StorageNotification;
use zksync_types::event::{EventId, ZkSyncEvent};
// Local uses
use c... | code_fim | medium | {
"lang": "rust",
"repo": "ssing2/zksync",
"path": "/core/bin/zksync_event_listener/src/messages.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[derive(Debug, Message)]
#[rtype(result = "()")]
pub struct NewStorageEvent(pub EventId);
impl From<StorageNotification> for NewStorageEvent {
fn from(notification: StorageNotification) -> Self {
Self(notification.payload().parse::<u64>().unwrap().into())
}
}<|fim_prefix|>// repo: ssing2... | code_fim | hard | {
"lang": "rust",
"repo": "ssing2/zksync",
"path": "/core/bin/zksync_event_listener/src/messages.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let policy = inp.parse::<PortPolicy>().unwrap();
assert_eq!(format!("{}", policy), outp);
for p in allow {
assert!(policy.allows_port(*p));
}
for p in deny {
assert!(!policy.allows_port(*p));
}
... | code_fim | hard | {
"lang": "rust",
"repo": "erglabs/arti",
"path": "/crates/tor-netdoc/src/types/policy/portpolicy.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: erglabs/arti path: /crates/tor-netdoc/src/types/policy/portpolicy.rs
//! Implement port-based policies
//!
//! These are also known as "short policies" or "policy summaries".
use std::fmt::Display;
use std::str::FromStr;
use std::sync::Arc;
use super::{PolicyError, PortRange};
use crate::util:... | code_fim | hard | {
"lang": "rust",
"repo": "erglabs/arti",
"path": "/crates/tor-netdoc/src/types/policy/portpolicy.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl FromStr for PortPolicy {
type Err = PolicyError;
fn from_str(mut s: &str) -> Result<Self, PolicyError> {
let invert = if s.starts_with("accept ") {
false
} else if s.starts_with("reject ") {
true
} else {
return Err(PolicyError::Inva... | code_fim | hard | {
"lang": "rust",
"repo": "erglabs/arti",
"path": "/crates/tor-netdoc/src/types/policy/portpolicy.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> BenchIndex { n }
}
}
impl fmt::Display for BenchIndex {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{}", self.n)
}
}
/// A range of bench indices.
///
/// Can only be created by an `Instance`.
pub struct BenchRange {
/// Cursor.
current: usize... | code_fim | hard | {
"lang": "rust",
"repo": "AdrienChampion/benchi",
"path": "/src/common/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: AdrienChampion/benchi path: /src/common/mod.rs
bad: if colored {
Colour::Red.normal().bold()
} else {
Style::new()
},
}
}
}
/// Has a verbosity setting.
pub trait VerbExt {
/// Access to the verbosity.
fn verb(&sel... | code_fim | hard | {
"lang": "rust",
"repo": "AdrienChampion/benchi",
"path": "/src/common/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: toams69/nmea-log-player path: /src/main.rs
#![warn(rust_2018_idioms)]
mod nmea_reader;
mod settings;
use bus::Bus;
use tokio::net::TcpListener;
use nmea_reader::{get_nmea_positions, get_stamp_from_nmea_line};
use tokio::io::AsyncWriteExt;
use std::error::Error;
use std::fs::File;
use std::io... | code_fim | hard | {
"lang": "rust",
"repo": "toams69/nmea-log-player",
"path": "/src/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
// First getting and checking settings
let opts = settings::get_settings().await.unwrap();
// Create bus
let bus = Bus::new(1);
let bus_handle = bus.read_handle();
let filename = opts.input_file;
match opts.out_pip... | code_fim | hard | {
"lang": "rust",
"repo": "toams69/nmea-log-player",
"path": "/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> match opts.out_pipe {
Some(mut pipe) => {
let is_verbose = opts.is_verbose;
let replay_factor = opts.replay_factor;
std::thread::spawn(move || {
read_file(bus, &filename, replay_factor, is_verbose);
});
let mut receive... | code_fim | hard | {
"lang": "rust",
"repo": "toams69/nmea-log-player",
"path": "/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: detuur/sbtrfs path: /src/src/maintenance.rs
use std::fs::File;
use std::fs::OpenOptions;
use std::path::Path;
use byteorder::{BigEndian, WriteBytesExt};
use super::dir::{Dir, DirEntry};
use std::io::prelude::*;
use super::fusebindings::FuseBindFS;
<|fim_suffix|> // Write our unique magic: 5(... | code_fim | hard | {
"lang": "rust",
"repo": "detuur/sbtrfs",
"path": "/src/src/maintenance.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Write our unique magic: 5(S)ecure Btrfs File 5(S)ystem
let magic_bytes:u16 = 0x5BF5;
file.write_u16::<BigEndian>( magic_bytes ).unwrap();
file.set_len( 40*1024*1024 ); // TODO: Not make this hardcoded to 40MB
println!("Just created a SuperBlock in the loaded file");
}<|fim_prefix... | code_fim | hard | {
"lang": "rust",
"repo": "detuur/sbtrfs",
"path": "/src/src/maintenance.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: will0225/Polkadex path: /pallets/generic_asset/src/lib.rs
te_permission(
origin,
#[compact] asset_id: T::AssetId,
new_permission: PermissionLatest<T::AccountId>
) -> DispatchResult {
let origin = ensure_signed(origin)?;
let permissions: PermissionVersions<T::AccountId> = new_pe... | code_fim | hard | {
"lang": "rust",
"repo": "will0225/Polkadex",
"path": "/pallets/generic_asset/src/lib.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: will0225/Polkadex path: /pallets/generic_asset/src/lib.rs
id, who)
}
/// Get an account's reserved balance of an asset kind.
pub fn reserved_balance(asset_id: &T::AssetId, who: &T::AccountId) -> T::Balance {
<ReservedBalance<T>>::get(asset_id, who)
}
/// Mint to an ... | code_fim | hard | {
"lang": "rust",
"repo": "will0225/Polkadex",
"path": "/pallets/generic_asset/src/lib.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> Ok(())
}
/// Move `amount` from free balance to reserved balance.
///
/// If the free balance is lower than `amount`, then no funds will be moved and an `Err` will
/// be returned. This is different behavior than `unreserve`.
pub fn reserve(asset_id: &T::AssetId, who: &T::... | code_fim | hard | {
"lang": "rust",
"repo": "will0225/Polkadex",
"path": "/pallets/generic_asset/src/lib.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> &self,
constraint_set: &VariableConstraintSet,
) -> Result<HashMap<usize, Type>, CompileError> {
let mut substitutions = HashMap::<usize, Type>::new();
for (id, constraint) in constraint_set.constraints() {
let constraint_type = self
.constr... | code_fim | hard | {
"lang": "rust",
"repo": "ein-lang/ein",
"path": "/lib/lang/src/compile/type_inference/constraint_solver.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ein-lang/ein path: /lib/lang/src/compile/type_inference/constraint_solver.rs
use super::{
super::{error::CompileError, reference_type_resolver::ReferenceTypeResolver},
constraint_converter::ConstraintConverter,
subsumption_set::SubsumptionSet,
variable_constraint_set::VariableCon... | code_fim | hard | {
"lang": "rust",
"repo": "ein-lang/ein",
"path": "/lib/lang/src/compile/type_inference/constraint_solver.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.pending_requests.insert(
key,
Request {
dns: value.dns,
state: RequestState::WaitingForExternalServer,
requester: value.requester,
},
);
... | code_fim | hard | {
"lang": "rust",
"repo": "lholznagel/rust-dns",
"path": "/daemon/src/server.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.pending_requests.entry(dns.id).and_modify(|e| {
if !dns.resource_records.is_empty() {
let dns = dns.clone();
e.state = RequestState::ReadyToSend;
e.dns.resource_records = dns.resource_records.to_vec();
}
});
... | code_fim | hard | {
"lang": "rust",
"repo": "lholznagel/rust-dns",
"path": "/daemon/src/server.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: lholznagel/rust-dns path: /daemon/src/server.rs
use crate::error::*;
use log::debug;
use rdns_proto::*;
use std::collections::HashMap;
use std::net::SocketAddr;
use std::time::SystemTime;
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
pub enum RequestState {
Added,
ReadyToSend,
Waiti... | code_fim | hard | {
"lang": "rust",
"repo": "lholznagel/rust-dns",
"path": "/daemon/src/server.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn routes(
pg_pool: Pool,
) -> impl Filter<Extract = (impl warp::Reply,), Error = std::convert::Infallible> + Clone {
warp::any()
.and(version::routes("version"))
.or(todo_lists::routes("todo-lists", pg_pool.clone()))
.or(todos::routes("todos", pg_pool))
.recove... | code_fim | easy | {
"lang": "rust",
"repo": "towaanu/rutodo",
"path": "/src/rest/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: towaanu/rutodo path: /src/rest/mod.rs
pub mod models;
pub mod rejection;
pub mod todo_lists;
pub mod todos;
pub mod version;
<|fim_suffix|>pub fn routes(
pg_pool: Pool,
) -> impl Filter<Extract = (impl warp::Reply,), Error = std::convert::Infallible> + Clone {
warp::any()
.and(v... | code_fim | easy | {
"lang": "rust",
"repo": "towaanu/rutodo",
"path": "/src/rest/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl<T> From<T> for Algorithm
where
jws::Algorithm: From<T>,
{
#[inline]
fn from(alg: T) -> Self {
Self::Signing(jws::Algorithm::from(alg))
}
}
impl TryFrom<Algorithm> for jws::Algorithm {
type Error = error::IncompatibleAlgorithm;
#[inline]
fn try_from(alg: Algorithm... | code_fim | hard | {
"lang": "rust",
"repo": "mibac138/aliri",
"path": "/aliri/src/jwa/algorithm.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mibac138/aliri path: /aliri/src/jwa/algorithm.rs
use std::{convert::TryFrom, fmt};
use serde::{Deserialize, Serialize};
use crate::{error, jwa, jws};
/// An algorithm
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
#[non_exhaustive]
pub enum Algor... | code_fim | hard | {
"lang": "rust",
"repo": "mibac138/aliri",
"path": "/aliri/src/jwa/algorithm.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> Self::Signing(jws::Algorithm::from(alg))
}
}
impl TryFrom<Algorithm> for jws::Algorithm {
type Error = error::IncompatibleAlgorithm;
#[inline]
fn try_from(alg: Algorithm) -> Result<Self, Self::Error> {
match alg {
Algorithm::Signing(alg) => Ok(alg),
... | code_fim | hard | {
"lang": "rust",
"repo": "mibac138/aliri",
"path": "/aliri/src/jwa/algorithm.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tertsdiepraam/vrp path: /vrp-core/src/solver/mutation/recreate/recreate_with_gaps.rs
use crate::construction::heuristics::InsertionContext;
use crate::construction::heuristics::*;
use crate::models::problem::Job;
use crate::solver::mutation::recreate::Recreate;
use crate::solver::mutation::Confi... | code_fim | hard | {
"lang": "rust",
"repo": "tertsdiepraam/vrp",
"path": "/vrp-core/src/solver/mutation/recreate/recreate_with_gaps.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> // TODO improve formula
let max_jobs = self.min_jobs.max(ctx.solution.required.len());
let take_jobs = ctx.environment.random.uniform_int(self.min_jobs as i32, max_jobs as i32) as usize;
Box::new(ctx.solution.required.iter().take(take_jobs).cloned())
}
}
/// A recreat... | code_fim | medium | {
"lang": "rust",
"repo": "tertsdiepraam/vrp",
"path": "/vrp-core/src/solver/mutation/recreate/recreate_with_gaps.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Default for RecreateWithGaps {
fn default() -> Self {
Self::new(2)
}
}
impl Recreate for RecreateWithGaps {
fn run(&self, refinement_ctx: &RefinementContext, insertion_ctx: InsertionContext) -> InsertionContext {
self.recreate.run(refinement_ctx, insertion_ctx)
}
}<|f... | code_fim | hard | {
"lang": "rust",
"repo": "tertsdiepraam/vrp",
"path": "/vrp-core/src/solver/mutation/recreate/recreate_with_gaps.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn draw(builder: &mut PanelBuilder) {
let char_w = builder.layer.char_w;
let char_h = builder.layer.char_h;
let x = builder.x.in_pixels(char_w);
let y = builder.y.in_pixels(char_h);
let w = builder.w.in_pixels(char_w);
let h = builder.h.in_pixels(char_h);
builder.layer.last_x = builder.x;
bui... | code_fim | hard | {
"lang": "rust",
"repo": "bbodi/meal_planner",
"path": "/imgui/src/panel.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: bbodi/meal_planner path: /imgui/src/panel.rs
extern crate sdl2;
extern crate sdl2_ttf;
use sdl2::pixels::RGB;
use base;
use base::SizeInCharacters;
pub struct PanelBuilder<'a> {
layer: &'a mut base::Layer,
x: SizeInCharacters,
y: SizeInCharacters,
w: SizeInCharacters,
h: SizeInCharacter... | code_fim | hard | {
"lang": "rust",
"repo": "bbodi/meal_planner",
"path": "/imgui/src/panel.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn get_message(message: &Message) -> &'static str {
match message {
Message::AccessNonArray => "unable to access non-array",
Message::AccessNonIndex => {
"unable to access array with non-numeric index"
}
Message::ArrayMultiType => "array contains multiple ty... | code_fim | hard | {
"lang": "rust",
"repo": "albertgoncalves/tyj",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> match message {
Message::AccessNonArray => "unable to access non-array",
Message::AccessNonIndex => {
"unable to access array with non-numeric index"
}
Message::ArrayMultiType => "array contains multiple types",
Message::AssignNonIdent => "unable to ... | code_fim | hard | {
"lang": "rust",
"repo": "albertgoncalves/tyj",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: albertgoncalves/tyj path: /src/main.rs
mod commenter;
mod parser;
mod tokenizer;
mod typer;
mod types;
use crate::commenter::{get_sigs, Comment, Error as SigError};
use crate::parser::{get_ast, Error as ParseError, Syntax};
use crate::tokenizer::{get_tokens, Count};
use crate::typer::{get_types... | code_fim | hard | {
"lang": "rust",
"repo": "albertgoncalves/tyj",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jonasbb/serde_with path: /serde_with/src/utils/duration.rs
ive,
Negative,
}
impl Sign {
#[allow(dead_code)]
pub(crate) fn is_positive(&self) -> bool {
*self == Sign::Positive
}
#[allow(dead_code)]
pub(crate) fn is_negative(&self) -> bool {
*self == Sign:... | code_fim | hard | {
"lang": "rust",
"repo": "jonasbb/serde_with",
"path": "/serde_with/src/utils/duration.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jonasbb/serde_with path: /serde_with/src/utils/duration.rs
xible, Format, Strict, Strictness},
prelude::*,
};
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(test, derive(Debug))]
pub(crate) enum Sign {
Positive,
Negative,
}
impl Sign {
#[allow(dead_code)]
pub(crate) fn is... | code_fim | hard | {
"lang": "rust",
"repo": "jonasbb/serde_with",
"path": "/serde_with/src/utils/duration.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let sign = match value.chars().next() {
// Advance by the size of the parsed char
Some('+') => {
value = &value[1..];
Sign::Positive
}
Some('-') => {
value = &value[1..];
Sign::Negative
}
_ => Sign::Positiv... | code_fim | hard | {
"lang": "rust",
"repo": "jonasbb/serde_with",
"path": "/serde_with/src/utils/duration.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[pallet::call]
impl<T: Config> Pallet<T> {
/// Unlock any vested funds of the sender account.
///
/// The dispatch origin for this call must be _Signed_ and the sender must have funds still
/// locked under this pallet.
///
/// Emits either `VestingCompleted` or `VestingUpdated`.
///
//... | code_fim | hard | {
"lang": "rust",
"repo": "HCastano/substrate",
"path": "/frame/vesting/src/lib.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> Self::add_vesting_schedule(
&who,
schedule.locked,
schedule.per_block,
schedule.starting_block,
)
.expect("user does not have an existing vesting schedule; q.e.d.");
Ok(())
}
/// Force a vested transfer.
///
/// The dispatch origin for this call must be _Root_.
///
... | code_fim | hard | {
"lang": "rust",
"repo": "HCastano/substrate",
"path": "/frame/vesting/src/lib.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: HCastano/substrate path: /frame/vesting/src/lib.rs
// This file is part of Substrate.
// Copyright (C) 2019-2021 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 compli... | code_fim | hard | {
"lang": "rust",
"repo": "HCastano/substrate",
"path": "/frame/vesting/src/lib.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub(crate) fn set_seed(&mut self, val: f64){
self.z = (val as i32 as u32 >> 0) as f64;
}
pub(crate) fn rand(&mut self) -> f64{
self.z = (a * self.z + c) % m;
self.z / m
}
}
}<|fim_prefix|>// repo: limzykenneth/p5.wasm path: /rust/src/p5_wasm.rs
use wasm_bindgen::prelude::*;
use crate:... | code_fim | hard | {
"lang": "rust",
"repo": "limzykenneth/p5.wasm",
"path": "/rust/src/p5_wasm.rs",
"mode": "spm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> P5Wasm {
perlin: p,
perlin_octaves: 4,
perlin_amp_falloff: 0.5,
perlin_lcg: lcg::LCG::new(),
_lcg: lcg::LCG::new(),
color_mode: String::from("rgb"),
color_maxes: maxes,
}
}
}
mod lcg {
#![allow(non_upper_case_globals)]
const m:f64 = 4294967296.0;
const a:f64 = 1664525.0;
con... | code_fim | hard | {
"lang": "rust",
"repo": "limzykenneth/p5.wasm",
"path": "/rust/src/p5_wasm.rs",
"mode": "spm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: limzykenneth/p5.wasm path: /rust/src/p5_wasm.rs
use wasm_bindgen::prelude::*;
use crate::utils::set_panic_hook;
use std::collections::HashMap;
const PERLIN_SIZE:usize = 4095;
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = Math)]
fn random() -> f64;
}
#[wasm_bindgen]
pub struct P... | code_fim | medium | {
"lang": "rust",
"repo": "limzykenneth/p5.wasm",
"path": "/rust/src/p5_wasm.rs",
"mode": "psm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Dzejkop/crowley path: /src/url_encoded.rs
use std::str::FromStr;
#[derive(Debug)]
pub struct UrlEncoded<T>(T);
impl<T> UrlEncoded<T> {
pub fn into_inner(self) -> T {
self.0
}
}
impl<T> FromStr for UrlEncoded<T>
where
T: FromStr,
<T as FromStr>::Err: Send + Sync + std::... | code_fim | hard | {
"lang": "rust",
"repo": "Dzejkop/crowley",
"path": "/src/url_encoded.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test_case("http%3A%2F%2Flocalhost%3A8080%2F" => "http://localhost:8080/")]
#[test_case("String%20with%20spaces" => "String with spaces")]
#[test_case("https%3A%2F%2Fgithub.com%2Flaunchbadge%2Fsqlx%2Fissues%2F294" => "https://github.com/launchbadge/sqlx/issues/294")]
fn url_encoded_parse(... | code_fim | hard | {
"lang": "rust",
"repo": "Dzejkop/crowley",
"path": "/src/url_encoded.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn current_slot(&self) -> usize {
self.active_slot
}
pub fn item(&self, slot: usize) -> Option<BlockType> {
match self.slots[slot] {
Slot::Finite(b, _) | Slot::Infinite(b) => Some(b),
_ => None,
}
}
#[allow(dead_code)]
pub fn cu... | code_fim | hard | {
"lang": "rust",
"repo": "offdroid/cobble",
"path": "/src/inventory.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: offdroid/cobble path: /src/inventory.rs
use crate::world::BlockType;
#[derive(Copy, Clone)]
pub enum Slot {
Empty,
/// Finite number of blocks where the number n is zero-indexed meaning `n = 0` means that there
/// is one block stored
Finite(BlockType, u32),
Infinite(BlockTy... | code_fim | hard | {
"lang": "rust",
"repo": "offdroid/cobble",
"path": "/src/inventory.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn absorb(&mut self, block: BlockType, quantity: u32) -> Option<usize> {
for i in 0..SLOTS {
match &mut self.slots[i] {
Slot::Infinite(b) if *b == block => {
return Some(i);
}
Slot::Finite(b, n) if *b == block ... | code_fim | hard | {
"lang": "rust",
"repo": "offdroid/cobble",
"path": "/src/inventory.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Shock-1/teensy4-rs path: /imxrt1062-pac/imxrt1062-bee/src/ctr_nonce1_w1.rs
#[doc = "Writer for register CTR_NONCE1_W1"]
pub type W = crate::W<u32, super::CTR_NONCE1_W1>;
#[doc = "Register CTR_NONCE1_W1 `reset()`'s with value 0"]
impl crate::ResetValue for super::CTR_NONCE1_W1 {
type Type <|f... | code_fim | hard | {
"lang": "rust",
"repo": "Shock-1/teensy4-rs",
"path": "/imxrt1062-pac/imxrt1062-bee/src/ctr_nonce1_w1.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.