text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_prefix|>// repo: jtdaugherty/flux path: /fluxcore/src/manager.rs
use crossbeam::channel::{Sender, Receiver, bounded, unbounded};
use crossbeam::sync::WaitGroup;
use crossbeam::channel::SendError;
use std::fs::File;
use std::thread;
use std::sync::{Arc, Mutex};
use std::time::SystemTime;
use crate::scene::{Scen... | code_fim | hard | {
"lang": "rust",
"repo": "jtdaugherty/flux",
"path": "/fluxcore/src/manager.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> Self {
sender: s,
}
}
pub fn sender(&self) -> Sender<Option<RenderEvent>> {
self.sender.clone()
}
}
pub struct ImageBuilder {
sender: Sender<Option<RenderEvent>>,
thread_handle: thread::JoinHandle<()>,
image: Arc<Mutex<Option<Image>>>,
}
impl ... | code_fim | hard | {
"lang": "rust",
"repo": "jtdaugherty/flux",
"path": "/fluxcore/src/manager.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: avrham408/comapny path: /src/test.rs
#[cfg(test)]
mod tests {
#[test]
fn test_valid_employee_not_exist() {
let mut company = crate::create_company();
assert_eq!(
crate::valid_employee_not_exist(&company, &String::from("avi")),
false
);
... | code_fim | hard | {
"lang": "rust",
"repo": "avrham408/comapny",
"path": "/src/test.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut company = crate::create_company();
assert_eq!(
crate::add_employee_to_department(
&mut company,
&String::from("engineering"),
&String::from("dana")
),
true
);
assert!(company["engine... | code_fim | hard | {
"lang": "rust",
"repo": "avrham408/comapny",
"path": "/src/test.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let c = TESTRefCell::new(5);
let c = Arc::new(c);
let x = c.borrow();
{
let c2 = c.clone();
thread::spawn(move || {
{
let mut v = c2.borrow_mut();
*v = 100;
}
println!("{:?} in child", c2.value);
}... | code_fim | hard | {
"lang": "rust",
"repo": "system-pclub/rust-study",
"path": "/section-6-thread-safety-issues/reproduced_concurrency_bugs/non-blocking-bugs/servo-nonblocking-16/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: system-pclub/rust-study path: /section-6-thread-safety-issues/reproduced_concurrency_bugs/non-blocking-bugs/servo-nonblocking-16/src/main.rs
use std::cell::{BorrowError, BorrowMutError, Ref, RefCell, RefMut};
use std::sync::Arc;
use std::thread;
#[derive(Clone, Debug)]
pub struct TESTRefCell {
... | code_fim | medium | {
"lang": "rust",
"repo": "system-pclub/rust-study",
"path": "/section-6-thread-safety-issues/reproduced_concurrency_bugs/non-blocking-bugs/servo-nonblocking-16/src/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn borrow_mut(&self) -> RefMut<i32> {
self.try_borrow_mut().expect("error in borrow_mut")
}
}
fn main() {
let c = TESTRefCell::new(5);
let c = Arc::new(c);
let x = c.borrow();
{
let c2 = c.clone();
thread::spawn(move || {
{
... | code_fim | hard | {
"lang": "rust",
"repo": "system-pclub/rust-study",
"path": "/section-6-thread-safety-issues/reproduced_concurrency_bugs/non-blocking-bugs/servo-nonblocking-16/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // And overwrite the existing data so that we will not read the data back after a crash.
let size = self.size();
let zeroes: [u8; 16] = [0; 16];
copy_memory(&zeroes, &mut self.as_mut_slice()[size..]);
}
/// Flushes recently written entries to durable storage.
p... | code_fim | hard | {
"lang": "rust",
"repo": "dyxushuai/wal",
"path": "/src/segment.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dyxushuai/wal path: /src/segment.rs
a segment file is reused for a new segment, the old
/// entries will be ignored (since the CRC will not match).
///
/// ### Entry Format
///
/// | component | type |
/// | ---------------------------- | ---- |
/// | length ... | code_fim | hard | {
"lang": "rust",
"repo": "dyxushuai/wal",
"path": "/src/segment.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let padding = padding(entry.len());
let padded_len = entry.len() + padding;
let offset = self.size();
let mut crc = self.crc;
LittleEndian::write_u64(&mut self.as_mut_slice()[offset..], entry.len() as u64);
copy_memory(entry.deref(), &mut self.as_mut_slic... | code_fim | hard | {
"lang": "rust",
"repo": "dyxushuai/wal",
"path": "/src/segment.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> for _ in WalkDir::new(&p)
.min_depth(2)
.max_depth(2)
.into_iter()
.filter_map(|e| e.ok())
.filter(|e| image_alloweds(e, &formats)) {
c += 1.0;
}
(c)
}<|fim_prefix|>// repo: eij/rs-convert path: /src/utils/folders.rs
use std::path::PathBuf;
use walkdir::{WalkDir, DirEntry};
use... | code_fim | hard | {
"lang": "rust",
"repo": "eij/rs-convert",
"path": "/src/utils/folders.rs",
"mode": "spm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: eij/rs-convert path: /src/utils/folders.rs
use std::path::PathBuf;
use walkdir::{WalkDir, DirEntry};
use crate::globals;
pub fn image_alloweds(entry: &DirEntry, formats: &Vec<String>) -> bool {
if entry.file_type().is_file() {
if formats.contains(&entry.path().extension().unwrap().to_str().... | code_fim | hard | {
"lang": "rust",
"repo": "eij/rs-convert",
"path": "/src/utils/folders.rs",
"mode": "psm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_suffix|> let student1 = Student::new("A".to_string(), 2, 20);
let student2 = Student::new("B".to_string(), 3, 21);
let student3 = Student::new("C".to_string(), 1, 22);
let mut student_v = vec![student1.clone(), student2.clone(), student3.clone()];
student_v.sort_unstable_by(|stu1, stu2| stu2.id... | code_fim | medium | {
"lang": "rust",
"repo": "Orca-bit/DataStructureAndAlgorithm",
"path": "/src/chapt2/comparator.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Orca-bit/DataStructureAndAlgorithm path: /src/chapt2/comparator.rs
#[derive(Clone, Debug)]
struct Student {
name: String,
id: i32,
score: i32
}
<|fim_suffix|> let student1 = Student::new("A".to_string(), 2, 20);
let student2 = Student::new("B".to_string(), 3, 21);
let stu... | code_fim | medium | {
"lang": "rust",
"repo": "Orca-bit/DataStructureAndAlgorithm",
"path": "/src/chapt2/comparator.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: defvar/toy path: /pkg/toy-core/src/data/error.rs
//! Error returned from the Serialize or Deserialize.
//!
use crate::data::Value;
use std::fmt::Display;
use thiserror::Error as ThisError;
#[derive(Debug, ThisError)]
pub enum SerializeError {
#[error(
"serialize error:invalid type.... | code_fim | hard | {
"lang": "rust",
"repo": "defvar/toy",
"path": "/pkg/toy-core/src/data/error.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> where
T: Display,
{
SerializeError::error(msg)
}
}
impl DeserializeError {
pub fn error<T>(msg: T) -> DeserializeError
where
T: Display,
{
DeserializeError::Error {
inner: msg.to_string(),
}
}
pub fn invalid_type<T>(expe... | code_fim | hard | {
"lang": "rust",
"repo": "defvar/toy",
"path": "/pkg/toy-core/src/data/error.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn invalid_type<T>(expected: T, v: Value) -> SerializeError
where
T: Display,
{
SerializeError::InvalidType {
expected: expected.to_string(),
candidate: v,
}
}
}
impl serde::ser::Error for SerializeError {
fn custom<T>(msg: T) -> Sel... | code_fim | hard | {
"lang": "rust",
"repo": "defvar/toy",
"path": "/pkg/toy-core/src/data/error.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> traverse(traverse, 5);
}<|fim_prefix|>// repo: xiaoqixian/Rusty path: /code/traverse.rs
/* A traverse attemtation*/
fn traverse(func: Fn(), i: i32) {
if i != 0 {
println!("{}", i);
func(func, i-1);
}
}
<|fim_middle|>fn main() {
| code_fim | easy | {
"lang": "rust",
"repo": "xiaoqixian/Rusty",
"path": "/code/traverse.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: xiaoqixian/Rusty path: /code/traverse.rs
/* A traverse attemtation*/
fn traverse(func: Fn(), i: i32) {
if i != 0 {
println!("{}", i);
func(func, i-1);
}
}
<|fim_suffix|> traverse(traverse, 5);
}<|fim_middle|>fn main() {
| code_fim | easy | {
"lang": "rust",
"repo": "xiaoqixian/Rusty",
"path": "/code/traverse.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Nukesor/pueue path: /pueue/src/client/display/group.rs
use crossterm::style::{Attribute, Color};
use pueue_lib::{
network::message::GroupResponseMessage,
state::{Group, GroupStatus},
};
use crate::client::cli::SubCommand;
use super::OutputStyle;
/// Print some info about the daemon's... | code_fim | hard | {
"lang": "rust",
"repo": "Nukesor/pueue",
"path": "/pueue/src/client/display/group.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut text = String::new();
let mut group_iter = message.groups.iter().peekable();
while let Some((name, group)) = group_iter.next() {
let styled = get_group_headline(name, group, style);
text.push_str(&styled);
if group_iter.peek().is_some() {
text.push(... | code_fim | hard | {
"lang": "rust",
"repo": "Nukesor/pueue",
"path": "/pueue/src/client/display/group.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // fn add(&self, histogram: HDRHistogram) {}
// fn subtract(&self) {}
// fn addWhileCorrectingForCoordinatedOmission() {}
// fn allValues() {}
// fn copyInto() {}
// fn copyIntoCorrectedForCoordinatedOmission() {}
// fn encodeIntoByteBuffer() {}
// f... | code_fim | hard | {
"lang": "rust",
"repo": "johnmcdnl/http_load",
"path": "/src/hdr_histogram/hdr_histogram.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.start_time = Instant::now()
}
pub fn get_end_time_stamp(&self) -> Instant {
return self.end_time;
}
fn set_end_time_stamp(&mut self) {
self.end_time = Instant::now()
}
pub fn get_sum(&mut self) -> Duration {
self.sum = Duration::from_nanos(se... | code_fim | hard | {
"lang": "rust",
"repo": "johnmcdnl/http_load",
"path": "/src/hdr_histogram/hdr_histogram.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: johnmcdnl/http_load path: /src/hdr_histogram/hdr_histogram.rs
use std::time::{Duration, Instant};
use std::ops::Div;
extern crate time;
#[derive(Debug)]
pub struct HDRHistogram {
total_count: u64,
counts: Vec<u64>,
start_time: Instant,
end_time: Instant,
min_value: Durati... | code_fim | hard | {
"lang": "rust",
"repo": "johnmcdnl/http_load",
"path": "/src/hdr_histogram/hdr_histogram.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> .map(|ip| ip.cidr_ip.clone().unwrap_or_else(|| "N/A".to_string()))
.collect::<Vec<String>>()
.join(", "))
.unwrap_or_else(|| "N/A".to_string()),
);
}... | code_fim | hard | {
"lang": "rust",
"repo": "jacklund/aws-instance",
"path": "/src/commands/list_security_groups.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jacklund/aws-instance path: /src/commands/list_security_groups.rs
use crate::Result;
use rusoto_ec2::{DescribeSecurityGroupsRequest, Ec2, Ec2Client, Filter};
pub async fn list_security_groups(ec2_client: &Ec2Client, name: &Option<String>) -> Result<()> {
let mut request = DescribeSecurityGr... | code_fim | hard | {
"lang": "rust",
"repo": "jacklund/aws-instance",
"path": "/src/commands/list_security_groups.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> };
println!(
" {0: <10} {1: <15}",
port_string,
egress
.ip_ranges
.map(|v| v
.iter()
... | code_fim | hard | {
"lang": "rust",
"repo": "jacklund/aws-instance",
"path": "/src/commands/list_security_groups.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: sonro/linurgy path: /examples/multi-thread-basic-inserter.rs
use std::sync::Arc;
/// Multi-threaded insert dashes
fn main() {
<|fim_suffix|> for _ in 0..10 {
let editor = Arc::clone(&editor);
std::thread::spawn(move || {
// note the final single newline character... | code_fim | medium | {
"lang": "rust",
"repo": "sonro/linurgy",
"path": "/examples/multi-thread-basic-inserter.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // single newline is untouched
let expected = "example line---\n\nanother line\n";
assert_eq!(expected, output);
});
}
}<|fim_prefix|>// repo: sonro/linurgy path: /examples/multi-thread-basic-inserter.rs
use std::sync::Arc;
/// Multi-threaded insert dashe... | code_fim | medium | {
"lang": "rust",
"repo": "sonro/linurgy",
"path": "/examples/multi-thread-basic-inserter.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Alkamist/LanguageTranspilerTest path: /src/binary_expression.rs
use nom::{
IResult,
character::complete::*,
bytes::complete::*,
combinator::*,
sequence::*,
multi::*,
branch::*,
};
use crate::instruction::*;
use crate::expression::*;
#[derive(Debug)]
pub struct Binar... | code_fim | hard | {
"lang": "rust",
"repo": "Alkamist/LanguageTranspilerTest",
"path": "/src/binary_expression.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> Ok((
remainder,
Expression::Binary(Self {
operator: operator.to_string(),
left: Box::new(left),
right: Box::new(right),
})
))
}
}<|fim_prefix|>// repo: Alkamist/LanguageTranspilerTest path: /src/binary... | code_fim | hard | {
"lang": "rust",
"repo": "Alkamist/LanguageTranspilerTest",
"path": "/src/binary_expression.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let data = TestData::new()
.with_args("--time 8:15 --really")
.run()
.unwrap();
assert!(data.activitiesfile.close().unwrap().is_empty());
assert_eq!(data.logfile.close().unwrap(), "08:00 really 08:15\n");
}
#[test]
fn add_known_activity() {
let data = TestData::new... | code_fim | hard | {
"lang": "rust",
"repo": "mradziej/tt-timetracker",
"path": "/src/tests/test_add.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[test]
fn add_known_activity() {
let data = TestData::new()
.with_args("shortcut tag-1")
.write_activitiesfile("shortcut something tag-2\n".to_string())
.run()
.unwrap();
assert_eq!(
data.activitiesfile.close().unwrap(),
"shortcut something tag-2\n"... | code_fim | hard | {
"lang": "rust",
"repo": "mradziej/tt-timetracker",
"path": "/src/tests/test_add.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mradziej/tt-timetracker path: /src/tests/test_add.rs
use crate::{
error::{TTError, TTErrorKind},
tests::TestData,
};
// fn run_test(setup: Fn(&mut FakeFile, &mut FakeFile, &mut FakeFile, &mut NaiveDateTime, &mut String), )
// integration tests for the add subcommand
#[test]
fn add_simpl... | code_fim | hard | {
"lang": "rust",
"repo": "mradziej/tt-timetracker",
"path": "/src/tests/test_add.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: MichaelSheely/memsafe-final-project path: /src/kruskal.rs
extern crate mjgraph;
extern crate union_find;
use mjgraph::Graph;
use mjgraph::Edge;
use mjgraph::Vertex;
use union_find::QuickFindUf;
use std::hash::Hash;
pub fn kruskal<V: Copy + Clone + Eq + Hash,
E: Ord + Copy + Clone + Default>... | code_fim | hard | {
"lang": "rust",
"repo": "MichaelSheely/memsafe-final-project",
"path": "/src/kruskal.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> for e in v.edges() {
// edges.push(*e);
// }
//}
//edges.sort();
//for ref v in g.vertices() {
// vertices.insert(v);
//}
//for e in edges {
// let (u, v) = g.endpoints(e);
// let id1 = vertices.find(u);
// let id2 = vertices.find(v);
... | code_fim | hard | {
"lang": "rust",
"repo": "MichaelSheely/memsafe-final-project",
"path": "/src/kruskal.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: emseibert/RustCompletion path: /rust_src/libcollections/trie.rs
t self, key: &uint) -> Option<T> {
let ret = remove(&mut self.root.count,
&mut self.root.children[chunk(*key, 0)],
*key, 1);
if ret.is_some() { self.length -= 1 }
... | code_fim | hard | {
"lang": "rust",
"repo": "emseibert/RustCompletion",
"path": "/rust_src/libcollections/trie.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn test_find_mut() {
let mut m = TrieMap::new();
assert!(m.insert(1, 12));
assert!(m.insert(2, 8));
assert!(m.insert(5, 14));
let new = 100;
match m.find_mut(&5) {
None => fail!(), Some(x) => *x = new
}
assert_eq!(... | code_fim | hard | {
"lang": "rust",
"repo": "emseibert/RustCompletion",
"path": "/rust_src/libcollections/trie.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.iter().all(|v| !other.contains(&v))
}
#[inline]
fn is_subset(&self, other: &TrieSet) -> bool {
self.iter().all(|v| other.contains(&v))
}
#[inline]
fn is_superset(&self, other: &TrieSet) -> bool {
other.is_subset(self)
}
}
impl MutableSet<uint> fo... | code_fim | hard | {
"lang": "rust",
"repo": "emseibert/RustCompletion",
"path": "/rust_src/libcollections/trie.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn test_score_list() {
assert_eq!(score_list(&[String::from("ALICE"),
String::from("BOB"),
String::from("COLIN")]),
compute_score("ALICE")
+ 2 * compute_score("BOB")
+ 3 * compute_score("COLIN"... | code_fim | hard | {
"lang": "rust",
"repo": "emilssolmanis/project-euler-rust",
"path": "/src/solutions/problem_22.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> res
}
pub fn solve(filename: &str) -> u32 {
let mut name_list = read_name_list(filename);
name_list.sort();
score_list(name_list.as_slice())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_name_score() {
assert_eq!(compute_score("COLIN"), 53);
asser... | code_fim | hard | {
"lang": "rust",
"repo": "emilssolmanis/project-euler-rust",
"path": "/src/solutions/problem_22.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: emilssolmanis/project-euler-rust path: /src/solutions/problem_22.rs
use std::fs::File;
use std::io::Read;
fn compute_score(name: &str) -> u32 {
name.chars().map(|b| u32::from(b) - u32::from('A') + 1).sum()
}
fn read_name_list(filename: &str) -> Vec<String> {
let mut contents = String::... | code_fim | medium | {
"lang": "rust",
"repo": "emilssolmanis/project-euler-rust",
"path": "/src/solutions/problem_22.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> while a > 0 || b > 0 {
if a > 0 {
result.push(chara);
a -= 1;
}
if a > b {
result.push(chara);
a -= 1;
}
if b > 0 {
result.push(charb);
b -= 1... | code_fim | hard | {
"lang": "rust",
"repo": "ltoddy/leetcode",
"path": "/algorithms/string-without-aaa-or-bbb.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ltoddy/leetcode path: /algorithms/string-without-aaa-or-bbb.rs
impl Solution {
pub fn str_without3a3b(a: i32, b: i32) -> String {
let length = (a + b) as usize;
let mut result = String::with_capacity(length);
<|fim_suffix|> while a > 0 || b > 0 {
if a > 0 ... | code_fim | hard | {
"lang": "rust",
"repo": "ltoddy/leetcode",
"path": "/algorithms/string-without-aaa-or-bbb.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dsbrgg/exercises path: /rust/dig_pow/src/main.rs
fn main() {
// assert_eq!(dig_pow(89, 1), 1); // should return 1 since 8¹ + 9² = 89 = 89 * 1
// assert_eq!(dig_pow(92, 1), -1); // should return -1 since there is no k such as 9¹ + 2² equals 92 * k
<|fim_suffix|> let t: i64 = n
.to_strin... | code_fim | medium | {
"lang": "rust",
"repo": "dsbrgg/exercises",
"path": "/rust/dig_pow/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn dig_pow(n: i64, p: i32) -> i64 {
let mut k: i64 = 0;
let mut i = p.clone() as u32;
let t: i64 = n
.to_string()
.chars()
.fold(0, |acc, d| {
let digit = d.to_digit(10).unwrap() as i64;
let sum = acc + digit.pow(i);
i += 1;
sum
});
while n * k <= t && n *... | code_fim | medium | {
"lang": "rust",
"repo": "dsbrgg/exercises",
"path": "/rust/dig_pow/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut k: i64 = 0;
let mut i = p.clone() as u32;
let t: i64 = n
.to_string()
.chars()
.fold(0, |acc, d| {
let digit = d.to_digit(10).unwrap() as i64;
let sum = acc + digit.pow(i);
i += 1;
sum
});
while n * k <= t && n * k != t { k += 1; }
if n * k ==... | code_fim | medium | {
"lang": "rust",
"repo": "dsbrgg/exercises",
"path": "/rust/dig_pow/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: bytecodealliance/wasmtime path: /cranelift/codegen/src/isa/x64/inst/emit.rs
de ib
// When the shift amount is 1, there's an even shorter encoding, but we don't
// bother with that nicety here.
emit_std_enc_enc(sink, prefix, opcode, 1, s... | code_fim | hard | {
"lang": "rust",
"repo": "bytecodealliance/wasmtime",
"path": "/cranelift/codegen/src/isa/x64/inst/emit.rs",
"mode": "psm",
"license": "LLVM-exception",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: bytecodealliance/wasmtime path: /cranelift/codegen/src/isa/x64/inst/emit.rs
inst.emit(&[], sink, info, state);
let handle_large = sink.get_label();
one_way_jmp(sink, CC::NB, handle_large); // jump to handle_large if src >= large_threshold
if *is_saturatin... | code_fim | hard | {
"lang": "rust",
"repo": "bytecodealliance/wasmtime",
"path": "/cranelift/codegen/src/isa/x64/inst/emit.rs",
"mode": "psm",
"license": "LLVM-exception",
"source": "the-stack-v2"
} |
<|fim_suffix|> let inst = Inst::jmp_known(done);
inst.emit(&[], sink, info, state);
sink.bind_label(not_nan, state.ctrl_plane_mut());
} else {
// Trap.
let inst = Inst::trap_if(CC::P, TrapCode::BadConversionToInteger);
... | code_fim | hard | {
"lang": "rust",
"repo": "bytecodealliance/wasmtime",
"path": "/cranelift/codegen/src/isa/x64/inst/emit.rs",
"mode": "spm",
"license": "LLVM-exception",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: juntyr/necsim-rust path: /rustcoalescence/src/args/config/sample/origin.rs
use std::{collections::HashSet, fmt};
use fnv::FnvBuildHasher;
use serde::{Deserialize, Deserializer};
use serde_state::DeserializeState;
use necsim_core::lineage::Lineage;
use necsim_impls_std::lineage_file::loader::Li... | code_fim | hard | {
"lang": "rust",
"repo": "juntyr/necsim-rust",
"path": "/rustcoalescence/src/args/config/sample/origin.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl<'de> DeserializeState<'de, &'de Option<Pause>> for SampleOrigin {
fn deserialize_state<D: Deserializer<'de>>(
pause: &mut &'de Option<Pause>,
deserializer: D,
) -> Result<Self, D::Error> {
let raw = SampleOriginRaw::deserialize(deserializer)?;
if let Some(paus... | code_fim | hard | {
"lang": "rust",
"repo": "juntyr/necsim-rust",
"path": "/rustcoalescence/src/args/config/sample/origin.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> match change {
Change::Put(value) => collection.insert(buffer.to_vec(), value),
Change::Delete => collection.remove(buffer.as_ref()),
};
}
} else {
// Write changes to the co... | code_fim | hard | {
"lang": "rust",
"repo": "exonum/exonum",
"path": "/components/merkledb/src/backends/temporarydb/memory.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> if self.ended {
return None;
}
let (key, value) = self.iter.next()?;
if let Some(ref prefix) = self.prefix {
if &key[..ID_SIZE] != prefix {
self.ended = true;
return None;
}
}
let key = i... | code_fim | hard | {
"lang": "rust",
"repo": "exonum/exonum",
"path": "/components/merkledb/src/backends/temporarydb/memory.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: exonum/exonum path: /components/merkledb/src/backends/temporarydb/memory.rs
// Copyright 2022 The Exonum Team
//
// 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
//
//... | code_fim | hard | {
"lang": "rust",
"repo": "exonum/exonum",
"path": "/components/merkledb/src/backends/temporarydb/memory.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mrutyunjayan/ray_tracing_in_one_weekend path: /src/lib/aabb.rs
use crate::lib::{ray::*, vec3::*};
use partial_min_max::*;
#[derive(Copy, Clone, Default)]
pub struct AABB {
_min: Point3,
_max: Point3,
}
#[allow(dead_code)]
impl AABB {
pub fn new(min: &Point3, max: &Point3) -> Self ... | code_fim | hard | {
"lang": "rust",
"repo": "mrutyunjayan/ray_tracing_in_one_weekend",
"path": "/src/lib/aabb.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> //𝑡y0 = min((y0 − 𝐴y) / 𝑏y, (y1 − 𝐴y) / 𝑏y)
t_0 = min(
(self._min.y() - ray.origin().y()) * inv_d,
(self._max.y() - ray.origin().y()) * inv_d,
);
//𝑡y0 = max((y0 − 𝐴y) / ... | code_fim | hard | {
"lang": "rust",
"repo": "mrutyunjayan/ray_tracing_in_one_weekend",
"path": "/src/lib/aabb.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: qiniu/rust-sdk path: /http-client/src/regions/cache_key.rs
use super::super::Endpoints;
use md5::{
digest::{generic_array::GenericArray, FixedOutputDirty},
Md5,
};
use qiniu_credential::AccessKey;
use qiniu_upload_token::BucketName;
use serde::{
de::{Error as DeError, Visitor},
D... | code_fim | hard | {
"lang": "rust",
"repo": "qiniu/rust-sdk",
"path": "/http-client/src/regions/cache_key.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Serialize for CacheKey {
#[inline]
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
if let Some(ak_and_bucket) = &self.ak_and_bucket {
s.collect_str(&format!(
"qiniu-cache-key-v1:{}:{}:{}",
self.uc_md5_hex, ak_and_bucket... | code_fim | hard | {
"lang": "rust",
"repo": "qiniu/rust-sdk",
"path": "/http-client/src/regions/cache_key.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dora-gt/tower-web path: /src/routing/captures.rs
#[derive(Debug)]
pub(crate) struct Captures {
/// Captures extracted from the request
captures: Vec<(usize, usize)>,
}
<|fim_suffix|> /// Get a capture
pub fn get<'a>(&self, index: usize, src: &'a str) -> &'a str {
let (pos... | code_fim | hard | {
"lang": "rust",
"repo": "dora-gt/tower-web",
"path": "/src/routing/captures.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Get a capture
pub fn get<'a>(&self, index: usize, src: &'a str) -> &'a str {
let (pos, len) = self.captures[index];
&src[pos..(pos + len)]
}
}<|fim_prefix|>// repo: dora-gt/tower-web path: /src/routing/captures.rs
#[derive(Debug)]
pub(crate) struct Captures {
/// Captu... | code_fim | medium | {
"lang": "rust",
"repo": "dora-gt/tower-web",
"path": "/src/routing/captures.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[cfg(test)]
pub(crate) fn len(&self) -> usize {
self.captures.len()
}
/// Get a capture
pub fn get<'a>(&self, index: usize, src: &'a str) -> &'a str {
let (pos, len) = self.captures[index];
&src[pos..(pos + len)]
}
}<|fim_prefix|>// repo: dora-gt/tower-web... | code_fim | medium | {
"lang": "rust",
"repo": "dora-gt/tower-web",
"path": "/src/routing/captures.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rcls/svd2rust-example path: /stm32l051x/src/exti/pr.rs
#[doc = "Field `PR4` reader - Pending bit 4"]
pub struct PR4_R(crate::FieldReader<bool, bool>);
impl PR4_R {
pub(crate) fn new(bits: bool) -> Self {
PR4_R(crate::FieldReader::new(bits))
}
}
impl core::ops::Deref for PR4_R {
... | code_fim | hard | {
"lang": "rust",
"repo": "rcls/svd2rust-example",
"path": "/stm32l051x/src/exti/pr.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rcls/svd2rust-example path: /stm32l051x/src/exti/pr.rs
lears the field bit"]
#[inline(always)]
pub fn clear_bit(self) -> &'a mut W {
self.bit(false)
}
#[doc = r"Writes raw bits to the field"]
#[inline(always)]
pub fn bit(self, value: bool) -> &'a mut W {
s... | code_fim | hard | {
"lang": "rust",
"repo": "rcls/svd2rust-example",
"path": "/stm32l051x/src/exti/pr.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> &self.0
}
}
#[doc = "Field `PR14` writer - Pending bit 14"]
pub struct PR14_W<'a> {
w: &'a mut W,
}
impl<'a> PR14_W<'a> {
#[doc = r"Sets the field bit"]
#[inline(always)]
pub fn set_bit(self) -> &'a mut W {
self.bit(true)
}
#[doc = r"Clears the field bit"]
#... | code_fim | hard | {
"lang": "rust",
"repo": "rcls/svd2rust-example",
"path": "/stm32l051x/src/exti/pr.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert!(
*cursor < T::SIZE,
"Index out of range: {} overflows {}",
*cursor,
T::SIZE,
);
(T::MASK - *cursor).into()
}
}
impl Cursor for LittleEndian {
const TYPENAME: &'static str = "LittleEndian";
/// Maps a semantic count to a concrete position.
///
/// `LittleEndian` order moves... | code_fim | hard | {
"lang": "rust",
"repo": "mozmark/bitvec",
"path": "/src/cursor.rs",
"mode": "spm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_suffix|># Usage
`bitvec` structures store and operate on semantic counts, not bit positions. The
`Cursor::at` function takes a semantic cursor, `BitIdx`, and produces an
electrical position, `BitPos`.
**/
pub trait Cursor {
/// Name of the cursor type, for use in text display.
const TYPENAME: &'static str;
/... | code_fim | hard | {
"lang": "rust",
"repo": "mozmark/bitvec",
"path": "/src/cursor.rs",
"mode": "spm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mozmark/bitvec path: /src/cursor.rs
/*! Bit Cursors
`bitvec` structures are parametric over any ordering of bits within an element.
The `Cursor` trait maps a cursor position (indicated by the `BitIdx` type) to an
electrical position (indicated by the `BitPos` type) within that element, and
also... | code_fim | hard | {
"lang": "rust",
"repo": "mozmark/bitvec",
"path": "/src/cursor.rs",
"mode": "psm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_suffix|>
impl Key for ConfigMisc {
type Value = ConfigMisc;
}<|fim_prefix|>// repo: anjumkaiser/iron-backend path: /src/lib/common/configmisc/mod.rs
use iron::typemap::Key;
<|fim_middle|>
#[derive(Debug)]
pub struct ConfigMisc {
pub jwt_secret: String,
pub jwt_time_variation: i64
}
| code_fim | medium | {
"lang": "rust",
"repo": "anjumkaiser/iron-backend",
"path": "/src/lib/common/configmisc/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: anjumkaiser/iron-backend path: /src/lib/common/configmisc/mod.rs
use iron::typemap::Key;
<|fim_suffix|>impl Key for ConfigMisc {
type Value = ConfigMisc;
}<|fim_middle|>
#[derive(Debug)]
pub struct ConfigMisc {
pub jwt_secret: String,
pub jwt_time_variation: i64
}
| code_fim | medium | {
"lang": "rust",
"repo": "anjumkaiser/iron-backend",
"path": "/src/lib/common/configmisc/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: liyichao/rust-test path: /src/lib.rs
#[macro_export]
macro_rules! m1 { () => ((println!("m1"))) }
// visible here: m1
pub mod foo {
// visible here: m1
#[macro_export]
macro_rules! m2 { () => (println!("m2")) }
<|fim_suffix|>#[macro_use]
mod bar {
// visible here: m1, m3
... | code_fim | medium | {
"lang": "rust",
"repo": "liyichao/rust-test",
"path": "/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> macro_rules! m4 { () => (()) }
// visible here: m1, m3, m4
}<|fim_prefix|>// repo: liyichao/rust-test path: /src/lib.rs
#[macro_export]
macro_rules! m1 { () => ((println!("m1"))) }
// visible here: m1
pub mod foo {
// visible here: m1
#[macro_export]
macro_rules! m2 { () => (print... | code_fim | hard | {
"lang": "rust",
"repo": "liyichao/rust-test",
"path": "/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[macro_export]
macro_rules! m2 { () => (println!("m2")) }
pub fn test2() {
m2!();
}
// visible here: m1, m2
}
pub fn test3() {
m1!();
}
// visible here: m1
macro_rules! m3 { () => (()) }
// visible here: m1, m3
#[macro_use]
mod bar {
// visible here: m1, m3
m... | code_fim | medium | {
"lang": "rust",
"repo": "liyichao/rust-test",
"path": "/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let json_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("json");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("generated.rs");
spatialos_gdk_codegen::codegen(json_path, out_path);
}<|fim_prefix|>// repo: samsnyder/RustGDK path: /demo-project/snapshot/src/build.rs
u... | code_fim | easy | {
"lang": "rust",
"repo": "samsnyder/RustGDK",
"path": "/demo-project/snapshot/src/build.rs",
"mode": "spm",
"license": "LicenseRef-scancode-warranty-disclaimer",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: samsnyder/RustGDK path: /demo-project/snapshot/src/build.rs
use std::env;
use std::path::PathBuf;
<|fim_suffix|> let json_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("json");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("generated.rs");
spatialos_gdk_co... | code_fim | easy | {
"lang": "rust",
"repo": "samsnyder/RustGDK",
"path": "/demo-project/snapshot/src/build.rs",
"mode": "psm",
"license": "LicenseRef-scancode-warranty-disclaimer",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Urgau/rsix path: /tests/time/main.rs
#![cfg_attr(target_os = "wasi", feature(wasi_ext))]
#![cfg_attr(io_lifetimes_use_std, feature(io_safety))]
mod clocks<|fim_suffix|>rget_os = "wasi")))]
mod monotonic;
mod timespec;
mod y2038;<|fim_middle|>;
mod dynamic_clocks;
#[cfg(not(any(target_os = "redo... | code_fim | easy | {
"lang": "rust",
"repo": "Urgau/rsix",
"path": "/tests/time/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>;
mod dynamic_clocks;
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
mod monotonic;
mod timespec;
mod y2038;<|fim_prefix|>// repo: Urgau/rsix path: /tests/time/main.rs
#![cfg_attr(target_os = "wasi", feature(wasi_ext))]
#![cfg_<|fim_middle|>attr(io_lifetimes_use_std, feature(io_safety))]
mod ... | code_fim | easy | {
"lang": "rust",
"repo": "Urgau/rsix",
"path": "/tests/time/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>rget_os = "wasi")))]
mod monotonic;
mod timespec;
mod y2038;<|fim_prefix|>// repo: Urgau/rsix path: /tests/time/main.rs
#![cfg_attr(target_os = "wasi", feature(wasi_ext))]
#![cfg_attr(io_lifetimes_use_std, feature(io_safety))]
mod clocks<|fim_middle|>;
mod dynamic_clocks;
#[cfg(not(any(target_os = "redo... | code_fim | easy | {
"lang": "rust",
"repo": "Urgau/rsix",
"path": "/tests/time/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> TargetSelector::Unspecified(value)
}
}
impl From<()> for TargetSelector {
fn from(_value: ()) -> Self {
TargetSelector::Auto
}
}
impl From<Target> for TargetSelector {
fn from(target: Target) -> Self {
TargetSelector::Specified(target)
}
}<|fim_prefix|>// repo... | code_fim | hard | {
"lang": "rust",
"repo": "blueluna/probe-rs",
"path": "/probe-rs/src/config/target.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: blueluna/probe-rs path: /probe-rs/src/config/target.rs
use super::chip::Chip;
use super::flash_algorithm::RawFlashAlgorithm;
use super::memory::MemoryRegion;
use super::registry::TargetIdentifier;
use crate::core::{Architecture, CoreType};
/// This describes a complete target with a fixed chip ... | code_fim | hard | {
"lang": "rust",
"repo": "blueluna/probe-rs",
"path": "/probe-rs/src/config/target.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> TargetSelector::Unspecified(value.into())
}
}
impl From<&String> for TargetSelector {
fn from(value: &String) -> Self {
TargetSelector::Unspecified(value.into())
}
}
impl From<String> for TargetSelector {
fn from(value: String) -> Self {
TargetSelector::Unspecifie... | code_fim | hard | {
"lang": "rust",
"repo": "blueluna/probe-rs",
"path": "/probe-rs/src/config/target.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[wasm_bindgen(js_name = roundToNearestAxial)]
pub fn round_to_nearest_axial(q: f32, r: f32) -> Vec2 {
// convert to cube
let [x, z] = [q, r];
let y = -x - z;
// round
let [mut rx, ry, mut rz] = [x.round(), y.round(), z.round()];
let [dx, dy, dz] = [(rx - x).abs(), (ry - y).abs(), ... | code_fim | hard | {
"lang": "rust",
"repo": "caolo-game/cao-math",
"path": "/src/hex.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: caolo-game/cao-math path: /src/hex.rs
//! Hex-Grid utilities
mod hexagon;
pub use hexagon::*;
use crate::array::Array3f;
use crate::mat::mat2::Mat2f;
use crate::vec::vec2::Vec2;
use crate::vec::vec3::Vec3;
use wasm_bindgen::prelude::*;
const SQRT3APROX: f32 = 1.732_050_807_57;
/// Converts a ... | code_fim | hard | {
"lang": "rust",
"repo": "caolo-game/cao-math",
"path": "/src/hex.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: trishume/syntect path: /examples/synhtml-css-classes.rs
//! Generates highlighted HTML with CSS classes for a Rust and a C++ source.
//! Run with ```cargo run --example synhtml-css-classes```
//!
//! will generate 4 files as usage example
//! * synhtml-css-classes.html
//! * synhtml-css-classes.... | code_fim | hard | {
"lang": "rust",
"repo": "trishume/syntect",
"path": "/examples/synhtml-css-classes.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> writeln!(css_writer, "{}", css)?;
// ---------------------------------------------------------------------------------------------
// generate css files for themes
let ts = ThemeSet::load_defaults();
// create dark color scheme css
let dark_theme = &ts.themes["Solarized (dark)"];... | code_fim | hard | {
"lang": "rust",
"repo": "trishume/syntect",
"path": "/examples/synhtml-css-classes.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ozbe/exercisim path: /rust/sieve/src/lib.rs
pub fn primes_up_to(upper_bound: u64) -> Vec<u64> {
// Add 1 to account for zero based index
let mut a: Vec<_> = std::iter::repeat(true).take((upper_bound + 1) as usize).collect();
for i in 2..=(upper_bound as f64).sqrt() as u64 {
if... | code_fim | medium | {
"lang": "rust",
"repo": "ozbe/exercisim",
"path": "/rust/sieve/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> }
}
}
a.iter()
.enumerate()
.skip(2) // skip 0 & 1
.filter(|(_, p)| **p)
.map(|(i, _)| i as u64)
.collect()
}
/*
less optimal but more fluent
const LOWER_BOUND: u64 = 2;
let mut primes: Vec<_> = (LOWER_BOUND..=upper_bound).map(|n| Some(n)).collect(... | code_fim | medium | {
"lang": "rust",
"repo": "ozbe/exercisim",
"path": "/rust/sieve/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>let mut primes: Vec<_> = (LOWER_BOUND..=upper_bound).map(|n| Some(n)).collect();
for i in LOWER_BOUND..=(upper_bound as f64).sqrt() as u64 {
(i..=upper_bound).step_by(i as usize).skip(1).for_each(|p| {
if let Some(v) = primes.get_mut((p - LOWER_BOUND) as usize) {
v.take();
... | code_fim | medium | {
"lang": "rust",
"repo": "ozbe/exercisim",
"path": "/rust/sieve/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(test)]
mod tests {
use super::*;
#[test]
fn subsets_test() {
assert_eq!(
subsets(&(['A', 'B', 'C'])),
[
vec![],
vec!['A'],
vec!['B'],
vec!['A', 'B'],
vec!['C'],
... | code_fim | hard | {
"lang": "rust",
"repo": "0xisk/rust-algorithms",
"path": "/src/miscellaneous/generating_subsets.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: 0xisk/rust-algorithms path: /src/miscellaneous/generating_subsets.rs
/**
* Generating subsets (O(2^n) time).
*/
pub fn subsets<T: Copy>(set: &[T]) -> Vec<Vec<T>> {
let mut sets: Vec<Vec<T>> = vec![];
for mut n in 0..2_i32.pow(set.len() as u32) {
let mut pos = 0;
let mut... | code_fim | hard | {
"lang": "rust",
"repo": "0xisk/rust-algorithms",
"path": "/src/miscellaneous/generating_subsets.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn subsets_test() {
assert_eq!(
subsets(&(['A', 'B', 'C'])),
[
vec![],
vec!['A'],
vec!['B'],
vec!['A', 'B'],
vec!['C'],
vec!['A', 'C'],
vec!['B', ... | code_fim | hard | {
"lang": "rust",
"repo": "0xisk/rust-algorithms",
"path": "/src/miscellaneous/generating_subsets.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> match self {
Self::ImproperFraction => write!(f, "fraction"),
Self::MixedFraction => write!(f, "mixed_fraction"),
Self::ExactFloat => write!(f, "float"),
Self::Exact => write!(f, "exact"),
Self::DecimalPlaces(d) => write!(f, "{} dp", d),
... | code_fim | medium | {
"lang": "rust",
"repo": "FliegendeWurst/fend",
"path": "/core/src/num/formatting_style.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: FliegendeWurst/fend path: /core/src/num/formatting_style.rs
use std::fmt;
#[derive(PartialEq, Eq, Clone, Copy)]
#[must_use]
pub(crate) enum FormattingStyle {
/// Print value as an improper fraction
ImproperFraction,
/// Print as a mixed fraction, e.g. 1 1/2
MixedFraction,
//... | code_fim | hard | {
"lang": "rust",
"repo": "FliegendeWurst/fend",
"path": "/core/src/num/formatting_style.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl fmt::Display for FormattingStyle {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match self {
Self::ImproperFraction => write!(f, "fraction"),
Self::MixedFraction => write!(f, "mixed_fraction"),
Self::ExactFloat => write!(f, "flo... | code_fim | medium | {
"lang": "rust",
"repo": "FliegendeWurst/fend",
"path": "/core/src/num/formatting_style.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> new = old + 1;
if let Ok(_) = sweep_chunk_index.compare_exchange(
old,
new,
atomic::Ordering::SeqCst,
atomic::Ordering::SeqCst,
) {
return self.get_page_index(index);
}
... | code_fim | hard | {
"lang": "rust",
"repo": "Lol3rrr/free_access",
"path": "/free_access/src/allocator/page.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Lol3rrr/free_access path: /free_access/src/allocator/page.rs
use std::sync::atomic;
#[derive(Debug, Clone, PartialEq)]
pub struct NodeMarks {
pub marked: bool,
pub phase: u64,
}
impl From<u64> for NodeMarks {
fn from(raw: u64) -> Self {
let marked = raw & 0x01 == 0x01;
... | code_fim | hard | {
"lang": "rust",
"repo": "Lol3rrr/free_access",
"path": "/free_access/src/allocator/page.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> for i in begin..nums.len() {
let mut nums = nums.clone();
nums.swap(begin, i);
Self::backtrace(result, nums, begin + 1);
}
}
}<|fim_prefix|>// repo: y-yagi/til path: /leetcode/permutations/rust/src/lib.rs
#[cfg(test)]
mod tests {
use super::*;
... | code_fim | hard | {
"lang": "rust",
"repo": "y-yagi/til",
"path": "/leetcode/permutations/rust/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn backtrace(result: &mut Vec<Vec<i32>>, nums: Vec<i32>, begin: usize) {
if begin >= nums.len() {
result.push(nums);
return
}
for i in begin..nums.len() {
let mut nums = nums.clone();
nums.swap(begin, i);
Self::ba... | code_fim | medium | {
"lang": "rust",
"repo": "y-yagi/til",
"path": "/leetcode/permutations/rust/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: y-yagi/til path: /leetcode/permutations/rust/src/lib.rs
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
assert_eq!(Solution::permute(vec![0, 1]), vec![vec![0, 1], vec![1, 0]]);
}
}
struct Solution { }
impl Solution {
pub fn permute(nums: Vec<i32>) ->... | code_fim | medium | {
"lang": "rust",
"repo": "y-yagi/til",
"path": "/leetcode/permutations/rust/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ctjhoa/dotext path: /src/doc.rs
use zip::ZipArchive;
use xml::reader::Reader;
use xml::events::Event;
use std::path::{Path, PathBuf};
use std::fs::File;
use std::io::prelude::*;
use std::io;
use std::clone::Clone;
use zip::read::ZipFile;
pub trait HasKind {
// kind
fn kind(&self) ... | code_fim | hard | {
"lang": "rust",
"repo": "ctjhoa/dotext",
"path": "/src/doc.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.