text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_suffix|>impl fmt::Display for RpcError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "code {}\nmessage {}", self.code, self.message)
}
}<|fim_prefix|>// repo: jorian/komodorpc-rust-client path: /src/rpcconn/response.rs
use std::result::Result as StdResult;
use std::{error::Er... | code_fim | hard | {
"lang": "rust",
"repo": "jorian/komodorpc-rust-client",
"path": "/src/rpcconn/response.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ChosunOne/physics path: /src/units/si/derived/mod.rs
use crate::expr_op;
use crate::expr_unit;
use crate::units::si::si_unit::{SIUnit, Expression, Operator};
use crate::units::si::base::BaseUnit::{Float, Second, Meter, Kilogram, Kelvin, Ampere, Mole, Candela};
#[derive(Copy, Clone)]
pub enum De... | code_fim | hard | {
"lang": "rust",
"repo": "ChosunOne/physics",
"path": "/src/units/si/derived/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> match self {
DerivedUnit::Becquerel => {
"Bq".to_string()
}
DerivedUnit::Celsius => {
"°C".to_string()
}
DerivedUnit::Coulomb => {
"C".to_string()
}
DerivedUnit::Fara... | code_fim | hard | {
"lang": "rust",
"repo": "ChosunOne/physics",
"path": "/src/units/si/derived/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: kalyankondapally/crosvm path: /sys_util/src/signal.rs
// Copyright 2017 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use libc::{
c_int, pthread_kill, pthread_sigmask, pthread_t, sigactio... | code_fim | hard | {
"lang": "rust",
"repo": "kalyankondapally/crosvm",
"path": "/sys_util/src/signal.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Safe - return values are checked.
unsafe {
let mut old_sigset: sigset_t = mem::zeroed();
let ret = pthread_sigmask(SIG_BLOCK, null(), &mut old_sigset as *mut sigset_t);
if ret < 0 {
return Err(Error::RetrieveSignalMask(ret));
}
for num in 0..... | code_fim | hard | {
"lang": "rust",
"repo": "kalyankondapally/crosvm",
"path": "/sys_util/src/signal.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ohadkoren/deno path: /cli/coverage.rs
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
use crate::colors;
use crate::file_fetcher::SourceFile;
use crate::global_state::GlobalState;
use crate::inspector::DenoInspector;
use crate::permissions::Permissions;
use deno_core:... | code_fim | hard | {
"lang": "rust",
"repo": "ohadkoren/deno",
"path": "/cli/coverage.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let b = Box::new(MaybeUninit::<T>::uninit());
let p = Box::into_raw(b) as *mut T;
unsafe { ptr::write(p, new_fn(p)) };
unsafe { Box::from_raw(p) }
}
pub fn filter_script_coverages(
coverages: Vec<ScriptCoverage>,
test_file_url: Url,
test_modules: Vec<Url>,
) -> Vec<ScriptCoverage> {
cover... | code_fim | hard | {
"lang": "rust",
"repo": "ohadkoren/deno",
"path": "/cli/coverage.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: axtstar/c-samples path: /postgres-spi-mecab-sample-rust/test/src/lib.rs
use pgx::*;
pg_module_magic!();
#[pg_extern]
fn hello_test() -> &'static str {
<|fim_suffix|> assert_eq!("Hello, test", crate::hello_test());
}
}
#[cfg(test)]
pub mod pg_test {
pub fn setup(_options: Vec<&... | code_fim | medium | {
"lang": "rust",
"repo": "axtstar/c-samples",
"path": "/postgres-spi-mecab-sample-rust/test/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn postgresql_conf_options() -> Vec<&'static str> {
// return any postgresql.conf settings that are required for your tests
vec![]
}
}<|fim_prefix|>// repo: axtstar/c-samples path: /postgres-spi-mecab-sample-rust/test/src/lib.rs
use pgx::*;
pg_module_magic!();
#[pg_extern]
f... | code_fim | medium | {
"lang": "rust",
"repo": "axtstar/c-samples",
"path": "/postgres-spi-mecab-sample-rust/test/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn tick(&mut self) {
let high = self.memory.data[self.registers.program_counter as usize];
let low = self.memory.data[self.registers.program_counter as usize + 1];
let instruction_code = ((high as u16) << 8) + low as u16;
self.execute(instruction_code);
}
f... | code_fim | hard | {
"lang": "rust",
"repo": "tglanz/chip8",
"path": "/arch/src/cpu.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tglanz/chip8 path: /arch/src/cpu.rs
use {Address, Byte, Renderer};
use memory::{Memory, PROGRAM_OFFSET};
use registers::{Registers};
use instructions::{Instruction};
use display::{Display};
use keyboard::{Keyboard};
use executions::execute_instruction;
const STACK_SIZE: usize = 0x0F;
pub type ... | code_fim | hard | {
"lang": "rust",
"repo": "tglanz/chip8",
"path": "/arch/src/cpu.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl SelectionSorter {
pub fn sort<T: Ord>(l: &mut Vec<T>) {
if l.len() <= 1 {
return;
}
for i in 0..(l.len() - 1) {
for j in (i + 1)..l.len() {
if l[j].cmp(&l[i]) == Ordering::Less {
swap(l, i, j);
}... | code_fim | medium | {
"lang": "rust",
"repo": "koqizhao/rust-projects",
"path": "/algorithms/src/sort/selection_sort.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: koqizhao/rust-projects path: /algorithms/src/sort/selection_sort.rs
use std::cmp::Ordering;
use super::swap::*;
pub struct SelectionSorter {
}
impl<T: Ord> super::Sorter<T> for SelectionSorter {
<|fim_suffix|> for i in 0..(l.len() - 1) {
for j in (i + 1)..l.len() {
... | code_fim | medium | {
"lang": "rust",
"repo": "koqizhao/rust-projects",
"path": "/algorithms/src/sort/selection_sort.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> for i in 0..(l.len() - 1) {
for j in (i + 1)..l.len() {
if l[j].cmp(&l[i]) == Ordering::Less {
swap(l, i, j);
}
}
}
}
}<|fim_prefix|>// repo: koqizhao/rust-projects path: /algorithms/src/sort/selection_sort.r... | code_fim | medium | {
"lang": "rust",
"repo": "koqizhao/rust-projects",
"path": "/algorithms/src/sort/selection_sort.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ftilde/rust-x86asm path: /src/test/instruction_tests/instr_pcmpistrm.rs
use instruction_def::*;
use test::run_test;
use Operand::*;
use Reg::*;
use RegScale::*;
use RegType::*;
use {BroadcastMode, Instruction, MaskReg, MergeMode, Mnemonic, OperandSize, Reg, RoundingMode};
#[test]
fn pcmpistrm_1... | code_fim | hard | {
"lang": "rust",
"repo": "ftilde/rust-x86asm",
"path": "/src/test/instruction_tests/instr_pcmpistrm.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[test]
fn pcmpistrm_4() {
run_test(
&Instruction {
mnemonic: Mnemonic::PCMPISTRM,
operand1: Some(Direct(XMM2)),
operand2: Some(IndirectScaledIndexed(
RCX,
RDX,
Four,
Some(OperandSize::Xmmword),... | code_fim | hard | {
"lang": "rust",
"repo": "ftilde/rust-x86asm",
"path": "/src/test/instruction_tests/instr_pcmpistrm.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Expand all invocation arguments and bind them to their new variable names
let mut new_vars = HashMap::new();
let mut match_state_new = String::new();
if match_state.is_none() {
match_state_new.push_str(name);
}
fo... | code_fim | hard | {
"lang": "rust",
"repo": "jD91mZM2/generic-turing-machine",
"path": "/src/expander.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jD91mZM2/generic-turing-machine path: /src/expander.rs
use crate::{
parser::{Types, Node},
types::{Move, Type, Root, TypedNode},
FINISH_STATE
};
use rowan::TextRange;
use std::collections::HashMap;
#[derive(Debug, Fail, PartialEq, Eq)]
pub enum GenerateError {
#[fail(display = ... | code_fim | hard | {
"lang": "rust",
"repo": "jD91mZM2/generic-turing-machine",
"path": "/src/expander.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Make sure we have at least one
functions.peek().ok_or_else(|| (Some(invocation.node().range()), GenerateError::Unknown(name.to_string())))?;
let mut match_state = None;
for f in functions {
let sign = f.match_state();
let body = f.do_state();
... | code_fim | hard | {
"lang": "rust",
"repo": "jD91mZM2/generic-turing-machine",
"path": "/src/expander.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: pcein/pathanapuram path: /code/basics/part1/count-doubles/a1.rs
fn main() {
let s = "abbcdde";
let v:Vec<(char, char)> = s.chars().zip(s.chars().skip(1)).collect();
<|fim_suffix|> println!("{}", n);
}<|fim_middle|> let mut n = 0;
for (c1, c2) in v {
if c1 == c... | code_fim | medium | {
"lang": "rust",
"repo": "pcein/pathanapuram",
"path": "/code/basics/part1/count-doubles/a1.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> for (c1, c2) in v {
if c1 == c2 {
n += 1;
}
}
println!("{}", n);
}<|fim_prefix|>// repo: pcein/pathanapuram path: /code/basics/part1/count-doubles/a1.rs
fn main() {
let s = "abbcdde";
<|fim_middle|> let v:Vec<(char, char)> = s.chars().zip(s.chars().... | code_fim | medium | {
"lang": "rust",
"repo": "pcein/pathanapuram",
"path": "/code/basics/part1/count-doubles/a1.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> if buff_size == 0 {
proxy_tunnel(source_stream, server_stream, rc4).await
} else {
proxy_tunnel_buf(source_stream, server_stream, rc4, buff_size).await
}
}
}
pub struct TcpHandle {
tcp_proxy: TcpProxy
}
impl TcpHandle {
pub async fn new(remote_hosts: &Array, buff_size: usiz... | code_fim | hard | {
"lang": "rust",
"repo": "xutianyi1999/rs-proxy",
"path": "/src/client/tcp_client.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: xutianyi1999/rs-proxy path: /src/client/tcp_client.rs
use std::net::SocketAddr;
use bytes::BufMut;
use crypto::rc4::Rc4;
use rand::Rng;
use tokio::io::{AsyncWriteExt, Error, ErrorKind, Result};
use tokio::net::TcpStream;
use yaml_rust::yaml::Array;
use crate::commons::{Address, MAGIC_CODE, Opt... | code_fim | hard | {
"lang": "rust",
"repo": "xutianyi1999/rs-proxy",
"path": "/src/client/tcp_client.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(feature = "frontend")]
mod frontend;
#[cfg(feature = "frontend")]
pub use frontend::components::root::RootComponent;
pub mod protocol_capnp {
#![allow(dead_code)]
#![allow(missing_docs)]
#![allow(unknown_lints)]
#![allow(clippy)]
include!(concat!(env!("OUT_DIR"), "/src/protocol... | code_fim | hard | {
"lang": "rust",
"repo": "pickfire/webapp.rs",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: pickfire/webapp.rs path: /src/lib.rs
#![deny(missing_docs)]
//! The main library interface
extern crate capnp;
extern crate serde;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate failure;
#[macro_use]
extern crate lazy_static;
#[cfg(feature = "default")]
extern crate actix... | code_fim | hard | {
"lang": "rust",
"repo": "pickfire/webapp.rs",
"path": "/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: sueken5/resea path: /servers/net/endian.rs
#[repr(transparent)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct NetEndian<T>(T);
impl<T: Into<NetEndian<T>>> NetEndian<T> {
pub fn new(value: T) -> NetEndian<T> {
NetEndian(value)
}
}
impl Into<NetEn... | code_fim | medium | {
"lang": "rust",
"repo": "sueken5/resea",
"path": "/servers/net/endian.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Into<NetEndian<u32>> for u32 {
fn into(self) -> NetEndian<u32> {
NetEndian(swap32(self))
}
}
impl Into<u16> for NetEndian<u16> {
fn into(self) -> u16 {
swap16(self.0)
}
}
impl Into<u32> for NetEndian<u32> {
fn into(self) -> u32 {
swap32(self.0)
}
}
p... | code_fim | hard | {
"lang": "rust",
"repo": "sueken5/resea",
"path": "/servers/net/endian.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let text =
reqwest::blocking::get(&(url.to_owned() + "/dldir.txt"))?.text()?;
println!(".");
for line in
text.lines()
.map(|line| line.trim())
.filter(|line| match &excluded {
Some(pat) => !pat.is_match(line),
None => tr... | code_fim | hard | {
"lang": "rust",
"repo": "Darazaki/dldir",
"path": "/src/main.rs",
"mode": "spm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Darazaki/dldir path: /src/main.rs
#[macro_use]
extern crate clap;
use regex::Regex;
use walkdir::WalkDir;
use std::{fs, fs::File, io, io::Write};
fn main() -> io::Result<()> {
let matches = clap_app!(dldir =>
(version: crate_version!())
(author: crate_authors!())
(... | code_fim | hard | {
"lang": "rust",
"repo": "Darazaki/dldir",
"path": "/src/main.rs",
"mode": "psm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_suffix|> .short("i")
.long("init")
.help("Creates the config file"))
.get_matches()
}<|fim_prefix|>// repo: cricketnest/fundoc path: /src/cli.rs
extern crate clap;
use clap::{App, Arg, ArgMatches};
pub fn create_cli() -> ArgMatches<'static> {
App::new("Fundoc")
.... | code_fim | medium | {
"lang": "rust",
"repo": "cricketnest/fundoc",
"path": "/src/cli.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: cricketnest/fundoc path: /src/cli.rs
extern crate clap;
use clap::{App, Arg, ArgMatches};
pub fn create_cli() -> ArgMatches<'static> {
App::new("<|fim_suffix|> .short("i")
.long("init")
.help("Creates the config file"))
.get_matches()
}<|fim_middle|>Fund... | code_fim | hard | {
"lang": "rust",
"repo": "cricketnest/fundoc",
"path": "/src/cli.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: EFanZh/LeetCode path: /src/problem_1773_count_items_matching_a_rule/mod.rs
pub mod iterative;
pub trait Solution {
fn count_matches(items: Vec<Vec<String>>, rule_key: String, rule_value: String) -> i32;
}
#[cfg(test)]
mod tests {
use super::Solution;
<|fim_suffix|> for ((items,... | code_fim | hard | {
"lang": "rust",
"repo": "EFanZh/LeetCode",
"path": "/src/problem_1773_count_items_matching_a_rule/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> for ((items, rule_key, rule_value), expected) in test_cases {
assert_eq!(
S::count_matches(
items
.iter()
.map(|item| item.iter().copied().map(str::to_string).collect())
.collect... | code_fim | hard | {
"lang": "rust",
"repo": "EFanZh/LeetCode",
"path": "/src/problem_1773_count_items_matching_a_rule/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // TODO: test vulnerability finding code
let lockfile = Lockfile::load("Cargo.lock").unwrap();
let vulns = db.vulnerabilities(&lockfile);
assert!(vulns.is_empty());
}<|fim_prefix|>// repo: rob-solana/rustsec-crate path: /tests/integration.rs
extern crate rustsec;
extern crate semver;
use... | code_fim | hard | {
"lang": "rust",
"repo": "rob-solana/rustsec-crate",
"path": "/tests/integration.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rob-solana/rustsec-crate path: /tests/integration.rs
extern crate rustsec;
extern crate semver;
use rustsec::{AdvisoryDatabase, AdvisoryId, Lockfile, PackageName};
use semver::VersionReq;
// End-to-end integration test (has online dependency on GitHub)
#[test]
fn test_integration() {
<|fim_suf... | code_fim | hard | {
"lang": "rust",
"repo": "rob-solana/rustsec-crate",
"path": "/tests/integration.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: xCrypt0r/Baekjoon path: /src/8/8719.rs
/**
* 8719. Piłeczka
*
* 작성자: xCrypt0r
* 언어: Rust 2018
* 사용 메모리: 13,032 KB
* 소요 시간: 316 ms
* 해결 날짜: 2020년 10월 2일
*/
#![allow(non_snake_case)]
use std::io;
use io::Write;
macro_rules! get_line {
( $( $t: ty ),+ ) => {
{
le... | code_fim | hard | {
"lang": "rust",
"repo": "xCrypt0r/Baekjoon",
"path": "/src/8/8719.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let stdout = io::stdout();
let mut out = io::BufWriter::new(stdout.lock());
let T = get_line!(i32);
for _ in 0..T {
let (mut x, w) = get_line!(i32, i32);
let mut bounce = 0;
while x < w {
x *= 2;
bounce += 1;
}
writ... | code_fim | medium | {
"lang": "rust",
"repo": "xCrypt0r/Baekjoon",
"path": "/src/8/8719.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> for _ in 0..T {
let (mut x, w) = get_line!(i32, i32);
let mut bounce = 0;
while x < w {
x *= 2;
bounce += 1;
}
writeln!(out, "{}", bounce).unwrap();
}
}<|fim_prefix|>// repo: xCrypt0r/Baekjoon path: /src/8/8719.rs
/**
* 87... | code_fim | medium | {
"lang": "rust",
"repo": "xCrypt0r/Baekjoon",
"path": "/src/8/8719.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut pos_cur = (0, 0);
let mut pos_oth = (0, 0);
for &move_ in moves {
pos_cur = (pos_cur.0+move_.0, pos_cur.1+move_.1);
field.insert(pos_cur);
std::mem::swap(&mut pos_cur, &mut pos_oth);
}
field.len()
}<|fim_prefix|>// repo: DanielKeep/rust-advent-of-code ... | code_fim | hard | {
"lang": "rust",
"repo": "DanielKeep/rust-advent-of-code",
"path": "/src/bin/day3.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: DanielKeep/rust-advent-of-code path: /src/bin/day3.rs
use std::collections::HashSet;
use std::io::{Read, stdin};
fn main() {
let moves: Vec<_> = stdin().bytes()
.filter_map(|b| match b {
Ok(b'^') => Some((0, 1)),
Ok(b'>') => Some((1, 0)),
Ok(b'v')... | code_fim | hard | {
"lang": "rust",
"repo": "DanielKeep/rust-advent-of-code",
"path": "/src/bin/day3.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut pos = (0, 0);
for &move_ in moves {
pos = (pos.0+move_.0, pos.1+move_.1);
field.insert(pos);
}
field.len()
}
fn part_2(moves: &[(i32, i32)]) -> usize {
let mut field = HashSet::new();
field.insert((0, 0));
let mut pos_cur = (0, 0);
let mut pos_oth... | code_fim | medium | {
"lang": "rust",
"repo": "DanielKeep/rust-advent-of-code",
"path": "/src/bin/day3.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: bouzuya/rust-atcoder path: /cargo-atcoder/contests/utpc2020/src/bin/a.rs
use proconio::input;
fn main() {
input! {
n: usize,
l: i64,
mut xa: [(i64, i64); n],
};
xa.push((l, 0));
<|fim_suffix|> if is_ok {
ok = t;
} else {
... | code_fim | hard | {
"lang": "rust",
"repo": "bouzuya/rust-atcoder",
"path": "/cargo-atcoder/contests/utpc2020/src/bin/a.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> if is_ok {
ok = t;
} else {
ng = t;
}
}
let ans = ok;
println!("{}", ans);
}<|fim_prefix|>// repo: bouzuya/rust-atcoder path: /cargo-atcoder/contests/utpc2020/src/bin/a.rs
use proconio::input;
fn main() {
input! {
n: usize,
... | code_fim | hard | {
"lang": "rust",
"repo": "bouzuya/rust-atcoder",
"path": "/cargo-atcoder/contests/utpc2020/src/bin/a.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut v = t;
let mut p = 0;
for (x, a) in xa.iter().copied() {
v += x - p;
v = v.min(t);
v -= a;
if v < 0 {
is_ok = false;
break;
}
p = x;
}
if is_ok {
... | code_fim | medium | {
"lang": "rust",
"repo": "bouzuya/rust-atcoder",
"path": "/cargo-atcoder/contests/utpc2020/src/bin/a.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let h = h % (256 * 6);
let t = if (h & 256) == 0 { h & 255 } else { 512 - (h & 255) };
let max = v;
let min = max - (s as u32 * max as u32 / 255) as u8;
let d = (max - min) as u32;
match h / 256 {
0 => (max, (t * d / 256) as u8 + min, min),
1 => ((t * d / 256) as u8... | code_fim | hard | {
"lang": "rust",
"repo": "hoangpq/galangua",
"path": "/galangua-core/src/app/game/enemy/tractor_beam.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: hoangpq/galangua path: /galangua-core/src/app/game/enemy/tractor_beam.rs
use crate::framework::types::Vec2I;
use crate::framework::RendererTrait;
use crate::util::math::{round_up, ONE};
const SPRITE_NAMES: [&str; 29] = [
"beam00", "beam01", "beam02", "beam03", "beam04", "beam05",
"beam0... | code_fim | hard | {
"lang": "rust",
"repo": "hoangpq/galangua",
"path": "/galangua-core/src/app/game/enemy/tractor_beam.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn get_file_with_path_and_options_and_file_system_entry_callback(
this: &FileSystemDirectoryEntry,
path: Option<&str>,
options: &FileSystemFlags,
success_callback: &FileSystemEntryCallback,
);
#[cfg(feature = "FileSystemFlags")]
# [wasm_bindgen (method , s... | code_fim | hard | {
"lang": "rust",
"repo": "rustwasm/wasm-bindgen",
"path": "/crates/web-sys/src/features/gen_FileSystemDirectoryEntry.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rustwasm/wasm-bindgen path: /crates/web-sys/src/features/gen_FileSystemDirectoryEntry.rs
#![allow(unused_imports)]
#![allow(clippy::all)]
use super::*;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = FileSystemEntry , extends = :: js_sys :: Object , js_n... | code_fim | hard | {
"lang": "rust",
"repo": "rustwasm/wasm-bindgen",
"path": "/crates/web-sys/src/features/gen_FileSystemDirectoryEntry.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn validate_maker_payment(
&self,
payment_tx: &[u8],
time_lock: u32,
maker_pub: &[u8],
priv_bn_hash: &[u8],
amount: BigDecimal,
_swap_contract_address: &Option<BytesJson>,
) -> Box<dyn Future<Item = (), Error = String> + Send> {
utxo_... | code_fim | hard | {
"lang": "rust",
"repo": "smartdev0218/atomicDEX-API",
"path": "/mm2src/coins/utxo/bch.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: smartdev0218/atomicDEX-API path: /mm2src/coins/utxo/bch.rs
rialization::Error),
}
#[derive(Debug, Default)]
pub struct BchUnspents {
/// Standard BCH UTXOs
standard: Vec<UnspentInfo>,
/// SLP related UTXOs
slp: HashMap<H256, Vec<SlpUnspent>>,
/// SLP minting batons outputs, ... | code_fim | hard | {
"lang": "rust",
"repo": "smartdev0218/atomicDEX-API",
"path": "/mm2src/coins/utxo/bch.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: smartdev0218/atomicDEX-API path: /mm2src/coins/utxo/bch.rs
match amounts.get(unspent.outpoint.index as usize - 1) {
Some(slp_amount) => result.add_slp(token_id, unspent, *slp_amount),
None => result.add_standa... | code_fim | hard | {
"lang": "rust",
"repo": "smartdev0218/atomicDEX-API",
"path": "/mm2src/coins/utxo/bch.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: goffrie/lighthouse path: /beacon_node/network/src/sync/range_sync/chain_collection.rs
*node_sync_state = new_state;
}
}
/// A fully synced peer has joined.
///
/// We could be awaiting a head sync. If we are in the head syncing state, without any head
/// chains,... | code_fim | hard | {
"lang": "rust",
"repo": "goffrie/lighthouse",
"path": "/beacon_node/network/src/sync/range_sync/chain_collection.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> &mut self,
network: &mut SyncNetworkContext<T::EthSpec>,
local_epoch: Epoch,
local_head_epoch: Epoch,
) {
// There are no finalized chains, update the state.
if self.head_chains.is_empty() {
self.state = RangeSyncState::Idle;
retu... | code_fim | hard | {
"lang": "rust",
"repo": "goffrie/lighthouse",
"path": "/beacon_node/network/src/sync/range_sync/chain_collection.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// This is called once a head chain has completed syncing. It removes all non-syncing head
/// chains and re-status their peers.
pub fn clear_head_chains(&mut self, network: &mut SyncNetworkContext<T::EthSpec>) {
let log_ref = &self.log;
self.head_chains.retain(|_id, chain| {
... | code_fim | hard | {
"lang": "rust",
"repo": "goffrie/lighthouse",
"path": "/beacon_node/network/src/sync/range_sync/chain_collection.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: zheland/custom-print path: /tests/cchar_writer.rs
#![cfg(feature = "std")]
#![no_std]
extern crate std;
use std::os::raw::c_char;
use std::string::String;
use std::sync::Mutex;
use std::vec::Vec;
use once_cell::sync::Lazy;
static CHUNKS: Lazy<Mutex<Vec<String>>> = Lazy::new(Mutex::default);
... | code_fim | hard | {
"lang": "rust",
"repo": "zheland/custom-print",
"path": "/tests/cchar_writer.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub mod submodule {
#[test]
fn test_cchar_writer() {
use crate::{black_box, take_chunks};
println!();
assert_eq!(take_chunks(), &["\n"]);
println!("first");
assert_eq!(take_chunks(), &["first\n"]);
println!("first {}\nthird\n", black_box("second"));... | code_fim | hard | {
"lang": "rust",
"repo": "zheland/custom-print",
"path": "/tests/cchar_writer.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>}
#[system(for_each)]
pub fn render_update(ctrl: &mut Controller, transform: &mut Tranform, sprite: &StaticGraphic) {
if ctrl.pressed {
transform.position += transform.velocity
};
let context = utils::get_canvas();
context.clear_rect(0., 0., 1280., 720.);
context
.dra... | code_fim | medium | {
"lang": "rust",
"repo": "CrosszPai/wasm-soul-eater-clone",
"path": "/src/game_system/render.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: CrosszPai/wasm-soul-eater-clone path: /src/game_system/render.rs
use crate::components::{
controller::Controller, static_graphic::StaticGraphic, transform::Tranform,
};
use crate::utils;
use legion::*;
use wasm_bindgen::prelude::*;
#[wasm_bindgen(raw_module = "../js/getResource.js")]
extern... | code_fim | medium | {
"lang": "rust",
"repo": "CrosszPai/wasm-soul-eater-clone",
"path": "/src/game_system/render.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[test]
fn domains_to_id_domain() {
let client = graph();
client.v1().domains().id(ID_VEC[0].as_str()).get_domain();
assert_url_eq(&client, &format!("/domains/{}", ID_VEC[0]));
}<|fim_prefix|>// repo: Arstman/graph-rs path: /tests/domains_path.rs
#[macro_use]
extern crate lazy_static;
use ... | code_fim | hard | {
"lang": "rust",
"repo": "Arstman/graph-rs",
"path": "/tests/domains_path.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Arstman/graph-rs path: /tests/domains_path.rs
#[macro_use]
extern crate lazy_static;
use graph_http::BlockingHttpClient;
use graph_rs_sdk::prelude::*;
use test_tools::assert_url_eq;
use test_tools::common::TestTools;
lazy_static! {
static ref ID_VEC: Vec<String> = TestTools::random_strings... | code_fim | medium | {
"lang": "rust",
"repo": "Arstman/graph-rs",
"path": "/tests/domains_path.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(test)]
mod tests {
use super::Token;
use super::Token::*;
use super::tokenize;
// Construct helpers
fn lambda(arg: &str) -> Token { Lambda(String::from(arg)) }
fn var(arg: &str) -> Token { Identifier(String::from(arg)) }
fn let_token(arg: &str) -> Token { Let(String::fr... | code_fim | hard | {
"lang": "rust",
"repo": "meddle0x53/ulc-rust",
"path": "/src/lexer.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(
tokenize("lambda x.x").ok().unwrap(),
vec![lambda("x"), var("x")]
);
assert_eq!(
tokenize("\\x.x").ok().unwrap(),
vec![lambda("x"), var("x")]
);
assert_eq!(
tokenize("λx.y x").ok().unwrap(),
... | code_fim | hard | {
"lang": "rust",
"repo": "meddle0x53/ulc-rust",
"path": "/src/lexer.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: meddle0x53/ulc-rust path: /src/lexer.rs
use std::fmt;
use std::str::Chars;
use std::iter::{Peekable, Enumerate};
#[derive(Clone, Debug, PartialEq)]
pub enum Token {
Lambda(String),
OpenParen,
CloseParen,
Identifier(String),
Let(String),
Binding(String)
}
use self::Token... | code_fim | hard | {
"lang": "rust",
"repo": "meddle0x53/ulc-rust",
"path": "/src/lexer.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: sameo/hasard path: /src/lib.rs
pub fn randnum() -> u8 {
14
}
#[cfg(test)]
mod tests {
use super::*;
<|fim_suffix|> assert_eq!(randnum(), 42);
}
}<|fim_middle|> #[test]
fn test_randnum() {
| code_fim | easy | {
"lang": "rust",
"repo": "sameo/hasard",
"path": "/src/lib.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn test_randnum() {
assert_eq!(randnum(), 42);
}
}<|fim_prefix|>// repo: sameo/hasard path: /src/lib.rs
pub fn randnum() -> u8 {
14
}
<|fim_middle|>#[cfg(test)]
mod tests {
use super::*;
| code_fim | easy | {
"lang": "rust",
"repo": "sameo/hasard",
"path": "/src/lib.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(odd_or_even(vec![1]), "odd");
}
#[test]
fn test_even() {
assert_eq!(odd_or_even(vec![0, 1, 5]), "even");
}
#[test]
fn test_odd() {
assert_eq!(odd_or_even(vec![0, 1, 4]), "odd");
}
#[test]
fn test_negative_even() {
assert_eq!(od... | code_fim | hard | {
"lang": "rust",
"repo": "TummeliRuonakoski/CodeWars",
"path": "/7 kyu/Odd or Even/Rust.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(odd_or_even(vec![0, 1, 4]), "odd");
}
#[test]
fn test_negative_even() {
assert_eq!(odd_or_even(vec![0, -1, -5]), "even");
}
#[test]
fn test_negative_odd() {
assert_eq!(odd_or_even(vec![0, -1, 2]), "odd");
}
}<|fim_prefix|>// repo: TummeliRuona... | code_fim | medium | {
"lang": "rust",
"repo": "TummeliRuonakoski/CodeWars",
"path": "/7 kyu/Odd or Even/Rust.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: TummeliRuonakoski/CodeWars path: /7 kyu/Odd or Even/Rust.rs
fn odd_or_even(numbers: Vec<i32>) -> String {
if numbers.iter().sum::<i32>() %2 == 0{
"even".to_string()
}else{
"odd".to_string()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_e... | code_fim | hard | {
"lang": "rust",
"repo": "TummeliRuonakoski/CodeWars",
"path": "/7 kyu/Odd or Even/Rust.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>table! {
tokens (id) {
id -> Uuid,
user_id -> Uuid,
created_at -> Timestamp,
updated_at -> Timestamp,
deleted_at -> Nullable<Timestamp>,
}
}
table! {
users (id) {
id -> Uuid,
email -> Varchar,
salutation -> Varchar,
is_ad... | code_fim | hard | {
"lang": "rust",
"repo": "trisiel/trisiel",
"path": "/src/schema.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: trisiel/trisiel path: /src/schema.rs
table! {
executions (id) {
id -> Uuid,
handler_id -> Uuid,
finished -> Bool,
stderr -> Nullable<Varchar>,
created_at -> Timestamp,
updated_at -> Timestamp,
execution_time -> Nullable<Int4>,
}
}
... | code_fim | hard | {
"lang": "rust",
"repo": "trisiel/trisiel",
"path": "/src/schema.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let camera_point = Point3f::new(0., 0., 1000.);
let resolution = Vector2u::new(1024, 768);
let camera = Box::new(PerspectiveCamera::new(40., resolution));
let r = camera.clone().raster_to_camera.inverse();
let film = camera_point.apply(&r);
assert_eq!(film, ... | code_fim | hard | {
"lang": "rust",
"repo": "CurryPseudo/curry-pbrt",
"path": "/src/camera/perspective.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: CurryPseudo/curry-pbrt path: /src/camera/perspective.rs
use super::Camera;
use crate::*;
#[derive(Clone)]
pub struct PerspectiveCamera {
raster_to_camera: Transform,
resolution: Vector2f,
}
impl PerspectiveCamera {
pub fn new(fov: Float, resolution: Vector2u) -> Self {
let ... | code_fim | hard | {
"lang": "rust",
"repo": "CurryPseudo/curry-pbrt",
"path": "/src/camera/perspective.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(test)]
mod tests {
use super::*;
#[test]
fn perspective_works() {
let camera_point = Point3f::new(0., 0., 1000.);
let resolution = Vector2u::new(1024, 768);
let camera = Box::new(PerspectiveCamera::new(40., resolution));
let r = camera.clone().raster_to_ca... | code_fim | hard | {
"lang": "rust",
"repo": "CurryPseudo/curry-pbrt",
"path": "/src/camera/perspective.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>me(slab.entries.len());
}
// insert holes as necessary
while slab.entries.len() < key {
// add the entry to the start of the vacant list
let next = slab.next;
slab.next = slab.entries.len();
slab.entries.pu... | code_fim | hard | {
"lang": "rust",
"repo": "mozilla/gecko-dev",
"path": "/third_party/rust/slab/src/builder.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>.len() {
// no vacant entries, so next might not have been updated
slab.next = slab.entries.len();
} else if self.vacant_list_broken {
slab.recreate_vacant_list();
} else if let Some(first_vacant_index) = self.first_vacant_index {
let next = ... | code_fim | hard | {
"lang": "rust",
"repo": "mozilla/gecko-dev",
"path": "/third_party/rust/slab/src/builder.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mozilla/gecko-dev path: /third_party/rust/slab/src/builder.rs
use crate::{Entry, Slab};
// Building `Slab` from pairs (usize, T).
pub(crate) struct Builder<T> {
slab: Slab<T>,
vacant_list_broken: bool,
first_vacant_index: Option<usize>,
}
impl<T> Builder<T> {
pub(crate) fn with... | code_fim | hard | {
"lang": "rust",
"repo": "mozilla/gecko-dev",
"path": "/third_party/rust/slab/src/builder.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: autokrator-uog/jackie path: /src/db.rs
use std::{thread, time};
use couchbase::{Bucket, Cluster, CouchbaseError};
pub const BUCKET_NAME: &str = "events";
const MAX_RETRIES: u8 = 60;
const RETRY_INTERVAL_MILLIS: u64 = 1000;
pub fn connect_to_bucket(couchbase_host: &String, bucket_name: &str) -... | code_fim | hard | {
"lang": "rust",
"repo": "autokrator-uog/jackie",
"path": "/src/db.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> while bucket.is_err() && retries > 0 {
match bucket {
Ok(_) => {
panic!("Bucket should be err... this shouldn't happen!");
},
// This is the error that is called if the bucket does not exist, somehow...
Err(CouchbaseError::AuthFai... | code_fim | hard | {
"lang": "rust",
"repo": "autokrator-uog/jackie",
"path": "/src/db.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let name =
DatabaseName::new(rules.name.clone()).expect("protobuf mapping didn't validate name");
match self.server.create_database(name, rules).await {
Ok(_) => Ok(Response::new(CreateDatabaseResponse {})),
Err(Error::DatabaseAlreadyExists { db_name })... | code_fim | hard | {
"lang": "rust",
"repo": "mitch292/influxdb_iox",
"path": "/src/influxdb_ioxd/rpc/management.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mitch292/influxdb_iox path: /src/influxdb_ioxd/rpc/management.rs
use std::convert::TryInto;
use std::fmt::Debug;
use std::sync::Arc;
use tonic::{Request, Response, Status};
use tracing::error;
use data_types::database_rules::DatabaseRules;
use data_types::DatabaseName;
use generated_types::goo... | code_fim | hard | {
"lang": "rust",
"repo": "mitch292/influxdb_iox",
"path": "/src/influxdb_ioxd/rpc/management.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rickardbrannvall/tfhe_linreg path: /src/bin/encode_data1.rs
#![allow(non_snake_case)]
#![allow(unused_imports)]
use concrete::*;
use std::path::Path;
//use std::fs::File;
//use std::io::Read;
use std::str::FromStr;
use std::fs;
use csv::{ReaderBuilder, WriterBuilder};
use ndarray::{Array, Arra... | code_fim | hard | {
"lang": "rust",
"repo": "rickardbrannvall/tfhe_linreg",
"path": "/src/bin/encode_data1.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> println!("loading LWE key... \n");
let sk0_LWE_path = format!("{}/sk0_LWE.json",path);
let sk0 = LWESecretKey::load(&sk0_LWE_path).unwrap();
// create an encoder
//let enc = Encoder::new(-27., 23., 8, 1)?;
let enc = Encoder::new(-50., 50., 6, 1)?;
// Process test ... | code_fim | hard | {
"lang": "rust",
"repo": "rickardbrannvall/tfhe_linreg",
"path": "/src/bin/encode_data1.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let file_names: Vec<ProtoPathBuf> = fds
.file
.iter()
.map(|f| ProtoPathBuf::new(f.get_name().to_owned()))
.collect::<anyhow::Result<_>>()?;
gen_and_write(
&fds.file,
&format!("unknown, file {}", bin),
&file_names,
Path::new("."),
... | code_fim | hard | {
"lang": "rust",
"repo": "psaia/rust-protobuf",
"path": "/protobuf-codegen/src/bin/protobuf-bin-gen-rust-do-not-use.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn main() {
let args: Vec<String> = std::env::args().collect();
if args.len() != 2 {
panic!("must have exactly one argument");
}
let ref pb_bin = args[1];
write_file(&pb_bin).unwrap();
}<|fim_prefix|>// repo: psaia/rust-protobuf path: /protobuf-codegen/src/bin/protobuf-bin-gen... | code_fim | hard | {
"lang": "rust",
"repo": "psaia/rust-protobuf",
"path": "/protobuf-codegen/src/bin/protobuf-bin-gen-rust-do-not-use.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: psaia/rust-protobuf path: /protobuf-codegen/src/bin/protobuf-bin-gen-rust-do-not-use.rs
extern crate protobuf;
extern crate protobuf_codegen;
use std::fs::*;
use std::io::Read;
use std::path::Path;
use protobuf::descriptor::*;
use protobuf::Message;
use protobuf_codegen::gen_and_write::gen_and... | code_fim | hard | {
"lang": "rust",
"repo": "psaia/rust-protobuf",
"path": "/protobuf-codegen/src/bin/protobuf-bin-gen-rust-do-not-use.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> for i in 0..VARS.len() {
let var = &VARS[i..i+1];
map.insert(var, Variable { state: VariableState::Undefined, rules: LinkedList::new() });
}
Mutex::new(map)
};
}<|fim_prefix|>// repo: Git-Math/expert_system path: /src/variables.rs
use std::collection... | code_fim | hard | {
"lang": "rust",
"repo": "Git-Math/expert_system",
"path": "/src/variables.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>lazy_static! {
pub static ref VARIABLEMAP: Mutex<HashMap<&'static str, Variable>> = {
let mut map = HashMap::new();
for i in 0..VARS.len() {
let var = &VARS[i..i+1];
map.insert(var, Variable { state: VariableState::Undefined, rules: LinkedList::new() });
... | code_fim | hard | {
"lang": "rust",
"repo": "Git-Math/expert_system",
"path": "/src/variables.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Git-Math/expert_system path: /src/variables.rs
use std::collections::HashMap;
use std::collections::LinkedList;
use std::sync::Mutex;
use btree::BTree;
use my_option::MyOption;
#[derive(Debug, PartialEq, Clone)]
pub enum VariableState {
Undefined,
True,
False
}
#[derive(Clone)]
p... | code_fim | medium | {
"lang": "rust",
"repo": "Git-Math/expert_system",
"path": "/src/variables.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: lfkeitel/lazuli-lisp path: /lazuli_vm/src/object/mod.rs
pub mod cons_list;
use std::cell::RefCell;
use std::cmp::Ordering;
use std::collections::HashMap;
use std::rc::Rc;
use std::str::FromStr;
use crate::vm::VM;
use cons_list::ConsList;
pub type Program = ConsList<Node>;
pub type BuiltinFn =... | code_fim | hard | {
"lang": "rust",
"repo": "lfkeitel/lazuli-lisp",
"path": "/lazuli_vm/src/object/mod.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Symbol {
pub fn new(name: &str) -> Self {
Symbol {
name: str_to_symbol_name(&name),
value: None,
function: None,
properties: None,
}
}
pub fn with_builtin(name: &str, func: BuiltinFn) -> Self {
Symbol {
n... | code_fim | hard | {
"lang": "rust",
"repo": "lfkeitel/lazuli-lisp",
"path": "/lazuli_vm/src/object/mod.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Yatekii/stm32mp1-pac path: /src/adc2/adc_pcsel.rs
lf) -> &'a mut W {
self.bit(false)
}
#[doc = r"Writes raw bits to the field"]
#[inline(always)]
pub fn bit(self, value: bool) -> &'a mut W {
self.w.bits = (self.w.bits & !(0x01 << 2)) | (((value as u32) & 0x01) << ... | code_fim | hard | {
"lang": "rust",
"repo": "Yatekii/stm32mp1-pac",
"path": "/src/adc2/adc_pcsel.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>R {
PCSEL9_R::new(((self.bits >> 9) & 0x01) != 0)
}
#[doc = "Bit 10 - PCSEL10"]
#[inline(always)]
pub fn pcsel10(&self) -> PCSEL10_R {
PCSEL10_R::new(((self.bits >> 10) & 0x01) != 0)
}
#[doc = "Bit 11 - PCSEL11"]
#[inline(always)]
pub fn pcsel11(&self) -> PC... | code_fim | hard | {
"lang": "rust",
"repo": "Yatekii/stm32mp1-pac",
"path": "/src/adc2/adc_pcsel.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Yatekii/stm32mp1-pac path: /src/adc2/adc_pcsel.rs
always)]
pub fn clear_bit(self) -> &'a mut W {
self.bit(false)
}
#[doc = r"Writes raw bits to the field"]
#[inline(always)]
pub fn bit(self, value: bool) -> &'a mut W {
self.w.bits = (self.w.bits & !(0x01 << 4)... | code_fim | hard | {
"lang": "rust",
"repo": "Yatekii/stm32mp1-pac",
"path": "/src/adc2/adc_pcsel.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let sum = part_1(&answers);
assert_eq!(sum, 11)
}
#[test]
fn example_part_2() {
let input = String::from(
"abc
a
b
c
ab
ac
a
a
a
a
b",
);
let sum = part_2(&input);
assert_eq!(sum, 6)
}<|fim_prefix|>// repo: m-vellinga/advent_2020 path: /src/day_06.rs
use std::collect... | code_fim | hard | {
"lang": "rust",
"repo": "m-vellinga/advent_2020",
"path": "/src/day_06.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: m-vellinga/advent_2020 path: /src/day_06.rs
use std::collections::HashSet;
pub fn run(input: String) {
let answers = convert_input(&input);
println!("Day 6 Part 1: {}", part_1(&answers));
println!("Day 6 Part 2: {}", part_2(&input));
}
fn convert_input(input: &String) -> Vec<Strin... | code_fim | hard | {
"lang": "rust",
"repo": "m-vellinga/advent_2020",
"path": "/src/day_06.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> answered_sum += unique_chars.len() as u64
}
answered_sum
}
fn part_2(input: &String) -> u64 {
let group_answers: Vec<&str> = input.split("\n\n").collect();
let mut group_answered: u64 = 0;
for group in group_answers {
let mut first_line_chars = vec![];
let mut... | code_fim | hard | {
"lang": "rust",
"repo": "m-vellinga/advent_2020",
"path": "/src/day_06.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tismith/device-checkout-rs path: /src/routes.rs
#![cfg_attr(feature = "cargo-clippy", allow(print_literal))]
use chrono;
use chrono::Offset;
use database;
use failure;
use models;
use pool;
use rocket;
use rocket_contrib;
use std;
use utils;
use validator;
use validator::Validate;
pub fn html_... | code_fim | hard | {
"lang": "rust",
"repo": "tismith/device-checkout-rs",
"path": "/src/routes.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
#[post("/devices", data = "<device_update>")]
pub fn post_devices(
config: rocket::State<utils::types::Settings>,
database: pool::DbConn,
device_update: Result<rocket::request::Form<models::DeviceUpdate>, rocket::request::For... | code_fim | hard | {
"lang": "rust",
"repo": "tismith/device-checkout-rs",
"path": "/src/routes.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: MiloHX/paddle_strike_amethyst path: /src/components/mod.rs
//====================================
// Modules declaration for components
//====================================
//
// An Entity represents a single object in your world.
// Component represents one aspect of an object.
// For examp... | code_fim | medium | {
"lang": "rust",
"repo": "MiloHX/paddle_strike_amethyst",
"path": "/src/components/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>made of a material (usually plastic).
// In this example, the bottle is the entity, and the properties are components.
//
// declare modules
pub mod ui_glowing_comp;
pub mod ui_swinging_comp;
pub mod ui_cursor_comp;
pub mod ui_cursor_option_comp;
pub mod ui_waving_comp;
pub mod ui_flashing_comp;<|fim_pr... | code_fim | medium | {
"lang": "rust",
"repo": "MiloHX/paddle_strike_amethyst",
"path": "/src/components/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.