text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_prefix|>// repo: nudded/oci_ffi path: /src/types.rs
#![allow(non_camel_case_types, dead_code)]
use libc::{c_int, c_uint, c_uchar, c_ushort};
// Add standard oracle types for more compliant external FFI description
pub type ub4 = c_uint;
pub type sb4 = c_int;
pub type ub2 = c_ushort;
pub type sword = c_int;
pub... | code_fim | hard | {
"lang": "rust",
"repo": "nudded/oci_ffi",
"path": "/src/types.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// all possible modes as defined
pub enum OCIMode {
OCI_DEFAULT = 0,
OCI_THREADED = 1,
OCI_OBJECT = 2,
OCI_EVENTS = 4,
OCI_NO_UCB = 40,
OCI_ENV_NO_MUTEX = 80,
OCI_NEW_LENGTH_SEMANTICS = 20000,
OCI_SUPPRESS_NLS_VALIDATION = 100000,
OCI_NCHAR_LITERAL_REPLACE_ON = 400000,... | code_fim | hard | {
"lang": "rust",
"repo": "nudded/oci_ffi",
"path": "/src/types.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Levijatan/Voxel-Render path: /src/input.rs
use crate::Camera;
use std::collections::HashMap;
use glfw::Key;
pub struct KeyState<'a> {
key_state: HashMap<Key, State<'a>>,
}
pub struct State<'a> {
held: bool,
action: Box<dyn FnMut(&mut Camera) + 'a>,
}
impl<'a> State<'a> {
fn p... | code_fim | hard | {
"lang": "rust",
"repo": "Levijatan/Voxel-Render",
"path": "/src/input.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn process(&mut self, x: f32, y: f32, cam: &mut Camera) {
let x_offset = (x - self.last_x) * self.sensitivity * cam.delta_time as f32;
let y_offset = (self.last_y - y) * self.sensitivity * cam.delta_time as f32;
self.last_x = x;
self.last_y = y;
cam.rotate(... | code_fim | hard | {
"lang": "rust",
"repo": "Levijatan/Voxel-Render",
"path": "/src/input.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Can't use split_whitespace() here, because we need to splitn and then get the remainder of the line
// after we've split the first 7 columns by whitespace. So we write a custom closure to group multiple whitespaces together.
// We use "splitn(8, ..)" because it stops... | code_fim | hard | {
"lang": "rust",
"repo": "theseus-os/Theseus",
"path": "/kernel/mod_mgmt/src/parse_nano_core.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: theseus-os/Theseus path: /kernel/mod_mgmt/src/parse_nano_core.rs
es]),
)),
}
};
}
let (nano_core_file, real_namespace) = try_mp!(
CrateNamespace::get_crate_object_file_starting_with(namespace, NANO_CORE_FILENAME_PREFIX)
.ok_or("cou... | code_fim | hard | {
"lang": "rust",
"repo": "theseus-os/Theseus",
"path": "/kernel/mod_mgmt/src/parse_nano_core.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // second, skip ahead to the start of the symbol table: a line which contains ".symtab" but does NOT contain "SYMTAB"
let is_start_of_symbol_table = |line: &str| { line.contains(".symtab") && !line.contains("SYMTAB") };
let mut file_iterator = file_iterator.skip_while(|(_line_num, line)| !is_... | code_fim | hard | {
"lang": "rust",
"repo": "theseus-os/Theseus",
"path": "/kernel/mod_mgmt/src/parse_nano_core.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: lowRISC/opentitan path: /sw/host/tests/manuf/manuf_cp_device_info_flash_wr/src/main.rs
// Copyright lowRISC contributors.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
use std::time::Duration;
use anyhow::{anyhow, Result};
us... | code_fim | hard | {
"lang": "rust",
"repo": "lowRISC/opentitan",
"path": "/sw/host/tests/manuf/manuf_cp_device_info_flash_wr/src/main.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[arg(
long,
value_parser = humantime::parse_duration,
default_value = "600s",
help = "Console receive timeout",
)]
timeout: Duration,
}
fn manuf_cp_device_info_flash_wr(opts: &Opts, transport: &TransportWrapper) -> Result<()> {
// Set CPU TAP straps, reset... | code_fim | hard | {
"lang": "rust",
"repo": "lowRISC/opentitan",
"path": "/sw/host/tests/manuf/manuf_cp_device_info_flash_wr/src/main.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: luisbg/ente path: /src/main.rs
// ENTE (Educational Nimble Text Editor)
// `error_chain!` can recurse deeply
#![recursion_limit = "1024"]
#![cfg_attr(feature="clippy", feature(plugin))]
#![cfg_attr(feature="clippy", plugin(clippy))]
extern crate rustbox;
#[macro_use]
extern crate error_chain;... | code_fim | hard | {
"lang": "rust",
"repo": "luisbg/ente",
"path": "/src/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl slog_stream::Format for LogFormat {
fn format(&self,
io: &mut io::Write,
rinfo: &slog::Record,
_logger_values: &slog::OwnedKeyValueList)
-> io::Result<()> {
let mut msg = format!("{}: {}", rinfo.level(), rinfo.msg());
if msg.... | code_fim | hard | {
"lang": "rust",
"repo": "luisbg/ente",
"path": "/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: nicoder/tools path: /crates/formatter/src/format_tokens_macro.rs
/// The macro `format_tokens` is a convenience macro to
/// use when writing a list of tokens that should be at the same level
/// without particular rule.
///
/// # Examples
///
/// Let's suppose you need to create tokens for the ... | code_fim | hard | {
"lang": "rust",
"repo": "nicoder/tools",
"path": "/crates/formatter/src/format_tokens_macro.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>rt_eq!(r#"single"#, format_token(&unique_token, FormatOptions::default()).code());
/// ```
#[macro_export]
macro_rules! format_tokens {
// called for things like format_tokens!("hey")
($token:expr) => {
{
use $crate::FormatToken;
FormatToken::from($token)
}
};
( $( $token:expr ),+ $(,)?) =... | code_fim | hard | {
"lang": "rust",
"repo": "nicoder/tools",
"path": "/crates/formatter/src/format_tokens_macro.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> IndentToken::new(
/// format_tokens!(FormatToken::Space, "bar:", FormatToken::Space, "lorem")
/// ),
/// FormatToken::Space,
/// "}"
/// );
/// assert_eq!(r#"foo: { bar: lorem }"#, format_token(&token, FormatOptions::default()).code());
/// ```
/// Or you can also create single tokens:
/// `... | code_fim | hard | {
"lang": "rust",
"repo": "nicoder/tools",
"path": "/crates/formatter/src/format_tokens_macro.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> RpcService {
ipc,
http,
tcp: None,
ws: None,
}
}
pub fn close(self) {
self.ipc.close();
if let Some(http) = self.http {
http.close();
}
if let Some(tcp) = self.tcp {
tcp.close()... | code_fim | hard | {
"lang": "rust",
"repo": "megamcloud/starcoin",
"path": "/rpc/server/src/service.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: megamcloud/starcoin path: /rpc/server/src/service.rs
// Copyright (c) The Starcoin Core Contributors
// SPDX-License-Identifier: Apache-2.0
use jsonrpc_core::IoHandler;
use jsonrpc_http_server;
use jsonrpc_server_utils::cors::AccessControlAllowOrigin;
use jsonrpc_server_utils::hosts::DomainsVal... | code_fim | hard | {
"lang": "rust",
"repo": "megamcloud/starcoin",
"path": "/rpc/server/src/service.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> tree.remove(60);
println!("------------------");
tree.print(|elem| println!("{}", elem));
}<|fim_prefix|>// repo: arun11299/Rust-Practice path: /data_structures/bst/src/bin/main.rs
extern crate bst;
use bst::BST;
use bst::Node;
fn main() {
let mut tree : BST<i32> = BST::new();
tr... | code_fim | medium | {
"lang": "rust",
"repo": "arun11299/Rust-Practice",
"path": "/data_structures/bst/src/bin/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: arun11299/Rust-Practice path: /data_structures/bst/src/bin/main.rs
extern crate bst;
use bst::BST;
use bst::Node;
fn main() {
let mut tree : BST<i32> = BST::new();
tree.add(50); // the head
tree.add(20);
tree.add(10);
tree.add(30);
tree.add(60);
tree.add(70);
tr... | code_fim | easy | {
"lang": "rust",
"repo": "arun11299/Rust-Practice",
"path": "/data_structures/bst/src/bin/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> println!("------------------");
tree.print(|elem| println!("{}", elem));
tree.remove(60);
println!("------------------");
tree.print(|elem| println!("{}", elem));
}<|fim_prefix|>// repo: arun11299/Rust-Practice path: /data_structures/bst/src/bin/main.rs
extern crate bst;
use bst... | code_fim | medium | {
"lang": "rust",
"repo": "arun11299/Rust-Practice",
"path": "/data_structures/bst/src/bin/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let response = client
.get("https://api.waqi.info/search/")
.query(&[("token", api_token), ("keyword", args)])
.header(USER_AGENT, "rafael")
.send()
.expect("a successful request")
.json::<serde_json::Value>()
.expect("the body to be json");
... | code_fim | medium | {
"lang": "rust",
"repo": "rrrahal/rust-adventure",
"path": "/weather-cli/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rrrahal/rust-adventure path: /weather-cli/src/main.rs
use reqwest::header::USER_AGENT;
fn main() {
let api_token = std::env::var("API_TOKEN")
.expect("to be a token");
<|fim_suffix|> let client = reqwest::blocking::Client::new();
let response = client
.get("https://... | code_fim | medium | {
"lang": "rust",
"repo": "rrrahal/rust-adventure",
"path": "/weather-cli/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let _ = Node::<Vec<()>>(Vec::new());
}<|fim_prefix|>// repo: rust-lang/rust path: /tests/ui/sized/coinductive-1.rs
// check-pass
struct Node<C: Trait<Self>>(C::Assoc);
trait Trait<T> {
type Assoc;
}
impl<T> Trait<T> for Vec<()> {
type Assoc = Vec<T>;
}
<|fim_middle|>fn main() {
| code_fim | easy | {
"lang": "rust",
"repo": "rust-lang/rust",
"path": "/tests/ui/sized/coinductive-1.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rust-lang/rust path: /tests/ui/sized/coinductive-1.rs
// check-pass
struct Node<C: Trait<Self>>(C::Assoc);
<|fim_suffix|>impl<T> Trait<T> for Vec<()> {
type Assoc = Vec<T>;
}
fn main() {
let _ = Node::<Vec<()>>(Vec::new());
}<|fim_middle|>trait Trait<T> {
type Assoc;
}
| code_fim | easy | {
"lang": "rust",
"repo": "rust-lang/rust",
"path": "/tests/ui/sized/coinductive-1.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: marco-c/gecko-dev-wordified path: /third_party/rust/tokio/src/runtime/tests/mod.rs
use
self
:
:
unowned_wrapper
:
:
unowned
;
mod
unowned_wrapper
{
use
crate
:
:
runtime
:
:
blocking
:
:
NoopSchedule
;
use
crate
:
:
runtime
:
:
task
:
:
{
JoinHandle
Notified
}
;
#
[
cfg
(
all
(
tokio_unstable
fe... | code_fim | hard | {
"lang": "rust",
"repo": "marco-c/gecko-dev-wordified",
"path": "/third_party/rust/tokio/src/runtime/tests/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>)
}
#
[
cfg
(
not
(
all
(
tokio_unstable
feature
=
"
tracing
"
)
)
)
]
pub
(
crate
)
fn
unowned
<
T
>
(
task
:
T
)
-
>
(
Notified
<
NoopSchedule
>
JoinHandle
<
T
:
:
Output
>
)
where
T
:
std
:
:
future
:
:
Future
+
Send
+
'
static
T
:
:
Output
:
Send
+
'
static
{
let
(
task
handle
)
=
crate
:
:
runtime
:
... | code_fim | hard | {
"lang": "rust",
"repo": "marco-c/gecko-dev-wordified",
"path": "/third_party/rust/tokio/src/runtime/tests/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: cambricorp/neopixel_rs path: /src/lib.rs
#![no_std]
#![feature(asm)]
extern crate photon_hal as hal;
extern "C" {
#[link_name = "_Z18neopixelFastSetPinhb"]
pub fn neopixelFastSetPin(pin: u8, on: bool);
}
#[derive(Clone, Copy)]
pub struct NeopixelRGB {
pub r: u8,
pub g: u8,
pub b:... | code_fim | hard | {
"lang": "rust",
"repo": "cambricorp/neopixel_rs",
"path": "/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> if (mask & package) > 0 {
unsafe {
asm!("mov r0, r0\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\... | code_fim | hard | {
"lang": "rust",
"repo": "cambricorp/neopixel_rs",
"path": "/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> for byte_index in 0..self.pin_count {
let byte = self.pixel_colors[byte_index as usize];
let package: u32 = ((byte.g as u32) << 16) | ((byte.r as u32) << 8) | (byte.b as u32);
let mut mask: u32 = 0x800000;
for i in 0..24 {
unsafe {
neopixelFastSetPin(self.pin... | code_fim | hard | {
"lang": "rust",
"repo": "cambricorp/neopixel_rs",
"path": "/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> for i in 11..21 {
if gcd(result, i) != i {
result *= i / gcd(result, i);
}
}
println!("{}", result);
}<|fim_prefix|>// repo: liupangzi/codekata path: /projecteuler/5.SmallestMultiple/rust.rs
fn gcd(a: i32, b: i32) -> i32 {
<|fim_middle|> if b == 0 {
... | code_fim | medium | {
"lang": "rust",
"repo": "liupangzi/codekata",
"path": "/projecteuler/5.SmallestMultiple/rust.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: liupangzi/codekata path: /projecteuler/5.SmallestMultiple/rust.rs
fn gcd(a: i32, b: i32) -> i32 {
<|fim_suffix|>fn main() {
let mut result = 2520;
for i in 11..21 {
if gcd(result, i) != i {
result *= i / gcd(result, i);
}
}
println!("{}", r... | code_fim | medium | {
"lang": "rust",
"repo": "liupangzi/codekata",
"path": "/projecteuler/5.SmallestMultiple/rust.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: longfangsong/mini-kv path: /src/test/benchmark.rs
use std::collections::HashSet;
use rand::seq::IteratorRandom;
use std::sync::atomic::AtomicU64;
use std::sync::atomic::Ordering;
use std::time::Instant;
use std::sync::Arc;
use std::sync::mpsc::channel;
use grpcio::{EnvBuilder, ChannelBuilder};
u... | code_fim | hard | {
"lang": "rust",
"repo": "longfangsong/mini-kv",
"path": "/src/test/benchmark.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>isting, but good enough
} else {
*already_putted.iter().choose(&mut rng).unwrap()
};
let mut delete_request = DeleteRequest::new();
delete_request.set_key(key.to_vec());
client.delet... | code_fim | hard | {
"lang": "rust",
"repo": "longfangsong/mini-kv",
"path": "/src/test/benchmark.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn test_day23_part1() {
let prob = Day23 {};
let input = indoc! {""};
assert_eq!(prob.part1(input), None);
}
#[test]
fn test_day23_part2() {
let prob = Day23 {};
let input = indoc! {""};
assert_eq!(prob.part2(input), None);
}
}<|fim_prefix|>// repo: kdheepak/ad... | code_fim | medium | {
"lang": "rust",
"repo": "kdheepak/adventofcode",
"path": "/2021/src/day23.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: kdheepak/adventofcode path: /2021/src/day23.rs
use std::{
cmp::{max, min, Ordering},
collections::{BinaryHeap, HashMap, HashSet, VecDeque},
ops::Add,
};
use ansi_term::Style;
use itertools::Itertools;
<|fim_suffix|> let prob = Day23 {};
let input = indoc! {""};
assert_eq!(prob... | code_fim | hard | {
"lang": "rust",
"repo": "kdheepak/adventofcode",
"path": "/2021/src/day23.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let prob = Day23 {};
let input = indoc! {""};
assert_eq!(prob.part1(input), None);
}
#[test]
fn test_day23_part2() {
let prob = Day23 {};
let input = indoc! {""};
assert_eq!(prob.part2(input), None);
}
}<|fim_prefix|>// repo: kdheepak/adventofcode path: /2021/src/day23.rs... | code_fim | hard | {
"lang": "rust",
"repo": "kdheepak/adventofcode",
"path": "/2021/src/day23.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: zaksky7/Rust-project path: /src/year2019/day20.rs
use ahash::AHashMap;
use crate::utils::*;
use crate::year2019::day20::Portal::*;
type Pos = (usize, usize);
#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
enum Portal {
Outer(Pos),
Inner(Pos),
}
#[derive(Eq, PartialEq)]
... | code_fim | hard | {
"lang": "rust",
"repo": "zaksky7/Rust-project",
"path": "/src/year2019/day20.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn part2(input: &str) -> Option<usize> {
let (mut maze, start, end) = parse_maze(input);
dijkstra((start, 0), |(x, depth)| {
maze.available_moves(x)
.into_iter()
.filter_map(|(dist, (r, c))| match maze.grid[r][c] {
Tile::Portal(Outer(p)) if p == ... | code_fim | hard | {
"lang": "rust",
"repo": "zaksky7/Rust-project",
"path": "/src/year2019/day20.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: FreeMasen/mail_slot path: /src/mac/server.rs
use core::task::Poll;
use core::task::Context;
use crate::Error;
use mach::{
bootstrap::{bootstrap_register, bootstrap_port},
port::{mach_port_t, MACH_PORT_RIGHT_RECEIVE, MACH_PORT_NULL, MACH_MSG_TIMED_OUT},
kern_return::KERN_SUCCESS,
... | code_fim | hard | {
"lang": "rust",
"repo": "FreeMasen/mail_slot",
"path": "/src/mac/server.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn get_next_message(port: mach_port_t) -> Result<Option<Vec<u8>>, Error> {
let header = Default::default();
let trailer = Default::default();
let mut msg = Message {
header,
content: &[],
trailer,
};
let res = unsafe {
mach_msg(
&mut msg.hea... | code_fim | hard | {
"lang": "rust",
"repo": "FreeMasen/mail_slot",
"path": "/src/mac/server.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let header = Default::default();
let trailer = Default::default();
let mut msg = Message {
header,
content: &[],
trailer,
};
let res = unsafe {
mach_msg(
&mut msg.header as _,
MACH_RCV_MSG | MACH_RCV_TIMEOUT,
0,
... | code_fim | hard | {
"lang": "rust",
"repo": "FreeMasen/mail_slot",
"path": "/src/mac/server.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let book: Book = book_form.into_inner();
let mut dummy_db: Vec<Book> = Vec::new();
dummy_db.push(book);
format!("Book added successfully: {:?}", dummy_db)
}
fn main() {
rocket::ignite()
.register(catchers![not_found])
.mount("/", routes![index])
.mount("/api", routes![hello, new_bo... | code_fim | hard | {
"lang": "rust",
"repo": "ebenezerdon/rust_rocket",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> format!("Book added successfully: {:?}", dummy_db)
}
fn main() {
rocket::ignite()
.register(catchers![not_found])
.mount("/", routes![index])
.mount("/api", routes![hello, new_book])
.attach(Template::fairing())
.launch();
}<|fim_prefix|>// repo: ebenezerdon/rust_rocket path: /sr... | code_fim | medium | {
"lang": "rust",
"repo": "ebenezerdon/rust_rocket",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ebenezerdon/rust_rocket path: /src/main.rs
#![feature(decl_macro)]
#[macro_use] extern crate rocket;
use rocket::Request;
use rocket::response::content::Json;
use rocket::request::Form;
use rocket_contrib::templates::Template;
use serde::Serialize;
#[derive(FromForm, Debug)]
struct Book {
t... | code_fim | hard | {
"lang": "rust",
"repo": "ebenezerdon/rust_rocket",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: nilsys/tmc-langs-rust path: /tmc-langs-framework/src/plugin.rs
ng::Language;
use super::domain::{
ExerciseDesc, ExercisePackagingConfiguration, RunResult, RunStatus, TestResult, TmcProjectYml,
ValidationResult,
};
use super::io::{submission_processing, tmc_zip};
use super::policy::Stude... | code_fim | hard | {
"lang": "rust",
"repo": "nilsys/tmc-langs-rust",
"path": "/tmc-langs-framework/src/plugin.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: nilsys/tmc-langs-rust path: /tmc-langs-framework/src/plugin.rs
ectory for
/// this language.
fn scan_exercise(&self, path: &Path, exercise_name: String) -> Result<ExerciseDesc>;
/// Runs the tests for the exercise.
fn run_tests(&self, path: &Path) -> Result<RunResult> {
... | code_fim | hard | {
"lang": "rust",
"repo": "nilsys/tmc-langs-rust",
"path": "/tmc-langs-framework/src/plugin.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn get_student_file_policy(_project_path: &Path) -> Self::StudentFilePolicy {
Self::StudentFilePolicy {}
}
fn find_project_dir_in_zip<R: Read + Seek>(
_zip_archive: &mut ZipArchive<R>,
) -> Result<PathBuf> {
todo!()
}
fn... | code_fim | hard | {
"lang": "rust",
"repo": "nilsys/tmc-langs-rust",
"path": "/tmc-langs-framework/src/plugin.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: repos-rust/iron path: /src/request.rs
//! An alias of the rust-http Request struct.
use http::server::request::{AbsolutePath};
pub use Request = http::server::request::Request;
<|fim_suffix|>}
impl GetUrl for Request {
/// Get the url from a Request
///
/// Returns Some(&url) if t... | code_fim | hard | {
"lang": "rust",
"repo": "repos-rust/iron",
"path": "/src/request.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> match self.request_uri {
AbsolutePath(ref mut path) => Some(path),
_ => None
}
}
}<|fim_prefix|>// repo: repos-rust/iron path: /src/request.rs
//! An alias of the rust-http Request struct.
use http::server::request::{AbsolutePath};
pub use Request = http::serv... | code_fim | hard | {
"lang": "rust",
"repo": "repos-rust/iron",
"path": "/src/request.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: marco-c/gecko-dev-wordified path: /third_party/rust/url/src/lib.rs
)
ParseError
>
{
let
this_document
=
Url
:
:
parse
(
"
http
:
/
/
servo
.
github
.
io
/
rust
-
url
/
url
/
index
.
html
"
)
?
;
let
css_url
=
this_document
.
join
(
"
.
.
/
main
.
css
"
)
?
;
assert_eq
!
(
css_url
.
as_str
(
)
"... | code_fim | hard | {
"lang": "rust",
"repo": "marco-c/gecko-dev-wordified",
"path": "/third_party/rust/url/src/lib.rs",
"mode": "psm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_suffix|>
)
other
.
host_str
(
)
)
=
=
(
None
Some
(
"
"
)
)
)
;
assert_eq
!
(
self
.
port
other
.
port
)
;
assert_eq
!
(
self
.
path_start
other
.
path_start
)
;
assert_eq
!
(
self
.
query_start
other
.
query_start
)
;
assert_eq
!
(
self
.
fragment_start
other
.
fragment_start
)
;
Ok
(
(
)
)
}
/
/
/
Return
the
or... | code_fim | hard | {
"lang": "rust",
"repo": "marco-c/gecko-dev-wordified",
"path": "/third_party/rust/url/src/lib.rs",
"mode": "spm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_suffix|>
(
self
.
path_start
)
=
=
b
'
/
'
)
;
let
new_path_start
=
self
.
scheme_end
+
1
;
self
.
serialization
.
drain
(
new_path_start
as
usize
.
.
self
.
path_start
as
usize
)
;
let
offset
=
self
.
path_start
-
new_path_start
;
self
.
path_start
=
new_path_start
;
self
.
username_end
=
new_path_start
;
self
.... | code_fim | hard | {
"lang": "rust",
"repo": "marco-c/gecko-dev-wordified",
"path": "/third_party/rust/url/src/lib.rs",
"mode": "spm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jmageau/advent_of_code path: /src/year_2017/day_8.rs
use regex::Regex;
use std::collections::HashMap;
use std::fs::File;
use std::io::prelude::*;
pub fn answers() -> String {
format!("{}, {}", answer_one(), answer_two())
}
fn answer_one() -> String {
let input = input();
execute_in... | code_fim | hard | {
"lang": "rust",
"repo": "jmageau/advent_of_code",
"path": "/src/year_2017/day_8.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut registers = HashMap::new();
let register_regex =
Regex::new(r"^(\w+) (inc|dec) (-?\d+) if (\w+) (==|!=|<=|>=|<|>) (-?\d+)$").unwrap();
for line in input.lines() {
let captures = register_regex.captures(line).unwrap();
let register = captures.get(1).unwrap().as_... | code_fim | medium | {
"lang": "rust",
"repo": "jmageau/advent_of_code",
"path": "/src/year_2017/day_8.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: marco-c/gecko-dev-wordified path: /third_party/rust/futures-util/src/sink/unfold.rs
use
super
:
:
assert_sink
;
use
crate
:
:
unfold_state
:
:
UnfoldState
;
use
core
:
:
{
future
:
:
Future
pin
:
:
Pin
}
;
use
futures_core
:
:
ready
;
use
futures_core
:
:
task
:
:
{
Context
Poll
}
;
use
futures_... | code_fim | hard | {
"lang": "rust",
"repo": "marco-c/gecko-dev-wordified",
"path": "/third_party/rust/futures-util/src/sink/unfold.rs",
"mode": "psm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_suffix|>re
{
future
}
)
;
Ok
(
(
)
)
}
fn
poll_flush
(
self
:
Pin
<
&
mut
Self
>
cx
:
&
mut
Context
<
'
_
>
)
-
>
Poll
<
Result
<
(
)
Self
:
:
Error
>
>
{
let
mut
this
=
self
.
project
(
)
;
Poll
:
:
Ready
(
if
let
Some
(
future
)
=
this
.
state
.
as_mut
(
)
.
project_future
(
)
{
match
ready
!
(
future
.
poll
(
... | code_fim | hard | {
"lang": "rust",
"repo": "marco-c/gecko-dev-wordified",
"path": "/third_party/rust/futures-util/src/sink/unfold.rs",
"mode": "spm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// A parameter of a model.
#[derive(Copy, Clone, Debug)]
pub struct Parameter<'model> {
/// The parameter's identifier
pub id: &'model str,
/// The parameter's current value
pub value: f32,
/// The parameter's minimum value
pub min_value: f32,
/// The parameter's maximum v... | code_fim | hard | {
"lang": "rust",
"repo": "FaneTheEternal/cubism-rs",
"path": "/cubism-core/src/model.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: FaneTheEternal/cubism-rs path: /cubism-core/src/model.rs
e is none
/// with the given name.
pub fn part_mut(&mut self, name: &str) -> Option<PartMut<'_>> {
if let Some(idx) = self.part_ids().iter().position(|id| *id == name) {
Some(self.part_at_mut(idx))
} els... | code_fim | hard | {
"lang": "rust",
"repo": "FaneTheEternal/cubism-rs",
"path": "/cubism-core/src/model.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// An iterator that iterates over a model's parameters.
#[derive(Clone, Debug)]
pub struct ParameterIter<'model> {
model: &'model Model,
idx: usize,
}
impl<'model> iter::ExactSizeIterator for ParameterIter<'model> {}
impl<'model> iter::FusedIterator for ParameterIter<'model> {}
impl<'model> Iter... | code_fim | hard | {
"lang": "rust",
"repo": "FaneTheEternal/cubism-rs",
"path": "/cubism-core/src/model.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: oxidecomputer/rustwide path: /tests/integration/purge_caches.rs
use failure::Error;
use rustwide::cmd::SandboxBuilder;
use rustwide::{Crate, Toolchain};
use std::collections::HashMap;
use std::path::{Path, PathBuf};
const WORKSPACE_NAME: &str = "purge-caches";
#[test]
fn test_purge_caches() ->... | code_fim | hard | {
"lang": "rust",
"repo": "oxidecomputer/rustwide",
"path": "/tests/integration/purge_caches.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut files = HashMap::new();
for entry in walkdir::WalkDir::new(path)
.into_iter()
.filter_entry(|entry| should_compare(path, entry.path()))
{
let entry = entry?;
let metadata = entry.metadata()?;
if !metadata.is_file... | code_fim | hard | {
"lang": "rust",
"repo": "oxidecomputer/rustwide",
"path": "/tests/integration/purge_caches.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> println!("=== start directory differences ===");
for (path, start_digest) in self.files.into_iter() {
if let Some(end_digest) = other.files.remove(&path) {
if start_digest != end_digest {
println!("file {} changed its size", path.display());... | code_fim | hard | {
"lang": "rust",
"repo": "oxidecomputer/rustwide",
"path": "/tests/integration/purge_caches.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(output, &[][..]);
}
#[test]
#[ntest::timeout(1000)]
fn empty_chunk() {
let input = utils::InputStream::from(vec![vec![]]);
... | code_fim | hard | {
"lang": "rust",
"repo": "celtra/k8s-aws-nlb-proxy-protocol-operator",
"path": "/vendor/async-compression/tests/utils/mod.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: celtra/k8s-aws-nlb-proxy-protocol-operator path: /vendor/async-compression/tests/utils/mod.rs
:unwrap)
.flatten()
.collect()
}
}
pub mod brotli {
pub mod sync {
use crate::utils::prelude::*;
pub fn compress(bytes: &[u8]) -> Vec<u8> {
... | code_fim | hard | {
"lang": "rust",
"repo": "celtra/k8s-aws-nlb-proxy-protocol-operator",
"path": "/vendor/async-compression/tests/utils/mod.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: celtra/k8s-aws-nlb-proxy-protocol-operator path: /vendor/async-compression/tests/utils/mod.rs
let stream = utils::InputStream::from(vec![compressed]);
let output = utils::$variant::stream::decompress(stream.stream());
assert_eq!(outpu... | code_fim | hard | {
"lang": "rust",
"repo": "celtra/k8s-aws-nlb-proxy-protocol-operator",
"path": "/vendor/async-compression/tests/utils/mod.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn destroy_string_array_c(ptr: *mut CStringArray) -> Result<()> {
take_back_c_string_array!(ptr);
Ok(())
}
pub fn destroy_token_array_c(ptr: *mut CTokenArray) -> Result<()> {
let _ = unsafe { CTokenArray::from_raw_pointer(ptr) };
Ok(())
}
pub fn destroy_ngram_array_c(ptr: *mut CNgram... | code_fim | medium | {
"lang": "rust",
"repo": "pguyot/snips-nlu-utils",
"path": "/python/ffi/src/destroy.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: pguyot/snips-nlu-utils path: /python/ffi/src/destroy.rs
use crate::types::CNgramArray;
use crate::types::CTokenArray;
use crate::Result;
use ffi_utils::{take_back_c_string, take_back_c_string_array, CStringArray, RawPointerConverter};
pub fn destroy_string_c(ptr: *mut libc::c_char) -> Result<()... | code_fim | medium | {
"lang": "rust",
"repo": "pguyot/snips-nlu-utils",
"path": "/python/ffi/src/destroy.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn destroy_token_array_c(ptr: *mut CTokenArray) -> Result<()> {
let _ = unsafe { CTokenArray::from_raw_pointer(ptr) };
Ok(())
}
pub fn destroy_ngram_array_c(ptr: *mut CNgramArray) -> Result<()> {
let _ = unsafe { CNgramArray::from_raw_pointer(ptr) };
Ok(())
}<|fim_prefix|>// repo: pgu... | code_fim | medium | {
"lang": "rust",
"repo": "pguyot/snips-nlu-utils",
"path": "/python/ffi/src/destroy.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: simon-auch/projecteuler path: /src/bin/problem_0031.rs
use projecteuler::partition;
<|fim_suffix|> //dbg!(binomial::binomial_coefficient(100, 50));
dbg!(solve(20));
dbg!(solve(200));
//dbg!(solve(200));
}
fn solve(n: usize) -> usize {
partition::partition_into(n, COINS)
}<|f... | code_fim | medium | {
"lang": "rust",
"repo": "simon-auch/projecteuler",
"path": "/src/bin/problem_0031.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> partition::partition_into(n, COINS)
}<|fim_prefix|>// repo: simon-auch/projecteuler path: /src/bin/problem_0031.rs
use projecteuler::partition;
static COINS: &[usize] = &[1, 2, 5, 10, 20, 50, 100, 200];
fn main() {
<|fim_middle|> //dbg!(binomial::binomial_coefficient(100, 50));
dbg!(solve(20... | code_fim | medium | {
"lang": "rust",
"repo": "simon-auch/projecteuler",
"path": "/src/bin/problem_0031.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: primary-byte/CPSC_323_Compiler_Project path: /src/parser_old.rs
use crate::file_handling::lexer::*;
use std::fs::OpenOptions;
use std::io::Write; //string operations
//node in the parse tree
#[derive(Debug, Clone)]
pub struct ParseNode {
pub children: Vec<ParseNode>,
pub entry: String,
... | code_fim | hard | {
"lang": "rust",
"repo": "primary-byte/CPSC_323_Compiler_Project",
"path": "/src/parser_old.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn parse_assignment(
token_list: &Vec<TokenType>,
position: usize,
//hold rules so far
rules_so_far: &mut Vec<String>,
) -> Result<(ParseNode, usize), String> {
let (node_expression, next_position) = parse_expression(token_list, position, rules_so_far)?;
if next_position < token_l... | code_fim | hard | {
"lang": "rust",
"repo": "primary-byte/CPSC_323_Compiler_Project",
"path": "/src/parser_old.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> Ok((node_declar, next_position + 1))
}
_ => Ok((node_assign, next_position)),
}
} else {
Ok((node_assign, next_position))
}
}
fn parse_assignment(
token_list: &Vec<TokenType>,
position: usize,
//hold rules so far
rules_so_far... | code_fim | hard | {
"lang": "rust",
"repo": "primary-byte/CPSC_323_Compiler_Project",
"path": "/src/parser_old.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: PSeitz/lz4_flex path: /fuzz/fuzz_targets/fuzz_roundtrip.rs
#![no_main]
use libfuzzer_sys::fuzz_target;
use lz4_flex::decompress_size_prepended;
use lz4_flex::compress_prepend_size;
fuzz_target!(|data: &[u8]| {
// fuzzed code goes <|fim_suffix|>_size_prepended(&compressed).unwrap();
asse... | code_fim | medium | {
"lang": "rust",
"repo": "PSeitz/lz4_flex",
"path": "/fuzz/fuzz_targets/fuzz_roundtrip.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>here
let compressed = compress_prepend_size(data);
let decompressed = decompress_size_prepended(&compressed).unwrap();
assert_eq!(data, decompressed.as_slice());
});<|fim_prefix|>// repo: PSeitz/lz4_flex path: /fuzz/fuzz_targets/fuzz_roundtrip.rs
#![no_main]
use libfuzzer_sys::fuzz_target;
u... | code_fim | medium | {
"lang": "rust",
"repo": "PSeitz/lz4_flex",
"path": "/fuzz/fuzz_targets/fuzz_roundtrip.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let max = (10 as u64).pow(digits) - 1;
let diff = max - (max/10);
(0..diff).map(|n| max - n )
.filter_map(|n| {
(0..((max - n) / 2 + 1))
.map(|off| (max - off) * (n+off))
.filter(|c| *c == c.reverse())
.max()
})
// Get first only
.take(1).last()
... | code_fim | medium | {
"lang": "rust",
"repo": "portablejim/project-euler",
"path": "/rust/src/bin/task4b.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: portablejim/project-euler path: /rust/src/bin/task4b.rs
trait Reversable {
fn reverse(&self) -> u64;
}
impl Reversable for u64 {
fn reverse(&self) -> u64 {
reverse_int(*self, 0)
}
}
<|fim_suffix|> let max = (10 as u64).pow(digits) - 1;
let diff = max - (max/10);
... | code_fim | hard | {
"lang": "rust",
"repo": "portablejim/project-euler",
"path": "/rust/src/bin/task4b.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn write(&self, filename: &str) -> Result<(), ()> {
let s = CString::new(filename).unwrap();
let ptr = s.as_bytes_with_nul().as_ptr();
unsafe {
match ffi::embPattern_write(self.inner, ptr as *const i8) {
0 => Err(()),
_ => Ok(()),... | code_fim | hard | {
"lang": "rust",
"repo": "hakasec/libembroidery-rs",
"path": "/src/pattern.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let p = EmbPattern::new();
p.read("./examples/rose.pes").unwrap();
assert_eq!(p.thread().len(), 1);
assert_eq!(p.thread().get_at(0).description(), "Black");
assert_eq!(p.stitches().len(), 5322);
assert_eq!(p.stitches().get_at(0).flags(), 1);
}
}<|fim_p... | code_fim | hard | {
"lang": "rust",
"repo": "hakasec/libembroidery-rs",
"path": "/src/pattern.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: hakasec/libembroidery-rs path: /src/pattern.rs
use std::ffi::CString;
use crate::thread::EmbThreadList;
use crate::stitch::EmbStitchList;
pub struct EmbPattern {
inner: *mut ffi::EmbPattern,
}
impl Drop for EmbPattern {
fn drop(&mut self) {
unsafe {
ffi::embPattern... | code_fim | hard | {
"lang": "rust",
"repo": "hakasec/libembroidery-rs",
"path": "/src/pattern.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let reflected = reflect(ray_in.direction.unit(), hit_record.normal);
if Vec3::dot(reflected, hit_record.normal) > 0.0 {
return Some((
self.albedo,
Ray::new(
hit_record.p,
reflected + random_in_unit_sphere(r... | code_fim | medium | {
"lang": "rust",
"repo": "peterzheng98/raytracer.rs",
"path": "/src/tracer/materials/metal.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: peterzheng98/raytracer.rs path: /src/tracer/materials/metal.rs
use super::{HitRecord, Material, Ray, Vec3};
use crate::tracer::utils::{random_in_unit_sphere, reflect};
use rand::{Rng, SeedableRng, rngs::SmallRng};
pub struct Metal {
pub albedo: Vec3,
pub fuzz: f32,
}
<|fim_suffix|> ... | code_fim | medium | {
"lang": "rust",
"repo": "peterzheng98/raytracer.rs",
"path": "/src/tracer/materials/metal.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[derive(thiserror::Error, Debug)]
pub(super) enum SideEffectMachineError {}
pub(super) enum SideEffectCommand {}
#[derive(Default, Clone)]
pub(super) struct Created {}
impl Created {
pub(super) fn on_schedule(
self,
) -> SideEffectMachineTransition<MarkerCommandCreatedOrMarkerCommandCr... | code_fim | medium | {
"lang": "rust",
"repo": "yiminc/sdk-core",
"path": "/src/machines/side_effect_state_machine.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Created {
pub(super) fn on_schedule(
self,
) -> SideEffectMachineTransition<MarkerCommandCreatedOrMarkerCommandCreatedReplaying> {
unimplemented!()
}
}
#[derive(Default, Clone)]
pub(super) struct MarkerCommandCreated {}
impl MarkerCommandCreated {
pub(super) fn on_co... | code_fim | medium | {
"lang": "rust",
"repo": "yiminc/sdk-core",
"path": "/src/machines/side_effect_state_machine.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: yiminc/sdk-core path: /src/machines/side_effect_state_machine.rs
use rustfsm::{fsm, TransitionResult};
fsm! {
pub(super) name SideEffectMachine; command SideEffectCommand; error SideEffectMachineError;
Created --(Schedule, on_schedule) --> MarkerCommandCreated;
Created --(Schedule,... | code_fim | medium | {
"lang": "rust",
"repo": "yiminc/sdk-core",
"path": "/src/machines/side_effect_state_machine.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: synlestidae/rust-ratelimiting path: /src/bucket/bucket.rs
use crate::time::TimeWindow;
pub trait Bucket {
fn get_count(&self) -> u32;
fn get_window(&self) -> &TimeWindow;
fn next(&self, window: &TimeWindow) -> Self;
fn increment(&mut self, delta: u32, window: &TimeWindow) -> ... | code_fim | easy | {
"lang": "rust",
"repo": "synlestidae/rust-ratelimiting",
"path": "/src/bucket/bucket.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn next(&self, window: &TimeWindow) -> Self;
fn increment(&mut self, delta: u32, window: &TimeWindow) -> u32;
fn clear_local_count(&mut self) -> u32;
fn set_global_count(&mut self, global_count: u32);
}<|fim_prefix|>// repo: synlestidae/rust-ratelimiting path: /src/bucket/bucket.rs
use... | code_fim | easy | {
"lang": "rust",
"repo": "synlestidae/rust-ratelimiting",
"path": "/src/bucket/bucket.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: paritytech/substrate path: /frame/session/src/historical/offchain.rs
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except i... | code_fim | hard | {
"lang": "rust",
"repo": "paritytech/substrate",
"path": "/frame/session/src/historical/offchain.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> crate::GenesisConfig::<Test> { keys }.assimilate_storage(&mut t).unwrap();
let mut ext = sp_io::TestExternalities::new(t);
let (offchain, offchain_state) = TestOffchainExt::with_offchain_db(ext.offchain_db());
const ITERATIONS: u32 = 5u32;
let mut seed = [0u8; 32];
seed[0..4].copy_from_slic... | code_fim | hard | {
"lang": "rust",
"repo": "paritytech/substrate",
"path": "/frame/session/src/historical/offchain.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Cargill/splinter path: /libsplinter/src/store/command/mod.rs
// Copyright 2022 Cargill Incorporated
//
// 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:... | code_fim | medium | {
"lang": "rust",
"repo": "Cargill/splinter",
"path": "/libsplinter/src/store/command/mod.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl<C> StoreCommand for Box<dyn StoreCommand<Context = C>> {
type Context = C;
fn execute(&self, conn: &Self::Context) -> Result<(), InternalError> {
(&**self).execute(conn)
}
}<|fim_prefix|>// repo: Cargill/splinter path: /libsplinter/src/store/command/mod.rs
// Copyright 2022 Carg... | code_fim | hard | {
"lang": "rust",
"repo": "Cargill/splinter",
"path": "/libsplinter/src/store/command/mod.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// Trait for defining a command
///
/// A command will contain information that is to be applied to a database
pub trait StoreCommand {
type Context;
/// Update the database using the provided connection
///
/// # Arguments
///
/// * `conn` - Connection to the database being upda... | code_fim | medium | {
"lang": "rust",
"repo": "Cargill/splinter",
"path": "/libsplinter/src/store/command/mod.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: frondeus/guacamole path: /src/runtime/dep.rs
use crate::{Invalidation, Revision};
use std::any::TypeId;
use std::fmt;
#[derive(Copy, Clone, PartialEq)]
pub(crate) struct DepIdx {
pub(crate) query_name: &'static str, //TODO only in debug
pub(crate) query_type: TypeId,
pub(crate) quer... | code_fim | hard | {
"lang": "rust",
"repo": "frondeus/guacamole",
"path": "/src/runtime/dep.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl fmt::Debug for Dep {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "({:?}: {:?})", self.query_rev, self.idx,)?;
if !self.query_deps.is_empty() {
write!(f, "=>{:?}", self.query_deps)?;
}
Ok(())
}
}
pub(crate) trait DepsExt {
... | code_fim | hard | {
"lang": "rust",
"repo": "frondeus/guacamole",
"path": "/src/runtime/dep.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> SessionConfig::new(
Duration::default(),
Duration::default(),
None,
16,
1000,
None,
QueueFullAction::DropNew,
)
}
#[test]
fn test_subscribe_to() {
let id = "id1".to_string();
le... | code_fim | hard | {
"lang": "rust",
"repo": "richma-ms/iotedge",
"path": "/mqtt/mqtt-broker/src/session/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: richma-ms/iotedge path: /mqtt/mqtt-broker/src/session/mod.rs
mod connected;
mod disconnecting;
pub(crate) mod identifiers;
mod offline;
mod state;
use chrono::{DateTime, Utc};
pub use connected::ConnectedSession;
use disconnecting::DisconnectingSession;
use offline::OfflineSession;
pub use stat... | code_fim | hard | {
"lang": "rust",
"repo": "richma-ms/iotedge",
"path": "/mqtt/mqtt-broker/src/session/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(ack, proto::SubAckQos::Failure);
assert_eq!(subscription, None);
}
#[test]
fn test_unsubscribe() {
let id = "id1".to_string();
let client_id = ClientId::from(id.clone());
let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8... | code_fim | hard | {
"lang": "rust",
"repo": "richma-ms/iotedge",
"path": "/mqtt/mqtt-broker/src/session/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: wasm-network/quicksilver path: /src/graphics/blend_mode.rs
#[repr(u32)]
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
/// The way the colors are blended when drawing on top of other color
///
/// Blend modes only apply to RGB values
pub enum BlendMode {
/// Add the color being dra... | code_fim | hard | {
"lang": "rust",
"repo": "wasm-network/quicksilver",
"path": "/src/graphics/blend_mode.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>ing drawn
///
/// Subtracting red from purple will produce blue for example
Subtractive,
/// Take the minimum of each component of the color
///
/// Purple and red will produce red, blue and red will produce black
Minimum,
/// Take the maximum of each component of t... | code_fim | hard | {
"lang": "rust",
"repo": "wasm-network/quicksilver",
"path": "/src/graphics/blend_mode.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: richardwhiuk/adventofcode path: /2019/rust/src/fifteen.rs
use crate::intcode::*;
use std::io::Write;
use std::collections::{HashMap, HashSet};
type Position = (i32, i32);
type Map = HashMap<Position, Location>;
type Graph = HashMap<Position, Node>;
#[derive(Debug, Clone, Copy, PartialEq)]
enu... | code_fim | hard | {
"lang": "rust",
"repo": "richardwhiuk/adventofcode",
"path": "/2019/rust/src/fifteen.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut look_at = vec![start];
let mut depth = 0;
while !look_at.is_empty() {
let mut next = vec![];
for position in look_at {
match graph.get(&position).expect("Incomplete graph provided") {
Unknown => panic!("Incomplete graph provided"),
... | code_fim | hard | {
"lang": "rust",
"repo": "richardwhiuk/adventofcode",
"path": "/2019/rust/src/fifteen.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.