text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_prefix|>// repo: quangtung97-study/20191-software-economics-version2 path: /src/rrgame.rs
use crate::relation::{ProductMap, Relation, RetailerMap};
#[derive(Clone)]
pub struct Parameter {
pub p_mg: RetailerMap<ProductMap<f64>>,
pub a_mg: RetailerMap<ProductMap<f64>>,
}
<|fim_suffix|> #[allow(dead_co... | code_fim | hard | {
"lang": "rust",
"repo": "quangtung97-study/20191-software-economics-version2",
"path": "/src/rrgame.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[allow(dead_code)]
pub fn input_a_mg(&mut self, relation: &Relation, data: &[&[f64]]) {
for m in relation.initial_retailers() {
for g in relation.initial_products(m) {
self.a_mg[m][g] = data[m.id][g.id];
}
}
}
#[allow(dead_code)]
... | code_fim | hard | {
"lang": "rust",
"repo": "quangtung97-study/20191-software-economics-version2",
"path": "/src/rrgame.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: pearzl/leetcode_rust path: /src/answer/q0125_valid_palindrome.rs
// q0125_valid_palindrome
struct Solution;
impl Solution {
pub fn is_palindrome(s: String) -> bool {
let s: Vec<char> = s
.chars()
.filter(char::is_ascii_alphanumeric)
.map(|c| {
... | code_fim | hard | {
"lang": "rust",
"repo": "pearzl/leetcode_rust",
"path": "/src/answer/q0125_valid_palindrome.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn it_works() {
assert_eq!(
true,
Solution::is_palindrome(String::from("A man, a plan, a canal: Panama"))
);
assert_eq!(false, Solution::is_palindrome(String::from("race a car")));
}
}<|fim_prefix|>// repo: pearzl/leetcode_rust path: /sr... | code_fim | hard | {
"lang": "rust",
"repo": "pearzl/leetcode_rust",
"path": "/src/answer/q0125_valid_palindrome.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rhysd/reading-pfds path: /rust/src/deque.rs
// p.49
//
// Exercise 5.10: Amortized O(1) deque
use std::fmt::Debug;
use list::{List, Node};
// Invariant: When it contains two or more elements, both f and r contains at least one element.
#[derive(Clone, Debug)]
pub struct Deque<T: Clone + Debug>... | code_fim | hard | {
"lang": "rust",
"repo": "rhysd/reading-pfds",
"path": "/rust/src/deque.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let d = Deque::empty().enq_back(1);
assert_eq!(d.front(), &1);
assert_eq!(d.back(), &1);
let d = d.enq_back(2).enq_back(3);
assert_eq!(d.front(), &1);
assert_eq!(d.back(), &3);
let d = d.deq_front();
assert_eq!(d.front(), &2);
asser... | code_fim | hard | {
"lang": "rust",
"repo": "rhysd/reading-pfds",
"path": "/rust/src/deque.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let d = Deque::empty().enq_front(2).enq_back(3).enq_front(1).enq_back(4);
assert_eq!(d.front(), &1);
assert_eq!(d.back(), &4);
let d = d.deq_back().deq_front().deq_back().deq_front();
assert!(d.is_empty());
let d = Deque::empty().enq_front(2).enq_back(3).en... | code_fim | hard | {
"lang": "rust",
"repo": "rhysd/reading-pfds",
"path": "/rust/src/deque.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rutrum/diet-database path: /api/src/bin/cli.rs
use std::env;
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
help();
return;
}
let table = &args[1];
match table.as_ref() {
"bowel" => manage_bowel(&args[2..]),
_... | code_fim | easy | {
"lang": "rust",
"repo": "rutrum/diet-database",
"path": "/api/src/bin/cli.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn manage_bowel(args: &[String]) {
if args.len() < 1 {
println!("need subcommand for bowel");
help();
return;
}
}
fn help() {
println!("Bad, try again.");
}<|fim_prefix|>// repo: rutrum/diet-database path: /api/src/bin/cli.rs
use std::env;
fn main() {
let args: V... | code_fim | medium | {
"lang": "rust",
"repo": "rutrum/diet-database",
"path": "/api/src/bin/cli.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ahpaleus/rusty_harvester path: /src/main.rs
mod rng;
use std::error::Error;
use std::fs::File;
use std::fs;
use std::collections::{BTreeSet, HashSet};
use std::io::{Read, Write, BufReader, BufRead};
use std::process::{Command, Stdio};
use rng::Rng;
use std::env;
use std::time::Instant;
use std:... | code_fim | hard | {
"lang": "rust",
"repo": "ahpaleus/rusty_harvester",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Running through the bytes amount_of_byte many times
for _ in 0..amount_of_byte {
let random_byte = rng.rand() % data_to_fuzz.len();
// Bitflipping mutation
let values = vec![1, 2, 4, 8, 16, 32, 64, 128];
data_to_fuzz[random_byte] = values[rng.rand() % 8];
}
return data_to_fuzz
}
fn read_... | code_fim | hard | {
"lang": "rust",
"repo": "ahpaleus/rusty_harvester",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut i: i32 = start;
while i * i <= goal {
if goal % i == 0 {
cur.push(i);
search(goal / i, i, cur, global);
cur.pop();
}
i += 1;
}
if cur.len() > 0 {
cur.push(goal);
global.push(cur.clone());
cur.pop();... | code_fim | medium | {
"lang": "rust",
"repo": "SuanFaRuoJi/coding_exercise_rust",
"path": "/src/factor_combinations_254.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: SuanFaRuoJi/coding_exercise_rust path: /src/factor_combinations_254.rs
pub fn get_factors(n: i32) -> Vec<Vec<i32>> {
let mut cur: Vec<i32> = Vec::new();
let mut global = Vec::new();
search(n, 2, &mut cur, &mut global);
return global;
}
fn search(goal: i32, start: i32, cur: &mut ... | code_fim | medium | {
"lang": "rust",
"repo": "SuanFaRuoJi/coding_exercise_rust",
"path": "/src/factor_combinations_254.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dirk-dms/mini-pov path: /src/spisetup.rs
use stm32ral::{modify_reg, write_reg};
pub fn spiconfig(
rcc: &stm32ral::rcc::Instance,
spi: &stm32ral::spi::Instance,
) {
//Enable SPI2 clock
modify_reg!(stm32ral::rcc, rcc, APB1ENR, SPI2EN: Enabled);
cortex_m::asm::dmb(); // ensure ... | code_fim | hard | {
"lang": "rust",
"repo": "dirk-dms/mini-pov",
"path": "/src/spisetup.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // we only need tx on first rising edge data is already stable and latched
// since APB1 is already half the clock speed compared to AHB1
// we only divide by 8 and not by 16 to get 6MBit SPI Line speed
write_reg!(
stm32ral::spi,
spi,
CR1,
BIDIMODE: Unidire... | code_fim | hard | {
"lang": "rust",
"repo": "dirk-dms/mini-pov",
"path": "/src/spisetup.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: CasualX/intptr path: /src/ptr64.rs
use core::{cmp, fmt, hash, marker, mem, ops, str};
#[inline]
const fn nibbles(word: u64) -> [u8; 16] {
let b = word.to_le_bytes();
[
b[7] >> 4, b[7] & 0xf,
b[6] >> 4, b[6] & 0xf,
b[5] >> 4, b[5] & 0xf,
b[4] >> 4, b[4] & 0xf,
b[3] >> 4, b[3] & 0xf,
... | code_fim | hard | {
"lang": "rust",
"repo": "CasualX/intptr",
"path": "/src/ptr64.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(feature = "dataview_0_1")]
unsafe impl<T: ?Sized + 'static> dataview_0_1::Pod for IntPtr64<T> {}
#[cfg(feature = "dataview_1")]
unsafe impl<T: ?Sized + 'static> dataview_1::Pod for IntPtr64<T> {}
#[cfg(feature = "serde")]
impl<T: ?Sized> serde::Serialize for IntPtr64<T> {
#[inline]
fn serialize<... | code_fim | hard | {
"lang": "rust",
"repo": "CasualX/intptr",
"path": "/src/ptr64.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> ptr.address
}
}
impl<T> ops::Add<usize> for IntPtr64<T> {
type Output = IntPtr64<T>;
#[inline]
fn add(self, other: usize) -> IntPtr64<T> {
let address = self.address + (other * mem::size_of::<T>()) as u64;
IntPtr64 { address, phantom_data: self.phantom_data }
}
}
impl<T> ops::Sub<usize> for In... | code_fim | hard | {
"lang": "rust",
"repo": "CasualX/intptr",
"path": "/src/ptr64.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> key.chars().next().unwrap().is_numeric()
}
for (idx, &(key, winfo, _ord)) in sorted.iter().enumerate() {
if idx > 0 && is_numeric(sorted[idx - 1].0) != is_numeric(key) {
println!();
}
println!(
"[{}{}{}] {}{}{}",
crossterm::Color... | code_fim | hard | {
"lang": "rust",
"repo": "rasmushalland/cwintab",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rasmushalland/cwintab path: /src/main.rs
#[macro_use]
extern crate bitflags;
mod winx;
use std::ffi::OsString;
use winapi::shared::minwindef::BOOL;
use winapi::shared::minwindef::LPARAM;
use winapi::shared::windef::HWND;
use winapi::um::winbase::LocalFree;
use winapi::um::winnt::LPWSTR;
#[lin... | code_fim | hard | {
"lang": "rust",
"repo": "rasmushalland/cwintab",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: victorhuberta/practice path: /blockchain/src/ledger/mod.rs
//! # Ledger
//!
//! Defines a general distributed ledger trait and everything else required by it.
pub mod error;
pub mod util;
pub mod example;
use self::error::*;
use self::util::Timestamp;
<|fim_suffix|>
fn new_block(&mut self... | code_fim | hard | {
"lang": "rust",
"repo": "victorhuberta/practice",
"path": "/blockchain/src/ledger/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn new_block(&mut self, timestamp: Timestamp, proof: Self::Proof) -> Result<&Self::LedgerRepr, BlockError>;
fn add_transaction(&mut self, tx: T) -> Result<usize, TransactionError>;
fn find_proof(&self, last_proof: Self::Proof) -> Self::Proof;
fn last_block(&self) -> Option<&B>;
fn is_v... | code_fim | hard | {
"lang": "rust",
"repo": "victorhuberta/practice",
"path": "/blockchain/src/ledger/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Mission reset button
if Button::new()
.w_h(100.0, 30.0)
.x_y((-ui.win_w / 2.0) + 160.0, (ui.win_h / 2.0) - 100.0)
.rgb(0.3, 0.8, 0.3)
.border(1.0)
.label("Reset")
.set(MISSION_RESET_BUTTON, ui)
.was_clic... | code_fim | hard | {
"lang": "rust",
"repo": "PISCES-HI/rover-gui",
"path": "/src/tele_ui.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: PISCES-HI/rover-gui path: /src/tele_ui.rs
(format!("{0:.2}V", v), self.p_12_e_v_limits.get_color(v))
},
None => {
("NO DATA".to_string(), rgb(0.0, 0.0, 0.0))
},
};
let (p_12_e_a, p_12_e_a_color) =
... | code_fim | hard | {
"lang": "rust",
"repo": "PISCES-HI/rover-gui",
"path": "/src/tele_ui.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: PISCES-HI/rover-gui path: /src/tele_ui.rs
pressure: None,
altitude: None,
temp: None,
pitch_roll_heading: None,
log_files: log_files,
image_map: conrod::image::Map::new(),
}
}
pub fn log_data(&mut self) {
... | code_fim | hard | {
"lang": "rust",
"repo": "PISCES-HI/rover-gui",
"path": "/src/tele_ui.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let opt = Opt::from_args();
let port = opt.port;
let thread_pool_size = opt.thread_pool_size;
let pool = ThreadPoolBuilder::new().pool_size(thread_pool_size).create().expect("Failed to create thread pool");
let mut db = taras::TarasNabad::new("d.db").to_owned();
let server = Server... | code_fim | hard | {
"lang": "rust",
"repo": "faruken/TarasNabad",
"path": "/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: faruken/TarasNabad path: /src/main.rs
mod taras;
extern crate tiny_http;
use tiny_http::{Server, Response, Method};
use crate::taras::{TarasNabadImpl, TarasNabad};
use uuid::Uuid;
use rocksdb::Error;
use structopt::StructOpt;
use futures::executor::{ThreadPoolBuilder, ThreadPool};
use futures:... | code_fim | hard | {
"lang": "rust",
"repo": "faruken/TarasNabad",
"path": "/src/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: csixteen/LeetCode path: /Problems/Algorithms/src/Rust/toeplitz-matrix/src/lib.rs
// https://leetcode.com/problems/toeplitz-matrix/
struct Solution;
impl Solution {
pub fn is_toeplitz_matrix(matrix: Vec<Vec<i32>>) -> bool {
let (rows, cols) = (matrix.len(), matrix[0].len());
... | code_fim | hard | {
"lang": "rust",
"repo": "csixteen/LeetCode",
"path": "/Problems/Algorithms/src/Rust/toeplitz-matrix/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert!(
!Solution::is_toeplitz_matrix(
vec![vec![1, 2], vec![2, 2]],
),
);
}
}<|fim_prefix|>// repo: csixteen/LeetCode path: /Problems/Algorithms/src/Rust/toeplitz-matrix/src/lib.rs
// https://leetcode.com/problems/toeplitz-matrix/
struct Solu... | code_fim | hard | {
"lang": "rust",
"repo": "csixteen/LeetCode",
"path": "/Problems/Algorithms/src/Rust/toeplitz-matrix/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> true
}
}
#[cfg(test)]
mod tests {
use super::Solution;
#[test]
fn example1() {
assert!(
Solution::is_toeplitz_matrix(
vec![
vec![1, 2, 3, 4],
vec![5, 1, 2, 3],
vec![9, 5, 1, 2],
... | code_fim | hard | {
"lang": "rust",
"repo": "csixteen/LeetCode",
"path": "/Problems/Algorithms/src/Rust/toeplitz-matrix/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[repr(C)]
pub struct Bool {
b: bool,
}
// CHECK: define i64 @structbool()
// CHECK-NEXT: start:
// CHECK-NEXT: ret i64 72057594037927936
#[no_mangle]
pub extern "C" fn structbool() -> Bool {
Bool { b: true }
}<|fim_prefix|>// repo: IThawk/rust-project path: /rust-master/src/test/codegen/sparc-s... | code_fim | medium | {
"lang": "rust",
"repo": "IThawk/rust-project",
"path": "/rust-master/src/test/codegen/sparc-struct-abi.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: IThawk/rust-project path: /rust-master/src/test/codegen/sparc-struct-abi.rs
//
// Checks that we correctly codegen extern "C" functions returning structs.
// See issue #52638.
// only-sparc64
// compile-flags: -O --target=sparc64-unknown-linux-gnu --crate-type=rlib
#![feature(no_core, lang_item... | code_fim | medium | {
"lang": "rust",
"repo": "IThawk/rust-project",
"path": "/rust-master/src/test/codegen/sparc-struct-abi.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[interrupt]
fn ADC_COMP() {
// Do nothing for now.
}
fn usb_interrupt() {
cortex_m::interrupt::free(|cs| {
if let (Some(ref mut usb_dev), Some(ref mut serial), Some(ref mut hid)) = (
USB_DEV.borrow(cs).borrow_mut().deref_mut(),
USB_SERIAL.borrow(cs).borrow_mut().d... | code_fim | hard | {
"lang": "rust",
"repo": "bentwire/stm32f072-usb-test",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: bentwire/stm32f072-usb-test path: /src/main.rs
//! CDC-ACM serial port example using cortex-m-rtfm.
#![no_main]
#![no_std]
#![allow(unused_variables)]
#![allow(non_snake_case)]
extern crate panic_semihosting;
extern crate stm32f0;
mod hid;
mod hiddesc;
use hid::HidClass;
use usbd_serial::Cdc... | code_fim | hard | {
"lang": "rust",
"repo": "bentwire/stm32f072-usb-test",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Static mut is unsafe. Since we kow what we are doing here it is ok.
let hid = HidClass::new(unsafe { USB_BUS.as_ref().unwrap() }, true, &hiddesc::DESC);
let serial = CdcAcmClass::new(unsafe { USB_BUS.as_ref().unwrap() }, 64);
let usb_dev = UsbDeviceBuild... | code_fim | hard | {
"lang": "rust",
"repo": "bentwire/stm32f072-usb-test",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: frostRed/bitcoin_reuni path: /src/wallet/secp256k1/s256_field.rs
use num_bigint::{BigInt, BigUint, Sign};
use num_traits::zero;
use std::fmt::{self, Display};
use std::ops::{Add, Div, Mul, Sub};
use super::ec::field_element::FieldElementError;
use super::ec::utils::{U256, U512};
/// Secp256k1 ... | code_fim | hard | {
"lang": "rust",
"repo": "frostRed/bitcoin_reuni",
"path": "/src/wallet/secp256k1/s256_field.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl<T> Mul<T> for S256Field
where
T: Into<U256>,
{
type Output = S256Field;
fn mul(self, rhs: T) -> Self::Output {
let self_num = Into::<BigUint>::into(self.num);
let rhs_num = Into::<BigUint>::into(rhs.into());
let self_prime = Into::<BigUint>::into(self.prime);
... | code_fim | hard | {
"lang": "rust",
"repo": "frostRed/bitcoin_reuni",
"path": "/src/wallet/secp256k1/s256_field.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: austinglaser/bk168xb-rs path: /src/response/core.rs
use crate::{
response::{Error, Result},
SupplyVariant,
};
use std::{io, str};
/// A type which may be a supply's response to a command.
///
/// This forms the core of the receive end of a power supply interface. Because
/// the interf... | code_fim | hard | {
"lang": "rust",
"repo": "austinglaser/bk168xb-rs",
"path": "/src/response/core.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> variant: &SupplyVariant,
sep: char,
ack: &str
) -> Expectation {
let mut resp = dummy_arg_for::<R>();
resp.push(sep);
resp.push_str(ack);
expect_deserialize_error::<R>(&resp, MalformedResponse, variant)
}
... | code_fim | hard | {
"lang": "rust",
"repo": "austinglaser/bk168xb-rs",
"path": "/src/response/core.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let _e = expect_invalid_ack_parse_error::<()>(variant, sep, ack);
let _e = expect_invalid_ack_parse_error::<Voltage>(variant, sep, ack);
let _e = expect_invalid_ack_parse_error::<Current>(variant, sep, ack);
let _e = expect_invalid_ack_parse_error::<Settings>(variant, sep, ... | code_fim | hard | {
"lang": "rust",
"repo": "austinglaser/bk168xb-rs",
"path": "/src/response/core.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: g2xpf/ecs-rs path: /src/lib/types/dispatcher.rs
use crate::types::{ComponentDispatcher, IterableContainer, Pointer};
use std::vec::IntoIter;
<|fim_suffix|> let mask = self.get_component_mask();
let v: Vec<_> = self
.get_entity()
.iter()
.filter... | code_fim | hard | {
"lang": "rust",
"repo": "g2xpf/ecs-rs",
"path": "/src/lib/types/dispatcher.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mask = self.get_component_mask();
let v: Vec<_> = self
.get_entity()
.iter()
.filter_map(|(ent_index, ent_mask)| {
if ent_mask & mask == mask {
Some(ent_index)
} else {
None
... | code_fim | hard | {
"lang": "rust",
"repo": "g2xpf/ecs-rs",
"path": "/src/lib/types/dispatcher.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: joe-bowman/tendermint-rs path: /light-client/src/contracts.rs
//! Predicates used in components contracts.
use crate::{
store::{LightStore, VerifiedStatus},
types::{Height, LightBlock, Time},
};
<|fim_suffix|>pub fn is_within_trust_period(
light_block: &LightBlock,
trusting_per... | code_fim | hard | {
"lang": "rust",
"repo": "joe-bowman/tendermint-rs",
"path": "/light-client/src/contracts.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn light_store_contains_block_within_trusting_period(
light_store: &dyn LightStore,
trusting_period: Duration,
now: Time,
) -> bool {
light_store
.all(VerifiedStatus::Verified)
.any(|lb| is_within_trust_period(&lb, trusting_period, now))
}
// pub fn target_height_great... | code_fim | hard | {
"lang": "rust",
"repo": "joe-bowman/tendermint-rs",
"path": "/light-client/src/contracts.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: wasmerio/wapm-cli path: /src/data/manifest.rs
//! The Manifest file is where the core metadata of a wapm package lives
pub use wapm_toml::{
Command, CommandV1<|fim_suffix|>idationError,
MANIFEST_FILE_NAME, PACKAGES_DIR_NAME,
};<|fim_middle|>, CommandV2, Manifest, ManifestError, Module, P... | code_fim | easy | {
"lang": "rust",
"repo": "wasmerio/wapm-cli",
"path": "/src/data/manifest.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>idationError,
MANIFEST_FILE_NAME, PACKAGES_DIR_NAME,
};<|fim_prefix|>// repo: wasmerio/wapm-cli path: /src/data/manifest.rs
//! The Manifest file is where the core metadata of a wapm<|fim_middle|> package lives
pub use wapm_toml::{
Command, CommandV1, CommandV2, Manifest, ManifestError, Module, P... | code_fim | medium | {
"lang": "rust",
"repo": "wasmerio/wapm-cli",
"path": "/src/data/manifest.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>mod primary;
pub use self::primary::{Line, Margin, Mode, Modes, Marker, Symbol};<|fim_prefix|>// repo: jblondin/rhubarb path: /rhubarb-graph/src/common/mod.rs
mod axis;
pub use self::axis::{Axis, AxisKind};
<|fim_middle|>mod legend;
pub use self::legend::Legend;
| code_fim | easy | {
"lang": "rust",
"repo": "jblondin/rhubarb",
"path": "/rhubarb-graph/src/common/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jblondin/rhubarb path: /rhubarb-graph/src/common/mod.rs
mod axis;
pub use self::axis::{Axis, AxisKind};
<|fim_suffix|>mod primary;
pub use self::primary::{Line, Margin, Mode, Modes, Marker, Symbol};<|fim_middle|>mod legend;
pub use self::legend::Legend;
| code_fim | easy | {
"lang": "rust",
"repo": "jblondin/rhubarb",
"path": "/rhubarb-graph/src/common/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(feature = "alloc")]
impl From<FromUtf8Error> for Error {
fn from(_err: FromUtf8Error) -> Error {
// TODO: preserve cause or error message?
Error::EncodingInvalid
}
}<|fim_prefix|>// repo: iqlusioninc/crates path: /subtle-encoding/src/error.rs
//! Error type
#[cfg(all(featur... | code_fim | medium | {
"lang": "rust",
"repo": "iqlusioninc/crates",
"path": "/subtle-encoding/src/error.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: iqlusioninc/crates path: /subtle-encoding/src/error.rs
//! Error type
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::string::FromUtf8Error;
use core::fmt;
#[cfg(feature = "std")]
use std::{io, string::FromUtf8Error};
/// Error type
#[derive(Clone, Eq, PartialEq, Debug)]
pub en... | code_fim | hard | {
"lang": "rust",
"repo": "iqlusioninc/crates",
"path": "/subtle-encoding/src/error.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>// For any given node, we divide the binary tree into a series of successively
// lower subtrees that don't contain the node. The highest subtree consists of
// the half of the binary tree not containing the node
impl BinTree {
fn insert(&self, node: Node) {
}
fn delete(&self, node: Node) {... | code_fim | hard | {
"lang": "rust",
"repo": "chrisreiter/kademlia",
"path": "/src/routing.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: chrisreiter/kademlia path: /src/routing.rs
extern crate node;
// Kademlia's basic routing table structure is fairly straight-forward
// given the protocol, though a slight subtlety is needed to handle highly
// unbalanced trees.
// The routing table is a binary tree whose leaves are k-bucket... | code_fim | medium | {
"lang": "rust",
"repo": "chrisreiter/kademlia",
"path": "/src/routing.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> b.iter(|| {
day06::solve();
});
}
#[bench]
fn all_days(b: &mut Bencher) {
b.iter(|| {
day01::solve();
day02::solve();
day03::solve();
day04::solve();
day05::solve();
day06::solve();
... | code_fim | hard | {
"lang": "rust",
"repo": "saik0/rust-aoc-2020",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: saik0/rust-aoc-2020 path: /src/main.rs
#![cfg_attr(feature = "unstable", feature(test))]
use day01;
use day02;
use day03;
use day04;
use day05;
use day06;
use std::fmt::Display;
fn solve_day<A, B, S>(day: usize, solver: S) where
A: Display,
B: Display,
S: Fn() -> (A, B)
{
let (... | code_fim | hard | {
"lang": "rust",
"repo": "saik0/rust-aoc-2020",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: libdist-rs/libchatter-rs path: /crypto/src/hash.rs
use sha2::{Digest, Sha256};
use serde::Serialize;
pub const HASH_SIZE:usize = 32;
<|fim_suffix|>pub const EMPTY_HASH:Hash = [0 as u8; 32];
pub fn do_hash(bytes: &[u8]) -> Hash {
let hash = Sha256::digest(bytes);
return hash.into();
} ... | code_fim | easy | {
"lang": "rust",
"repo": "libdist-rs/libchatter-rs",
"path": "/crypto/src/hash.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn ser_and_hash(obj: &impl Serialize) -> Hash {
let serialized_bytes = bincode::serialize(obj).unwrap();
return do_hash(&serialized_bytes);
}<|fim_prefix|>// repo: libdist-rs/libchatter-rs path: /crypto/src/hash.rs
use sha2::{Digest, Sha256};
use serde::Serialize;
<|fim_middle|>pub const HAS... | code_fim | hard | {
"lang": "rust",
"repo": "libdist-rs/libchatter-rs",
"path": "/crypto/src/hash.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dequbed/rust-signals path: /tests/signal.rs
use std::rc::Rc;
use std::cell::Cell;
use std::task::Poll;
use futures_signals::cancelable_future;
use futures_signals::signal::{SignalExt, Mutable, channel};
use futures_signals::signal_vec::VecDiff;
use futures_util::future::{ready, poll_fn};
mod ut... | code_fim | hard | {
"lang": "rust",
"repo": "dequbed/rust-signals",
"path": "/tests/signal.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> drop(mutable);
assert_eq!(s2.poll_change_unpin(cx), Poll::Ready(Some(5)));
assert_eq!(s2.poll_change_unpin(cx), Poll::Ready(None));
assert_eq!(s1.poll_change_unpin(cx), Poll::Ready(None));
});
}
}
#[test]
fn test_send_sync() {
let a = cance... | code_fim | hard | {
"lang": "rust",
"repo": "dequbed/rust-signals",
"path": "/tests/signal.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: canndrew/crust-futures path: /crust/src/net/nat/hole_punch.rs
use util;
use priv_prelude::*;
/// Punch a hole to a remote peer. Both peers call this simultaneously try to perform a TCP
/// rendezvous connect to each other.
pub fn tcp_hole_punch(
handle: &Handle,
socket: TcpBuilder,
... | code_fim | hard | {
"lang": "rust",
"repo": "canndrew/crust-futures",
"path": "/crust/src/net/nat/hole_punch.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>sockets.push((socket, *addr));
};
let listener = socket.listen(100)?;
let listener = TcpListener::from_listener(listener, &local_addr, handle)?;
let incoming = listener.incoming();
let connectors = {
sockets
.into_iter()
.map(|(socket, addr)| {
TcpS... | code_fim | hard | {
"lang": "rust",
"repo": "canndrew/crust-futures",
"path": "/crust/src/net/nat/hole_punch.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> match std::str::from_utf8(&bytes_slice) {
Ok(v) => println!("Received text data, not good :/ : {}", v),
Err(e) => println!("Received data was not text, its good ! {}", e),
};
// todo: return none if there has been an error and that the received data is some text data
bytes
... | code_fim | medium | {
"lang": "rust",
"repo": "Dophix/inoft_vocal_framework",
"path": "/inoft_audio_engine_renderer/src/loader.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Dophix/inoft_vocal_framework path: /inoft_audio_engine_renderer/src/loader.rs
use std::time::Instant;
use reqwest::Url;
use std::io::{BufReader};
use hound::WavReader;
use bytes::Bytes;
/*
let url = "https://inoft-vocal-engine-web-test.s3.eu-west-3.amazonaws.com/b1fe5939-032b-462d-92e0-a942cd44... | code_fim | hard | {
"lang": "rust",
"repo": "Dophix/inoft_vocal_framework",
"path": "/inoft_audio_engine_renderer/src/loader.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let bytes: Bytes = file_response.bytes().await.unwrap() as Bytes;
let mut bytes_slice = &*bytes;
println!("Took {}ms to retrieve the file at url : {}", start.elapsed().as_millis(), url);
match std::str::from_utf8(&bytes_slice) {
Ok(v) => println!("Received text data, not good :/ :... | code_fim | hard | {
"lang": "rust",
"repo": "Dophix/inoft_vocal_framework",
"path": "/inoft_audio_engine_renderer/src/loader.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: MamadouSDiallo/advent_of_code_2020 path: /src/lib.rs
pub mod day_01 {
mod day01;
pub use crate::day_01::day01::{challenge_01, challenge_02};
}
pub mod day_02 {
mod day02;
pub use crate::day_02::day02::{challenge_01, challenge_02};
}
pub mod day_03 {
mod day03;
pub use cra... | code_fim | hard | {
"lang": "rust",
"repo": "MamadouSDiallo/advent_of_code_2020",
"path": "/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>
pub mod day_13 {
mod day13;
pub use crate::day_13::day13::{challenge_01, challenge_02};
}
pub mod day_14 {
mod day14;
pub use crate::day_14::day14::{challenge_01, challenge_02};
}
pub mod day_15 {
mod day15;
pub use crate::day_15::day15::{challenge_01, challenge_02};
}
pub mod day... | code_fim | hard | {
"lang": "rust",
"repo": "MamadouSDiallo/advent_of_code_2020",
"path": "/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub use receive::{
receive_value,
send_value_to,
send_value_to_async,
};<|fim_prefix|>// repo: balzers/ferrite path: /src/session/value/mod.rs
mod send;
mod receive;
<|fim_middle|>pub use send::{
send_value,
send_value_async,
receive_value_from,
};
| code_fim | medium | {
"lang": "rust",
"repo": "balzers/ferrite",
"path": "/src/session/value/mod.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: balzers/ferrite path: /src/session/value/mod.rs
mod send;
mod receive;
<|fim_suffix|>pub use receive::{
receive_value,
send_value_to,
send_value_to_async,
};<|fim_middle|>pub use send::{
send_value,
send_value_async,
receive_value_from,
};
| code_fim | medium | {
"lang": "rust",
"repo": "balzers/ferrite",
"path": "/src/session/value/mod.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>calDrain, LocalDrainSyncable, LocalNoFile};<|fim_prefix|>// repo: WanzenBug/rustsync path: /src/local/mod.rs
mod source;
mod drain;
pub use self::source::{LocalSource, LocalSourceSyncable, Loca<|fim_middle|>lSourceIterator};
pub use self::drain::{Lo | code_fim | easy | {
"lang": "rust",
"repo": "WanzenBug/rustsync",
"path": "/src/local/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: WanzenBug/rustsync path: /src/local/mod.rs
mod source;
mod drain;
pub use self::source::{LocalSource, LocalSourceSyncable, Loca<|fim_suffix|>calDrain, LocalDrainSyncable, LocalNoFile};<|fim_middle|>lSourceIterator};
pub use self::drain::{Lo | code_fim | easy | {
"lang": "rust",
"repo": "WanzenBug/rustsync",
"path": "/src/local/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: WanzenBug/rustsync path: /src/local/mod.rs
mod source;
mod drain;
pub use self::sour<|fim_suffix|>calDrain, LocalDrainSyncable, LocalNoFile};<|fim_middle|>ce::{LocalSource, LocalSourceSyncable, LocalSourceIterator};
pub use self::drain::{Lo | code_fim | medium | {
"lang": "rust",
"repo": "WanzenBug/rustsync",
"path": "/src/local/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> match resp {
SimpleString(s) => Ok(s),
BulkString(s) => Ok(String::from_utf8_lossy(&s).into()),
resp => Err(DeserializeError::new("CLUSTER SLOTS: not a string", resp)),
}
}
fn parse_entry(resp: RespValue) -> Result<Sl... | code_fim | hard | {
"lang": "rust",
"repo": "uchida/actix-extras",
"path": "/actix-redis/src/command/cluster_slots.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> use std::convert::TryInto;
match resp {
Array(values) if values.len() >= 3 => {
let mut it = values.into_iter();
let start: u16 = parse_int(it.next().unwrap())?.try_into().unwrap();
let end: u16 = parse_in... | code_fim | hard | {
"lang": "rust",
"repo": "uchida/actix-extras",
"path": "/actix-redis/src/command/cluster_slots.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: uchida/actix-extras path: /actix-redis/src/command/cluster_slots.rs
use super::{DeserializeError, RedisCommand};
use crate::{Error, Slots};
use actix::Message;
use redis_async::{resp::RespValue, resp_array};
use RespValue::*;
#[derive(Debug)]
pub struct ClusterSlots;
pub fn cluster_slots() ->... | code_fim | hard | {
"lang": "rust",
"repo": "uchida/actix-extras",
"path": "/actix-redis/src/command/cluster_slots.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tristan-zander/smithay path: /src/backend/egl/context.rs
//! EGL context related structs
use super::{ffi, wrap_egl_call, Error, MakeCurrentError};
use crate::backend::egl::display::{EGLDisplay, EGLDisplayHandle};
use crate::backend::egl::native::NativeSurface;
use crate::backend::egl::{native, ... | code_fim | hard | {
"lang": "rust",
"repo": "tristan-zander/smithay",
"path": "/src/backend/egl/context.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// Describes the requested OpenGL context profiles.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GlProfile {
/// Include all the immediate more functions and definitions.
Compatibility,
/// Include all the future-compatible functions and definitions.
Core,
}
/// Describes how th... | code_fim | hard | {
"lang": "rust",
"repo": "tristan-zander/smithay",
"path": "/src/backend/egl/context.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: talbergs/rust-coach path: /jira-lines/src/main.rs
use jira_lines::*;
fn main() -> Result<(), Box<std::error::Error>> {
let conf = config::Config::form_args()?;
let client = jira_sdk::client::Client::new(conf.url, conf.un, conf.pw);
<|fim_suffix|> for subissue in flow_ticket.subissue... | code_fim | medium | {
"lang": "rust",
"repo": "talbergs/rust-coach",
"path": "/jira-lines/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let ticket = client.fetch_ticket(&conf.ticket);
let flow_ticket = flow::FlowTicket::new(ticket);
for subissue in flow_ticket.subissues() {
println!("{}", subissue.fmt_oneline());
}
Ok(())
}<|fim_prefix|>// repo: talbergs/rust-coach path: /jira-lines/src/main.rs
use jira_line... | code_fim | medium | {
"lang": "rust",
"repo": "talbergs/rust-coach",
"path": "/jira-lines/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> mut stream: BufStream<TcpStream>,
own_builders: Vec<BaseShipBuilder>,
keys: &mut KeyManager,
player: usize)
-> RunResult {
let own_start = ClientStart { ships: own_builders };
if let Err(e) = stream.write(&own_start) {
return RunResult::IoError(e);
}
... | code_fim | hard | {
"lang": "rust",
"repo": "m-mueller678/space_game",
"path": "/client/src/play_server.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn create_stream(addr: &SocketAddr) -> Result<BufStream<TcpStream>, io::Error> {
let raw_stream = TcpStream::connect(addr)?;
raw_stream.set_read_timeout(Some(Duration::from_millis(1)))?;
raw_stream.set_nodelay(true)?;
Ok(BufStream::new(raw_stream))
}
fn run(window: &mut SfRender,
m... | code_fim | hard | {
"lang": "rust",
"repo": "m-mueller678/space_game",
"path": "/client/src/play_server.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: m-mueller678/space_game path: /client/src/play_server.rs
use sfml::graphics::RenderWindow;
use sfml::window::event::Event;
use sfml::window::Key;
use render::SfRender;
use common::game::ship::BaseShipBuilder;
use common::protocol::*;
use common::game::Game;
use key_manager::KeyManager;
use game_... | code_fim | hard | {
"lang": "rust",
"repo": "m-mueller678/space_game",
"path": "/client/src/play_server.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jeshy/vrp path: /vrp-pragmatic/src/checker/limits.rs
#[cfg(test)]
#[path = "../../tests/unit/checker/limits_test.rs"]
mod limits_test;
use super::*;
/// Check that shift limits are not violated:
/// * max shift time
/// * max distance
///
/// NOTE to ensure distance/duration correctness, routi... | code_fim | hard | {
"lang": "rust",
"repo": "jeshy/vrp",
"path": "/vrp-pragmatic/src/checker/limits.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> if tour_activities > tour_size_limit {
return Err(format!(
"tour size limit violation, expected: not more than {}, got: {}, vehicle id '{}', shift index: {}",
tour_size_limit, tour_activities, tour.vehicle_id, tour.shift_i... | code_fim | hard | {
"lang": "rust",
"repo": "jeshy/vrp",
"path": "/vrp-pragmatic/src/checker/limits.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> if let Some(tour_size_limit) = limits.tour_size {
let shift = context.get_vehicle_shift(tour)?;
let extra_activities = if shift.end.is_some() { 2 } else { 1 };
let tour_activities = tour.stops.iter().flat_map(|stop| stop.activities.iter()).count... | code_fim | hard | {
"lang": "rust",
"repo": "jeshy/vrp",
"path": "/vrp-pragmatic/src/checker/limits.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>struct Adapter<S, E> {
inner: S,
error: Option<E>,
}
pub type MaybeBrotli<S> = Either<Brotli<S>, S>;
impl <S:TryStream<Ok= Chunk> + Unpin> Brotli<S>
where
S::Error: Unpin,
{
fn new(s: S) -> Self {
Brotli(BrotliDecoder::new(Adapter {
inner: S,
error: None,
... | code_fim | hard | {
"lang": "rust",
"repo": "CavHack/khipu",
"path": "/src/brotli.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: CavHack/khipu path: /src/brotli.rs
use std::io;
use std::marker::Unpin;
use std::pin::Pin;
use std::task::{Context, Poll};
use async_compression::stream::BrotliDecoder;
use bytes::Bytes;
use futures_core::{Stream, TryStreasm};
use futures_util::future::Either;
use futures_util::{ready, StreamEx... | code_fim | hard | {
"lang": "rust",
"repo": "CavHack/khipu",
"path": "/src/brotli.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut queue = Vec::new();
queue.push(i);
// 当前点染成红色
color[i] = Color::RED;
while let Some(node) = queue.pop() {
let next_color = if color[node] == Color::RED {
Color::GREEN
} else {
... | code_fim | hard | {
"lang": "rust",
"repo": "rcore-os-infohub/ossoc2020-dingiso-daily",
"path": "/code/Leetcode-Exercize/785.判断二分图.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Solution {
// 广度优先
pub fn is_bipartite(graph: Vec<Vec<i32>>) -> bool {
let n = graph.len();
let mut color = vec![Color::UNCOLORED; n];
for i in 0..n {
// 已经染过色了,不处理它了
if color[i] != Color::UNCOLORED {
continue;
... | code_fim | hard | {
"lang": "rust",
"repo": "rcore-os-infohub/ossoc2020-dingiso-daily",
"path": "/code/Leetcode-Exercize/785.判断二分图.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rcore-os-infohub/ossoc2020-dingiso-daily path: /code/Leetcode-Exercize/785.判断二分图.rs
/**
* 785. 判断二分图
给定一个无向图graph,当这个图为二分图时返回true。
如果我们能将一个图的节点集合分割成两个独立的子集A和B,并使图中的每一条边的两个节点一个来自A集合,一个来自B集合,我们就将这个图称为二分图。
graph将会以邻接表方式给出,graph[i]表示图中与节点i相连的所有节点。每个节点都是一个在0到graph.length-1之间的整数。这图中没有自环和平行边: ... | code_fim | hard | {
"lang": "rust",
"repo": "rcore-os-infohub/ossoc2020-dingiso-daily",
"path": "/code/Leetcode-Exercize/785.判断二分图.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: m-labs/dslite2svd path: /crates/tm4c129x/src/can0/if2cmsk.rs
#[doc = "Reader of register IF2CMSK"]
pub type R = crate::R<u32, super::IF2CMSK>;
#[doc = "Writer for register IF2CMSK"]
pub type W = crate::W<u32, super::IF2CMSK>;
#[doc = "Register IF2CMSK `reset()`'s with value 0"]
impl crate::Reset... | code_fim | hard | {
"lang": "rust",
"repo": "m-labs/dslite2svd",
"path": "/crates/tm4c129x/src/can0/if2cmsk.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|>oc = "Bit 2 - Access Transmission Request"]
#[inline(always)]
pub fn txrqst(&self) -> TXRQST_R {
TXRQST_R::new(((self.bits >> 2) & 0x01) != 0)
}
#[doc = "Bit 3 - Clear Interrupt Pending Bit"]
#[inline(always)]
pub fn clrintpnd(&self) -> CLRINTPND_R {
CLRINTPND_R::ne... | code_fim | hard | {
"lang": "rust",
"repo": "m-labs/dslite2svd",
"path": "/crates/tm4c129x/src/can0/if2cmsk.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> if let Some(rustc) = env::var_os("RUSTC") {
if let Some(output) = Command::new(rustc).arg("--version").output().ok() {
if let Some(version) = str::from_utf8(&output.stdout).ok() {
let mut pieces = version.split('.');
if pieces.next() != Some("rustc 1... | code_fim | hard | {
"lang": "rust",
"repo": "elichai/random-rs",
"path": "/random-trait/build.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: elichai/random-rs path: /random-trait/build.rs
use std::process::Command;
use std::{env, str};
fn main() {
if let Some(v) = rustc_version() {
if v >= 26 {
println!("cargo:rustc-cfg=feature=\"u128\"");
}
}
}
<|fim_suffix|> if let Some(rustc) = env::var_os(... | code_fim | hard | {
"lang": "rust",
"repo": "elichai/random-rs",
"path": "/random-trait/build.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mobilipia/ibledger path: /vega_sodiumoxide/src/crypto/aead/chacha20poly1305_ietf.rs
//! The IETF variant of the ChaCha20-Poly1305 construction can safely encrypt a
//! practically unlimited number of messages, but individual messages cannot
//! exceed 64*(2^32)-64 bytes (approximatively 256 GB).... | code_fim | hard | {
"lang": "rust",
"repo": "mobilipia/ibledger",
"path": "/vega_sodiumoxide/src/crypto/aead/chacha20poly1305_ietf.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let c_expected = &[
0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb, 0x7b, 0x86, 0xaf, 0xbc, 0x53, 0xef,
0x7e, 0xc2, 0xa4, 0xad, 0xed, 0x51, 0x29, 0x6e, 0x08, 0xfe, 0xa9, 0xe2, 0xb5, 0xa7,
0x36, 0xee, 0x62, 0xd6, 0x3d, 0xbe, 0xa4, 0x5e, 0x8c, 0xa9, 0x67, 0x12, 0x... | code_fim | hard | {
"lang": "rust",
"repo": "mobilipia/ibledger",
"path": "/vega_sodiumoxide/src/crypto/aead/chacha20poly1305_ietf.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: panicbit/advent_of_code_19 path: /day07_2/src/main.rs
#[macro_use] extern crate aoc;
use itertools::Itertools;
use intcode::VM;
use std::sync::mpsc::channel;
use std::thread;
#[aoc(2019, 07, 2)]
fn main(input: &str) -> isize {
let mem = intcode::parse(input);
(5..=9)
.permutations... | code_fim | hard | {
"lang": "rust",
"repo": "panicbit/advent_of_code_19",
"path": "/day07_2/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let (tx, rx) = channel();
let rx = phases
.into_iter()
.rev()
.fold(rx, |rx, phase| {
let (tx, new_rx) = channel();
let mut vm = VM::new(mem);
vm.queue_input(phase);
vm.set_input_provider(move |_| {
let sign... | code_fim | medium | {
"lang": "rust",
"repo": "panicbit/advent_of_code_19",
"path": "/day07_2/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: vermaneerajin/jql path: /src/parser.rs
use crate::types::Selector;
use crate::types::{Group, Groups};
use pest::{iterators as pest_iterators, Parser};
use pest_derive::*;
#[derive(Parser)]
#[grammar = "grammar.pest"]
struct GroupsParser;
type PestPair<'a> = pest_iterators::Pair<'a, Rule>;
///... | code_fim | hard | {
"lang": "rust",
"repo": "vermaneerajin/jql",
"path": "/src/parser.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: scrogson/kafka-protocol path: /examples/api_versions.rs
use kafka_protocol::{ApiKey, ApiVersion, Error};
use std::convert::TryFrom;
use std::io::Cursor;
use async_std::net::TcpStream;
use async_std::io;
use async_std::prelude::*;
use async_std::task;
use byteorder::{BigEndian, ReadBytesExt};
fn... | code_fim | hard | {
"lang": "rust",
"repo": "scrogson/kafka-protocol",
"path": "/examples/api_versions.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut cursor = Cursor::new(buf);
let correlation_id = cursor.read_i32::<BigEndian>()?;
let error = cursor.read_i16::<BigEndian>()?;
let array_size = cursor.read_i32::<BigEndian>()?;
println!("Size: {:?}", len);
println!("Correlation ID: {:?}", correlatio... | code_fim | hard | {
"lang": "rust",
"repo": "scrogson/kafka-protocol",
"path": "/examples/api_versions.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[derive(Clone)]
enum Inner {
Disabled,
Enabled {
level: level::Handle,
tasks: tasks::Handle,
},
}
// === impl Handle ===
impl Handle {
/// Serve requests that controls the log level. The request is expected to be either a GET or PUT
/// request. PUT requests must hav... | code_fim | hard | {
"lang": "rust",
"repo": "hawkw/linkerd2-proxy",
"path": "/linkerd/tracing/src/lib.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.