text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_suffix|> if worth < best.0 {
best = (worth, dir);
}
}
if best.0 != std::u32::MAX {
Move(best.1)
} else {
Done
}
}
trait Print {
fn print(&self, position: Position);
}
impl Print for Map {
fn print(&self, position: Position) {
let mut mi... | code_fim | hard | {
"lang": "rust",
"repo": "richardwhiuk/adventofcode",
"path": "/2019/rust/src/fifteen.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// Parse Yaml builder
///
/// # Description
/// Retrieve the `yaml-rust` library yaml representation
///
/// # Argument
/// * `content` String
///
/// # Return
/// Result<Vec<yaml::Yaml>, yaml_rust::ScanError>
fn parse_yaml_builder(content: String) -> Result<Vec<yaml::Yaml> , yaml_rust::ScanError> {
... | code_fim | hard | {
"lang": "rust",
"repo": "shigedangao/capoomobi",
"path": "/src/docker/loader.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: shigedangao/capoomobi path: /src/docker/loader.rs
/// Yaml
///
/// # Description
///
/// Yaml parser module is use to extract the content of a yaml file
use std::path::PathBuf;
use yaml_rust::{YamlLoader, yaml};
use crate::core::fs::toolbox;
use crate::core::errors::cli_error::{CliErr, ErrMessag... | code_fim | hard | {
"lang": "rust",
"repo": "shigedangao/capoomobi",
"path": "/src/docker/loader.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: MikkoSpoo/advent2019 path: /src/bin/intcode/mod.rs
// Intcode computer from AoC
// https://adventofcode.com/2019/day/2
// https://adventofcode.com/2019/day/5
// Iterators as arguments bit tricky, would be nice here
//use std::iter;
// https://hermanradtke.com/2015/06/22/effectively-using-itera... | code_fim | hard | {
"lang": "rust",
"repo": "MikkoSpoo/advent2019",
"path": "/src/bin/intcode/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Using position mode, consider whether the input is
// less than 8; output 1 (if it is) or 0 (if it is not).
assert_eq!(rtl(&mut vec![3,9,7,9,10,9,4,9,99,-1,8], 7), Some(1));
assert_eq!(rtl(&mut vec![3,9,7,9,10,9,4,9,99,-1,8], 8), Some(0));
assert_eq!(rtl(&mut vec![3,9,7,9,10,9,4,9,9... | code_fim | hard | {
"lang": "rust",
"repo": "MikkoSpoo/advent2019",
"path": "/src/bin/intcode/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: peterbudai/adventofcode path: /2019/src/day3.rs
use anyhow::Result;
use crate::util::{Coord, Dir};
fn manhattan_distance((x, y): &Coord) -> usize {
x.abs() as usize + y.abs() as usize
}
type Step = (Dir, usize);
fn parse_step(s: &str) -> Result<Step> {
anyhow::ensure!(s.len() > 0, "Em... | code_fim | hard | {
"lang": "rust",
"repo": "peterbudai/adventofcode",
"path": "/2019/src/day3.rs",
"mode": "psm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert!(parse_path("X2").is_err());
assert!(parse_path("L2;U4").is_err());
}
#[test]
fn path_trace() {
let mut path = vec![(Dir::Right, 2000)];
assert!(walk_path(&path).iter().enumerate().all(|(i, (x,y))| *x == i as isize && *y == 0));
path = vec![(... | code_fim | hard | {
"lang": "rust",
"repo": "peterbudai/adventofcode",
"path": "/2019/src/day3.rs",
"mode": "spm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn step_parse() {
assert_eq!(parse_step("U20").unwrap(), (Dir::Up, 20));
assert_eq!(parse_step("D2").unwrap(), (Dir::Down, 2));
assert_eq!(parse_step("L1").unwrap(), (Dir::Left, 1));
assert_eq!(parse_step("R3333").unwrap(), (Dir::Right, 3333));
... | code_fim | hard | {
"lang": "rust",
"repo": "peterbudai/adventofcode",
"path": "/2019/src/day3.rs",
"mode": "spm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: blizmax/bevy-physics-weekend path: /physics/src/bounds.rs
use glam::Vec3;
use serde::{Deserialize, Serialize};
use std::ops::{Add, AddAssign};
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Bounds {
pub mins: Vec3,
pub maxs: Vec3,
}
impl Bounds {
pub fn... | code_fim | hard | {
"lang": "rust",
"repo": "blizmax/bevy-physics-weekend",
"path": "/physics/src/bounds.rs",
"mode": "psm",
"license": "CC0-1.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> Bounds {
mins: Vec3::select(pt.cmplt(self.mins), pt, self.mins),
maxs: Vec3::select(pt.cmpgt(self.maxs), pt, self.maxs),
}
}
}
impl AddAssign<Vec3> for Bounds {
fn add_assign(&mut self, pt: Vec3) {
self.mins = Vec3::select(pt.cmplt(self.mins), pt, s... | code_fim | hard | {
"lang": "rust",
"repo": "blizmax/bevy-physics-weekend",
"path": "/physics/src/bounds.rs",
"mode": "spm",
"license": "CC0-1.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Add<Vec3> for Bounds {
type Output = Self;
fn add(self, pt: Vec3) -> Self::Output {
Bounds {
mins: Vec3::select(pt.cmplt(self.mins), pt, self.mins),
maxs: Vec3::select(pt.cmpgt(self.maxs), pt, self.maxs),
}
}
}
impl AddAssign<Vec3> for Bounds {
... | code_fim | hard | {
"lang": "rust",
"repo": "blizmax/bevy-physics-weekend",
"path": "/physics/src/bounds.rs",
"mode": "spm",
"license": "CC0-1.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: AidoP/rysk-core path: /tests/variant.rs
use rysk_core::*;
use variant::Variant;
#[test]
fn variant_r() {
const ALL_BITS: [u8; 4] = [0xFF; 4];
assert_eq!(variant::R::decode(ALL_BITS), variant::R {
destination: 0x1F,
source1: 0x1F,
source2: 0x1F
});
}
<|fim_suf... | code_fim | medium | {
"lang": "rust",
"repo": "AidoP/rysk-core",
"path": "/tests/variant.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> const ALL_BITS: [u8; 4] = [0xFF; 4];
assert_eq!(variant::S::<Register32>::decode(ALL_BITS), variant::S {
source1: 0x1F,
source2: 0x1F,
immediate: 0xFFFFFFFFu32.into()
});
}<|fim_prefix|>// repo: AidoP/rysk-core path: /tests/variant.rs
use rysk_core::*;
use variant::Var... | code_fim | medium | {
"lang": "rust",
"repo": "AidoP/rysk-core",
"path": "/tests/variant.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ParthDesai/simple-mmr path: /src/math.rs
pub fn right_sibling(pos: usize, height: u32) -> usize {
pos + (2usize.pow(height + 1) - 1)
}
pub fn left_sibling(pos: usize, height: u32) -> usize {
pos - (2usize.pow(height + 1) - 1)
}
pub fn peak(max_pos: usize) -> usize {
f64::log2((max_... | code_fim | medium | {
"lang": "rust",
"repo": "ParthDesai/simple-mmr",
"path": "/src/math.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn right_child(pos: usize) -> usize {
pos - 1
}<|fim_prefix|>// repo: ParthDesai/simple-mmr path: /src/math.rs
pub fn right_sibling(pos: usize, height: u32) -> usize {
pos + (2usize.pow(height + 1) - 1)
}
<|fim_middle|>pub fn left_sibling(pos: usize, height: u32) -> usize {
pos - (2usize... | code_fim | hard | {
"lang": "rust",
"repo": "ParthDesai/simple-mmr",
"path": "/src/math.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: danbev/learning-rust path: /src/try_into.rs
struct Something {
x: u32,
}
impl std::convert::TryInto<u32> for Something {
type Error = ();
fn try_into(self) -> Result<u32, Self::Error> {
Ok(self.x)
}
}
#[derive(Clone, Copy)]
struct Something2 {
x: u8,
}
<|fim_suff... | code_fim | medium | {
"lang": "rust",
"repo": "danbev/learning-rust",
"path": "/src/try_into.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let b: [u8; 4] = [1, 2, 3, 4];
// The following can be used to display the type:
// let slice: () = &b[1..3];
let slice: &[u8] = &b[1..3];
println!("{:#?}", slice);
// The following try_into call is being done on the [u8] which is an array
// and implements TryFrom which implies Try... | code_fim | medium | {
"lang": "rust",
"repo": "danbev/learning-rust",
"path": "/src/try_into.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // [1518-04-14 00:51] wakes up
let wakes_regex = Regex::new(
r"\[(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2}) (?P<hour>\d{2}):(?P<minute>\d{2})] wakes up").unwrap();
// [1518-05-28 00:36] falls asleep
let sleep_regex = Regex::new(
r"\[(?P<year>\d{4})-(?P<month>\d{2})-(?... | code_fim | hard | {
"lang": "rust",
"repo": "TheJP/AdventOfCode2018",
"path": "/day4/task1/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> println!("{}", id * minute as i32);
// Task 2
let max = entries.iter().max_by_key(|entry| (entry.1).1.iter().max().unwrap()).unwrap();
let id = max.0;
let minute = (max.1).1.iter().enumerate().max_by_key(|entry| entry.1).unwrap().0;
println!("{}", id * minute as i32);
Ok(())... | code_fim | hard | {
"lang": "rust",
"repo": "TheJP/AdventOfCode2018",
"path": "/day4/task1/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: TheJP/AdventOfCode2018 path: /day4/task1/src/main.rs
extern crate regex;
use std::collections::HashMap;
use std::fs::File;
use std::io;
use std::io::BufRead;
use std::io::BufReader;
use regex::Regex;
enum Event {
Wake,
Sleep,
Begin,
}
fn main() -> io::Result<()> {
let f = File... | code_fim | hard | {
"lang": "rust",
"repo": "TheJP/AdventOfCode2018",
"path": "/day4/task1/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let expected = arr2(&[
[7. - 2. * 3., 8. - 2. * 4.],
[7. - 1. * 3., 8. - 1. * 4.],
[7. - 0. * 3., 8. - 0. * 4.],
[7. + 1. * 3., 8. + 1. * 4.],
[7. + 2. * 3., 8. + 2. * 4.],
]);
assert_eq!(
key_coordinates(&dire... | code_fim | hard | {
"lang": "rust",
"repo": "IshitaTakeshi/Tadataka",
"path": "/src/semi_dense/epipolar.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: IshitaTakeshi/Tadataka path: /src/semi_dense/epipolar.rs
use crate::vector::normalize;
use crate::projection::Projection;
use crate::transform::{get_rotation, get_translation, inv_transform};
use ndarray::{arr1, Array, Array1, Array2};
use ndarray_linalg::Norm;
static EPSILON: f64 = 1e-16;
pub... | code_fim | hard | {
"lang": "rust",
"repo": "IshitaTakeshi/Tadataka",
"path": "/src/semi_dense/epipolar.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: krasnobaev/rust path: /src/exercism/nth-prime/src/divide_and_conquer_submit.rs
use std::sync::Mutex;
const PRIME_MAX: usize = 200_000; // but locally stack overflow after 2_094_148
fn is_divisible (candidate: u32, n: usize, primes: &mut [u32;PRIME_MAX+1]) -> bool {
<|fim_suffix|>fn compute_pri... | code_fim | hard | {
"lang": "rust",
"repo": "krasnobaev/rust",
"path": "/src/exercism/nth-prime/src/divide_and_conquer_submit.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: sylvestre/coreutils path: /tests/by-util/test_cp.rs
FOLDER)
.run();
assert!(result_to_dir.success);
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
let result_from_dir = scene
.ucmd()
.arg(TEST_COPY_FROM_FOLDER_FILE)
.arg(TEST_HELLO_... | code_fim | hard | {
"lang": "rust",
"repo": "sylvestre/coreutils",
"path": "/tests/by-util/test_cp.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[cfg(not(windows))]
let _r = fs::symlink(TEST_HELLO_WORLD_SOURCE, TEST_HELLO_WORLD_SOURCE_SYMLINK);
#[cfg(windows)]
let _r = symlink_file(TEST_HELLO_WORLD_SOURCE, TEST_HELLO_WORLD_SOURCE_SYMLINK);
// Back to the initial cwd (breaks the other tests)
assert!(env::set_current_dir(&c... | code_fim | hard | {
"lang": "rust",
"repo": "sylvestre/coreutils",
"path": "/tests/by-util/test_cp.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: sylvestre/coreutils path: /tests/by-util/test_cp.rs
e() {
let (_, mut ucmd) = at_and_ucmd!();
let result = ucmd
.arg(TEST_HELLO_WORLD_SOURCE)
.arg(TEST_HOW_ARE_YOU_SOURCE)
.arg("-i")
.pipe_in("N\n")
.run();
assert!(result.success);
assert!... | code_fim | hard | {
"lang": "rust",
"repo": "sylvestre/coreutils",
"path": "/tests/by-util/test_cp.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: CasualX/pak-rs path: /src/directory/tests.rs
use crate::*;
#[test]
fn test_create_remove_create_links() {
<|fim_suffix|> let example1 = directory.as_ref()[2];
directory.create_link(b"aa/bb/example", &example1);
let example2 = directory.remove(b"a/b/example").unwrap();
directory.create_link(b... | code_fim | medium | {
"lang": "rust",
"repo": "CasualX/pak-rs",
"path": "/src/directory/tests.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let example1 = directory.as_ref()[2];
directory.create_link(b"aa/bb/example", &example1);
let example2 = directory.remove(b"a/b/example").unwrap();
directory.create_link(b"a/b/example", &example2);
dbg!(directory);
}<|fim_prefix|>// repo: CasualX/pak-rs path: /src/directory/tests.rs
use crate::*;
... | code_fim | medium | {
"lang": "rust",
"repo": "CasualX/pak-rs",
"path": "/src/directory/tests.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>e.print();
let step2 = game.step();
step2.print();
}<|fim_prefix|>// repo: ohmree/cellular path: /src/bin/cellular.rs
use cellular::automata::gol::*;
use cellular::Automaton;
pub fn main() {
let game = GameOfLife::new((10, 10));
<|fim_middle|> // This is just dummy code to get this to com... | code_fim | easy | {
"lang": "rust",
"repo": "ohmree/cellular",
"path": "/src/bin/cellular.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ohmree/cellular path: /src/bin/cellular.rs
use cellular::automata::gol::*;
use cellular::Automaton;
pub fn main() {
let game = GameOfLife::new((10, 10));
<|fim_suffix|>e.print();
let step2 = game.step();
step2.print();
}<|fim_middle|> // This is just dummy code to get this to com... | code_fim | easy | {
"lang": "rust",
"repo": "ohmree/cellular",
"path": "/src/bin/cellular.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jfarrell468/rlox path: /src/shared_list.rs
use std::cell::{Ref, RefCell, RefMut};
use std::rc::Rc;
#[derive(Debug)]
pub struct SharedList<T> {
head: Link<T>,
}
type Link<T> = Option<Rc<RefCell<Node<T>>>>;
#[derive(Debug)]
struct Node<T> {
elem: T,
next: Link<T>,
}
impl<T> Node<T>... | code_fim | hard | {
"lang": "rust",
"repo": "jfarrell468/rlox",
"path": "/src/shared_list.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn push(&mut self, elem: T) {
let new_head = Node::new(elem);
if let Some(old_head) = self.head.take() {
new_head.borrow_mut().next = Some(old_head);
}
self.head = Some(new_head);
}
pub fn peek(&self) -> Option<Ref<T>> {
self.head
... | code_fim | hard | {
"lang": "rust",
"repo": "jfarrell468/rlox",
"path": "/src/shared_list.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl<T> SharedList<T> {
pub fn new() -> Self {
SharedList { head: None }
}
pub fn push(&mut self, elem: T) {
let new_head = Node::new(elem);
if let Some(old_head) = self.head.take() {
new_head.borrow_mut().next = Some(old_head);
}
self.head ... | code_fim | hard | {
"lang": "rust",
"repo": "jfarrell468/rlox",
"path": "/src/shared_list.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn bytes(&self) -> &[u8] {
&self.bytes
}
fn information_fields(&self) -> Vec<Field> {
vec![Field::new("Mesh ID", format!("{:X?}", self.mesh_id()))]
}
}
impl_display_for_ie!(MeshId);<|fim_prefix|>// repo: zatchl/kawaiifi path: /src/ies/mesh_id.rs
use super::{Field, Inform... | code_fim | hard | {
"lang": "rust",
"repo": "zatchl/kawaiifi",
"path": "/src/ies/mesh_id.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: zatchl/kawaiifi path: /src/ies/mesh_id.rs
use super::{Field, InformationElement};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MeshId {
bytes: Vec<u8>,
}
impl MeshId {
pub fn new(bytes: Vec<u8>) -> MeshId {
MeshId { bytes }
}
pub fn mesh_id(&self) -> &[u8] {
... | code_fim | medium | {
"lang": "rust",
"repo": "zatchl/kawaiifi",
"path": "/src/ies/mesh_id.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: fudanchii/rust path: /exercises/leap/tests/leap.rs
extern crate leap;
#[test]
fn test_vanilla_leap_year() {
assert_eq!(leap::is_leap_year(1996), true);
}
<|fim_suffix|>#[test]
#[ignore]
fn test_exceptional_centuries() {
assert_eq!(leap::is_leap_year(1600), true);
assert_eq!(leap::i... | code_fim | hard | {
"lang": "rust",
"repo": "fudanchii/rust",
"path": "/exercises/leap/tests/leap.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let incorrect_years = (1600..1700)
.filter(|&year| leap::is_leap_year(year) != (year % 4 == 0))
.collect::<Vec<_>>();
if !incorrect_years.is_empty() {
panic!("incorrect result for years: {:?}", incorrect_years);
}
}<|fim_prefix|>// repo: fudanchii/rust path: /exercise... | code_fim | hard | {
"lang": "rust",
"repo": "fudanchii/rust",
"path": "/exercises/leap/tests/leap.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(leap::is_leap_year(1600), true);
assert_eq!(leap::is_leap_year(2000), true);
assert_eq!(leap::is_leap_year(2400), true);
}
#[test]
#[ignore]
fn test_years_1600_to_1699() {
let incorrect_years = (1600..1700)
.filter(|&year| leap::is_leap_year(year) != (year % 4 == 0))
... | code_fim | medium | {
"lang": "rust",
"repo": "fudanchii/rust",
"path": "/exercises/leap/tests/leap.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> match ram_size {
0x01 => RamSize::KBYTES_2,
0x02 => RamSize::KBYTES_8,
0x03 => RamSize::KBYTES_32,
0x04 => RamSize::KBYTES_128,
0x05 => RamSize::KBYTES_64,
_ => RamSize::NONE,
}
}
}<|fim_prefix|>// repo: pkmn-api/p... | code_fim | hard | {
"lang": "rust",
"repo": "pkmn-api/pkmnapi",
"path": "/pkmnapi-db/src/header/ram_size.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: pkmn-api/pkmnapi path: /pkmnapi-db/src/header/ram_size.rs
/// RAM size
///
/// # Example
///
/// ```
/// use pkmnapi_db::header::*;
///
/// let size = RamSize::KBYTES_32;
/// ```
#[derive(Debug, PartialEq)]
#[allow(non_camel_case_types)]
pub enum RamSize {
NONE,
KBYTES_2,
KBYTES_8,
... | code_fim | hard | {
"lang": "rust",
"repo": "pkmn-api/pkmnapi",
"path": "/pkmnapi-db/src/header/ram_size.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[command]
#[description = "Replies with whatever is passed to it as an argument"]
fn say(ctx: &mut Context, msg: &Message, args: Args) -> CommandResult {
msg.reply(&ctx, args.rest())?;
Ok(())
}<|fim_prefix|>// repo: LeonKeithFranco/KippyBot path: /src/commands/general.rs
use serenity::{
fram... | code_fim | hard | {
"lang": "rust",
"repo": "LeonKeithFranco/KippyBot",
"path": "/src/commands/general.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: LeonKeithFranco/KippyBot path: /src/commands/general.rs
use serenity::{
framework::standard::{
help_commands,
macros::{command, group, help},
Args, CommandGroup, CommandResult, HelpOptions,
},
model::{channel::Message, id::UserId},
prelude::*,
};
use std::... | code_fim | medium | {
"lang": "rust",
"repo": "LeonKeithFranco/KippyBot",
"path": "/src/commands/general.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[group]
#[commands(bark, say)]
#[description = "General commands"]
struct General;
#[command]
#[description = "Make the bot woof"]
fn bark(ctx: &mut Context, msg: &Message) -> CommandResult {
let init_msg = "wooooooooooooooooooooooooooof";
let mut bot_msg = msg.channel_id.say(&ctx.http, init_msg... | code_fim | hard | {
"lang": "rust",
"repo": "LeonKeithFranco/KippyBot",
"path": "/src/commands/general.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: DominicWrege/elenco path: /src/my_middleware/moderator.rs
use std::{
cell::RefCell,
pin::Pin,
rc::Rc,
task::{Context, Poll},
};
use actix_session::UserSession;
use actix_web::dev::{Service, ServiceRequest, ServiceResponse};
use actix_web::Error;
use actix_web::Result;
use actix_... | code_fim | hard | {
"lang": "rust",
"repo": "DominicWrege/elenco",
"path": "/src/my_middleware/moderator.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let srv = self.service.clone();
use crate::db::is_moderator;
Box::pin(async move {
let state = req
.app_data::<web::Data<crate::State>>()
.ok_or_else(|| log_error(anyhow!("State error")))?;
let db = &state.db_pool;
... | code_fim | hard | {
"lang": "rust",
"repo": "DominicWrege/elenco",
"path": "/src/my_middleware/moderator.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> if is_moderator(&client, user_id).await? {
srv.call(req).await
} else {
log::warn!("User has no permission to access the moderator site.");
Err(Error::from(ApiError::Forbidden))
}
})
}
}<|fim_prefix|>// repo: ... | code_fim | hard | {
"lang": "rust",
"repo": "DominicWrege/elenco",
"path": "/src/my_middleware/moderator.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: stm32-rs/stm32l0xx-hal path: /src/rng.rs
use crate::rcc::{Enable, Rcc, Reset, HSI48};
pub use crate::pac::{rng, RNG};
pub struct Rng {
rng: RNG,
}
impl Rng {
// Initializes the peripheral
pub fn new(rng: RNG, rcc: &mut Rcc, _: HSI48) -> Rng {
// Enable peripheral clock
... | code_fim | hard | {
"lang": "rust",
"repo": "stm32-rs/stm32l0xx-hal",
"path": "/src/rng.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn wait(&mut self) {
while self.rng.sr.read().drdy().bit_is_clear() {}
}
pub fn take_result(&mut self) -> u32 {
self.rng.dr.read().bits()
}
}<|fim_prefix|>// repo: stm32-rs/stm32l0xx-hal path: /src/rng.rs
use crate::rcc::{Enable, Rcc, Reset, HSI48};
pub use crate::pa... | code_fim | medium | {
"lang": "rust",
"repo": "stm32-rs/stm32l0xx-hal",
"path": "/src/rng.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[test]
pub fn metroid_header(){
let mut cartridge = Cartridge::new();
cartridge.load(load_mario());
println!("{}",cartridge.header);
}
#[test]
pub fn test_mapper1_read(){
let mut cartridge = Cartridge::new();
cartridge.load(load_mario());
assert_eq!(cartridge.prg_memory[0], car... | code_fim | hard | {
"lang": "rust",
"repo": "ykafia/Nes-Emulator-Rust",
"path": "/src/test/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ykafia/Nes-Emulator-Rust path: /src/test/mod.rs
use console::Term;
use std::fs::File;
use std::io;
use std::io::prelude::*;
use super::*;
pub fn test_cpu(cpu: &mut CPU6502, nes: &mut NesData, depth: Option<usize>) {
let dpth = match depth {
Some(x) => x,
None => 8,
};
... | code_fim | hard | {
"lang": "rust",
"repo": "ykafia/Nes-Emulator-Rust",
"path": "/src/test/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> expected: ExpectedStatus,
actual: &JsonValue,
error: PiHoleError,
) -> PiholeResult {
if actual == &JsonValue::from(expected.as_str()) {
Ok(())
} else {
Err(error)
}
}<|fim_prefix|>// repo: uyefe/pihole-switch path: /src/pihole/mod.rs
use serde_json::Value as JsonV... | code_fim | hard | {
"lang": "rust",
"repo": "uyefe/pihole-switch",
"path": "/src/pihole/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: uyefe/pihole-switch path: /src/pihole/mod.rs
use serde_json::Value as JsonValue;
use crate::pihole::config::PiHoleConfig;
use crate::pihole::disable_time::PiHoleDisableTime;
use crate::pihole::error::PiHoleError;
pub mod config;
pub mod disable_time;
pub mod error;
mod request;
enum ExpectedS... | code_fim | hard | {
"lang": "rust",
"repo": "uyefe/pihole-switch",
"path": "/src/pihole/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // // Open the image
let img = photon_rs::native::open_image(file_name)?;
let start = time::Instant::now();
// Seam Carver
let (w, h) = (img.get_width(), img.get_height());
println!("original = w: {}, h: {}", w, h);
let w = w - 60;
let h = h - 10;
let res = photon_rs::t... | code_fim | medium | {
"lang": "rust",
"repo": "silvia-odwyer/photon",
"path": "/crate/examples/seam_carver.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Write the contents of this image in JPEG format.
photon_rs::native::save_image(res, "output_seam_carver.jpg")?;
let end = time::Instant::now();
println!(
"Took {} seconds to seam carve image.",
(end - start).as_seconds_f64()
);
Ok(())
}<|fim_prefix|>// repo: sil... | code_fim | hard | {
"lang": "rust",
"repo": "silvia-odwyer/photon",
"path": "/crate/examples/seam_carver.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: silvia-odwyer/photon path: /crate/examples/seam_carver.rs
extern crate image;
extern crate photon_rs;
extern crate time;
fn main() -> Result<(), Box<dyn std::error::Error>> {
<|fim_suffix|> // Write the contents of this image in JPEG format.
photon_rs::native::save_image(res, "output_sea... | code_fim | hard | {
"lang": "rust",
"repo": "silvia-odwyer/photon",
"path": "/crate/examples/seam_carver.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: oxidecomputer/third-party-api-clients path: /zoom/src/contacts.rs
lt;
pub struct Contacts {
pub client: Client,
}
impl Contacts {
#[doc(hidden)]
pub fn new(client: Client) -> Self {
Contacts { client }
}
/**
* Search company contacts.
*
* This functi... | code_fim | hard | {
"lang": "rust",
"repo": "oxidecomputer/third-party-api-clients",
"path": "/zoom/src/contacts.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: oxidecomputer/third-party-api-clients path: /zoom/src/contacts.rs
crate::ClientResult;
pub struct Contacts {
pub client: Client,
}
impl Contacts {
#[doc(hidden)]
pub fn new(client: Client) -> Self {
Contacts { client }
}
/**
* Search company contacts.
*
... | code_fim | hard | {
"lang": "rust",
"repo": "oxidecomputer/third-party-api-clients",
"path": "/zoom/src/contacts.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut contacts = body.contacts;
let mut page = body.next_page_token;
// Paginate if we should.
while !page.is_empty() {
// Check if we already have URL params and need to concat the token.
if !url.contains('?') {
crate::Response::<... | code_fim | hard | {
"lang": "rust",
"repo": "oxidecomputer/third-party-api-clients",
"path": "/zoom/src/contacts.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.size = size;
self
}
/// Get the size of the icmp_v4 packet.
pub fn get_size(&self) -> usize {
self.size
}
fn real_dest(&mut self, addr: Ipv4Addr) -> &mut Self {
self.real_dest = addr;
self
}
/// If it is an `echo_reply` packet, it... | code_fim | hard | {
"lang": "rust",
"repo": "wladwm/surge-ping",
"path": "/src/icmp/icmpv4.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: wladwm/surge-ping path: /src/icmp/icmpv4.rs
use std::convert::TryInto;
use std::net::Ipv4Addr;
use pnet_packet::icmp::{self, IcmpCode, IcmpType};
use pnet_packet::Packet;
use pnet_packet::{ipv4, PacketSize};
use crate::error::{MalformedPacketError, Result, SurgeError};
pub fn make_icmpv4_echo... | code_fim | hard | {
"lang": "rust",
"repo": "wladwm/surge-ping",
"path": "/src/icmp/icmpv4.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: novel-archives/novel-archives path: /kernel/backend/src/domains/models/novels/novel.rs
use super::*;
#[derive(PartialEq)]
pub struct NovelTitle(String);
#[derive(Entity, new, Getters)]
pu<|fim_suffix|>Title,
order: Order,
parts: Vec<Id<Part>>,
}<|fim_middle|>b struct Novel {
id: Id... | code_fim | easy | {
"lang": "rust",
"repo": "novel-archives/novel-archives",
"path": "/kernel/backend/src/domains/models/novels/novel.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>Title,
order: Order,
parts: Vec<Id<Part>>,
}<|fim_prefix|>// repo: novel-archives/novel-archives path: /kernel/backend/src/domains/models/novels/novel.rs
use super::*;
#[derive(PartialEq)]
pub struct Nove<|fim_middle|>lTitle(String);
#[derive(Entity, new, Getters)]
pub struct Novel {
id: Id... | code_fim | medium | {
"lang": "rust",
"repo": "novel-archives/novel-archives",
"path": "/kernel/backend/src/domains/models/novels/novel.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>}
#[test]
fn test1() {
assert_eq!(report_repair(&[1721, 979, 366, 299, 675, 1456]), 514579);
}
#[test]
fn test2() {
assert_eq!(report_repair2(&[1721, 979, 366, 299, 675, 1456]), 241861950);
}<|fim_prefix|>// repo: GameRuiner/adventofcode path: /src/day1.rs
#[allow(dead_code)]
pub fn report_rep... | code_fim | hard | {
"lang": "rust",
"repo": "GameRuiner/adventofcode",
"path": "/src/day1.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: GameRuiner/adventofcode path: /src/day1.rs
#[allow(dead_code)]
pub fn report_repair(report: &[i32]) -> i32 {
let mut res = 0;
for x in report {
for y in report {
if *x+*y == 2020 {
res = (*x)*(*y);
} else {
continue;
... | code_fim | hard | {
"lang": "rust",
"repo": "GameRuiner/adventofcode",
"path": "/src/day1.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: venil7/rust-raytracer path: /src/raytracer.rs
use crate::color::Color;
use crate::scene::Intersection;
use crate::scene::Item;
use crate::scene::Ray;
use crate::scene::Scene;
use crate::vector::Vector;
const MAX_DEPTH: u8 = 5;
pub struct Raytracer;
impl Raytracer {
pub fn intersections(&self... | code_fim | hard | {
"lang": "rust",
"repo": "venil7/rust-raytracer",
"path": "/src/raytracer.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> &self,
item: &dyn Item,
pos: &Vector,
// norm: &Vector,
reflect_dir: &Vector,
scene: &Scene,
depth: u8,
) -> Color {
let surface = item.surface();
let factor = surface.reflect(pos);
let color = self.trace_ray(
&Ray {
start: *pos,
dir: *reflec... | code_fim | hard | {
"lang": "rust",
"repo": "venil7/rust-raytracer",
"path": "/src/raytracer.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let edit_form = goose_eggs::drupal::get_form(&edit_page, "node-article-edit-form");
let form_build_id = goose_eggs::drupal::get_form_value(&edit_form, "form_build_id");
let form_token = goose_eggs::drupal::get_form_value(&edit_form, "form_token");
let form_id = goose_eggs::drupal::get_form... | code_fim | hard | {
"lang": "rust",
"repo": "jeremyandrews/goose-eggs",
"path": "/examples/umami/admin.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jeremyandrews/goose-eggs path: /examples/umami/admin.rs
use goose::prelude::*;
use crate::common;
use rand::seq::SliceRandom;
use std::env;
/// Log into the website.
pub async fn log_in(user: &mut GooseUser) -> GooseTaskResult {
// Use ADMIN_USERNAME= to set custom admin username.
let... | code_fim | hard | {
"lang": "rust",
"repo": "jeremyandrews/goose-eggs",
"path": "/examples/umami/admin.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl TryFrom<Node> for NamedRelay {
type Error = syn::Error;
fn try_from(node: Node) -> Result<Self, Self::Error> {
let name_span = node.name_span().unwrap_or(Span::call_site());
match &node.node_type {
NodeType::Element => match node.name_as_string() {
... | code_fim | hard | {
"lang": "rust",
"repo": "RustWorks/mogwai",
"path": "/crates/mogwai-html-macro/src/relay.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: RustWorks/mogwai path: /crates/mogwai-html-macro/src/relay.rs
pub struct RelayInput {
pub msg_type: syn::Expr,
pub name: syn::Ident,
}
impl RelayInput {
/// The name of this input as it appears in a relay struct field definition.
pub fn struct_field_name(&self) -> syn::Ident {
... | code_fim | hard | {
"lang": "rust",
"repo": "RustWorks/mogwai",
"path": "/crates/mogwai-html-macro/src/relay.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> quote! {
#[derive(Clone)]
struct #name<T: mogwai::event::Eventable> {
inner: mogwai::prelude::Either<mogwai::channel::broadcast::Receiver<T>, T>,
#(#struct_field_defs,)*
}
}
}
///// Produces an implementation defi... | code_fim | hard | {
"lang": "rust",
"repo": "RustWorks/mogwai",
"path": "/crates/mogwai-html-macro/src/relay.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>mut px::Engine| {
game.clear(px::Color::WHITE);
game.draw_circle((25, 25), 25, px::Color::BLACK);
game.fill_circle((25, 25), 12, px::Color::BLUE);
Ok(true)
});
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen)]
pub fn circle() {
px::launch(init())
}<|fim_prefix|>/... | code_fim | medium | {
"lang": "rust",
"repo": "Maix0/pixel_engine",
"path": "/examples/simple/src/circle.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Maix0/pixel_engine path: /examples/simple/src/circle.rs
extern crate pixel_engine as px;
use px::traits::*;
#[cfg(target_arch = "wasm32")]
extern crate wasm_bindgen;
#[cfg(target_arch = "wasm32")]
use<|fim_suffix|>mut px::Engine| {
game.clear(px::Color::WHITE);
game.draw_circle(... | code_fim | medium | {
"lang": "rust",
"repo": "Maix0/pixel_engine",
"path": "/examples/simple/src/circle.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>5), 12, px::Color::BLUE);
Ok(true)
});
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen)]
pub fn circle() {
px::launch(init())
}<|fim_prefix|>// repo: Maix0/pixel_engine path: /examples/simple/src/circle.rs
extern crate pixel_engine as px;
use px::traits::*;
#[cfg(target_arch = "wasm32... | code_fim | hard | {
"lang": "rust",
"repo": "Maix0/pixel_engine",
"path": "/examples/simple/src/circle.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Azure/azure-sdk-for-rust path: /services/autorust/openapi/src/operation.rs
use crate::*;
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
/// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#operation-object
#[derive(Clone, Debug, Deserialize, Serialize, Part... | code_fim | hard | {
"lang": "rust",
"repo": "Azure/azure-sdk-for-rust",
"path": "/services/autorust/openapi/src/operation.rs",
"mode": "psm",
"license": "LicenseRef-scancode-generic-cla",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[serde(rename = "externalDocs", skip_serializing_if = "Option::is_none")]
pub external_docs: Option<ExternalDocumentation>,
/// A reference to the definition that describes object used in the odata filter
#[serde(rename = "x-ms-odata", skip_serializing_if = "Option::is_none")]
pub x_... | code_fim | hard | {
"lang": "rust",
"repo": "Azure/azure-sdk-for-rust",
"path": "/services/autorust/openapi/src/operation.rs",
"mode": "spm",
"license": "LicenseRef-scancode-generic-cla",
"source": "the-stack-v2"
} |
<|fim_suffix|> let state = State::new(DebugRenderer::new());
let command = blank_command();
state
.default_key_map
.lock()
.bind(vec![kbd("a"), kbd("b")], command.clone());
state
.default_key_map
.lock()
.map(vec![kbd... | code_fim | hard | {
"lang": "rust",
"repo": "czipperz/ted",
"path": "/ted_core/src/state.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: czipperz/ted path: /ted_core/src/state.rs
use command::*;
use display::Display;
use input::*;
use insert_command::insert_command;
use key_map::*;
use logger::log;
use mode::*;
use parking_lot::Mutex;
use renderer::Renderer;
use std::collections::VecDeque;
use std::sync::Arc;
use window::Window;
... | code_fim | hard | {
"lang": "rust",
"repo": "czipperz/ted",
"path": "/ted_core/src/state.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let state = Arc::new(Mutex::new(State::new(DebugRenderer::new())));
let insert = state.lock().lookup(&mut vec![kbd("a")].into()).unwrap();
insert.execute(state.clone()).unwrap();
let buffer = state.lock().display.selected_window_buffer();
assert_eq!(buffer.lock().to... | code_fim | hard | {
"lang": "rust",
"repo": "czipperz/ted",
"path": "/ted_core/src/state.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>use serde_derive::Serialize;
/// Latitude and longitude in degrees.
#[derive(Clone, Copy, Debug, PartialEq, Serialize)]
pub struct Coordinates {
pub latitude: f64,
pub longitude: f64,
}<|fim_prefix|>// repo: stephaneyfx/geocode-rs path: /src/lib.rs
// Copyright (C) 2018 Stephane Raux. Distribute... | code_fim | medium | {
"lang": "rust",
"repo": "stephaneyfx/geocode-rs",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: stephaneyfx/geocode-rs path: /src/lib.rs
// Copyright (C) 2018 Stephane Raux. Distributed under the MIT license.
<|fim_suffix|>use serde_derive::Serialize;
/// Latitude and longitude in degrees.
#[derive(Clone, Copy, Debug, PartialEq, Serialize)]
pub struct Coordinates {
pub latitude: f64,... | code_fim | hard | {
"lang": "rust",
"repo": "stephaneyfx/geocode-rs",
"path": "/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: anowell/pam-rs path: /pam/src/module.rs
//! Functions for use in pam modules.
use libc::c_char;
use std::ffi::{CStr, CString};
use constants::{PamFlag, PamResultCode};
/// Opaque type, used as a pointer when making pam API calls.
///
/// A module is invoked via an external function such as `p... | code_fim | hard | {
"lang": "rust",
"repo": "anowell/pam-rs",
"path": "/pam/src/module.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub extern "C" fn cleanup<T>(_: *const PamHandle, c_data: *mut libc::c_void, _: PamResultCode) {
unsafe {
let _data: Box<T> = Box::from_raw(c_data.cast::<T>());
}
}
pub type PamResult<T> = Result<T, PamResultCode>;
impl PamHandle {
/// Gets some value, identified by `key`, that has b... | code_fim | hard | {
"lang": "rust",
"repo": "anowell/pam-rs",
"path": "/pam/src/module.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: cithiLoe/exercism path: /rust/acronym/src/lib.rs
pub fn abbreviate(phrase: &str) -> String {
phrase
.split(|c: char| !c.is_alphanumeric())
.filter(|word| !word.is_empty())
.flat_map(|word| {<|fim_suffix|> .filter(|c| c.is_uppercase())
... | code_fim | hard | {
"lang": "rust",
"repo": "cithiLoe/exercism",
"path": "/rust/acronym/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> .filter(|c| c.is_uppercase())
.collect::<Vec<_>>()
}
})
.collect::<String>()
.to_uppercase()
}<|fim_prefix|>// repo: cithiLoe/exercism path: /rust/acronym/src/lib.rs
pub fn abbreviate(phrase: &str) -> String {
phrase
... | code_fim | hard | {
"lang": "rust",
"repo": "cithiLoe/exercism",
"path": "/rust/acronym/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(
metadata_file_exists,
Metadata {
foo: "Metadata from file",
do_bar: true,
baz_count: 42 * 42
}
);
assert_eq!(metadata_file_missing, DEFAULT_METADATA);
}<|fim_prefix|>// repo: lyricwulf/include_optional path: /examples/inc... | code_fim | hard | {
"lang": "rust",
"repo": "lyricwulf/include_optional",
"path": "/examples/include_optional.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: lyricwulf/include_optional path: /examples/include_optional.rs
use include_optional::include_optional;
#[derive(Debug, Copy, Clone, PartialEq)]
struct Metadata {
foo: &'static str,
do_bar: bool,
baz_count: u32,
}
<|fim_suffix|>fn main() {
let metadata_file_exists: Metadata =
... | code_fim | medium | {
"lang": "rust",
"repo": "lyricwulf/include_optional",
"path": "/examples/include_optional.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> {}.",
self.name, self.age, self.is_student
)
}
}<|fim_prefix|>// repo: jens1o/rust-api path: /src/model/user.rs
#[derive(FromForm)]
pub struct User {
name: String,
age: u8,
is_student: bool,
}
impl User {
pub fn greet(&self) -> String {
<|fim_middle|> form... | code_fim | medium | {
"lang": "rust",
"repo": "jens1o/rust-api",
"path": "/src/model/user.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jens1o/rust-api path: /src/model/user.rs
#[derive(FromForm)]
pub struct User {
name: String,
age: u8,
<|fim_suffix|> format!(
"Hello, I'm {} and {} years old! I'm a student: {}.",
self.name, self.age, self.is_student
)
}
}<|fim_middle|> is_stude... | code_fim | medium | {
"lang": "rust",
"repo": "jens1o/rust-api",
"path": "/src/model/user.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub(crate) fn reject_message(&mut self, message_id: &MessageId, reason: &RejectReason) {
// A message got rejected, so we can stop tracking promises and let the score penalty apply
// from invalid message delivery.
// We do take exception and apply promise penalty regardless in... | code_fim | hard | {
"lang": "rust",
"repo": "libp2p/rust-libp2p",
"path": "/protocols/gossipsub/src/gossip_promises.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Track a promise to deliver a message from a list of [`MessageId`]s we are requesting.
pub(crate) fn add_promise(&mut self, peer: PeerId, messages: &[MessageId], expires: Instant) {
for message_id in messages {
// If a promise for this message id and peer already exists we d... | code_fim | hard | {
"lang": "rust",
"repo": "libp2p/rust-libp2p",
"path": "/protocols/gossipsub/src/gossip_promises.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: libp2p/rust-libp2p path: /protocols/gossipsub/src/gossip_promises.rs
// Copyright 2020 Sigma Prime Pty Ltd.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software witho... | code_fim | hard | {
"lang": "rust",
"repo": "libp2p/rust-libp2p",
"path": "/protocols/gossipsub/src/gossip_promises.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: winksaville/fuchsia path: /garnet/public/rust/fuchsia-vfs/pseudo-fs/src/directory/connection.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.
use crate::{common::send_on_open_wi... | code_fim | hard | {
"lang": "rust",
"repo": "winksaville/fuchsia",
"path": "/garnet/public/rust/fuchsia-vfs/pseudo-fs/src/directory/connection.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Seek position for this connection to the directory. We just store the element that was
/// returned last by ReadDirents for this connection. Next call will look for the next element
/// in alphabetical order and resume from there.
///
/// An alternative is to use an intrusive tre... | code_fim | hard | {
"lang": "rust",
"repo": "winksaville/fuchsia",
"path": "/garnet/public/rust/fuchsia-vfs/pseudo-fs/src/directory/connection.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: thespis-rs/thespis_remote path: /src/service_map_macro.rs
} ,
thespis_impl :: { Addr, Receiver, ThesErr, ThesRes } ,
serde_cbor :: { self, from_slice as des } ,
serde :: { Serialize, Deserialize, de::Deseri... | code_fim | hard | {
"lang": "rust",
"repo": "thespis-rs/thespis_remote",
"path": "/src/service_map_macro.rs",
"mode": "psm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_suffix|> {
let sid = <S as Service>::sid().clone();
// Deserialize the message.
//
let message: S = match des( &msg.mesg() )
{
Ok(x) => x,
Err(_) =>
{
let ctx = Peer::err_ctx( &peer, sid.clone(), msg.conn_id(), "Actor message while processing call for local Actor".to_string() );
retu... | code_fim | hard | {
"lang": "rust",
"repo": "thespis-rs/thespis_remote",
"path": "/src/service_map_macro.rs",
"mode": "spm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: thespis-rs/thespis_remote path: /src/service_map_macro.rs
it from const code so it has no runtime
/// overhead.
///
/// For a given Service and Namespace, the output should always be the same, even accross processes
/// compiled with different versions of rustc. Ideally the algorithm is also... | code_fim | hard | {
"lang": "rust",
"repo": "thespis-rs/thespis_remote",
"path": "/src/service_map_macro.rs",
"mode": "psm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: purposed/rood path: /src/lib.rs
/// Useful functionality for command-line interfaces.
///
/// Features CLI prompts, colored & stacked outputs.
#[cfg(feature = "cli")]
pub mod cli;
<|fim_suffix|>#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}<|fim_m... | code_fim | medium | {
"lang": "rust",
"repo": "purposed/rood",
"path": "/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn set_name(&mut self, name: &str) {
self.name = name.to_string()
}
pub fn set_model(&mut self, model: sfml::graphics::Sprite<'a>) {
self.model = Box::new(model)
}
pub fn set_hidden(&mut self, hidden: bool) {
self.hidden = hidden;
}
pub fn is_hidd... | code_fim | hard | {
"lang": "rust",
"repo": "Borderliner/platformer-rust",
"path": "/src/containers/model.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Borderliner/platformer-rust path: /src/containers/model.rs
extern crate sfml;
use std::boxed::Box;
use std::fmt;
pub struct Model<'a> {
pub name: String,
pub model: Box<sfml::graphics::Sprite<'a>>,
pub hidden: bool
}
<|fim_suffix|> pub fn set_hidden(&mut self, hidden: bool) {
... | code_fim | hard | {
"lang": "rust",
"repo": "Borderliner/platformer-rust",
"path": "/src/containers/model.rs",
"mode": "psm",
"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.