text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_prefix|>// repo: 1u0/puzzles path: /advent-of-code-2019/day-4/src/main.rs
fn get_digits(num: u64) -> Vec<u8> {
let mut digits = Vec::new();
let mut num = num;
while num > 0 {
digits.push((num % 10) as u8);
num /= 10;
}
digits
}
fn is_non_decreasing(digits: &[u8]) -> bool {
... | code_fim | medium | {
"lang": "rust",
"repo": "1u0/puzzles",
"path": "/advent-of-code-2019/day-4/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jianshu93/drprg path: /src/interval.rs
use std::cmp::{max, min};
use std::ops::Range;
/// A trait for defining interval operations (intended for use with Range)
pub trait IntervalOp {
/// Returns the intersection between two Ranges, or None is they do not overlap
fn intersect(&self, oth... | code_fim | hard | {
"lang": "rust",
"repo": "jianshu93/drprg",
"path": "/src/interval.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let i = 1..3;
let j = 2..6;
let overlap = i.intersect(&j);
let expected = Some(2..3);
assert_eq!(overlap, expected)
}
#[test]
fn interval_op_intersect_no_intersection_self() {
let i = 1..3;
let j = 1..3;
let overlap = i.inters... | code_fim | hard | {
"lang": "rust",
"repo": "jianshu93/drprg",
"path": "/src/interval.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let opts: Options = Options::from_args();
let paths = opts.paths;
let max_job_count = opts.job_count;
let io_lock = Arc::new(Semaphore::new(max_job_count as isize));
let use_mmap = opts.mmap;
rayon::scope(|s| {
for path in paths {
if let Err(err) = do_checksum(
... | code_fim | medium | {
"lang": "rust",
"repo": "lefth/b3sum-ng",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: lefth/b3sum-ng path: /src/main.rs
// Copyright 2021 Daniel Zwell.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not... | code_fim | medium | {
"lang": "rust",
"repo": "lefth/b3sum-ng",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>use multi_semaphore::Semaphore;
use structopt::*;
mod lib;
use lib::*;
fn main() {
let opts: Options = Options::from_args();
let paths = opts.paths;
let max_job_count = opts.job_count;
let io_lock = Arc::new(Semaphore::new(max_job_count as isize));
let use_mmap = opts.mmap;
rayon... | code_fim | medium | {
"lang": "rust",
"repo": "lefth/b3sum-ng",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// Creates a DNS-Package which contains a Header and a Question.
/// Sends and retreives it.
/// Prints Records of the receiving packet.
/// The response contains the same Header + Question and in addition one or more concatenated Answers.
/// # Arguments
/// * `message` - u8 vector, containing Header an... | code_fim | hard | {
"lang": "rust",
"repo": "RustProfi/DNSLookup",
"path": "/nslookup/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: RustProfi/DNSLookup path: /nslookup/src/main.rs
extern crate nslookup;
use std::env;
use std::str;
use std::vec::Vec;
mod customerror;
mod qtype;
mod question;
mod response;
use crate::qtype::Qtype;
use crate::question::{DnsMessageBuilder, Header, Question};
use crate::response::Response;
use c... | code_fim | hard | {
"lang": "rust",
"repo": "RustProfi/DNSLookup",
"path": "/nslookup/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // avoid unnecessary tail-end shuffle
round!();
for _round in 0..4 - 1 {
b = shuffle!(b, b, [1, 2, 3, 0]);
c = shuffle!(c, c, [2, 3, 0, 1]);
d = shuffle!(d, d, [3, 0, 1, 2]);
round!();
}
a += self.a;
b += se... | code_fim | hard | {
"lang": "rust",
"repo": "TheIronBorn/simd_prngs",
"path": "/src/prngs/chacha.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> for _round in 0..4 - 1 {
b = shuffle!(b, b, [1, 2, 3, 0]);
c = shuffle!(c, c, [2, 3, 0, 1]);
d = shuffle!(d, d, [3, 0, 1, 2]);
round!();
}
a += self.a;
b += self.b;
c += self.c;
d += self.d;
// updat... | code_fim | hard | {
"lang": "rust",
"repo": "TheIronBorn/simd_prngs",
"path": "/src/prngs/chacha.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: TheIronBorn/simd_prngs path: /src/prngs/chacha.rs
//! The ChaCha random number generator.
//!
//! https://cr.yp.to/chacha.html
use rng_impl::*;
const CHACHA_SEED: u32x4 = u32x4::new(0x61707865, 0x3320646E, 0x79622D32, 0x6B206574);
/// 4 rounds of ChaCha
///
/// Not cryptographically strong bu... | code_fim | hard | {
"lang": "rust",
"repo": "TheIronBorn/simd_prngs",
"path": "/src/prngs/chacha.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let str_length: usize = s.len();
(s, str_length)
}
fn share_by_reference(s: &mut String) {
s.push_str(" was pushed");
}
pub fn run() {
{
let str_1 = String::from("heap string");
// Like shallow copy but str_1 was moved
// Rust never 'deep' copy data
let str_2 = str_1;
let s... | code_fim | hard | {
"lang": "rust",
"repo": "dangduoc08/rust-concepts",
"path": "/src/ownership/src/rules.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dangduoc08/rust-concepts path: /src/ownership/src/rules.rs
/*
Stack
- Extremely Fast
- Values must have Fixed Sizes
- Always puts data in on Top
- data pushed down as new data comes in
*/
/*
Heap
- Less Organized and Slower
- Accepts Dynamicly Sized Data or Data that can Grow
... | code_fim | hard | {
"lang": "rust",
"repo": "dangduoc08/rust-concepts",
"path": "/src/ownership/src/rules.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: svmk/fund-watch-bot path: /src/event_emitter/service_handler/packed_event_handler.rs
use crate::prelude::*;
use crate::event_emitter::model::packed_event::PackedEvent;
use std::future::Future;
<|fim_suffix|>#[async_trait]
impl <F, Fut> PackedEventHandler for F
where
F: Fn(PackedEve... | code_fim | medium | {
"lang": "rust",
"repo": "svmk/fund-watch-bot",
"path": "/src/event_emitter/service_handler/packed_event_handler.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>
#[async_trait]
impl <F, Fut> PackedEventHandler for F
where
F: Fn(PackedEvent) -> Fut,
Fut: Future<Output=Result<(), Failure>> + Send + 'static,
F: Send + Sync,
{
async fn handle_event(&self, event: PackedEvent) -> Result<(), Failure> {
ret... | code_fim | medium | {
"lang": "rust",
"repo": "svmk/fund-watch-bot",
"path": "/src/event_emitter/service_handler/packed_event_handler.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ytyaru/Rust.Iterator.20190703074228 path: /src/2/iterator_0/src/main.rs
fn main() {
let v = vec![1,2,3];
let mut i = v.iter(); // next()を呼ぶならmutableにする必要が<|fim_suffix|>rintln!("{:?}", i); // Iter([1, 2, 3])
assert_eq!(i.next(), Some(&1));
assert_eq!(i.next(), Some(&2));
asser... | code_fim | medium | {
"lang": "rust",
"repo": "ytyaru/Rust.Iterator.20190703074228",
"path": "/src/2/iterator_0/src/main.rs",
"mode": "psm",
"license": "CC0-1.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>i.next(), Some(&2));
assert_eq!(i.next(), Some(&3));
assert_eq!(i.next(), None);
}<|fim_prefix|>// repo: ytyaru/Rust.Iterator.20190703074228 path: /src/2/iterator_0/src/main.rs
fn main() {
let v = vec![1,2,3];
let mut i = v.iter(); // next()を呼ぶならmutableにする必要が<|fim_middle|>ある。さもなくばerror[E0... | code_fim | medium | {
"lang": "rust",
"repo": "ytyaru/Rust.Iterator.20190703074228",
"path": "/src/2/iterator_0/src/main.rs",
"mode": "spm",
"license": "CC0-1.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jamesmunns/slack-rs-api path: /src/files.rs
// Copyright 2015-2016 the slack-rs authors.
//
// 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
//
// http://www.apache.or... | code_fim | hard | {
"lang": "rust",
"repo": "jamesmunns/slack-rs-api",
"path": "/src/files.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> "name" : "file.htm",
"title" : "My HTML file",
"mimetype" : "text\/plain",
"filetype" : "text",
"pretty_type": "Text",
"user" : "U2147483697",
"mode" : "hosted",
... | code_fim | hard | {
"lang": "rust",
"repo": "jamesmunns/slack-rs-api",
"path": "/src/files.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ovo/hyvee-vaccine-monitor path: /src/main.rs
pub mod hyvee;
use dotenv::dotenv;
use std::{env, time::Duration};
use tokio::time;
#[tokio::main]
async fn main() {
dotenv().ok();
let lat = env::var("LAT")
.map_err(|e| println!("could not get latitude, {:?}", e))
.unwrap()
... | code_fim | hard | {
"lang": "rust",
"repo": "ovo/hyvee-vaccine-monitor",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> if comparable[i].location.is_covid_vaccine_available
&& !current[i].location.is_covid_vaccine_available
{
println!("Vaccine available: {:?}", comparable[i].location)
}
i = i + 1;
}
current = comparable;
}... | code_fim | hard | {
"lang": "rust",
"repo": "ovo/hyvee-vaccine-monitor",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // convert to string
let mut str = String::from_utf8_lossy(&raw).to_string();
// remove the newline sequence
str.pop();
// parse the string
str.parse().expect(&format!("unable to convert '{}' to a number", str))
}<|fim_prefix|>// repo: j-keck/free path: /tests/stats_test.rs
extern crate fre... | code_fim | medium | {
"lang": "rust",
"repo": "j-keck/free",
"path": "/tests/stats_test.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>
fn sysctl(name: &str) -> u64 {
let raw = Command::new("sysctl")
.arg("-n")
.arg(name)
.output()
.expect(&format!("Failed to execute 'sysctl -n {}", name))
.stdout;
// convert to string
let mut str = String::from_utf8_lossy(&raw).to_string();
// remove the newline sequence
... | code_fim | hard | {
"lang": "rust",
"repo": "j-keck/free",
"path": "/tests/stats_test.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: j-keck/free path: /tests/stats_test.rs
extern crate free;
use std::process::Command;
#[test]
fn validate_stats() {
let stats = free::Stats::collect().unwrap();
let pagesize = sysctl("hw.pagesize");
let mem_total = sysctl("vm.stats.vm.v_page_count") * pagesize;
assert_eq!(stats.mem... | code_fim | hard | {
"lang": "rust",
"repo": "j-keck/free",
"path": "/tests/stats_test.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: maotv/roteld path: /src/common.rs
extern crate ws;
// use ws::{Handler, Handshake, Result, Message};
use serde_json::Value;
<|fim_suffix|>pub enum Event {
RotelMessage(KeyValueRaw),
VolumioState(Value),
SerialData(String),
SocketSerialBroadcaster(ws::Sender),
VolumioConne... | code_fim | medium | {
"lang": "rust",
"repo": "maotv/roteld",
"path": "/src/common.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> RotelMessage(KeyValueRaw),
VolumioState(Value),
SerialData(String),
SocketSerialBroadcaster(ws::Sender),
VolumioConnect(ws::Sender),
VolumioPing
}<|fim_prefix|>// repo: maotv/roteld path: /src/common.rs
extern crate ws;
// use ws::{Handler, Handshake, Result, Message};
use serd... | code_fim | easy | {
"lang": "rust",
"repo": "maotv/roteld",
"path": "/src/common.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[actix_rt::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
//.service(get_lead)
.service(web::scope("/lead").configure(config))
})
.bind("127.0.0.1:8088")?
.run()
.await
}<|fim_prefix|>// repo: Dhanabalanvb/Rust p... | code_fim | medium | {
"lang": "rust",
"repo": "Dhanabalanvb/Rust",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Dhanabalanvb/Rust path: /src/main.rs
extern crate actix_web;
mod models;
mod actions;
<|fim_suffix|>#[actix_rt::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
//.service(get_lead)
.service(web::scope("/lead").configure... | code_fim | medium | {
"lang": "rust",
"repo": "Dhanabalanvb/Rust",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn find_crates_to_copy(
metadata: &Metadata,
crates: impl Iterator<Item = String>,
) -> BTreeSet<LocalCrate<'_>> {
crates
.flat_map(|krate| get_local_dependencies_of_crate(metadata, &krate))
.collect()
}
#[derive(Debug, PartialEq, PartialOrd, Eq, Ord)]
struct LocalCrate<'a> {
... | code_fim | hard | {
"lang": "rust",
"repo": "topecongiro/auto-publish-rustfmt-syntax",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> if CRATES_WHICH_REQUIRES_RUSTC_PRIVATE_FEATURES.contains(&krate.name) {
add_rustc_private_feature(&krate, &to)?;
}
cargo_toml_content.push_str(&format!(" \"{}\",\n", krate.root_path.file_name().unwrap().to_string_lossy()));
}
cargo_toml_content.push_str("]\n")... | code_fim | hard | {
"lang": "rust",
"repo": "topecongiro/auto-publish-rustfmt-syntax",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: topecongiro/auto-publish-rustfmt-syntax path: /src/main.rs
#[macro_use]
extern crate log;
use std::{
collections::BTreeSet,
fs,
io::{self, Write},
iter::once,
path::{Path, PathBuf},
};
use cargo_metadata::{Metadata, MetadataCommand};
use structopt::StructOpt;
use walkdir::W... | code_fim | hard | {
"lang": "rust",
"repo": "topecongiro/auto-publish-rustfmt-syntax",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> variant as u8 != 0
}
}
#[doc = "Reader of field `ROV`"]
pub type ROV_R = crate::R<bool, ROV_A>;
impl ROV_R {
#[doc = r"Get enumerated values variant"]
#[inline(always)]
pub fn variant(&self) -> ROV_A {
match self.bits {
false => ROV_A::ROV_0,
true =>... | code_fim | hard | {
"lang": "rust",
"repo": "Shock-1/teensy4-rs",
"path": "/imxrt1062-pac/imxrt1062-gpt1/src/sr.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Shock-1/teensy4-rs path: /imxrt1062-pac/imxrt1062-gpt1/src/sr.rs
#[doc = "Reader of register SR"]
pub type R = crate::R<u32, super::SR>;
#[doc = "Writer for register SR"]
pub type W = crate::W<u32, super::SR>;
#[doc = "Register SR `reset()`'s with value 0"]
impl crate::ResetValue for super::SR {... | code_fim | hard | {
"lang": "rust",
"repo": "Shock-1/teensy4-rs",
"path": "/imxrt1062-pac/imxrt1062-gpt1/src/sr.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: abusch/advent20 path: /src/bin/day05.rs
use std::collections::HashSet;
use anyhow::format_err;
use anyhow::Result;
#[derive(Debug, Eq, PartialEq, Hash)]
pub struct Seat(u8, u8);
impl Seat {
pub fn from_code(code: &str) -> Result<Seat> {
let (row_code, column_code) = code.split_at(... | code_fim | hard | {
"lang": "rust",
"repo": "abusch/advent20",
"path": "/src/bin/day05.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> println!("part 2: {}", seat_id);
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_id() {
let seat = Seat(44, 5);
assert_eq!(357, seat.id());
}
#[test]
fn test_seat_from_code() {
let seat = Seat::from_code("FBFBBFFRLR").unwrap();
... | code_fim | hard | {
"lang": "rust",
"repo": "abusch/advent20",
"path": "/src/bin/day05.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: redsnapper2006/leetcode-cn path: /L/1079-letter-tile-possibilities/main.rs
struct Solution {}
use std::collections::HashSet;
impl Solution {
pub fn num_tile_possibilities(tiles: String) -> i32 {
let buf: Vec<u8> = tiles.as_bytes().to_vec();
let mut set: HashSet<String> = HashSet::new(... | code_fim | medium | {
"lang": "rust",
"repo": "redsnapper2006/leetcode-cn",
"path": "/L/1079-letter-tile-possibilities/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> println!("{}", Solution::num_tile_possibilities("AAABBC".to_string()));
println!("{}", Solution::num_tile_possibilities("V".to_string()));
}<|fim_prefix|>// repo: redsnapper2006/leetcode-cn path: /L/1079-letter-tile-possibilities/main.rs
struct Solution {}
use std::collections::HashSet;
impl Soluti... | code_fim | medium | {
"lang": "rust",
"repo": "redsnapper2006/leetcode-cn",
"path": "/L/1079-letter-tile-possibilities/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Open DB
let key_db = KeyDB::try_new("./test_db/ttl_ok").unwrap();
// Generate metadata with 10 sec TTL
let timestamp = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs() as i64;
let payload = Payload {
... | code_fim | hard | {
"lang": "rust",
"repo": "hlb8122/keyserver-rust",
"path": "/src/db.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: hlb8122/keyserver-rust path: /src/db.rs
use std::{
sync::Arc,
time::{SystemTime, UNIX_EPOCH},
};
use crate::{
crypto::Address,
models::address_metadata::{AddressMetadata, Payload},
};
use prost::Message;
use rocksdb::{CompactionDecision, Error, Options, DB};
use crate::net::err... | code_fim | hard | {
"lang": "rust",
"repo": "hlb8122/keyserver-rust",
"path": "/src/db.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn test_ttl_ok() {
// Open DB
let key_db = KeyDB::try_new("./test_db/ttl_ok").unwrap();
// Generate metadata with 10 sec TTL
let timestamp = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs() as i64;
... | code_fim | hard | {
"lang": "rust",
"repo": "hlb8122/keyserver-rust",
"path": "/src/db.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tamanishi/rust_ffi_tutorial path: /src/main.rs
extern crate libc;
use libc::{c_char, size_t};
use std::ffi::CStr;
#[link(name = "print", kind = "static")]
extern "C" {
fn print_str(str: *const c_char, len: size_t) -> *const c_char;
}
<|fim_suffix|> let str: &str = "Hello world!";
le... | code_fim | easy | {
"lang": "rust",
"repo": "tamanishi/rust_ffi_tutorial",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>}
fn main() {
let str: &str = "Hello world!";
let ret_ptr: *const c_char = unsafe { print_str(str.as_ptr() as *const c_char, str.len()) };
let ret_str: &CStr = unsafe { CStr::from_ptr(ret_ptr) };
println!("{}", ret_str.to_str().unwrap());
}<|fim_prefix|>// repo: tamanishi/rust_ffi_tutoria... | code_fim | medium | {
"lang": "rust",
"repo": "tamanishi/rust_ffi_tutorial",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let str: &str = "Hello world!";
let ret_ptr: *const c_char = unsafe { print_str(str.as_ptr() as *const c_char, str.len()) };
let ret_str: &CStr = unsafe { CStr::from_ptr(ret_ptr) };
println!("{}", ret_str.to_str().unwrap());
}<|fim_prefix|>// repo: tamanishi/rust_ffi_tutorial path: /src/m... | code_fim | easy | {
"lang": "rust",
"repo": "tamanishi/rust_ffi_tutorial",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: xcaptain/rust-algorithms path: /codeforces/src/p263a.rs
// https://codeforces.com/problemset/problem/263/A
use crate::{Scanner, Solution};
use std::io::{Read, Write};
pub struct Solution1;
impl Solution for Solution1 {
fn solve(&self, input: &mut dyn Read, output: &mut dyn Write) {
... | code_fim | medium | {
"lang": "rust",
"repo": "xcaptain/rust-algorithms",
"path": "/codeforces/src/p263a.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn solution1() {
let cases = vec![
[
"0 0 0 0 0
0 0 0 0 1
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
",
"3",
],
[
"0 0 0 0 0
0 0 0 0 0
0 1 0 0 0
0 0 0 0 0
0 0 0 0 0
",
"1",
],
... | code_fim | medium | {
"lang": "rust",
"repo": "xcaptain/rust-algorithms",
"path": "/codeforces/src/p263a.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn from_str(base_str: &str) -> Result<Self, Self::Err> {
let base = match base_str {
"identity" => Ok(Base::Identity),
"base2" => Ok(Base::Base2),
"base8" => Ok(Base::Base8),
"base10" => Ok(Base::Base10),
"base16" => Ok(Base::Base16Lo... | code_fim | hard | {
"lang": "rust",
"repo": "multiformats/rust-multibase",
"path": "/cli/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: multiformats/rust-multibase path: /cli/main.rs
use std::fmt;
use std::str::FromStr;
use anyhow::{anyhow, Error, Result};
use multibase::Base;
use structopt::StructOpt;
#[derive(StructOpt, Debug)]
struct Opts {
/// The mode
#[structopt(subcommand)]
mode: Mode,
}
#[derive(StructOpt,... | code_fim | hard | {
"lang": "rust",
"repo": "multiformats/rust-multibase",
"path": "/cli/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl From<StrBase> for Base {
fn from(base: StrBase) -> Self {
base.0
}
}
fn encode(base: StrBase, input: &[u8]) -> Result<()> {
log::debug!("Encode {:?} with {}", input, base);
let result = multibase::encode(base.into(), input);
println!("Result: {}", result);
Ok(())
}
f... | code_fim | hard | {
"lang": "rust",
"repo": "multiformats/rust-multibase",
"path": "/cli/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>g.org/
//! [ogc]: https://github.com/devkitPro/libogc
#![no_std]<|fim_prefix|>// repo: rust-wii/luma path: /src/lib.rs
//! ``luma`` is a [Rust][rs] rewrite of devkitPro's [libogc][ogc<|fim_middle|>].
//!
//! **NOTE**: This is currently in a very experimental state and is subject to change.
//!
//! [rs]: ... | code_fim | medium | {
"lang": "rust",
"repo": "rust-wii/luma",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rust-wii/luma path: /src/lib.rs
//! ``luma`` is a [Rust][rs] rewrite of devkitPro's [libogc][ogc<|fim_suffix|>ate and is subject to change.
//!
//! [rs]: https://www.rust-lang.org/
//! [ogc]: https://github.com/devkitPro/libogc
#![no_std]<|fim_middle|>].
//!
//! **NOTE**: This is currently in a ... | code_fim | medium | {
"lang": "rust",
"repo": "rust-wii/luma",
"path": "/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mutexlox/aoc-2018 path: /src/day03_fabric.rs
use std::collections::HashMap;
use std::error;
use std::fmt;
use std::io::{self, Read};
use std::str::FromStr;
#[derive(Debug)]
struct Claim {
id: u32,
left_margin: u32,
top_margin: u32,
width: u32,
height: u32,
}
#[derive(Debug,... | code_fim | hard | {
"lang": "rust",
"repo": "mutexlox/aoc-2018",
"path": "/src/day03_fabric.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> //#1 @ 257,829: 10x23
let no_whitespace: String = s.replace(" ", "");
let pieces: Vec<&str> = no_whitespace
.trim_matches('#')
.split(|c| c == '@' || c == ',' || c == ':' || c == 'x')
.collect();
let ints_parsed = pieces
.into... | code_fim | hard | {
"lang": "rust",
"repo": "mutexlox/aoc-2018",
"path": "/src/day03_fabric.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: edgex004/rust-hdl path: /rust-hdl-core/src/struct_valued.rs
use crate::ast::VerilogLiteral;
use crate::bits::{bit_cast, clog2, Bit, Bits};
use crate::synth::{Synth, VCDValue};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum CmdType {
Noop,
Read,
Write,
}
pub fn raw_cast<S: Synth,... | code_fim | hard | {
"lang": "rust",
"repo": "edgex004/rust-hdl",
"path": "/rust-hdl-core/src/struct_valued.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(MIGCmd::BITS, 9);
let x = MIGCmd {
cmd: CmdType::Read,
active: true,
len: 35_usize.into(),
};
let y: Bits<9> = x.into();
assert_eq!(y.get_bits::<{ CmdType::BITS }>(0), 1u32);
assert_eq!(y.get_bits::<{ bool::BITS }>(2), true);
assert_eq!(y.get... | code_fim | hard | {
"lang": "rust",
"repo": "edgex004/rust-hdl",
"path": "/rust-hdl-core/src/struct_valued.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[test]
fn test_composite() {
assert_eq!(MIGCmd::BITS, 9);
let x = MIGCmd {
cmd: CmdType::Read,
active: true,
len: 35_usize.into(),
};
let y: Bits<9> = x.into();
assert_eq!(y.get_bits::<{ CmdType::BITS }>(0), 1u32);
assert_eq!(y.get_bits::<{ bool::BITS }>(2... | code_fim | hard | {
"lang": "rust",
"repo": "edgex004/rust-hdl",
"path": "/rust-hdl-core/src/struct_valued.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub mod groups {
pub use super::admin::ADMIN_GROUP;
pub use super::general::GENERAL_GROUP;
pub use super::owner::OWNER_GROUP;
}
#[check]
#[name = "admin"]
async fn admin_check(ctx: &Context, msg: &Message, _: &mut Args, _: &CommandOptions) -> Result<(), Reason> {
// Is the user on the list of own... | code_fim | medium | {
"lang": "rust",
"repo": "ScottyThePilot/a3f_sentinel",
"path": "/src/commands.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ScottyThePilot/a3f_sentinel path: /src/commands.rs
mod admin;
mod general;
mod owner;
use serenity::{
prelude::*,
framework::standard::{
Args, CommandOptions, Reason,
macros::*
},
model::{
id::UserId,
channel::Message,
guild::Member
}
};
use crate::data::config::C... | code_fim | hard | {
"lang": "rust",
"repo": "ScottyThePilot/a3f_sentinel",
"path": "/src/commands.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub mod env;
pub mod rand;
pub mod sleep;
pub mod tasks;
pub mod time;<|fim_prefix|>// repo: silverweed/ecsde path: /inle/inle_core/src/lib.rs
#![warn(clippy::all)]
#![allow(clippy::new_without_default)]
#![allow(clippy::too_many_arguments)]
#![allow(non_camel_case_types)]
#![cfg_attr(debug_assertions, a... | code_fim | easy | {
"lang": "rust",
"repo": "silverweed/ecsde",
"path": "/inle/inle_core/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: silverweed/ecsde path: /inle/inle_core/src/lib.rs
#![warn(clippy::all)]
#![allow(clippy::new_without_default)]
#![allow(clippy::too_many_arguments)]
#![allow(non_camel_case_types)]
#![cfg_attr(debug_assertions, allow(dead_code))]
<|fim_suffix|>pub mod env;
pub mod rand;
pub mod sleep;
pub mod t... | code_fim | easy | {
"lang": "rust",
"repo": "silverweed/ecsde",
"path": "/inle/inle_core/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Xorlev/AdventOfCode path: /aoc2021/src/bin/main_07.rs
use itertools::{Itertools, MinMaxResult};
use std::num::ParseIntError;
use util::aoc::*;
fn main() -> AocResult<()> {
let input: Vec<i32> = input::read_all(7)?
.split(',')
.map(|value| value.parse().map_err(|e: ParseIntEr... | code_fim | hard | {
"lang": "rust",
"repo": "Xorlev/AdventOfCode",
"path": "/aoc2021/src/bin/main_07.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(37, part1(&positions));
}
#[test]
fn part2_sample() {
let positions = SAMPLE_INPUT
.split(',')
.map(|value| value.parse().map_err(|e: ParseIntError| e.into()))
.collect::<AocResult<Vec<_>>>()
.unwrap();
assert... | code_fim | hard | {
"lang": "rust",
"repo": "Xorlev/AdventOfCode",
"path": "/aoc2021/src/bin/main_07.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let positions = SAMPLE_INPUT
.split(',')
.map(|value| value.parse().map_err(|e: ParseIntError| e.into()))
.collect::<AocResult<Vec<_>>>()
.unwrap();
assert_eq!(168, part2(&positions));
}
}<|fim_prefix|>// repo: Xorlev/AdventOfCode path:... | code_fim | hard | {
"lang": "rust",
"repo": "Xorlev/AdventOfCode",
"path": "/aoc2021/src/bin/main_07.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: yzx0115/engula path: /engula/src/cache/mod.rs
use std::sync::Arc;
use async_trait::async_trait;
<|fim_suffix|> async fn put(&self, key: Vec<u8>, value: Arc<Vec<u8>>);
}<|fim_middle|>#[async_trait]
pub trait Cache: Send + Sync {
async fn get(&self, key: &[u8]) -> Option<Arc<Vec<u8>>>;
| code_fim | medium | {
"lang": "rust",
"repo": "yzx0115/engula",
"path": "/engula/src/cache/mod.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> async fn put(&self, key: Vec<u8>, value: Arc<Vec<u8>>);
}<|fim_prefix|>// repo: yzx0115/engula path: /engula/src/cache/mod.rs
use std::sync::Arc;
use async_trait::async_trait;
<|fim_middle|>#[async_trait]
pub trait Cache: Send + Sync {
async fn get(&self, key: &[u8]) -> Option<Arc<Vec<u8>>>;
| code_fim | medium | {
"lang": "rust",
"repo": "yzx0115/engula",
"path": "/engula/src/cache/mod.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: actix/examples path: /graphql/juniper-advanced/src/main.rs
use actix_cors::Cors;
use actix_web::{middleware::Logger, web::Data, App, HttpServer};
mod db;
mod handlers;
mod schemas;
use self::{db::get_db_pool, handlers::register};
<|fim_suffix|> let pool = get_db_pool();
log::info!("st... | code_fim | medium | {
"lang": "rust",
"repo": "actix/examples",
"path": "/graphql/juniper-advanced/src/main.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> HttpServer::new(move || {
App::new()
.app_data(Data::new(pool.clone()))
.configure(register)
.wrap(Cors::permissive())
.wrap(Logger::default())
})
.workers(2)
.bind(("127.0.0.1", 8080))?
.run()
.await
}<|fim_prefix|>// repo: a... | code_fim | hard | {
"lang": "rust",
"repo": "actix/examples",
"path": "/graphql/juniper-advanced/src/main.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>, j );
if i > 10 {
break
}
}
}<|fim_prefix|>// repo: halimabergaoui/rust-training-halima path: /cycle/src/main.rs
fn main() {
let rust_group = vec!["Bacem", "Karima", "Amal<|fim_middle|>", "Jawaher", "Halima", "Khouloud"];
for (i,j) in (&rust_group).into_iter().cy... | code_fim | medium | {
"lang": "rust",
"repo": "halimabergaoui/rust-training-halima",
"path": "/cycle/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: halimabergaoui/rust-training-halima path: /cycle/src/main.rs
fn main() {
let rust_group = vec!["Bacem", "Karima", "Amal<|fim_suffix|>roup).into_iter().cycle().enumerate() {
println!("{} ", j );
if i > 10 {
break
}
}
}<|fim_middle|>", "Jawaher", "Halim... | code_fim | medium | {
"lang": "rust",
"repo": "halimabergaoui/rust-training-halima",
"path": "/cycle/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>l, tag="1")]
pub ip: ::core::option::Option<IpAddress>,
#[prost(uint32, tag="2")]
pub prefix_len: u32,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct IPv6 {
/// hextets 1-4
#[prost(fixed64, tag="1")]
pub first: u64,
/// hextets 5-8
#[prost(fixed64, tag="2")]
... | code_fim | hard | {
"lang": "rust",
"repo": "gridgentoo/linkerd2-proxy-api",
"path": "/src/gen/io.linkerd.proxy.net.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: gridgentoo/linkerd2-proxy-api path: /src/gen/io.linkerd.proxy.net.rs
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct IpAddress {
#[prost(oneof="ip_address::Ip", tags="1, 2")]
pub ip: ::core::option::Option<ip_address::Ip>,
}
/// Nested message and enum types in `IPAddress`.
pub ... | code_fim | hard | {
"lang": "rust",
"repo": "gridgentoo/linkerd2-proxy-api",
"path": "/src/gen/io.linkerd.proxy.net.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> println!("part 1 - fuel: {}", fuel);
println!("part 2 - fuel: {}", part2(&contents));
Ok(())
}<|fim_prefix|>// repo: wcastand/advent-2019 path: /src/main.rs
use std::fs::File;
use std::io::prelude::*;
fn part1(input: &str) -> i32 {
input
.lines()
.map(|s| {
l... | code_fim | hard | {
"lang": "rust",
"repo": "wcastand/advent-2019",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut file = File::open("./inputs/1.txt")?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
let fuel = part1(&contents);
println!("part 1 - fuel: {}", fuel);
println!("part 2 - fuel: {}", part2(&contents));
Ok(())
}<|fim_prefix|>// repo: wcastand/adv... | code_fim | hard | {
"lang": "rust",
"repo": "wcastand/advent-2019",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: wcastand/advent-2019 path: /src/main.rs
use std::fs::File;
use std::io::prelude::*;
fn part1(input: &str) -> i32 {
input
.lines()
.map(|s| {
let i: i32 = s.parse().unwrap();
return i / 3 - 2;
})
.sum()
}
fn part2(input: &str) -> i32 {... | code_fim | hard | {
"lang": "rust",
"repo": "wcastand/advent-2019",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ddelange/HomeAutomation path: /src/input/mpd_status.rs
use crate::errors::Error;
use crossbeam_channel::{Receiver, Sender};
use mpd::{idle::Idle, idle::Subsystem, Client};
use std::sync::{Arc, RwLock};
use std::thread;
//mpd watcher, waits on mpd sys changes and stores in struct/sends updates t... | code_fim | medium | {
"lang": "rust",
"repo": "ddelange/HomeAutomation",
"path": "/src/input/mpd_status.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn start_updating() -> Result<(Self, thread::JoinHandle<()>, Sender<()>), Error> {
let mut client = mpd::Client::connect("127.0.0.1:6600")?;
let status = client.status()?;
let mpd_status = Self {
inner: Arc::new(RwLock::new(status)),
};
let mpd_... | code_fim | hard | {
"lang": "rust",
"repo": "ddelange/HomeAutomation",
"path": "/src/input/mpd_status.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: maxjoehnk/terminal-ui-rs path: /examples/multiline_string.rs
extern crate terminal_ui;
use terminal_ui::{Engine, Padding, Result, Text};
use terminal_ui::terminal::crossterm::CrosstermEngine;
pub fn main() -> Result<()> {
let mut engine = CrosstermEngine::new();
let mut <|fim_suffix|>l... | code_fim | medium | {
"lang": "rust",
"repo": "maxjoehnk/terminal-ui-rs",
"path": "/examples/multiline_string.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>text = Text::new("Hello World\nA long line to fill your terminal with. This should be way longer. Maybe I should've copied lorem ipsum");
let mut padding = Padding::new(8, &mut text);
engine.render(&mut padding)
}<|fim_prefix|>// repo: maxjoehnk/terminal-ui-rs path: /examples/multiline_string.rs
... | code_fim | medium | {
"lang": "rust",
"repo": "maxjoehnk/terminal-ui-rs",
"path": "/examples/multiline_string.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let z = z as f32 / Z_MAX as f32;
let n = gpu_mesh.vertices.len() as u32;
for abstract_vertex in &self.vertices {
gpu_mesh.vertices.push(GpuVertex {
pos: transform * abstract_vertex.pos,
tex_pos: abstract_vertex.tex_pos.map(|v| v * transfo... | code_fim | medium | {
"lang": "rust",
"repo": "jaxwilko/paddle",
"path": "/src/display/render.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jaxwilko/paddle path: /src/display/render.rs
use crate::{AbstractMesh, GpuMesh, GpuTriangle, GpuVertex, Transform, Z_MAX};
/// Some object that can be rendered to a GpuMesh with only the position as parameter
pub trait Render {
fn render(&self, mesh: &mut GpuMesh, transform: Transform, z: i... | code_fim | medium | {
"lang": "rust",
"repo": "jaxwilko/paddle",
"path": "/src/display/render.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> if let Some(exports) = self.exports {
if exports.contains(&id) {
return true;
}
}
false
}
}
impl Visit for SideEffectVisitor<'_> {
noop_visit_type!();
fn visit_expr(&mut self, node: &Expr, _: &dyn Node) {
if self.found ... | code_fim | hard | {
"lang": "rust",
"repo": "rehack/swc",
"path": "/ecmascript/transforms/optimization/src/simplify/dce/side_effect.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rehack/swc path: /ecmascript/transforms/optimization/src/simplify/dce/side_effect.rs
use super::Dce;
use rustc_hash::FxHashSet;
use swc_atoms::JsWord;
use swc_common::DUMMY_SP;
use swc_ecma_ast::*;
use swc_ecma_utils::{ident::IdentLike, ExprExt, Id};
use swc_ecma_visit::{noop_visit_type, Node, V... | code_fim | hard | {
"lang": "rust",
"repo": "rehack/swc",
"path": "/ecmascript/transforms/optimization/src/simplify/dce/side_effect.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> import.visit_children_with(self)
}
fn visit_member_expr(&mut self, _: &MemberExpr, _: &dyn Node) {
self.found = true;
// if self.found {
// return;
// }
// node.obj.visit_with(self);
// if node.comput... | code_fim | hard | {
"lang": "rust",
"repo": "rehack/swc",
"path": "/ecmascript/transforms/optimization/src/simplify/dce/side_effect.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(test)]
pub(crate) use self::file::FileOptions;
pub use self::settings::AppSettings;<|fim_prefix|>// repo: openshift/cincinnati path: /metadata-helper/src/config/mod.rs
//! Configuration lookup, parsing and validation.
//!
//! This module takes care of sourcing configuration options from
//! multip... | code_fim | medium | {
"lang": "rust",
"repo": "openshift/cincinnati",
"path": "/metadata-helper/src/config/mod.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: openshift/cincinnati path: /metadata-helper/src/config/mod.rs
//! Configuration lookup, parsing and validation.
//!
//! This module takes care of sourcing configuration options from
//! multiple inputs (CLI and files), merging, and validating them.
//! It contains the following entities:
//! * ... | code_fim | medium | {
"lang": "rust",
"repo": "openshift/cincinnati",
"path": "/metadata-helper/src/config/mod.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ehaskins/sam3x8e path: /src/pwm/isr1.rs
#[doc = "Register `ISR1` reader"]
pub struct R(crate::R<ISR1_SPEC>);
impl core::ops::Deref for R {
type Target = crate::R<ISR1_SPEC>;
#[inline(always)]
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl From<crate::R<ISR1_SPEC>> fo... | code_fim | hard | {
"lang": "rust",
"repo": "ehaskins/sam3x8e",
"path": "/src/pwm/isr1.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> &self.0
}
}
#[doc = "Field `FCHID5` reader - Fault Protection Trigger on Channel 5"]
pub struct FCHID5_R(crate::FieldReader<bool, bool>);
impl FCHID5_R {
pub(crate) fn new(bits: bool) -> Self {
FCHID5_R(crate::FieldReader::new(bits))
}
}
impl core::ops::Deref for FCHID5_R {
... | code_fim | hard | {
"lang": "rust",
"repo": "ehaskins/sam3x8e",
"path": "/src/pwm/isr1.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: joonazan/roll4 path: /src/main.rs
use aper::StateMachineContainerProgram;
use aper_actix::ServerBuilder;
use state::Game;
<|fim_suffix|> let builder = ServerBuilder::new(StateMachineContainerProgram(Game::default()));
if std::env::args().len() > 1 {
builder.serve_on("0.0.0.0", 66... | code_fim | easy | {
"lang": "rust",
"repo": "joonazan/roll4",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let builder = ServerBuilder::new(StateMachineContainerProgram(Game::default()));
if std::env::args().len() > 1 {
builder.serve_on("0.0.0.0", 666)
} else {
builder.serve()
}
}<|fim_prefix|>// repo: joonazan/roll4 path: /src/main.rs
use aper::StateMachineContainerProgram;
us... | code_fim | easy | {
"lang": "rust",
"repo": "joonazan/roll4",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: eagna-io/Eagna path: /backend/crop_domain/src/contest/poll/model/new.rs
use super::{Choice, ChoiceName, Poll, PollId, PollStatus, WithAttrs, WithUserChoices};
use crate::account::AccountId;
use chrono::{DateTime, Duration, Utc};
use std::collections::HashMap;
pub struct New {
pub id: PollId... | code_fim | hard | {
"lang": "rust",
"repo": "eagna-io/Eagna",
"path": "/backend/crop_domain/src/contest/poll/model/new.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn _resolved_choice(&self) -> Option<&ChoiceName> {
None
}
}
impl WithUserChoices for New {
fn _user_choices(&self) -> &HashMap<AccountId, ChoiceName> {
lazy_static::lazy_static! {
static ref EMPTY: HashMap<AccountId, ChoiceName> = HashMap::new();
}
... | code_fim | medium | {
"lang": "rust",
"repo": "eagna-io/Eagna",
"path": "/backend/crop_domain/src/contest/poll/model/new.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> Rustは、いくつかの関数(メソッドとも呼ばれる)に関連付けられた構造体であるオブジェクトの概念をサポートしています。
メソッドの最初のパラメータは、メソッド呼び出しに関連付けられたインスタンスへの参照でなければなりません。
* &self - インスタンスへの不変の参照
* &mut self - インスタンスへ可変の参照
メソッドはキーワード impl で実装ブロック内で定義されます。
*/
fn main() {
let creature = SeaCreature {
noise: String::from("blub"),
};
println... | code_fim | easy | {
"lang": "rust",
"repo": "say3no/try_rust",
"path": "/tour/src/chapter7_OOP/tour76_encapsulation_with_methods.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>/*
Encapsulation With Methods
Rustは、いくつかの関数(メソッドとも呼ばれる)に関連付けられた構造体であるオブジェクトの概念をサポートしています。
メソッドの最初のパラメータは、メソッド呼び出しに関連付けられたインスタンスへの参照でなければなりません。
* &self - インスタンスへの不変の参照
* &mut self - インスタンスへ可変の参照
メソッドはキーワード impl で実装ブロック内で定義されます。
*/
fn main() {
let creature = SeaCreature {
noise: String::... | code_fim | easy | {
"lang": "rust",
"repo": "say3no/try_rust",
"path": "/tour/src/chapter7_OOP/tour76_encapsulation_with_methods.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: say3no/try_rust path: /tour/src/chapter7_OOP/tour76_encapsulation_with_methods.rs
struct SeaCreature {
noise: String,
}
impl SeaCreature {
fn get_sound(&self) -> &str {
&self.noise
}
}
<|fim_suffix|> Rustは、いくつかの関数(メソッドとも呼ばれる)に関連付けられた構造体であるオブジェクトの概念をサポートしています。
メソッドの最初のパラメータ... | code_fim | easy | {
"lang": "rust",
"repo": "say3no/try_rust",
"path": "/tour/src/chapter7_OOP/tour76_encapsulation_with_methods.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>
pub fn start() {
println!("cargo repro: build and verify byte-for-byte reproducible Rust packages");
println!();
println!("WORK IN PROGRESS: This utility does not yet provide any functionality");
println!("If you are interested in contributing, please see the GitHub issues:");
println... | code_fim | hard | {
"lang": "rust",
"repo": "rust-secure-code/cargo-repro",
"path": "/src/lib.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rust-secure-code/cargo-repro path: /src/lib.rs
//! cargo repro: build and verify byte-for-byte reproducible Rust packages
#![forbid(unsafe_code)]
#![deny(
warnings,
missing_docs,
trivial_casts,
trivial_numeric_casts,
unused_impo<|fim_suffix|>ity");
println!("If you are i... | code_fim | hard | {
"lang": "rust",
"repo": "rust-secure-code/cargo-repro",
"path": "/src/lib.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tov/bv-rs path: /src/bit_vec/mod.rs
these traits (or `bv::*`) when you use `BitVec`.
///
/// # Examples
///
/// ```
/// use bv::BitVec;
///
/// let mut bv: BitVec = BitVec::new();
/// assert_eq!(bv.len(), 0);
///
/// bv.push(true);
/// bv.push(false);
/// bv.push(true);
/// assert_eq!(bv.len(),... | code_fim | hard | {
"lang": "rust",
"repo": "tov/bv-rs",
"path": "/src/bit_vec/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Gets the value of the bit at the given position.
///
/// This is an alias for [`Bits::get_bit`].
///
/// # Panics
///
/// If the position is out of bounds.
///
/// [`Bits::get_bit`]: ../trait.Bits.html#get_bit.method
pub fn get(&self, position: u64) -> bool {
... | code_fim | hard | {
"lang": "rust",
"repo": "tov/bv-rs",
"path": "/src/bit_vec/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tov/bv-rs path: /src/bit_vec/mod.rs
ock: BlockType + serde::Deserialize<'de>> serde::Deserialize<'de> for BitVec<Block> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
#[derive(Deserialize)]
struct Unchecked<... | code_fim | hard | {
"lang": "rust",
"repo": "tov/bv-rs",
"path": "/src/bit_vec/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: 01intelligence/hulk path: /src/erasure/coding.rs
use std::lazy::Lazy;
use anyhow::bail;
use reed_solomon_erasure::galois_8::ReedSolomon;
use reed_solomon_erasure::Error::*;
pub struct Erasure {
encoder: Lazy<ReedSolomon, Box<dyn FnOnce() -> ReedSolomon>>,
pub(super) data_blocks: usize,... | code_fim | hard | {
"lang": "rust",
"repo": "01intelligence/hulk",
"path": "/src/erasure/coding.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn decode_data_blocks(&self, data: &mut Vec<Option<Vec<u8>>>) -> anyhow::Result<()> {
if !data.iter().any(|v| v.is_none()) {
// No need to reconstruct.
return Ok(());
}
self.encoder.reconstruct_data(data)?;
Ok(())
}
pub fn decode_dat... | code_fim | hard | {
"lang": "rust",
"repo": "01intelligence/hulk",
"path": "/src/erasure/coding.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.