text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_suffix|>// The following 6 tests, test if the input is equal to 8
#[test]
fn test_is_equal_to_8_version1() {
let program = String::from("3,9,8,9,10,9,4,9,99,-1,8");
let (_, output) = run_program(program, -50);
assert_eq!(output, vec![0]);
}
#[test]
fn test_is_equal_to_8_version2() {
let... | code_fim | hard | {
"lang": "rust",
"repo": "jakubclark/advent-of-code-2019",
"path": "/intcode-computer/src/tests.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jakubclark/advent-of-code-2019 path: /intcode-computer/src/tests.rs
#![allow(unused_imports)]
#![allow(dead_code)]
use crate::run_program;
#[test]
fn test1() {
let program = String::from("3,0,4,0,99");
let (memory, output) = run_program(program, 50);
assert_eq!(output, vec... | code_fim | hard | {
"lang": "rust",
"repo": "jakubclark/advent-of-code-2019",
"path": "/intcode-computer/src/tests.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: CryZe/libtww path: /crates/rand/src/os.rs
// Copyright 2013-2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.... | code_fim | hard | {
"lang": "rust",
"repo": "CryZe/libtww",
"path": "/crates/rand/src/os.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Rng for OsRng {
fn next_u32(&mut self) -> u32 {
random_u32()
}
fn next_u64(&mut self) -> u64 {
((random_u32() as u64) << 32) | random_u32() as u64
}
fn fill_bytes(&mut self, v: &mut [u8]) {
for chunk in v.chunks_mut(4) {
let rand = random_u32(... | code_fim | hard | {
"lang": "rust",
"repo": "CryZe/libtww",
"path": "/crates/rand/src/os.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Insynia/zgog-io-server path: /src/communication/client.rs
use serde::Serialize;
use std::net::TcpStream;
use std::sync::{Arc, RwLock};
use uuid::Uuid;
use websocket::result::WebSocketError;
use websocket::sender::Writer;
use websocket::OwnedMessage;
use crate::communication::{OutgoingMessage, O... | code_fim | hard | {
"lang": "rust",
"repo": "Insynia/zgog-io-server",
"path": "/src/communication/client.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// Allows to acess the client's writing socket in a closure. It allows
/// to send messages to a specific client from it's id.
///
///
/// Example:
///
/// ```
/// with_client_id(id, &|s: &mut Socket| {
/// s.send_message(&OwnedMessage::Text("Hello"))
/// });
/// ```
pub fn with_client_id(
id: Uu... | code_fim | hard | {
"lang": "rust",
"repo": "Insynia/zgog-io-server",
"path": "/src/communication/client.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> true && match birth.captures(passport) {
Some(x) => (1920 <= x[1].parse::<u32>().unwrap() && x[1].parse::<u32>().unwrap() <= 2002),
None => false,
}
&& match issue.captures(passport) {
Some(x) => (2010 <= x[1].parse::<u32>().unwrap() && x[1].parse::<u32>().unwrap() <= 2... | code_fim | hard | {
"lang": "rust",
"repo": "RoryABrittain/Advent-of-code-2020",
"path": "/src/four.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: RoryABrittain/Advent-of-code-2020 path: /src/four.rs
use std::fs;
use regex::Regex;
pub fn run() {
let raw_data = fs::read_to_string("four_data.txt")
.expect("Can't find file");
let split_data: Vec<&str> = raw_data.split("\r\n\r\n").collect();
let mut number... | code_fim | medium | {
"lang": "rust",
"repo": "RoryABrittain/Advent-of-code-2020",
"path": "/src/four.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// Issues JWT access tokens
pub struct AccessTokenIssuer {
secret_manager: Arc<dyn SecretManager>,
#[cfg(feature = "biome-credentials")]
refresh_secret_manager: Arc<dyn SecretManager>,
}
impl AccessTokenIssuer {
/// Creates a new AccessTokenIssuer that will use the given secret manager f... | code_fim | medium | {
"lang": "rust",
"repo": "Cargill/splinter",
"path": "/libsplinter/src/rest_api/sessions/token_issuer.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Cargill/splinter path: /libsplinter/src/rest_api/sessions/token_issuer.rs
// Copyright 2018-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 ... | code_fim | hard | {
"lang": "rust",
"repo": "Cargill/splinter",
"path": "/libsplinter/src/rest_api/sessions/token_issuer.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl TokenIssuer<Claims> for AccessTokenIssuer {
fn issue_token_with_claims(&self, claims: Claims) -> Result<String, TokenIssuerError> {
let token = encode(
&Header::default(),
&claims,
&EncodingKey::from_secret(self.secret_manager.secret()?.as_ref()),
... | code_fim | hard | {
"lang": "rust",
"repo": "Cargill/splinter",
"path": "/libsplinter/src/rest_api/sessions/token_issuer.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> sm
}
}
#[async_trait]
impl<T: EventForwarder> ShardManager for PublicShardManager<T> {
async fn connect(self: Arc<Self>) {
for (_, shard) in self.shards.iter() {
let shard_id = shard.get_shard_id();
let shard = Arc::clone(shard);
let (ready_tx, ... | code_fim | hard | {
"lang": "rust",
"repo": "BEDSpEedTEST/tickets.rs",
"path": "/sharder/src/manager/public_shard_manager.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: BEDSpEedTEST/tickets.rs path: /sharder/src/manager/public_shard_manager.rs
use async_trait::async_trait;
use super::Options;
use super::ShardManager;
use crate::gateway::{Identify, Shard, ShardInfo};
use model::user::{ActivityType, StatusType, StatusUpdate};
use std::sync::Arc;
use std::col... | code_fim | hard | {
"lang": "rust",
"repo": "BEDSpEedTEST/tickets.rs",
"path": "/sharder/src/manager/public_shard_manager.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> sleep(Duration::from_millis(500)).await;
}
});
match ready_rx.await {
Ok(_) => println!("[{:0>2}] Loaded guilds", shard_id),
Err(e) => eprintln!("[{:0>2}] Error reading ready rx: {}", shard_id, e),
}
... | code_fim | hard | {
"lang": "rust",
"repo": "BEDSpEedTEST/tickets.rs",
"path": "/sharder/src/manager/public_shard_manager.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: avalarin/rust-pipeline path: /src/builder.rs
use std::sync::Arc;
use crate::types::{PipelineFunction, Pipeline, PipelineElement, PipelineTail};
pub struct PipelineBuilder<T> {
elements: Vec<Arc<PipelineFunction<T>>>
}
impl <T> PipelineBuilder<T> where T: 'static {
pub fn new() -> Self... | code_fim | medium | {
"lang": "rust",
"repo": "avalarin/rust-pipeline",
"path": "/src/builder.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn next(&mut self, func: Arc<PipelineFunction<T>>) -> &mut Self {
self.elements.push(func);
self
}
pub fn build(&self) -> Arc<Pipeline<T>> {
return self.elements.iter().rev().fold(
Arc::new(PipelineTail{}),
|pipeline,func| {
... | code_fim | hard | {
"lang": "rust",
"repo": "avalarin/rust-pipeline",
"path": "/src/builder.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl <T> PipelineBuilder<T> where T: 'static {
pub fn new() -> Self {
PipelineBuilder{
elements: vec![]
}
}
pub fn next(&mut self, func: Arc<PipelineFunction<T>>) -> &mut Self {
self.elements.push(func);
self
}
pub fn build(&self) -> Arc<Pi... | code_fim | medium | {
"lang": "rust",
"repo": "avalarin/rust-pipeline",
"path": "/src/builder.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: lythesia/leet path: /rs/src/quests/linked_list_in_binary_tree.rs
/**
* [1367] Linked List in Binary Tree
*
* Given a binary tree root and a linked list with head as the first node.
Return True if all the elements in the linked list starting from the head correspond to some downward path conn... | code_fim | hard | {
"lang": "rust",
"repo": "lythesia/leet",
"path": "/rs/src/quests/linked_list_in_binary_tree.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: sbwtw/ss-rs path: /src/chacha20poly1305.rs
use bytes::buf::BufMut;
use bytes::{Bytes, BytesMut};
use rand::{thread_rng, Rng};
use ring::aead::*;
use std::sync::Arc;
use crate::cipher::*;
use crate::config::*;
use crate::shadowsocks::*;
use crate::utils::nonce_plus_one;
pub struct Chacha20Poly... | code_fim | hard | {
"lang": "rust",
"repo": "sbwtw/ss-rs",
"path": "/src/chacha20poly1305.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl ShadowsocksDecryptor for Chacha20Poly1305Decryptor {
fn decrypt(&mut self, buf: &mut BytesMut) -> Result<Option<Bytes>, failure::Error> {
let tag_size = 16;
loop {
let wanted = self.waitting_payload.unwrap_or(2) + tag_size;
if buf.len() < wanted {
... | code_fim | hard | {
"lang": "rust",
"repo": "sbwtw/ss-rs",
"path": "/src/chacha20poly1305.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let encrypted_addr = self.encrypt_data(addr);
let mut data = BytesMut::new();
data.extend(&self.sealing_salt[..]);
data.extend(encrypted_addr);
data.freeze()
}
fn encrypt_data(&mut self, request_addr: &[u8]) -> Bytes {
self.encryptor
.... | code_fim | hard | {
"lang": "rust",
"repo": "sbwtw/ss-rs",
"path": "/src/chacha20poly1305.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> testing::run_test2(false, |cm, _handler| {
let fm = cm.new_source_file(FileName::Anon, "function foo(){ return 'I'; }".to_string());
let lexer = Lexer::new(
Default::default(),
EsVersion::latest(),
StringInput::from(&*fm),
None,
)... | code_fim | medium | {
"lang": "rust",
"repo": "swc-project/swc",
"path": "/crates/swc_ecma_parser/tests/visitor.rs",
"mode": "spm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: swc-project/swc path: /crates/swc_ecma_parser/tests/visitor.rs
use swc_common::{input::StringInput, FileName};
use swc_ecma_ast::*;
use swc_ecma_parser::{lexer::Lexer, Parser};
use swc_ecma_visit::{All, VisitAll, VisitWith};
struct Issue1967;
impl VisitAll for Issue1967 {
fn visit_expr(&mu... | code_fim | hard | {
"lang": "rust",
"repo": "swc-project/swc",
"path": "/crates/swc_ecma_parser/tests/visitor.rs",
"mode": "psm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_suffix|>ields: Vec<Field>,
timestamp: Option<i64>,
}<|fim_prefix|>// repo: WatchDG/rust-influx path: /src/measurement/mod.rs
pub struct Tag(String, String);
pub struct Fiel<|fim_middle|>d(String, String);
pub struct Measurement {
name: String,
tags: Option<Vec<Tag>>,
f | code_fim | medium | {
"lang": "rust",
"repo": "WatchDG/rust-influx",
"path": "/src/measurement/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: WatchDG/rust-influx path: /src/measurement/mod.rs
pub struct Tag(String, String);
pub struct Fiel<|fim_suffix|>name: String,
tags: Option<Vec<Tag>>,
fields: Vec<Field>,
timestamp: Option<i64>,
}<|fim_middle|>d(String, String);
pub struct Measurement {
| code_fim | easy | {
"lang": "rust",
"repo": "WatchDG/rust-influx",
"path": "/src/measurement/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let sdl_context = sdl2::init().unwrap();
let sdl_epump = sdl_context.event_pump().unwrap();
let mut window = init(&sdl_context);
let image = load_media();
{
let mut surface = window.surface_mut(&sdl_epump).unwrap();
image.blit(None, &mut surface, None).unwrap();
}
... | code_fim | hard | {
"lang": "rust",
"repo": "mikeyhc/lazyfoo-sdl2-rs",
"path": "/ch2/src/main.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn load_media() -> Surface<'static> {
Surface::load_bmp("hello_world.bmp").unwrap()
}
fn main() {
let sdl_context = sdl2::init().unwrap();
let sdl_epump = sdl_context.event_pump().unwrap();
let mut window = init(&sdl_context);
let image = load_media();
{
let mut surface = ... | code_fim | medium | {
"lang": "rust",
"repo": "mikeyhc/lazyfoo-sdl2-rs",
"path": "/ch2/src/main.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mikeyhc/lazyfoo-sdl2-rs path: /ch2/src/main.rs
extern crate sdl2;
use sdl2::surface::Surface;
const WIDTH: u32 = 640;
const HEIGHT: u32 = 480;
fn init(sdl_context: &sdl2::Sdl) -> sdl2::video::Window {
let sdl_video = sdl_context.video().unwrap();
let wbuilder = sdl_video.window("SDL ... | code_fim | medium | {
"lang": "rust",
"repo": "mikeyhc/lazyfoo-sdl2-rs",
"path": "/ch2/src/main.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[async_trait]
impl EventHandler for Handler {
async fn reaction_add(&self, ctx: Context, reaction: Reaction) {
events::code_executor::reaction_handler(ctx, reaction)
.await
.unwrap();
}
}<|fim_prefix|>// repo: loyston500/CodeGodRust path: /bot/src/events/event_han... | code_fim | easy | {
"lang": "rust",
"repo": "loyston500/CodeGodRust",
"path": "/bot/src/events/event_handler.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: loyston500/CodeGodRust path: /bot/src/events/event_handler.rs
use serenity::async_trait;
use serenity::client::Context;
use serenity::client::EventHandler;
use serenity::model::channel::Reaction;
<|fim_suffix|>#[async_trait]
impl EventHandler for Handler {
async fn reaction_add(&self, ctx: ... | code_fim | easy | {
"lang": "rust",
"repo": "loyston500/CodeGodRust",
"path": "/bot/src/events/event_handler.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn outputs(&self) -> Vec<BufferRef<Any>> { vec![self.unique_out, self.grouping_key_out.any(), self.cardinality_out.any()] }
fn can_stream_input(&self, _: usize) -> bool { false }
fn can_stream_output(&self, output: usize) -> bool { output != self.unique_out.i }
fn allocates(&self) -> bool ... | code_fim | hard | {
"lang": "rust",
"repo": "virattara/LocustDB",
"path": "/src/engine/operators/hashmap_grouping_byte_slices.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: virattara/LocustDB path: /src/engine/operators/hashmap_grouping_byte_slices.rs
use fnv::FnvHashMap;
use crate::engine::*;
use crate::ingest::raw_val::RawVal;
#[derive(Debug)]
pub struct HashMapGroupingByteSlices {
input: BufferRef<Any>,
unique_out: BufferRef<Any>,
grouping_key_out... | code_fim | hard | {
"lang": "rust",
"repo": "virattara/LocustDB",
"path": "/src/engine/operators/hashmap_grouping_byte_slices.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn inputs(&self) -> Vec<BufferRef<Any>> { vec![self.input] }
fn outputs(&self) -> Vec<BufferRef<Any>> { vec![self.unique_out, self.grouping_key_out.any(), self.cardinality_out.any()] }
fn can_stream_input(&self, _: usize) -> bool { false }
fn can_stream_output(&self, output: usize) -> bool... | code_fim | hard | {
"lang": "rust",
"repo": "virattara/LocustDB",
"path": "/src/engine/operators/hashmap_grouping_byte_slices.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: claudiomattera/advanced-langton-ant path: /src/main.rs
// Copyright Claudio Mattera 2020.
// Distributed under the MIT License.
// See accompanying file License.txt, or online at
// https://opensource.org/licenses/MIT
use log::*;
use std::path::{Path, PathBuf};
use clap::{app_from_crate, crat... | code_fim | hard | {
"lang": "rust",
"repo": "claudiomattera/advanced-langton-ant",
"path": "/src/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> info!("Saving final state of the board");
let image_path = subcommand
.value_of("image-path")
.map(Path::new)
.expect("Missing argument \"image-path\"");
match image.save(image_path) {
Ok(_) => {}
Err(error) => error!("Error: {}", error),
}
}
fn sav... | code_fim | hard | {
"lang": "rust",
"repo": "claudiomattera/advanced-langton-ant",
"path": "/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn parse_arguments() -> ArgMatches<'static> {
app_from_crate!()
.after_help(
"Some interesting rules:
* LR (original highway)
* LRRL (symmetric growth)
* LRRRRRLLR (diagonal tubes)
* RRLLLRLLLRRR (growing triangle)
* RRLLLRRL (ninja star)
* LRRRRLLLRRR (Archimedes' spiral)
*... | code_fim | hard | {
"lang": "rust",
"repo": "claudiomattera/advanced-langton-ant",
"path": "/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn get_gl_shader_type(shader_type: &ShaderType) -> Option<u32> {
match shader_type {
ShaderType::VERTEX => Some(gl::VERTEX_SHADER),
ShaderType::FRAGMENT => Some(gl::FRAGMENT_SHADER),
ShaderType::GEOMETRY => Some(gl::GEOMETRY_SHADER),
ShaderType::COMPUTE => Some(gl::... | code_fim | hard | {
"lang": "rust",
"repo": "maeln/stuffy",
"path": "/peglrs/src/shaders/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: maeln/stuffy path: /peglrs/src/shaders/mod.rs
pub mod shader_loader;
use std::collections::HashMap;
use std::fmt;
use std::path::Path;
use std::sync::Arc;
use std::sync::Mutex;
use std::time::SystemTime;
use gl;
#[derive(Debug)]
pub enum ShaderType {
VERTEX,
FRAGMENT,
GEOMETRY,
... | code_fim | hard | {
"lang": "rust",
"repo": "maeln/stuffy",
"path": "/peglrs/src/shaders/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl fmt::Display for Shader {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{} ({})", self.path, self.shader_type)
}
}
#[derive(Debug)]
pub struct Program {
pub addr: u32,
pub shaders: Vec<Arc<Mutex<Shader>>>,
pub uniforms_location: HashMap<String, i32>,
}... | code_fim | hard | {
"lang": "rust",
"repo": "maeln/stuffy",
"path": "/peglrs/src/shaders/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: megamcloud/starcoin path: /sync/src/state_sync/mod.rs
y_send(StateSyncTaskEvent::_new_accumulator(
peer_id,
node_key,
accumulator_node,
)) {
warn!("err:{:?}", err);
};
}
async fn sync_state_node(
node_key: HashValue,
peer_id: PeerId,
network_s... | code_fim | hard | {
"lang": "rust",
"repo": "megamcloud/starcoin",
"path": "/sync/src/state_sync/mod.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: megamcloud/starcoin path: /sync/src/state_sync/mod.rs
SyncReset, SyncMetadata};
use std::collections::{HashMap, VecDeque};
use std::convert::TryFrom;
use std::sync::Arc;
use types::{account_state::AccountState, peer_info::PeerId};
struct Roots {
state: HashValue,
accumulator: HashValue,... | code_fim | hard | {
"lang": "rust",
"repo": "megamcloud/starcoin",
"path": "/sync/src/state_sync/mod.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn handle_accumulator_sync(&mut self, task_event: StateSyncTaskEvent) {
let mut lock = self.accumulator_sync_task.lock();
if let Some(accumulator_node_hash) = lock.get(&task_event.peer_id) {
//1. push back
let current_node_key = task_event.node_key;
... | code_fim | hard | {
"lang": "rust",
"repo": "megamcloud/starcoin",
"path": "/sync/src/state_sync/mod.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: bigbrobro/grapl path: /graph-merger/src/main.rs
{
pre_nodes += sg.nodes.len();
pre_edges += sg.edges.len();
subgraph.merge(sg);
}
}
if subgraph.is_empty() {
warn!(
concat!(
"O... | code_fim | hard | {
"lang": "rust",
"repo": "bigbrobro/grapl",
"path": "/graph-merger/src/main.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> };
// async_handler(mg_client, subgraph).await;
let mut upsert_res = None;
let mut edge_res = None;
let mut node_key_to_uid = HashMap::new();
let upserts = subgraph.nodes.values().map(|node| {
upsert_node(&mg_client, node.clone()).map(move |u|... | code_fim | hard | {
"lang": "rust",
"repo": "bigbrobro/grapl",
"path": "/graph-merger/src/main.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: bigbrobro/grapl path: /graph-merger/src/main.rs
w(path_statements)]
let result = $x;
sw.stop();
info!("{} {} milliseconds", $msg, sw.elapsed_ms());
result
}
};
}
fn generate_edge_insert(from: &str, to: &str, edge_name: &str) -> api::Mu... | code_fim | hard | {
"lang": "rust",
"repo": "bigbrobro/grapl",
"path": "/graph-merger/src/main.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> for (n, expected) in test_cases {
assert_eq!(S::find_nth_digit(n), expected);
}
}
}<|fim_prefix|>// repo: EFanZh/LeetCode path: /src/problem_0400_nth_digit/mod.rs
pub mod binary_search;
pub mod iterative;
pub trait Solution {
fn find_nth_digit(n: i32) -> i32;
}
#[cfg... | code_fim | hard | {
"lang": "rust",
"repo": "EFanZh/LeetCode",
"path": "/src/problem_0400_nth_digit/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: EFanZh/LeetCode path: /src/problem_0400_nth_digit/mod.rs
pub mod binary_search;
pub mod iterative;
pub trait Solution {
fn find_nth_digit(n: i32) -> i32;
}
<|fim_suffix|> pub fn run<S: Solution>() {
let test_cases = [
(1, 1),
(5, 5),
(9, 9),
... | code_fim | medium | {
"lang": "rust",
"repo": "EFanZh/LeetCode",
"path": "/src/problem_0400_nth_digit/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn run<S: Solution>() {
let test_cases = [
(1, 1),
(5, 5),
(9, 9),
(10, 1),
(11, 0),
(1_000_000_000, 1),
(2_147_483_647, 2),
];
for (n, expected) in test_cases {
assert_eq!(S::f... | code_fim | medium | {
"lang": "rust",
"repo": "EFanZh/LeetCode",
"path": "/src/problem_0400_nth_digit/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: DiamondLovesYou/pkg-config-rs path: /src/lib.rs
use std::io::Command;
use std::os;
use std::str;
pub fn target_supported() -> bool {
os::getenv("HOST") == os::getenv("TARGET") ||
os::getenv("PKG_CONFIG_ALLOW_CROSS") == Some("1".to_string())
}
pub struct Options {
pub statik: bo... | code_fim | hard | {
"lang": "rust",
"repo": "DiamondLovesYou/pkg-config-rs",
"path": "/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> for arg in stdout.split(' ').filter(|l| !l.is_empty() && l.len() > 2) {
let val = arg.slice_from(2);
if arg.starts_with("-l") {
if options.statik {
println!("cargo:rustc-flags=-l {}:static", val);
} else {
println!("cargo:rustc-fl... | code_fim | hard | {
"lang": "rust",
"repo": "DiamondLovesYou/pkg-config-rs",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>read_test!(
can_read_gvalid_true,
is_gesture_data_valid,
true,
GSTATUS,
BitFlags::GVALID
);
read_test!(
can_read_gvalid_false,
is_gesture_data_valid,
false,
GSTATUS,
0
);
read_test!(can_read_gfifolvl, read_gesture_data_level, 15, GFLVL, 15);
read_test!(
can_read... | code_fim | hard | {
"lang": "rust",
"repo": "eldruin/apds9960-rs",
"path": "/tests/gesture.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: eldruin/apds9960-rs path: /tests/gesture.rs
extern crate apds9960;
use apds9960::GestureDataThreshold;
extern crate embedded_hal_mock as hal;
use hal::i2c::Transaction as I2cTrans;
mod common;
use common::{destroy, new, BitFlags, Register, DEV_ADDR};
write_test!(can_enable_gesture, enable_gestu... | code_fim | hard | {
"lang": "rust",
"repo": "eldruin/apds9960-rs",
"path": "/tests/gesture.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: sdroege/gst-plugin-rs path: /net/webrtc/src/webrtcsink/mod.rs
// SPDX-License-Identifier: MPL-2.0
use crate::signaller::Signallable;
/**
* SECTION:element-webrtcsink
* @symbols:
* - GstBaseWebRTCSink
* - GstRSWebRTCSignallableIface
*
* `webrtcsink` is an element that can be used to s... | code_fim | hard | {
"lang": "rust",
"repo": "sdroege/gst-plugin-rs",
"path": "/net/webrtc/src/webrtcsink/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[derive(thiserror::Error, Debug)]
pub enum WebRTCSinkError {
#[error("no session with id")]
NoSessionWithId(String),
#[error("consumer refused media")]
ConsumerRefusedMedia { session_id: String, media_idx: u32 },
#[error("consumer did not provide valid payload for media")]
Consume... | code_fim | hard | {
"lang": "rust",
"repo": "sdroege/gst-plugin-rs",
"path": "/net/webrtc/src/webrtcsink/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>use param_flags::*;
pub use row::*;
pub use signature::*;
pub use traits::*;
pub use type_kind::*;
pub use type_name::*;
pub use type_reader::*;
pub use type_tree::*;<|fim_prefix|>// repo: adumbidiot/windows-rs path: /crates/gen/src/parser/mod.rs
pub use super::*;
mod blob;
mod codes;
mod constant_value... | code_fim | hard | {
"lang": "rust",
"repo": "adumbidiot/windows-rs",
"path": "/crates/gen/src/parser/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: adumbidiot/windows-rs path: /crates/gen/src/parser/mod.rs
pub use super::*;
mod blob;
mod codes;
mod constant_value;
mod element_type;
mod file;
mod interface_info;
mod interface_kind;
mod method_info;
mod method_signature;
mod param_flags;
mod row;
mod signature;
mod traits;
mod type_kind;
mod... | code_fim | medium | {
"lang": "rust",
"repo": "adumbidiot/windows-rs",
"path": "/crates/gen/src/parser/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>//pub extern fn encode_to_json
//pub extern fn encode_to_blueprint
#[no_mangle]
pub extern fn free_return(s: *mut u8) {
unsafe { CString::from_raw(s as *mut i8) };
}<|fim_prefix|>// repo: Tim-Nosco/libblueprint path: /libblueprint/src/lib.rs
#[macro_use]
extern crate serde_derive;
extern crate serde;
... | code_fim | hard | {
"lang": "rust",
"repo": "Tim-Nosco/libblueprint",
"path": "/libblueprint/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Tim-Nosco/libblueprint path: /libblueprint/src/lib.rs
#[macro_use]
extern crate serde_derive;
extern crate serde;
mod decode;
use decode::{b64_to_json, json_to_grid};
use std::ffi::CString;
#[no_mangle]
pub extern fn decode_to_json(s: *const u8, size: usize) -> *mut u8 {
//takes base64 encoded... | code_fim | hard | {
"lang": "rust",
"repo": "Tim-Nosco/libblueprint",
"path": "/libblueprint/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Drumato/elf-utilities path: /src/file/elf32.rs
use crate::{
header,
section::{self, Section32},
segment,
};
#[repr(C)]
#[derive(Default, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)]
pub struct ELF32 {
pub ehdr: header::Ehdr32,
pub sections: Vec<section::Section32>,
pub ... | code_fim | hard | {
"lang": "rust",
"repo": "Drumato/elf-utilities",
"path": "/src/file/elf32.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut sections = self.sections.clone();
sections.sort_by_key(|sct| sct.header.sh_offset);
for (idx, sct) in sections.iter().enumerate() {
let mut section_binary = sct.to_le_bytes();
if idx >= 1 && sct.header.sh_addralign > 1 {
if sct.heade... | code_fim | hard | {
"lang": "rust",
"repo": "Drumato/elf-utilities",
"path": "/src/file/elf32.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> if !is!(self, "]") {
let span = self.input.cur_span()?;
attr_matcher = match cur!(self) {
tok!("~") | tok!("|") | tok!("^") | tok!("$") | tok!("*") => {
let tok = bump!(self);
expect!(self, "=");
... | code_fim | hard | {
"lang": "rust",
"repo": "timneutkens/swc",
"path": "/crates/swc_css_parser/src/parser/selector/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: timneutkens/swc path: /crates/swc_css_parser/src/parser/selector/mod.rs
{
unreachable!();
}
};
let last_pos = match children.last() {
Some(ComplexSelector { span, .. }) => span.hi,
_ => {
unreachable!();
... | code_fim | hard | {
"lang": "rust",
"repo": "timneutkens/swc",
"path": "/crates/swc_css_parser/src/parser/selector/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: timneutkens/swc path: /crates/swc_css_parser/src/parser/selector/mod.rs
= self.parse_complex_selector()?;
children.push(child);
}
let start_pos = match children.first() {
Some(ComplexSelector { span, .. }) => span.lo,
_ => {
... | code_fim | hard | {
"lang": "rust",
"repo": "timneutkens/swc",
"path": "/crates/swc_css_parser/src/parser/selector/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fromParentSender.send(22);
fromParentSender.send(23);
fromParentSender.send(24);
fromParentSender.send(25);
for _ in range(0u, 4) {
let answer = fromChildReceiver.recv();
println!("{:s}", answer.to_str());
fromParentSender.send(0);
}
}<|fim_prefix|>// repo:... | code_fim | hard | {
"lang": "rust",
"repo": "ErinCall/rust-futzing",
"path": "/comm_loop.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ErinCall/rust-futzing path: /comm_loop.rs
use std::comm::{channel, Sender, Receiver};
fn plus_one(sender: &Sender<int>, receiver: &Receiver<int>) {
let mut value: int;
loop {
value = receiver.recv();
sender.send(value + 1);
if value == 0 { break; }
}
}
fn ma... | code_fim | medium | {
"lang": "rust",
"repo": "ErinCall/rust-futzing",
"path": "/comm_loop.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>allow_tables_to_appear_in_same_query!(permission, user_access, users,);<|fim_prefix|>// repo: timothyhollabaugh/resource-website-backend path: /src/access/schema.rs
use crate::users::schema::users;
table! {
permission (id) {
id -> Unsigned<Bigint>,
permission_name -> Varchar,
}
}... | code_fim | medium | {
"lang": "rust",
"repo": "timothyhollabaugh/resource-website-backend",
"path": "/src/access/schema.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: timothyhollabaugh/resource-website-backend path: /src/access/schema.rs
use crate::users::schema::users;
table! {
permission (id) {
id -> Unsigned<Bigint>,
permission_name -> Varchar,
}
}
table! {
user_access (permission_id) {
access_id -> Unsigned<Bigint>,
... | code_fim | medium | {
"lang": "rust",
"repo": "timothyhollabaugh/resource-website-backend",
"path": "/src/access/schema.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mathroc/parser path: /source/ast.rs
/// ])
/// )
/// );
/// # }
/// ```
Isset(Vec<Expression<'a>>),
/// Match and assign one or more elements of the source array to
/// the target variables.
///
/// # Examples
///
/// A keyed list:
... | code_fim | hard | {
"lang": "rust",
"repo": "mathroc/parser",
"path": "/source/ast.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Unlike `echo`, `print` can be used in any context allowing an
/// expression. It always returns the value `1`.
///
/// # Examples
///
/// ```
/// # extern crate tagua_parser;
/// use tagua_parser::Result;
/// use tagua_parser::ast::{Expression, Variable};
/// us... | code_fim | hard | {
"lang": "rust",
"repo": "mathroc/parser",
"path": "/source/ast.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// A name.
///
/// # Examples
///
/// ```
/// # extern crate tagua_parser;
/// use tagua_parser::Result;
/// use tagua_parser::ast::{Expression, Name};
/// use tagua_parser::rules::expressions::expression;
///
/// # fn main() {
/// assert_eq!(
/// e... | code_fim | hard | {
"lang": "rust",
"repo": "mathroc/parser",
"path": "/source/ast.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ariard/rust-lightning path: /src/util/events.rs
//! Events are returned from various bits in the library which indicate some action must be taken
//! by the client.
//!
//! Because we don't have a built-in runtime, its up to the client to call events at a time in the
//! future, as well as gener... | code_fim | hard | {
"lang": "rust",
"repo": "ariard/rust-lightning",
"path": "/src/util/events.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>use std::time::Instant;
/// An Event which you should probably take some action in response to.
pub enum Event {
// Events a user will probably have to handle
/// Used to indicate that the client should generate a funding transaction with the given
/// parameters and then call ChannelManager::funding_... | code_fim | hard | {
"lang": "rust",
"repo": "ariard/rust-lightning",
"path": "/src/util/events.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Events indicating the network loop should send a message to a peer:
// TODO: Move these into a separate struct and make a top-level enum
/// Used to indicate that we've initialted a channel open and should send the open_channel
/// message provided to the given peer.
///
/// This event is handled... | code_fim | hard | {
"lang": "rust",
"repo": "ariard/rust-lightning",
"path": "/src/util/events.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: task-rs/task-rs path: /crates/task-rs/src/components/main/model/details/mod.rs
use serde::{Deserialize, Serialize};
<|fim_suffix|>pub use super::super::super::task_status_filter::Value as TaskStatusFilter;<|fim_middle|>#[derive(Debug, Default, Serialize, Deserialize, Copy, Clone)]
#[serde(renam... | code_fim | medium | {
"lang": "rust",
"repo": "task-rs/task-rs",
"path": "/crates/task-rs/src/components/main/model/details/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub use super::super::super::task_status_filter::Value as TaskStatusFilter;<|fim_prefix|>// repo: task-rs/task-rs path: /crates/task-rs/src/components/main/model/details/mod.rs
use serde::{Deserialize, Serialize};
<|fim_middle|>#[derive(Debug, Default, Serialize, Deserialize, Copy, Clone)]
#[serde(renam... | code_fim | medium | {
"lang": "rust",
"repo": "task-rs/task-rs",
"path": "/crates/task-rs/src/components/main/model/details/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tkrs/rust-sandbox path: /fluent-main/src/main.rs
extern crate poston;
extern crate rand;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate tmc;
use rand::Rng;
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::{Duration, Instant, SystemTime};
use tmc::DurationOp... | code_fim | hard | {
"lang": "rust",
"repo": "tkrs/rust-sandbox",
"path": "/fluent-main/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // thread::sleep(10.millis());
let pool = pool.lock().expect("Client couldn't be locked.");
pool.send(tag, &a, timestamp).unwrap();
thread::sleep(Duration::new(0, 5));
}
});
calls.push(t);
}
for c in calls... | code_fim | hard | {
"lang": "rust",
"repo": "tkrs/rust-sandbox",
"path": "/fluent-main/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn main() {
let addr = "127.0.0.1:24224".to_string();
// let pool = WorkerPool::new(&"127.0.0.1:24224".to_string()).expect("Couldn't create the worker pool.");
let settins = Settings {
workers: 4,
flush_period: 64.millis(),
max_flush_entries: 5120,
..Default::de... | code_fim | medium | {
"lang": "rust",
"repo": "tkrs/rust-sandbox",
"path": "/fluent-main/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> debug!("スレッドからのメッセージ: [{}]", message);
std::thread::sleep(std::time::Duration::from_millis(1));
}
// ========== 待機 ==========
debug!("スレッド終了まで待機しています...",);
let result = thread.join();
if result.is_err() {
let error = result.err().unwrap();
error!("スレッドは正常に終了しませんでした。エラー: {:?}", err... | code_fim | hard | {
"lang": "rust",
"repo": "mass10/rust.note",
"path": "/code/multithreading/example0/src/application/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mass10/rust.note path: /code/multithreading/example0/src/application/mod.rs
use crate::debug;
use crate::error;
use crate::thread;
use crate::util;
/// アプリケーション構造体
pub struct Application {}
impl Application {
/// 新しいインスタンスを返します。
///
/// # Returns
/// 新しいインスタンス
pub fn new() -> Application ... | code_fim | hard | {
"lang": "rust",
"repo": "mass10/rust.note",
"path": "/code/multithreading/example0/src/application/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: EmbarkStudios/rust-gpu path: /crates/rustc_codegen_spirv/src/linker/peephole_opts.rs
_index) =
match get_composite_and_index(types, defs, operand, vector_width) {
Some(x) => x,
None => {
return None;
}
};... | code_fim | hard | {
"lang": "rust",
"repo": "EmbarkStudios/rust-gpu",
"path": "/crates/rustc_codegen_spirv/src/linker/peephole_opts.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> types: &FxHashMap<Word, Instruction>,
defs: &FxHashMap<Word, Instruction>,
results: &[&Instruction],
vector_width: u32,
) -> Option<Vec<IdentifiedOperand>> {
let operation_opcode = results[0].class.opcode;
// Check to make sure they're all the same opcode, and have the same number ... | code_fim | hard | {
"lang": "rust",
"repo": "EmbarkStudios/rust-gpu",
"path": "/crates/rustc_codegen_spirv/src/linker/peephole_opts.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: EmbarkStudios/rust-gpu path: /crates/rustc_codegen_spirv/src/linker/peephole_opts.rs
o a `OpCompositeExtract`, get the vector it's extracting from, and the field
/// index.
fn get_composite_and_index(
types: &FxHashMap<Word, Instruction>,
defs: &FxHashMap<Word, Instruction>,
id: Word... | code_fim | hard | {
"lang": "rust",
"repo": "EmbarkStudios/rust-gpu",
"path": "/crates/rustc_codegen_spirv/src/linker/peephole_opts.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: chaosannals/ling path: /source/grammar/lexer.rs
use std::error::Error;
use std::fs::File;
use std::io::BufRead;
use std::io::BufReader;
use std::io::Lines;
use std::path::Path;
#[derive(Debug)]
enum Mode {
Normal,
Comment,
}
#[derive(Debug)]
pub enum Token {
Comma,
Dot,
Plu... | code_fim | hard | {
"lang": "rust",
"repo": "chaosannals/ling",
"path": "/source/grammar/lexer.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let text: String = self.buffer.clone().into_iter().collect();
let lexeme = Lexeme {
row: self.row,
column: self.offset,
token: Token::Identifier(text),
};
self.buffer.clear();
self.mode = Mode::Normal;
return lexeme;
}... | code_fim | hard | {
"lang": "rust",
"repo": "chaosannals/ling",
"path": "/source/grammar/lexer.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn calculate_center_x(radius: i32, aspect_ratio: i32) -> i32 {
let aspect_ratio_sqrt = (aspect_ratio as f32).sqrt();
(radius as f32 * aspect_ratio_sqrt).round() as i32
}<|fim_prefix|>// repo: jakobhellermann/piechart path: /src/utils.rs
use crate::Data;
pub fn data_angles(total: f32, data: ... | code_fim | hard | {
"lang": "rust",
"repo": "jakobhellermann/piechart",
"path": "/src/utils.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jakobhellermann/piechart path: /src/utils.rs
use crate::Data;
pub fn data_angles(total: f32, data: &[Data]) -> Vec<f32> {
let mut angle = 0.0;
data.iter()
.map(|d| d.value / total)
.map(|pct| {
let val = pct * 360.0;
angle += val;
angl... | code_fim | hard | {
"lang": "rust",
"repo": "jakobhellermann/piechart",
"path": "/src/utils.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // the next code applies to the first and last line of the circle.
// without it the circles have an ugly single dot on top and bottom.
// I just experimented until it looked alright for all combinations of radius and aspect_ratio
match (width, aspect_ratio) {
(0, 1) => width,
... | code_fim | medium | {
"lang": "rust",
"repo": "jakobhellermann/piechart",
"path": "/src/utils.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: house-of-vanity/mystem-rs path: /src/error.rs
use std::fmt;
use subprocess::PopenError;
#[derive(Debug)]
pub enum AppError {
PartOfSpeechError(&'static str),
GrammemError(&'static str),
PopenError(PopenError),
MystemError(&'static str),
}
impl fmt::Display for AppEr<|fim_suffix|... | code_fim | medium | {
"lang": "rust",
"repo": "house-of-vanity/mystem-rs",
"path": "/src/error.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>ror {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "An error occurred.")
}
}
impl From<PopenError> for AppError {
fn from(e: PopenError) -> AppError {
return AppError::PopenError(e);
}
}<|fim_prefix|>// repo: house-of-vanity/mystem-rs path: /src/error.r... | code_fim | medium | {
"lang": "rust",
"repo": "house-of-vanity/mystem-rs",
"path": "/src/error.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>rom<PopenError> for AppError {
fn from(e: PopenError) -> AppError {
return AppError::PopenError(e);
}
}<|fim_prefix|>// repo: house-of-vanity/mystem-rs path: /src/error.rs
use std::fmt;
use subprocess::PopenError;
#[derive(Debug)]
pub enum AppError {
PartOfSpeechError(&'static str),
... | code_fim | hard | {
"lang": "rust",
"repo": "house-of-vanity/mystem-rs",
"path": "/src/error.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: brunocodutra/reducer path: /src/reactor/sink.rs
use crate::reactor::*;
use derive_more::{Deref, DerefMut, From};
use futures::sink::{Sink, SinkExt};
use pin_project::pin_project;
use std::task::{Context, Poll};
use std::{borrow::ToOwned, pin::Pin};
/// An adapter for [`Sink`]s that behaves as a... | code_fim | hard | {
"lang": "rust",
"repo": "brunocodutra/reducer",
"path": "/src/reactor/sink.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(test)]
mod tests {
use super::*;
use mockall::predicate::*;
use std::{ops::*, string::String, vec::Vec};
use test_strategy::proptest;
use tokio::runtime;
#[proptest]
fn deref(sink: Vec<u8>) {
let mut dispatcher = AsyncReactor(sink.clone());
assert_eq!(di... | code_fim | hard | {
"lang": "rust",
"repo": "brunocodutra/reducer",
"path": "/src/reactor/sink.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: nmstate/nmstate path: /rust/src/lib/lldp.rs
TYPE_VLAN: u8 = 3;
const LLDP_ORG_OIU_MAC_PHY_CONF: &str = "00:12:0f";
const LLDP_ORG_SUBTYPE_MAC_PHY_CONF: u8 = 1;
const LLDP_ORG_OIU_PPVIDS: &str = "00:80:c2";
const LLDP_ORG_SUBTYPE_PPVIDS: u8 = 2;
const LLDP_ORG_OIU_MAX_FRAME_SIZE: &str = "00:12... | code_fim | hard | {
"lang": "rust",
"repo": "nmstate/nmstate",
"path": "/rust/src/lib/lldp.rs",
"mode": "psm",
"license": "LGPL-2.1-only",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: nmstate/nmstate path: /rust/src/lib/lldp.rs
TEM_CAPABILITIES_TYPE: u8 = 7;
const LLDP_MANAGEMENT_ADDRESSES_TYPE: u8 = 8;
const LLDP_ORGANIZATION_SPECIFIC_TYPE: u8 = 127;
const LLDP_CHASSIS_ID_RESERVED: u8 = 0;
const LLDP_CHASSIS_ID_CHASSIS_COMPONENT: u8 = 1;
const LLDP_CHASSIS_ID_IFACE_ALIAS: u... | code_fim | hard | {
"lang": "rust",
"repo": "nmstate/nmstate",
"path": "/rust/src/lib/lldp.rs",
"mode": "psm",
"license": "LGPL-2.1-only",
"source": "the-stack-v2"
} |
<|fim_suffix|> where
S: Serializer,
{
let mut serial_struct =
serializer.serialize_struct("lldp_port_id", 4)?;
serial_struct.serialize_field("_description", &self.id_type)?;
serial_struct.serialize_field("port-id-type", &(self.id_type as u8))?;
serial_struct.se... | code_fim | hard | {
"lang": "rust",
"repo": "nmstate/nmstate",
"path": "/rust/src/lib/lldp.rs",
"mode": "spm",
"license": "LGPL-2.1-only",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: naamancurtis/suaide path: /src/settings.rs
use config::{Config, ConfigError, Environment, File};
use lazy_static::lazy_static;
use serde::Deserialize;
use std::fs;
use std::path::Path;
use crate::domain::SuaideError;
lazy_static! {
static ref DEFAULT_SUAIDE_PATH: &'static str = "~/.suaide"... | code_fim | hard | {
"lang": "rust",
"repo": "naamancurtis/suaide",
"path": "/src/settings.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn generate_ticket_id(&self, ticket: String) -> String {
format!("{}{}", self.ticket_prefix, ticket)
}
}
fn verify_or_setup_folder_structure(path: String) -> Result<(), SuaideError> {
let path = Path::new(&path);
if path.exists() {
return Ok(());
}
let path_pa... | code_fim | hard | {
"lang": "rust",
"repo": "naamancurtis/suaide",
"path": "/src/settings.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Bernolt/odbc2parquet path: /src/query.rs
s,
writer::{FileWriter, RowGroupWriter, SerializedFileWriter},
},
schema::types::{Type, TypePtr},
};
use crate::{open_connection, parquet_buffer::ParquetBuffer, QueryOpt};
#[cfg(target_pointer_width = "64")]
const DEFAULT_BATCH_SIZE_BYTE... | code_fim | hard | {
"lang": "rust",
"repo": "Bernolt/odbc2parquet",
"path": "/src/query.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Bernolt/odbc2parquet path: /src/query.rs
// 1GB
/// Execute a query and writes the result to parquet.
pub fn query(environment: &Environment, opt: &QueryOpt) -> Result<(), Error> {
let QueryOpt {
connect_opts,
output,
parameters,
query,
batch_size_ro... | code_fim | hard | {
"lang": "rust",
"repo": "Bernolt/odbc2parquet",
"path": "/src/query.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.