text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_prefix|>// repo: Arios16/tiberius path: /src/tds/time/chrono.rs
//! Mappings between TDS and and Chrono types (with `chrono` feature flag
//! enabled).
//!
//! The chrono library offers better ergonomy and are highly recommended if
//! needing to modify and deal with date and time in SQL Server.
#[cfg(not(featu... | code_fim | hard | {
"lang": "rust",
"repo": "Arios16/tiberius",
"path": "/src/tds/time/chrono.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let date = Date::new(to_days(naive.date(), 1) as u32);
let time = Time {increments: nanos / 100, scale: 7};
DateTimeOffset::new(DateTime2::new(date, time), 0)
});
chrono::DateTime<FixedOffset>: (ColumnData::DateTimeOffset, {
use chrono::Time... | code_fim | hard | {
"lang": "rust",
"repo": "Arios16/tiberius",
"path": "/src/tds/time/chrono.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: lrs-lang/examples path: /src/fork.rs
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
<|fim_suffix|> let pid = fork(|| {
let mut bu... | code_fim | medium | {
"lang": "rust",
"repo": "lrs-lang/examples",
"path": "/src/fork.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let pid = fork(|| {
let mut buf = [0; 1024];
let mut args = CPtrPtr::buffered(&mut buf);
args.push("echo").unwrap();
args.push("hello").unwrap();
args.push("world").unwrap();
let args = args.finish().unwrap();
if let Err(e) = exec("echo", args) {... | code_fim | medium | {
"lang": "rust",
"repo": "lrs-lang/examples",
"path": "/src/fork.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: cryptape/sleepy path: /crypto/src/keypair.rs
use std::fmt;
use secp256k1::key;
use rustc_serialize::hex::ToHex;
use super::{PrivKey, PubKey, Address, SECP256K1, Error};
use util::hash::{H160, H256};
use sha3::sha3_256;
pub fn pubkey_to_address(pubkey: &PubKey) -> Address {
let mut hash: H25... | code_fim | hard | {
"lang": "rust",
"repo": "cryptape/sleepy",
"path": "/crypto/src/keypair.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn privkey(&self) -> &PrivKey {
&self.privkey
}
pub fn pubkey(&self) -> &PubKey {
&self.pubkey
}
pub fn address(&self) -> Address {
pubkey_to_address(&self.pubkey)
}
}
#[cfg(test)]
mod tests {
use std::str::FromStr;
use super::{KeyPair, PrivKe... | code_fim | hard | {
"lang": "rust",
"repo": "cryptape/sleepy",
"path": "/crypto/src/keypair.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let expected =
"privkey: a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65\npubkey: 8ce0db0b0359ffc5866ba61903cc2518c3675ef2cf380a7e54bde7ea20e6fa1ab45b7617346cd11b7610001ee6ae5b0155c41cad9527cbcdff44ec67848943a4\naddress: 5b073e9233944b5e729e46d618f0d8edf3d9c34a".to_owned();... | code_fim | hard | {
"lang": "rust",
"repo": "cryptape/sleepy",
"path": "/crypto/src/keypair.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn dynamic_result_f32(call_handle: DOMReference) -> f32;
fn dynamic_result_f64(call_handle: DOMReference) -> f64;
fn dynamic_result_cstring(call_handle: DOMReference) -> CString;
fn dynamic_result_memory(call_handle: DOMReference) -> i32;
fn dynamic_result_memory_len(call_handle: DOMRe... | code_fim | hard | {
"lang": "rust",
"repo": "kmat1984/web-dom",
"path": "/src/dynamic.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: kmat1984/web-dom path: /src/dynamic.rs
use alloc::string::String;
#[allow(unused_imports)]
use crate::*;
extern "C" {
fn dynamic_load(value: CString, listener: DOMReference);
fn dynamic_unload(dynamic_handle: DOMReference);
fn dynamic_begin(dynamic_handle: DOMReference) -> DOMRefere... | code_fim | hard | {
"lang": "rust",
"repo": "kmat1984/web-dom",
"path": "/src/dynamic.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut f = File::open("data/day06/input").context(Io)?;
let groups_2 = parse_groups(&mut f, GroupMode::Intersection)?;
println!(
"Question count {} union, {} intersection",
groups_1.iter().map(|g| g.len()).sum::<usize>(),
groups_2.iter().map(|g| g.len()).sum::<usize>(... | code_fim | hard | {
"lang": "rust",
"repo": "sseemayer/aoc2020",
"path": "/src/bin/day06.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: sseemayer/aoc2020 path: /src/bin/day06.rs
use bit_set::BitSet;
use snafu::{ResultExt, Snafu};
use std::fs::File;
use std::io::{BufRead, BufReader, Read};
#[derive(Debug, Snafu)]
enum Error {
#[snafu(display("I/O error: {}", source))]
Io { source: std::io::Error },
}
type Result<T> = st... | code_fim | hard | {
"lang": "rust",
"repo": "sseemayer/aoc2020",
"path": "/src/bin/day06.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let data = "aabbc\nadg\n\nfh";
assert_eq!(
parse_groups(&mut data.as_bytes(), GroupMode::Union).unwrap(),
vec![
BitSet::from_bytes(&[0b11110010]),
BitSet::from_bytes(&[0b00000101]),
]
);
assert_eq!(
... | code_fim | hard | {
"lang": "rust",
"repo": "sseemayer/aoc2020",
"path": "/src/bin/day06.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Lookup in L1 to find the right LowerBlock
let i = std::cmp::min(n, l1l2s.len() - 1);
let j = std::cmp::min(m, l1l2s.len());
let l1l2_index = num::binary_search(i, j, |k| remain < l1l2s[k].l1()) - 1;
let l1l2 = l1l2s[l1l2_index];
l... | code_fim | hard | {
"lang": "rust",
"repo": "mypmc/compacts",
"path": "/src/bits/bit_array.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mypmc/compacts path: /src/bits/bit_array.rs
#![allow(missing_docs)]
use std::ops::RangeBounds;
use crate::{
bits::Words,
num::{self, cast, Int, Word},
ops::*,
};
/// An immutable and uncompressed bit sequence.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct BitArray<T> {
... | code_fim | hard | {
"lang": "rust",
"repo": "mypmc/compacts",
"path": "/src/bits/bit_array.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> match super::to_exclusive(&range, self.size()).expect("out of bounds") {
(0, k) => rank(k),
(i, j) => rank(j) - rank(i),
}
}
fn select1(&self, nth: usize) -> Option<usize> {
if nth >= self.count1() {
return None;
};
let ... | code_fim | hard | {
"lang": "rust",
"repo": "mypmc/compacts",
"path": "/src/bits/bit_array.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: slyedoc/bevy_manim path: /src/draw/drawing.rs
use crate::core::{Indices, Color, Vertex, PackedAnimation, AnimationKind};
use bevy::render::mesh::Mesh;
use bevy::render::pipeline::PrimitiveTopology;
#[derive(Debug, Clone)]
pub struct Tessellation
{
pub vertices: Vec<Vertex>,
pub indices:... | code_fim | hard | {
"lang": "rust",
"repo": "slyedoc/bevy_manim",
"path": "/src/draw/drawing.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn get_mesh(&self) -> Mesh
{
let tessellation = self.get_tessellation();
let mut mesh = Mesh::new(PrimitiveTopology::TriangleList);
mesh.set_attribute(Mesh::ATTRIBUTE_POSITION, tessellation.vertices);
mesh.set_attribute(Mesh::ATTRIBUTE_COLOR, tessellation.colors);
... | code_fim | hard | {
"lang": "rust",
"repo": "slyedoc/bevy_manim",
"path": "/src/draw/drawing.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_send_sync(Global::new());
assert_send_sync(Global::with_pool(Foo))
}<|fim_prefix|>// repo: RustyYato/pui-old path: /tests/compile_fail/thread_local/runtime_thread_local 3.rs
use pui::runtime::{Global, GlobalId};
pui::make_global_pool! {
thread_local one Foo(GlobalId);
}
fn main() {
<... | code_fim | easy | {
"lang": "rust",
"repo": "RustyYato/pui-old",
"path": "/tests/compile_fail/thread_local/runtime_thread_local 3.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: RustyYato/pui-old path: /tests/compile_fail/thread_local/runtime_thread_local 3.rs
use pui::runtime::{Global, GlobalId};
pui::make_global_pool! {
thread_local one Foo(GlobalId);
}
fn main() {
<|fim_suffix|> assert_send_sync(Global::new());
assert_send_sync(Global::with_pool(Foo))
}<... | code_fim | easy | {
"lang": "rust",
"repo": "RustyYato/pui-old",
"path": "/tests/compile_fail/thread_local/runtime_thread_local 3.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[inline]
pub fn convert(
&self,
mode_from: WritingMode,
mode_to: WritingMode,
container_size: Size2D<T>,
) -> LogicalRect<T> {
if mode_from == mode_to {
self.debug_writing_mode.check(mode_from);
*self
} else {
... | code_fim | hard | {
"lang": "rust",
"repo": "emilio/nglayoutng",
"path": "/nglayoutng/src/logical_geometry.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> write!(
formatter,
"LogicalMargin({}i:{:?}..{:?} b:{:?}..{:?})",
writing_mode_string,
self.inline_start,
self.inline_end,
self.block_start,
self.block_end
)
}
}
impl<T: Zero> LogicalMargin<T> {
#[i... | code_fim | hard | {
"lang": "rust",
"repo": "emilio/nglayoutng",
"path": "/nglayoutng/src/logical_geometry.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: emilio/nglayoutng path: /nglayoutng/src/logical_geometry.rs
pub fn new(mode: WritingMode, i: T, b: T) -> LogicalPoint<T> {
LogicalPoint {
i,
b,
debug_writing_mode: DebugWritingMode::new(mode),
}
}
}
impl<T: Copy + Sub<T, Output = T>> Logic... | code_fim | hard | {
"lang": "rust",
"repo": "emilio/nglayoutng",
"path": "/nglayoutng/src/logical_geometry.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: wasmerio/wasi-data-rust path: /crates/wasi-interface-gen/tests/sanity.rs
use wasi_interface_gen::wasi_interface;
#[wasi_interface]
mod foo {
struct Input {
s: String,
i: i64,
}
struct Output {
a: i64,
b: f64,
c: String,
}
<|fim_suffix|> ... | code_fim | easy | {
"lang": "rust",
"repo": "wasmerio/wasi-data-rust",
"path": "/crates/wasi-interface-gen/tests/sanity.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> vec![Output {
a: input.i * input.i,
b: (input.i as f64) * 123.234,
c: format!("hello {}", input.s),
}]
}
}
#[test]
fn sanity() {}<|fim_prefix|>// repo: wasmerio/wasi-data-rust path: /crates/wasi-interface-gen/tests/sanity.rs
use wasi_interface_gen:... | code_fim | medium | {
"lang": "rust",
"repo": "wasmerio/wasi-data-rust",
"path": "/crates/wasi-interface-gen/tests/sanity.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Lymphatus/libcaesium-rust path: /src/jpeg.rs
use mozjpeg::{Decompress, Compress, ALL_MARKERS, NO_MARKERS};
use std::fs::File;
use std::io::Write;
use std::{io, mem};
use mozjpeg_sys as mjs;
use crate::CSParameters;
use std::fs;
pub struct Parameters {
pub quality: u32,
}
pub fn compress(in... | code_fim | hard | {
"lang": "rust",
"repo": "Lymphatus/libcaesium-rust",
"path": "/src/jpeg.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> c_info.start_compress();
if parameters.keep_metadata {
markers.for_each(|marker| {
c_info.write_marker(marker.marker, marker.data);
});
}
let mut bitmaps = [&mut Vec::new(), &mut Vec::new(), &mut Vec::new()];
let mut d_info = decompress.raw()?;
d_info.... | code_fim | hard | {
"lang": "rust",
"repo": "Lymphatus/libcaesium-rust",
"path": "/src/jpeg.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: torkleyy/rocket_auth path: /src/db/sqlite/sql.rs
pub(crate) const CREATE_TABLE: &str = "
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY,
email TEXT UNIQUE,
password TEXT NOT NULL,
is_admin BOOL DEFAULT 0
-- failed_login_attempts INTEGER DEFAULT 0
);";
<|fim_suffi... | code_fim | hard | {
"lang": "rust",
"repo": "torkleyy/rocket_auth",
"path": "/src/db/sqlite/sql.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub(crate) const SELECT_BY_EMAIL: &str = "
SELECT * FROM users WHERE email = ?1;
";
pub(crate) const REMOVE_BY_ID: &str = "
DELETE FROM users WHERE id =?1;
";
pub(crate) const REMOVE_BY_EMAIL: &str = "
DELETE FROM users WHERE email =?1;
";<|fim_prefix|>// repo: torkleyy/rocket_auth path: /src/db/sqlite/... | code_fim | hard | {
"lang": "rust",
"repo": "torkleyy/rocket_auth",
"path": "/src/db/sqlite/sql.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: kernelgonnapanic/rust-fe-be path: /backend/src/models.rs
use serde::{Deserialize, Serialize};
use crate::schema::products;
#[derive(Debug, Clone, Serialize, Deseria<|fim_suffix|> "products"]
pub struct NewProduct {
pub name: String,
pub price: i32,
pub description: String,
}<|fim_mi... | code_fim | hard | {
"lang": "rust",
"repo": "kernelgonnapanic/rust-fe-be",
"path": "/backend/src/models.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> "products"]
pub struct NewProduct {
pub name: String,
pub price: i32,
pub description: String,
}<|fim_prefix|>// repo: kernelgonnapanic/rust-fe-be path: /backend/src/models.rs
use serde::{Deserialize, Serialize};
use crate::schema::products;
#[derive(Debug, Clone, Serialize, Deserialize, Qu... | code_fim | medium | {
"lang": "rust",
"repo": "kernelgonnapanic/rust-fe-be",
"path": "/backend/src/models.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> spec
}
pub fn to_string(&self) -> &'static str {
match self {
Severity::Bug => "bug",
Severity::Error => "error",
Severity::Warning => "warning",
Severity::Info => "info",
Severity::Help => "help",
}
... | code_fim | hard | {
"lang": "rust",
"repo": "Cyberduc-k/.crates",
"path": "/diagnostics/src/diagnostic.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Cyberduc-k/.crates path: /diagnostics/src/diagnostic.rs
use crate::Span;
#[derive(Debug)]
pub struct Diagnostic {
pub severity: Severity,
pub code: Option<u16>,
pub message: String,
pub labels: Vec<Label>,
}
#[derive(Debug)]
pub struct Label {
pub span: Option<S... | code_fim | hard | {
"lang": "rust",
"repo": "Cyberduc-k/.crates",
"path": "/diagnostics/src/diagnostic.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> use commands::Command;
for cmd in DynamicCommand::examples("USLACKBOT") {
if let Err(()) = cmd.parse::<DynamicCommand>() {
panic!("Failed to parse {:?}", cmd);
}
}
}<|fim_prefix|>// repo: remexre/tri path: /src/nlp/commands/mod.rs
mod add_task;
mod change_done;
mo... | code_fim | hard | {
"lang": "rust",
"repo": "remexre/tri",
"path": "/src/nlp/commands/mod.rs",
"mode": "spm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: remexre/tri path: /src/nlp/commands/mod.rs
mod add_task;
mod change_done;
mod change_due_date;
mod change_priority;
mod help;
mod list;
mod remind;
use std::str::FromStr;
use nom::IResult;
use commands::DynamicCommand;
use nlp::commands::add_task::parser as add_task;
use nlp::commands::change... | code_fim | hard | {
"lang": "rust",
"repo": "remexre/tri",
"path": "/src/nlp/commands/mod.rs",
"mode": "psm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: avnerbarr/gitignore.rs path: /src/repo.rs
use crate::ignore_file::*;
use failure::Error;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
pub struct Repo {
ignore_files: HashMap<PathBuf, IgnoreFile>
}
/// Given the path to a Git repository, load up all of the ignore files in ... | code_fim | hard | {
"lang": "rust",
"repo": "avnerbarr/gitignore.rs",
"path": "/src/repo.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>
assert!(repo.is_ignored("not_me.no", false));
assert!(repo.is_ignored("or_even_me", false));
assert!(repo.is_ignored("or_me.no", false));
assert!(repo.is_ignored("a_dir/a_nested_dir/deeper_still/hello.greeting", false));
assert!(repo.is_ignored("a_dir/a_nested_dir/... | code_fim | hard | {
"lang": "rust",
"repo": "avnerbarr/gitignore.rs",
"path": "/src/repo.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn push_state(&mut self) {
self.state.push(self.range.clone());
}
pub fn pop_state(&mut self) {
match self.state.pop() {
Some(r) => self.range = r,
None => self.reset(),
}
}
pub fn reset(&mut self) {
self.range = self.stage.range.clone();
self.state.clear();... | code_fim | hard | {
"lang": "rust",
"repo": "dopitz/vulkanism",
"path": "/nobs-vulkanism-headless/src/mem/staging.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dopitz/vulkanism path: /nobs-vulkanism-headless/src/mem/staging.rs
use crate::cmd::commands;
use crate::mem;
use crate::mem::Handle;
use vk;
use vk::builder::Buildable;
pub struct Staging {
range: StagingRange,
}
impl Drop for Staging {
fn drop(&mut self) {
self.range.mem.trash.push_bu... | code_fim | hard | {
"lang": "rust",
"repo": "dopitz/vulkanism",
"path": "/nobs-vulkanism-headless/src/mem/staging.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn pop_state(&mut self) {
match self.state.pop() {
Some(r) => self.range = r,
None => self.reset(),
}
}
pub fn reset(&mut self) {
self.range = self.stage.range.clone();
self.state.clear();
}
pub fn capacity(&self) -> vk::DeviceSize {
self.stage.range.size
... | code_fim | hard | {
"lang": "rust",
"repo": "dopitz/vulkanism",
"path": "/nobs-vulkanism-headless/src/mem/staging.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: peahonen/cv-rs path: /src/highgui.rs
//! highgui: high-level GUI
use failure::Error;
use std::ffi::CString;
use std::mem;
use std::os::raw::{c_char, c_int, c_void};
use std::ptr;
use mat::*;
extern "C" {
fn cv_named_window(name: *const c_char, flags: WindowFlag);
fn cv_destroy_window(na... | code_fim | hard | {
"lang": "rust",
"repo": "peahonen/cv-rs",
"path": "/src/highgui.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// Flags for [highgui_named_window](fn.highgui_named_window.html). This only
/// supports a subset of all cv::WindowFlags because C/C++ allows enum with the
/// same value but Rust is stricter.
#[repr(C)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub enum WindowFlag {
/// the window can be r... | code_fim | hard | {
"lang": "rust",
"repo": "peahonen/cv-rs",
"path": "/src/highgui.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let duration = Utc::now().signed_duration_since(date);
println!("You are {} years, {} months, {} days old", duration.num_days() / 365, duration.num_days() / 30, duration.num_days())
*/
}<|fim_prefix|>// repo: binaryoverload/rust-basics path: /challenge-5/src/main.rs
use std::convert::TryInt... | code_fim | hard | {
"lang": "rust",
"repo": "binaryoverload/rust-basics",
"path": "/challenge-5/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: binaryoverload/rust-basics path: /challenge-5/src/main.rs
use std::convert::TryInto;
use chrono::offset::TimeZone;
use chrono::{Utc, Date};
use promptly::prompt;
fn main() {
<|fim_suffix|> println!("You are {} years, {} months, {} days old", duration.num_days() / 365, duration.num_days() / 3... | code_fim | hard | {
"lang": "rust",
"repo": "binaryoverload/rust-basics",
"path": "/challenge-5/src/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> println!("You are {} years, {} months, {} days old", duration.num_days() / 365, duration.num_days() / 30, duration.num_days())
*/
}<|fim_prefix|>// repo: binaryoverload/rust-basics path: /challenge-5/src/main.rs
use std::convert::TryInto;
use chrono::offset::TimeZone;
use chrono::{Utc, Date};
us... | code_fim | hard | {
"lang": "rust",
"repo": "binaryoverload/rust-basics",
"path": "/challenge-5/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: akaukone/nrf51_blinky path: /src/timer.rs
extern crate nrf51;
use nrf51::Timer0;
#[derive(Clone, Copy)]
pub struct Timer<'a>(pub &'a Timer0);
impl<'a> Timer<'a> {
/// Initializes the timer with a periodic timeout of `frequency` Hz
//
// NOTE: After initialization, the timer will b... | code_fim | hard | {
"lang": "rust",
"repo": "akaukone/nrf51_blinky",
"path": "/src/timer.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.clear()
}
pub fn resume(&self) {
self.0.tasks_start.write(|w| unsafe { w.bits(1) });
}
pub fn pause(&self) {
self.0.tasks_stop.write(|w| unsafe { w.bits(1) });
}
pub fn clear(&self) {
self.0.tasks_clear.write(|w| unsafe { w.bits(1) });
}
... | code_fim | hard | {
"lang": "rust",
"repo": "akaukone/nrf51_blinky",
"path": "/src/timer.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: SplittyDev/spotify-rs path: /src/lib.rs
#![warn(missing_docs)]
//! The Spotify crate.
//!
//! This crate contains methods to retrieve information from
//! and manipulate the local Spotify client instance.
// Extern crates
extern crate json;
extern crate reqwest;
extern crate time;
extern crate ... | code_fim | hard | {
"lang": "rust",
"repo": "SplittyDev/spotify-rs",
"path": "/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// Fetches the current status from Spotify.
fn get_status(connector: &SpotifyConnector) -> Result<SpotifyStatus> {
match connector.fetch_status_json() {
Ok(result) => Ok(SpotifyStatus::from(result)),
Err(error) => Err(SpotifyError::InternalError(error)),
}
}
/// Implements `Spoti... | code_fim | hard | {
"lang": "rust",
"repo": "SplittyDev/spotify-rs",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>al) => $exec($($args,)* val),
TensorContent::QInt32(ref val) => $exec($($args,)* val),
TensorContent::BFloat16(ref val) => $exec($($args,)* val),
TensorContent::Complex64(ref val) => $exec($($args,)* val),
TensorContent::Complex128(ref val) => $exec($($args,... | code_fim | hard | {
"lang": "rust",
"repo": "jimtla/tf-rs",
"path": "/src/macros.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jimtla/tf-rs path: /src/macros.rs
macro_rules! name_cmp {
($name:ident, $cmp:expr) => ( $name.as_ref().to_str().unwrap() == $cmp )
}
macro_rules! tensor_output_op {
($val:expr; $exec:path[$($args:tt,)*]) => (
match *$val {
TensorContent::Float(ref val) => $exec($($a... | code_fim | hard | {
"lang": "rust",
"repo": "jimtla/tf-rs",
"path": "/src/macros.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>($($args,)* val),
TensorContent::Bool(ref val) => $exec($($args,)* val),
TensorContent::String(ref val) => $exec($($args,)* val),
TensorContent::QUInt8(ref val) => $exec($($args,)* val),
TensorContent::QUInt16(ref val) => $exec($($args,)* val),
T... | code_fim | hard | {
"lang": "rust",
"repo": "jimtla/tf-rs",
"path": "/src/macros.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Parts for Day25 {
fn part1(&self) -> i32 {
let generator = Generator::new(&self.input[0]);
return generator.generate();
}
fn part2(&self) -> i32 {
return 0;
}
}<|fim_prefix|>// repo: c-goldschmidt/AoC_2015 path: /src/days/day25.rs
use crate::days::day::{New, ... | code_fim | medium | {
"lang": "rust",
"repo": "c-goldschmidt/AoC_2015",
"path": "/src/days/day25.rs",
"mode": "spm",
"license": "CC0-1.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let generator = Generator::new(&self.input[0]);
return generator.generate();
}
fn part2(&self) -> i32 {
return 0;
}
}<|fim_prefix|>// repo: c-goldschmidt/AoC_2015 path: /src/days/day25.rs
use crate::days::day::{New, Parts};
use regex::Regex;
pub struct Day25 {
in... | code_fim | medium | {
"lang": "rust",
"repo": "c-goldschmidt/AoC_2015",
"path": "/src/days/day25.rs",
"mode": "spm",
"license": "CC0-1.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: c-goldschmidt/AoC_2015 path: /src/days/day25.rs
use crate::days::day::{New, Parts};
use regex::Regex;
pub struct Day25 {
input: Vec<String>,
}
pub struct Generator {
search: (usize, usize),
}
impl Generator {
pub fn new(input: &String) -> Self {
// row 3010, column 3019
... | code_fim | medium | {
"lang": "rust",
"repo": "c-goldschmidt/AoC_2015",
"path": "/src/days/day25.rs",
"mode": "psm",
"license": "CC0-1.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rust-lang/rust path: /tests/ui/closures/2229_closure_analysis/bad-pattern.rs
// regression test for #108683
// edition:2021
enum Refutable {
A,
B,
}
<|fim_suffix|> const PAT: u32 = 0;
let v4 = &v2[..];
|| {
let 0 = v1; //~ ERROR refutable pattern in local binding
... | code_fim | medium | {
"lang": "rust",
"repo": "rust-lang/rust",
"path": "/tests/ui/closures/2229_closure_analysis/bad-pattern.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> const PAT: u32 = 0;
let v4 = &v2[..];
|| {
let 0 = v1; //~ ERROR refutable pattern in local binding
let (0 | 1) = v1; //~ ERROR refutable pattern in local binding
let 1.. = v1; //~ ERROR refutable pattern in local binding
let [0, 0, 0, 0] = v2; //~ ERROR refutab... | code_fim | medium | {
"lang": "rust",
"repo": "rust-lang/rust",
"path": "/tests/ui/closures/2229_closure_analysis/bad-pattern.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.iter.next()
}
fn size_hint(&self) -> (uint, Option<uint>) {
self.iter.size_hint()
}
}
impl<'a, K, V> DoubleEndedIterator<&'a K> for PhfOrderedMapKeys<'a, K, V> {
fn next_back(&mut self) -> Option<&'a K> {
self.iter.next_back()
}
}
impl<'a, K, V> RandomAc... | code_fim | hard | {
"lang": "rust",
"repo": "servo/rust-phf",
"path": "/phf/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Returns an iterator over the keys in the map.
///
/// Keys are returned in the same order in which they were defined.
pub fn keys<'a>(&'a self) -> PhfOrderedMapKeys<'a, K, V> {
PhfOrderedMapKeys { iter: self.entries().map(|&(ref k, _)| k) }
}
/// Returns an iterator ov... | code_fim | hard | {
"lang": "rust",
"repo": "servo/rust-phf",
"path": "/phf/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: servo/rust-phf path: /phf/src/lib.rs
e keys in the map.
///
/// Keys are returned in an arbitrary but fixed order.
pub fn keys<'a>(&'a self) -> PhfMapKeys<'a, K, V> {
PhfMapKeys { iter: self.entries().map(|&(ref k, _)| k) }
}
/// Returns an iterator over the values i... | code_fim | hard | {
"lang": "rust",
"repo": "servo/rust-phf",
"path": "/phf/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: marco-c/gecko-dev-wordified path: /third_party/rust/coremidi-sys/build.rs
fn
main
(
)
{
if
std
:
:
env
:
:
var
(
"
TARGET
"
)
.
expect
(
"
cannot
read
TARGET
environment
variable<|fim_suffix|>:
rustc
-
link
-
lib
=
framework
=
CoreMIDI
"
)
;
}
}<|fim_middle|>
"
)
.
contains
(
"
apple
"
)
{
print... | code_fim | easy | {
"lang": "rust",
"repo": "marco-c/gecko-dev-wordified",
"path": "/third_party/rust/coremidi-sys/build.rs",
"mode": "psm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_suffix|>:
rustc
-
link
-
lib
=
framework
=
CoreMIDI
"
)
;
}
}<|fim_prefix|>// repo: marco-c/gecko-dev-wordified path: /third_party/rust/coremidi-sys/build.rs
fn
main
(
)
{
if
std
:
:
env
:
:
var
(
"
TARGET
"
)
<|fim_middle|>.
expect
(
"
cannot
read
TARGET
environment
variable
"
)
.
contains
(
"
apple
"
)
{
print... | code_fim | medium | {
"lang": "rust",
"repo": "marco-c/gecko-dev-wordified",
"path": "/third_party/rust/coremidi-sys/build.rs",
"mode": "spm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_suffix|>
"
)
.
contains
(
"
apple
"
)
{
println
!
(
"
cargo
:
rustc
-
link
-
lib
=
framework
=
CoreMIDI
"
)
;
}
}<|fim_prefix|>// repo: marco-c/gecko-dev-wordified path: /third_party/rust/coremidi-sys/build.rs
fn
main
(
)
{
if
std
:
:
env
:
:
var
(
"
TARGET
"
)
<|fim_middle|>.
expect
(
"
cannot
read
TARGET
envir... | code_fim | easy | {
"lang": "rust",
"repo": "marco-c/gecko-dev-wordified",
"path": "/third_party/rust/coremidi-sys/build.rs",
"mode": "spm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_suffix|> if let Some(x) = self.index {
return x;
}
let _pos = self.stream.pos();
self.stream.seek((self._io.size - 8));
self.index = Box::new(PositionToEnd__IndexObj::new(self.stream, self, _root)?);
self.stream.seek(_pos);
return self.index;
... | code_fim | hard | {
"lang": "rust",
"repo": "kaitai-io/ci_targets",
"path": "/compiled/rust/position_to_end.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: kaitai-io/ci_targets path: /compiled/rust/position_to_end.rs
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
use std::option::Option;
use std::boxed::Box;
use std::io::Result;
use std::io::Cursor;
use std::vec::Vec;
use std::default::Default;
... | code_fim | hard | {
"lang": "rust",
"repo": "kaitai-io/ci_targets",
"path": "/compiled/rust/position_to_end.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> ecb::encrypt(&pkcs7::pad(&plaintext), &self.key).map_err(|e| Error::Ecb(e))
}
// convenience function for testing
#[allow(dead_code)]
pub fn prefix_len(&self) -> usize {
self.prefix.len()
}
}
/// Guess the length of the ECB oracle
pub fn guess_prefix_len(oracle: &Rand... | code_fim | hard | {
"lang": "rust",
"repo": "unseddd/cryptopals",
"path": "/src/oracle/ecb.rs",
"mode": "spm",
"license": "WTFPL",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: unseddd/cryptopals path: /src/oracle/ecb.rs
#![macro_use]
use alloc::vec;
use alloc::vec::Vec;
use rand::{thread_rng, Rng};
use craes::{aes, cbc, ecb, pkcs7};
use crate::encoding;
use super::{add_random_bytes, gen_rand_bytes, gen_rand_iv, gen_rand_key, AesMode, Error};
use super::{RAND_PREFI... | code_fim | hard | {
"lang": "rust",
"repo": "unseddd/cryptopals",
"path": "/src/oracle/ecb.rs",
"mode": "psm",
"license": "WTFPL",
"source": "the-stack-v2"
} |
<|fim_suffix|> // guess the prefix length to start solving at the next block
let prefix_len = guess_prefix_len(&oracle)?;
let extra_len = aes::BLOCK_LEN - (prefix_len % aes::BLOCK_LEN);
let full_prefix = prefix_len + extra_len;
for ciph_idx in 1..UNKNOWN_LEN {
// the current block number
... | code_fim | hard | {
"lang": "rust",
"repo": "unseddd/cryptopals",
"path": "/src/oracle/ecb.rs",
"mode": "spm",
"license": "WTFPL",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Dump the Chip8 memory into the console as
/// hex encoded strings.
pub fn dump_ram(&self) {
let len = self.ram.len();
for i in 0..len {
if i % 2 == 0 {
print!(" ");
}
if i % 32 == 0 {
println!("");
... | code_fim | hard | {
"lang": "rust",
"repo": "grant-wade/chip8-emulator",
"path": "/src/memory.rs",
"mode": "spm",
"license": "LicenseRef-scancode-public-domain",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: grant-wade/chip8-emulator path: /src/memory.rs
// Standard Library Modules //
use std::io;
use std::fs::File;
use std::io::prelude::*;
/// A representation of chip8 ram
pub struct ChipMemory {
/// a vector representing the ram
ram: Vec<u8>,
/// true if a rom has been loaded
loa... | code_fim | hard | {
"lang": "rust",
"repo": "grant-wade/chip8-emulator",
"path": "/src/memory.rs",
"mode": "psm",
"license": "LicenseRef-scancode-public-domain",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl<T, E, R> ResultFaker<T, E, R> {
pub fn new(ok: T, err: E, err_rate: R) -> ResultFaker<T, E, R> {
ResultFaker { ok, err, err_rate }
}
}
impl<T, E, U, V, X> Dummy<ResultFaker<U, V, X>> for Result<T, E>
where
T: Dummy<U>,
E: Dummy<V>,
u8: Dummy<X>,
{
fn dummy_with_rng<R:... | code_fim | hard | {
"lang": "rust",
"repo": "cksac/fake-rs",
"path": "/fake/src/impls/std/result.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: cksac/fake-rs path: /fake/src/impls/std/result.rs
use crate::{faker::boolean::en::Boolean, Dummy, Fake, Faker};
use rand::Rng;
impl<T, E> Dummy<Faker> for Result<T, E>
where
T: Dummy<Faker>,
E: Dummy<Faker>,
{
fn dummy_with_rng<R: Rng + ?Sized>(config: &Faker, rng: &mut R) -> Self {... | code_fim | hard | {
"lang": "rust",
"repo": "cksac/fake-rs",
"path": "/fake/src/impls/std/result.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl<T, E> ResultFaker<T, E, u8> {
pub fn with(ok: T, err: E) -> ResultFaker<T, E, u8> {
ResultFaker {
ok,
err,
err_rate: 50,
}
}
}
impl<T, E, R> ResultFaker<T, E, R> {
pub fn new(ok: T, err: E, err_rate: R) -> ResultFaker<T, E, R> {
... | code_fim | hard | {
"lang": "rust",
"repo": "cksac/fake-rs",
"path": "/fake/src/impls/std/result.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: joscha/dprint-plugin-markdown path: /src/parsing/yaml/parse_yaml_header.rs
use crate::parsing::common::{CharScanner, YamlHeader};
pub fn parse_yaml_header(text: &str) -> Option<YamlHeader> {
let mut scanner = CharScanner::new(0, text);
if !scanner.move_text("---") {
return None;
}
... | code_fim | medium | {
"lang": "rust",
"repo": "joscha/dprint-plugin-markdown",
"path": "/src/parsing/yaml/parse_yaml_header.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> scanner.move_next_line();
}
return None;
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn it_should_parse_yaml_header() {
let result = parse_yaml_header(
r#"---
a: b
---
Test"#,
)
.unwrap();
assert_eq!(result.range.start, 0);
assert_eq!(result.range.end, 12);
... | code_fim | hard | {
"lang": "rust",
"repo": "joscha/dprint-plugin-markdown",
"path": "/src/parsing/yaml/parse_yaml_header.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[test]
fn print_empty() {
test_print_message(&InteropMessageList::new());
}
#[test]
fn print_random() {
for m in special_messages_typed::<InteropMessage>() {
let mut l = InteropMessageList::new();
l.ts.push(m);
test_print_message(&l);
// This slow test is equivale... | code_fim | hard | {
"lang": "rust",
"repo": "mesalock-linux/rust-protobuf-sgx",
"path": "/protobuf-test/src/interop/json.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[test]
fn print_random() {
for m in special_messages_typed::<InteropMessage>() {
let mut l = InteropMessageList::new();
l.ts.push(m);
test_print_message(&l);
// This slow test is equivalent to the fast test below.
// Do just one iteration as smoke test.
... | code_fim | hard | {
"lang": "rust",
"repo": "mesalock-linux/rust-protobuf-sgx",
"path": "/protobuf-test/src/interop/json.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mesalock-linux/rust-protobuf-sgx path: /protobuf-test/src/interop/json.rs
use std::io::Read;
use std::io::Write;
use std::process;
use super::interop_pb::*;
use protobuf::json;
use protobuf::Message;
use protobuf_test_common::*;
fn test_parse_message(m: &InteropMessageList) {
let m_bytes... | code_fim | hard | {
"lang": "rust",
"repo": "mesalock-linux/rust-protobuf-sgx",
"path": "/protobuf-test/src/interop/json.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: uber/piranha path: /src/models/unit_tests/piranha_arguments_test.rs
/*
Copyright (c) 2023 Uber Technologies, Inc.
<p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of the License at
<p>ht... | code_fim | hard | {
"lang": "rust",
"repo": "uber/piranha",
"path": "/src/models/unit_tests/piranha_arguments_test.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[test]
#[should_panic(expected = "Invalid Piranha Argument. Missing `path_to_codebase` or `code_snippet`")]
fn piranha_argument_invalid_no_codebase_and_snippet() {
let _ = PiranhaArgumentsBuilder::default()
.path_to_configurations("some/path".to_string())
.language(PiranhaLanguage::from(JAVA))
... | code_fim | medium | {
"lang": "rust",
"repo": "uber/piranha",
"path": "/src/models/unit_tests/piranha_arguments_test.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let _ = PiranhaArgumentsBuilder::default()
.path_to_configurations("some/path".to_string())
.language(PiranhaLanguage::from(JAVA))
.substitutions(substitutions! {"super_interface_name" => "SomeInterface"})
.build();
}
#[test]
#[should_panic(
expected = "Invalid Piranha arguments. Plea... | code_fim | medium | {
"lang": "rust",
"repo": "uber/piranha",
"path": "/src/models/unit_tests/piranha_arguments_test.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: isgasho/prowl path: /src/systems/interaction_system.rs
use specs::prelude::*;
// use crate::ui::Panel;
// use crate::components::CharRenderer;
use crate::components::{
game_resources::{Food, GameResource, Metal, Water, Wood},
Active, CharRenderer, Named, Player, Ship,
};
use crate::even... | code_fim | hard | {
"lang": "rust",
"repo": "isgasho/prowl",
"path": "/src/systems/interaction_system.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> while let Some(event) = event_channel.events.pop() {
let parties = (event.entities[0], event.entities[1]);
let one = names.get(parties.0);
let two = names.get(parties.1);
let one = Named::name_or_noname(one);
let two = Named::name_or_nona... | code_fim | hard | {
"lang": "rust",
"repo": "isgasho/prowl",
"path": "/src/systems/interaction_system.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let (
names,
players,
ships,
mut panels,
mut interactive_uis,
foods,
waters,
metals,
woods,
// mut console,
mut actives,
mut game_data,
mut ev... | code_fim | hard | {
"lang": "rust",
"repo": "isgasho/prowl",
"path": "/src/systems/interaction_system.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mxmehl/bard path: /src/util.rs
use std::process::ExitStatus;
use std::path::{self, PathBuf, Path};
use std::env;
#[cfg(unix)]
use std::os::unix::process::ExitStatusExt as _;
use crate::error::*;
pub type BStr = Box<str>;
/// Byte slice extension (also for `Vec<u8>`)
pub trait ByteSliceExt {
... | code_fim | hard | {
"lang": "rust",
"repo": "mxmehl/bard",
"path": "/src/util.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.as_slice().into_bstr()
}
}
/// PathBuf extension
pub trait PathBufExt {
/// If the path is relative, resolve it as absolute wrt. `base_dir`
fn resolve(&mut self, base_dir: &Path);
fn resolved(self, base_dir: &Path) -> Self;
fn utf8_check(&self) -> Result<(), path::Display... | code_fim | hard | {
"lang": "rust",
"repo": "mxmehl/bard",
"path": "/src/util.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let new_path = new_path.as_ref();
env::set_current_dir(new_path).with_context(|| {
orig_path.push(new_path);
format!("Could not enter directory: `{}`", orig_path.display())
})?;
Ok(Self { orig_path })
}
}
impl Drop for CwdGuard {
fn drop(&m... | code_fim | hard | {
"lang": "rust",
"repo": "mxmehl/bard",
"path": "/src/util.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let piece = Piece::new(pos.0, pos.1, self.sprite_size, player.clone(), piece_type);
let mut transform = Transform::default();
transform.set_translation(piece.get_self_xy());
transform.set_scale(Vector3::new(scale, scale, 1.));
world
... | code_fim | hard | {
"lang": "rust",
"repo": "EmanuelBoehm/Rust",
"path": "/boardgame/src/state.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: EmanuelBoehm/Rust path: /boardgame/src/state.rs
use amethyst::{
assets::{AssetStorage, Handle, Loader},
core::transform::Transform,
input::{get_key, is_close_requested, is_key_down, VirtualKeyCode},
prelude::*,
renderer::{Camera, ImageFormat, SpriteRender, SpriteSheet, Sprite... | code_fim | hard | {
"lang": "rust",
"repo": "EmanuelBoehm/Rust",
"path": "/boardgame/src/state.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Creates an entity in the `world` for each of the provided `sprites`.
/// They are individually placed around the center of the screen.
fn init_background_sprites(&self, world: &mut World, spritesheethandle: Handle<SpriteSheet>) {
//----loading grid -----
let (grid_x, grid_y... | code_fim | hard | {
"lang": "rust",
"repo": "EmanuelBoehm/Rust",
"path": "/boardgame/src/state.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn from_str() {
assert_eq!(UseColor::Auto, UseColor::AUTO.parse().unwrap());
assert_eq!(UseColor::Always, UseColor::ALWAYS.parse().unwrap());
assert_eq!(UseColor::Never, UseColor::NEVER.parse().unwrap());
assert_eq!(
UseColor::Auto,
UseColor::AUTO.to_uppercase().par... | code_fim | hard | {
"lang": "rust",
"repo": "rrybarczyk/intermodal",
"path": "/src/use_color.rs",
"mode": "spm",
"license": "CC0-1.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rrybarczyk/intermodal path: /src/use_color.rs
use crate::common::*;
#[derive(Copy, Clone, Debug, PartialEq)]
pub(crate) enum UseColor {
Auto,
Always,
Never,
}
impl UseColor {
pub(crate) const ALWAYS: &'static str = "always";
pub(crate) const AUTO: &'static str = "auto";
pub(crate) ... | code_fim | medium | {
"lang": "rust",
"repo": "rrybarczyk/intermodal",
"path": "/src/use_color.rs",
"mode": "psm",
"license": "CC0-1.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: kitfre/kube-rs path: /examples/crd_reflector.rs
#[macro_use] extern crate log;
#[macro_use] extern crate serde_derive;
use kube::{
api::{Object, RawApi, Reflector, Void},
client::APIClient,
config,
};
<|fim_suffix|>#[tokio::main]
async fn main() -> anyhow::Result<()> {
std::env... | code_fim | hard | {
"lang": "rust",
"repo": "kitfre/kube-rs",
"path": "/examples/crd_reflector.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Read updated internal state (instant):
rf.state().await?.into_iter().for_each(|crd| {
info!("foo {}: {}", crd.metadata.name, crd.spec.info);
});
}
}<|fim_prefix|>// repo: kitfre/kube-rs path: /examples/crd_reflector.rs
#[macro_use] extern crate log;
#[macro_use]... | code_fim | medium | {
"lang": "rust",
"repo": "kitfre/kube-rs",
"path": "/examples/crd_reflector.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>i
(
zero
-
based
)
.
If
there
are
no
/
/
/
spans
for
the
given
line
then
None
is
returned
.
Otherwise
an
/
/
/
appropriately
space
padded
string
with
correctly
positioned
^
is
/
/
/
returned
accounting
for
line
numbers
.
fn
notate_line
(
&
self
i
:
usize
)
-
>
Option
<
String
>
{
let
spans
=
&
self
.
by_l... | code_fim | hard | {
"lang": "rust",
"repo": "marco-c/gecko-dev-wordified",
"path": "/third_party/rust/regex-syntax/src/error.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: marco-c/gecko-dev-wordified path: /third_party/rust/regex-syntax/src/error.rs
use
std
:
:
cmp
;
use
std
:
:
error
;
use
std
:
:
fmt
;
use
std
:
:
result
;
use
crate
:
:
ast
;
use
crate
:
:
hir
;
/
/
/
A
type
alias
for
dealing
with
errors
returned
by
this
crate
.
pub
type
Result
<
T
>
=
result
:
... | code_fim | hard | {
"lang": "rust",
"repo": "marco-c/gecko-dev-wordified",
"path": "/third_party/rust/regex-syntax/src/error.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: CraZySacX/aoc path: /src/year2017/day02.rs
//! Advent of Code - Day 2 "Corruption Checksum" Solution
use anyhow::{anyhow, Result};
use std::cmp;
use std::io::BufRead;
/// Parse the file at `filename` and generate the checksum.
pub fn find_solution<T: BufRead>(reader: T, use_div: bool) -> Result... | code_fim | hard | {
"lang": "rust",
"repo": "CraZySacX/aoc",
"path": "/src/year2017/day02.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let vals_iter = line.split_whitespace();
let mut vals_vec = Vec::new();
for val_str in vals_iter {
vals_vec.push(val_str.parse::<u32>()?);
}
let inner_vals_vec = vals_vec.clone();
for (idx, val) in vals_vec.iter().enumerate() {
for (next_idx, next_val) in inner_val... | code_fim | hard | {
"lang": "rust",
"repo": "CraZySacX/aoc",
"path": "/src/year2017/day02.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> if val > max {
max = val;
}
}
Ok(max - min)
}
/// Find the only two evenly divisible values in a whitespace separated string
fn row_evenly_divisible_value(line: &str) -> Result<u32> {
let vals_iter = line.split_whitespace();
let mut vals_vec = Vec::new();
... | code_fim | hard | {
"lang": "rust",
"repo": "CraZySacX/aoc",
"path": "/src/year2017/day02.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>ytes", contents.len());
/// # Ok(())
/// # }
/// ```
pub async fn read_to_string(path: impl AsRef<Path>) -> io::Result<String> {
let path = path.as_ref().to_owned();
asyncify(move || std::fs::read_to_string(path)).await
}<|fim_prefix|>// repo: tokio-rs/tokio path: /tokio/src/fs/read_to_string.rs
... | code_fim | hard | {
"lang": "rust",
"repo": "tokio-rs/tokio",
"path": "/tokio/src/fs/read_to_string.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tokio-rs/tokio path: /tokio/src/fs/read_to_string.rs
use crate::fs::asyncify;
use std::{io, path::Path};
/// Creates a future which will open a file for reading and read the entire
/// contents into a string and return said string.
///
/// This is the async equivalent of [`std::<|fim_suffix|>d... | code_fim | hard | {
"lang": "rust",
"repo": "tokio-rs/tokio",
"path": "/tokio/src/fs/read_to_string.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.