text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_prefix|>// repo: jakeschurch/badm path: /src/commands.rs
//! Includes the commands used by the badm crate/application.
use std::fs;
use std::io::{self, Error, ErrorKind};
use std::path::{Path, PathBuf};
use crate::paths::{is_symlink, join_full_paths};
use crate::Config;
use crate::FileHandler;
/// Take input ... | code_fim | hard | {
"lang": "rust",
"repo": "jakeschurch/badm",
"path": "/src/commands.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> eprintln!("Listening on {}:{}", host, port);
server.await
}<|fim_prefix|>// repo: kriscirx/rust-actix-demo path: /src/main.rs
use actix_web::{web, App, HttpServer};
use std::env;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
dotenv::dotenv().ok();
let host = env::var("HOST").ex... | code_fim | hard | {
"lang": "rust",
"repo": "kriscirx/rust-actix-demo",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: kriscirx/rust-actix-demo path: /src/main.rs
use actix_web::{web, App, HttpServer};
use std::env;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
dotenv::dotenv().ok();
<|fim_suffix|> let port = env::var("PORT").expect("PORT is not set.");
let server = HttpServer::new(|| {
... | code_fim | medium | {
"lang": "rust",
"repo": "kriscirx/rust-actix-demo",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let i = self.0;
self.0 += 1;
if (i as usize) < COUNT {
return Some(S(i));
}
None
}
fn size_hint(&self) -> (usize, Option<usize>) {
(COUNT - self.0 as usize, Some(COUNT - self.0 as usize))
}
}
impl std::iter::FusedIterator for Iter {}
... | code_fim | hard | {
"lang": "rust",
"repo": "cookie-s/cubers",
"path": "/src/solve/phase2/udslice.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: cookie-s/cubers path: /src/solve/phase2/udslice.rs
use super::p2move::{P2Move, P2MOVE_COUNT};
use crate::cube;
use cube::{Sym16, SYM16_COUNT};
use std::ops::Mul;
use strum::IntoEnumIterator;
const FACT4: usize = 4 * 3 * 2 * 1;
#[derive(Debug, Copy, Clone, PartialEq, Eq, FromPrimitive)]
pub str... | code_fim | hard | {
"lang": "rust",
"repo": "cookie-s/cubers",
"path": "/src/solve/phase2/udslice.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let lc = match tree_sitter_stack_graphs_java::try_language_configuration(&NoCancellation) {
Ok(lc) => lc,
Err(err) => {
eprintln!("{}", err.display_pretty());
return Err(anyhow!("Language configuration error"));
}
};
let test_path = PathBuf::from... | code_fim | medium | {
"lang": "rust",
"repo": "github/stack-graphs",
"path": "/languages/tree-sitter-stack-graphs-java/rust/test.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: github/stack-graphs path: /languages/tree-sitter-stack-graphs-java/rust/test.rs
use anyhow::anyhow;
use std::path::PathBuf;
use tree_sitter_stack_graphs::{ci::Tester, NoCancellation};
<|fim_suffix|> let lc = match tree_sitter_stack_graphs_java::try_language_configuration(&NoCancellation) {
... | code_fim | medium | {
"lang": "rust",
"repo": "github/stack-graphs",
"path": "/languages/tree-sitter-stack-graphs-java/rust/test.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> if component_updates.has_delta_frame_content() {
warn!("Delta frames are not currently supported in state acceptor, dropping payload");
continue;
}
if component_updates.has_key_frame_content() {
let mut known_entities_with_component =
state_blob.get_ent... | code_fim | hard | {
"lang": "rust",
"repo": "acmcarther/void",
"path": "/game/state/relay/state_acceptor.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: acmcarther/void path: /game/state/relay/state_acceptor.rs
#[macro_use]
extern crate log;
extern crate protobuf;
extern crate state_acceptor_api;
extern crate state_api;
extern crate state_proto;
use state_acceptor_api::StateAcceptor;
use state_api::ComponentTypeId;
use state_api::KeyFrameId;
us... | code_fim | hard | {
"lang": "rust",
"repo": "acmcarther/void",
"path": "/game/state/relay/state_acceptor.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rnestler/advent_of_code_2016 path: /22/src/main.rs
extern crate puzzle22;
use puzzle22::*;
<|fim_suffix|> let input = include_str!("../input.txt");
let viable_pairs = puzzle(input);
println!("{}", viable_pairs);
}<|fim_middle|>fn main() {
| code_fim | easy | {
"lang": "rust",
"repo": "rnestler/advent_of_code_2016",
"path": "/22/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn main() {
let input = include_str!("../input.txt");
let viable_pairs = puzzle(input);
println!("{}", viable_pairs);
}<|fim_prefix|>// repo: rnestler/advent_of_code_2016 path: /22/src/main.rs
extern crate puzzle22;
<|fim_middle|>use puzzle22::*;
| code_fim | easy | {
"lang": "rust",
"repo": "rnestler/advent_of_code_2016",
"path": "/22/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rnestler/advent_of_code_2016 path: /22/src/main.rs
extern crate puzzle22;
<|fim_suffix|>fn main() {
let input = include_str!("../input.txt");
let viable_pairs = puzzle(input);
println!("{}", viable_pairs);
}<|fim_middle|>use puzzle22::*;
| code_fim | easy | {
"lang": "rust",
"repo": "rnestler/advent_of_code_2016",
"path": "/22/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jhod0/integrators path: /src/gsl/mod.rs
//! Wrappers for GSL integration routines. See GSL documentation
//! [here](https://www.gnu.org/software/gsl/doc/html/integration.html).
//!
//! This module, and all its re-exports from the top-level `integrators`
//! module, are gated with the `gsl` featu... | code_fim | hard | {
"lang": "rust",
"repo": "jhod0/integrators",
"path": "/src/gsl/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> where A: IntegrandInput,
B: IntegrandOutput,
F: FnMut(A) -> B
{
let fnptr = params as *mut LandingPad<A, B, F>;
let fun: &mut LandingPad<A, B, F> = &mut *fnptr;
if A::input_size() != 1 {
panic!("integrand given to GSL integrator demands >1 input");
}
l... | code_fim | hard | {
"lang": "rust",
"repo": "jhod0/integrators",
"path": "/src/gsl/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub type GSLResult<T> = Result<T, GSLIntegrationError>;
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct GSLIntegrationResult {
pub value: Real,
pub error: Real
}
struct GSLIntegrationWorkspace {
pub(crate) nintervals: usize,
wkspc: *mut bindings::gsl_integration_workspace
}
impl fmt... | code_fim | hard | {
"lang": "rust",
"repo": "jhod0/integrators",
"path": "/src/gsl/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: brooks-builds/platformer_with_level_editor path: /src/system_manager/mod.rs
use bbecs::world::World;
use eyre::Result;
use ggez::Context;
use crate::events::EventManager;
use crate::image_manager::ImageManager;
use crate::level_manager::LevelManager;
use self::apply_friction_system::ApplyFrict... | code_fim | hard | {
"lang": "rust",
"repo": "brooks-builds/platformer_with_level_editor",
"path": "/src/system_manager/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> Self {
draw_text,
update_text,
update_selected,
draw_entities,
apply_gravity,
update_forces,
collide_with_platform,
update_camera_position,
move_player,
draw_editing_level,
... | code_fim | hard | {
"lang": "rust",
"repo": "brooks-builds/platformer_with_level_editor",
"path": "/src/system_manager/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let sig_redeem_t = secp256k1::decsig(&secp256k1::KeyPair::try_from(alpha)?, &sig_redeem_t);
secp256k1::verify(redeem_tx_digest, &sig_redeem_t, &X_t)
.context("failed to verify tumbler redeem signature after decryption")?;
let signed_redeem_transaction = bitcoin::compl... | code_fim | hard | {
"lang": "rust",
"repo": "LLFourn/a2l-poc",
"path": "/src/puzzle_solver/receiver.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: LLFourn/a2l-poc path: /src/puzzle_solver/receiver.rs
use crate::bitcoin;
use crate::puzzle_solver::Message4;
use crate::secp256k1;
use anyhow::Context;
use std::convert::TryFrom;
pub struct Receiver0 {
X_r: secp256k1::PublicKey,
X_t: secp256k1::PublicKey,
unsigned_redeem_transaction... | code_fim | hard | {
"lang": "rust",
"repo": "LLFourn/a2l-poc",
"path": "/src/puzzle_solver/receiver.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ronanM/makair path: /src/software/control/src/display/screen.rs
// MakAir
//
// Copyright: 2020, Makers For Life
// License: Public Domain License
use conrod_core::color::{self, Color};
use telemetry::alarm::AlarmCode;
use telemetry::structures::{AlarmTrap, MachineStateSnapshot};
use crate::c... | code_fim | hard | {
"lang": "rust",
"repo": "ronanM/makair",
"path": "/src/software/control/src/display/screen.rs",
"mode": "psm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Initialize the ratio widget
let ratio_config = TelemetryWidgetConfig {
title: "Insp-exp ratio",
value: "0:0".to_string(), //TODO
unit: "insp:exp.",
ids: (
self.ids.cycles_parent,
self.ids.ratio_parent,
... | code_fim | hard | {
"lang": "rust",
"repo": "ronanM/makair",
"path": "/src/software/control/src/display/screen.rs",
"mode": "spm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.widgets.render(ControlWidgetType::Initializing(config));
}
pub fn render_telemetry(&mut self) {
let mut last_widget_position = 0.0;
let machine_snapshot = self.machine_snapshot.unwrap();
let peak_config = TelemetryWidgetConfig {
title: "P(peak)",
... | code_fim | hard | {
"lang": "rust",
"repo": "ronanM/makair",
"path": "/src/software/control/src/display/screen.rs",
"mode": "spm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: PortalNetwork/graph-node path: /graph/src/components/subgraph/instance.rs
use crate::prelude::*;
use crate::util::lfu_cache::LfuCache;
use web3::types::Log;
#[derive(Clone, Debug)]
pub struct DataSourceTemplateInfo {
pub data_source: String,
pub template: DataSourceTemplate,
pub par... | code_fim | hard | {
"lang": "rust",
"repo": "PortalNetwork/graph-node",
"path": "/graph/src/components/subgraph/instance.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl BlockState {
pub fn with_cache(lfu_cache: LfuCache<EntityKey, Option<Entity>>) -> Self {
BlockState {
entity_cache: EntityCache::with_current(lfu_cache),
created_data_sources: Vec::new(),
}
}
}
/// Represents a loaded instance of a subgraph.
pub trait ... | code_fim | medium | {
"lang": "rust",
"repo": "PortalNetwork/graph-node",
"path": "/graph/src/components/subgraph/instance.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>//usb's not yet supported on stm32l4x5
//#[cfg(feature = "disco-l475")]
//#[macro_use]
//mod disco_l475;
//#[cfg(feature = "disco-l475")]
//pub use disco_l475 as platform;
#[cfg(feature = "nucleo-f401re")]
#[macro_use]
pub mod nucleo_f401re;
#[cfg(feature = "nucleo-f401re")]
pub use nucleo_f401re as plat... | code_fim | medium | {
"lang": "rust",
"repo": "ithinuel/usbd-dfu",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ithinuel/usbd-dfu path: /src/lib.rs
#![no_std]
#![feature(maybe_uninit_ref)]
#![feature(panic_info_message)]
#![feature(const_raw_ptr_to_usize_cast)]
#![feature(future_poll_fn)]
extern crate alloc;
pub mod executor;
pub mod trace;
<|fim_suffix|>#[cfg(feature = "nucleo-f401re")]
#[macro_use]
p... | code_fim | hard | {
"lang": "rust",
"repo": "ithinuel/usbd-dfu",
"path": "/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(feature = "nucleo-f401re")]
#[macro_use]
pub mod nucleo_f401re;
#[cfg(feature = "nucleo-f401re")]
pub use nucleo_f401re as platform;<|fim_prefix|>// repo: ithinuel/usbd-dfu path: /src/lib.rs
#![no_std]
#![feature(maybe_uninit_ref)]
#![feature(panic_info_message)]
#![feature(const_raw_ptr_to_usize_c... | code_fim | hard | {
"lang": "rust",
"repo": "ithinuel/usbd-dfu",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: uvd/rust-by-example-cn path: /examples/error/result/result_alias/alias.rs
use std::num::ParseIntError;
// 为带有错误类型 `ParseIntError` 的 `Result` 定义一个泛型别名。
type AliasedResult<T> = Result<T, ParseIntError>;
// 使用上面定义过的别名来表示我们特指的 `Result` 类型。
fn double_number(number_str: &str) -> AliasedResult<i32> {... | code_fim | medium | {
"lang": "rust",
"repo": "uvd/rust-by-example-cn",
"path": "/examples/error/result/result_alias/alias.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>// 这里的别名又让我们节省了一些空间(save some space)。
fn print(result: AliasedResult<i32>) {
match result {
Ok(n) => println!("n is {}", n),
Err(e) => println!("Error: {}", e),
}
}
fn main() {
print(double_number("10"));
print(double_number("t"));
}<|fim_prefix|>// repo: uvd/rust-by-exam... | code_fim | medium | {
"lang": "rust",
"repo": "uvd/rust-by-example-cn",
"path": "/examples/error/result/result_alias/alias.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: RusPiRo/ruspiro-loader path: /src/uart.rs
//! # miniUART
//!
//! Bare bone miniUART implementation for the bootloader
//!
use ruspiro_arch_aarch64::{RegisterField, RegisterFieldValue};
use ruspiro_mmio_register::define_mmio_register;
use ruspiro_timer as timer;
#[cfg(feature = "pi3")]
const PE... | code_fim | hard | {
"lang": "rust",
"repo": "RusPiRo/ruspiro-loader",
"path": "/src/uart.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> },
AUX_MU_STAT_REG<ReadWrite<u32>@(AUX_BASE + 0x64)>,
AUX_MU_BAUD_REG<ReadWrite<u32>@(AUX_BASE + 0x68)>
];
// Define the registers of the GPIO that are used to access the pin's
define_mmio_register! [
/// Alt-Function select register for pin 10..19
pub(crate) GPFSEL1<ReadWrite<u32>@(G... | code_fim | hard | {
"lang": "rust",
"repo": "RusPiRo/ruspiro-loader",
"path": "/src/uart.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut count = 0;
while AUX_MU_LSR_REG::Register.read(AUX_MU_LSR_REG::DATAREADY) == 0
&& (timeout == 0 || count < timeout)
{
timer::sleepcycles(1000);
count += 1;
}
if timeout != 0 && count >= timeout {
Err(())
} else {
Ok((AUX_MU_IO_REG::Register.get() & 0xFF) as u8)
}
... | code_fim | hard | {
"lang": "rust",
"repo": "RusPiRo/ruspiro-loader",
"path": "/src/uart.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: llogiq/luminance-rs path: /src/pipeline.rs
//! Dynamic rendering pipelines.
//!
//! This module gives you materials to build *dynamic* rendering **pipelines**. A `Pipeline`
//! represents a functional stream that consumes geometric data and rasterizes them.
use blending;
use framebuffer::{Color... | code_fim | hard | {
"lang": "rust",
"repo": "llogiq/luminance-rs",
"path": "/src/pipeline.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|>}
/// A dynamic rendering pipeline. A *pipeline* is responsible of rendering into a `Framebuffer`.
///
/// `L` refers to the `Layering` of the underlying `Framebuffer`.
///
/// `D` refers to the `Dim` of the underlying `Framebuffer`.
///
/// `CS` and `DS` are – respectively – the *color* and *depth* `Slo... | code_fim | hard | {
"lang": "rust",
"repo": "llogiq/luminance-rs",
"path": "/src/pipeline.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl<'a, C, T> RenderCommand<'a, C, T> where C: 'a + HasTessellation {
pub fn new<F: Fn(&T) + 'a>(blending: Option<(blending::Equation, blending::Factor, blending::Factor)>, depth_test: bool, update: F, tessellation: &'a Tessellation<C>, instances: u32, rasterization_size: Option<f32>) -> Self {
Ren... | code_fim | hard | {
"lang": "rust",
"repo": "llogiq/luminance-rs",
"path": "/src/pipeline.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> let setup = Vec::<G1Affine>::deserialize_unchecked(&setup_bytes[..]).unwrap();
let accts = Vec::<Vec<Fr>>::deserialize_unchecked(&accts_bytes[..]).unwrap();
let cha_1 = Fr::deserialize_unchecked(&cha_1_bytes[..]).unwrap();
let cha_2 = Fr::deserialize_unchecked(&cha_2_bytes[..]).unwrap();
... | code_fim | hard | {
"lang": "rust",
"repo": "kobigurk/zkhack-hidden-in-plain-sight",
"path": "/src/bin/verify-hidden-in-plain-sight.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> welcome();
puzzle(PUZZLE_DESCRIPTION);
let (setup, accts, cha_1, cha_2, commt, opn_1, opn_2) = read_cha_from_file();
// Replace with the solution polynomial, derived from the account!
let solution_blinded_acct = DensePolynomial::from_coefficients_vec(vec![]);
let solution_commit... | code_fim | hard | {
"lang": "rust",
"repo": "kobigurk/zkhack-hidden-in-plain-sight",
"path": "/src/bin/verify-hidden-in-plain-sight.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: kobigurk/zkhack-hidden-in-plain-sight path: /src/bin/verify-hidden-in-plain-sight.rs
#![allow(unused, unreachable_code, dead_code)]
use ark_bls12_381::{Fr, G1Affine};
use ark_ff::*;
use ark_poly::{
univariate::DensePolynomial, EvaluationDomain, GeneralEvaluationDomain, Polynomial,
UVPol... | code_fim | hard | {
"lang": "rust",
"repo": "kobigurk/zkhack-hidden-in-plain-sight",
"path": "/src/bin/verify-hidden-in-plain-sight.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Rect {
pub fn new(x: usize, y: usize, w: usize, h: usize) -> Rect {
Rect { x, y, w, h }
}
}<|fim_prefix|>// repo: ryankurte/rust-micro-gui path: /src/types/rect.rs
//! Types module defines types for use across ugui implementation
//!
//! Copyright 2019 Ryan Kurte
<|fim_middle|>/// R... | code_fim | medium | {
"lang": "rust",
"repo": "ryankurte/rust-micro-gui",
"path": "/src/types/rect.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ryankurte/rust-micro-gui path: /src/types/rect.rs
//! Types module defines types for use across ugui implementation
//!
//! Copyright 2019 Ryan Kurte
<|fim_suffix|>impl Rect {
pub fn new(x: usize, y: usize, w: usize, h: usize) -> Rect {
Rect { x, y, w, h }
}
}<|fim_middle|>/// R... | code_fim | medium | {
"lang": "rust",
"repo": "ryankurte/rust-micro-gui",
"path": "/src/types/rect.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Some additional tests that don't seem to be covered by the UCD tests.
#[test]
fn forward_additional() {
assert_eq!(vec!["a.. ", "A"], sentences(b"a.. A"));
assert_eq!(vec!["a.. a"], sentences(b"a.. a"));
assert_eq!(vec!["a... ", "A"], sentences(b"a... A"));
... | code_fim | hard | {
"lang": "rust",
"repo": "gnoliyil/fuchsia",
"path": "/third_party/rust_crates/vendor/bstr-0.2.12/src/unicode/sentence.rs",
"mode": "spm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: gnoliyil/fuchsia path: /third_party/rust_crates/vendor/bstr-0.2.12/src/unicode/sentence.rs
use regex_automata::DFA;
use ext_slice::ByteSlice;
use unicode::fsm::sentence_break_fwd::SENTENCE_BREAK_FWD;
use utf8;
/// An iterator over sentences in a byte string.
///
/// This iterator is typically ... | code_fim | hard | {
"lang": "rust",
"repo": "gnoliyil/fuchsia",
"path": "/third_party/rust_crates/vendor/bstr-0.2.12/src/unicode/sentence.rs",
"mode": "psm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn decode_sentence(bs: &[u8]) -> (&str, usize) {
if bs.is_empty() {
("", 0)
} else if let Some(end) = SENTENCE_BREAK_FWD.find(bs) {
// Safe because a match can only occur for valid UTF-8.
let sentence = unsafe { bs[..end].to_str_unchecked() };
(sentence, sentence.le... | code_fim | hard | {
"lang": "rust",
"repo": "gnoliyil/fuchsia",
"path": "/third_party/rust_crates/vendor/bstr-0.2.12/src/unicode/sentence.rs",
"mode": "spm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: satyamakgec/fe path: /common/src/utils/keccak.rs
use tiny_keccak::{
Hasher,
Keccak,
};
/// Get the full 32 byte hash of the content.
pub fn full(content: &[u8]) -> String {
partial(content, 32)
}
/// Take the first `size` number of bytes of the hash and pad the right side
/// with ... | code_fim | hard | {
"lang": "rust",
"repo": "satyamakgec/fe",
"path": "/common/src/utils/keccak.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// Take the first `size` number of bytes of the hash with no padding.
pub fn partial(content: &[u8], size: usize) -> String {
let result = full_as_bytes(content);
format!("0x{}", hex::encode(&result[0..size]))
}
/// Get the full 32 byte hash of the content as a byte array.
pub fn full_as_bytes(c... | code_fim | medium | {
"lang": "rust",
"repo": "satyamakgec/fe",
"path": "/common/src/utils/keccak.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// Get the full 32 byte hash of the content as a byte array.
pub fn full_as_bytes(content: &[u8]) -> [u8; 32] {
let mut keccak = Keccak::v256();
let mut selector = [0u8; 32];
keccak.update(content);
keccak.finalize(&mut selector);
selector
}<|fim_prefix|>// repo: satyamakgec/fe pat... | code_fim | hard | {
"lang": "rust",
"repo": "satyamakgec/fe",
"path": "/common/src/utils/keccak.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl AddServer for Result<DnsLookupBuilderB,String> {
type Out = DnsLookupBuilderB;
fn dns_server<S>( self, addr:S ) -> Result<Self::Out,String>
where S: Into<SocketAddrParse>
{
self.and_then(|d| d.dns_server(addr))
}
}
/// Создание клиента
pub trait BuildClient {
type Out;
/// С... | code_fim | hard | {
"lang": "rust",
"repo": "gochaorg/samples",
"path": "/kuber/raft/src/lookup.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: gochaorg/samples path: /kuber/raft/src/lookup.rs
use std::cell::RefCell;
use std::net::{IpAddr, SocketAddrV4, SocketAddrV6};
use std::{sync::Arc, net::SocketAddr};
use std::str::FromStr;
use trust_dns_client::client::{Client, SyncClient};
use trust_dns_client::udp::UdpClientConnection;
use trus... | code_fim | hard | {
"lang": "rust",
"repo": "gochaorg/samples",
"path": "/kuber/raft/src/lookup.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>
let port = if let Ok(port) = std::env::var("PORT") {
if let Ok(port) = port.parse::<u16>() {
port
} else {
DEFAULT_PORT
}
} else {
DEFAULT_PORT
};
let socket: SocketAddr = ([0, 0, 0, 0], port).into();
println!("serve at http://{... | code_fim | hard | {
"lang": "rust",
"repo": "ivanceras/sauron",
"path": "/examples/progressive-rendering/server/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let rendered_index_page = page::index(&app).render_to_string_pretty();
Response::builder().body(rendered_index_page)
};
// Render paths that include a name argument
let named = warp::path!(String)
.map(move|name: String| {
let name = percent_decode_str(&na... | code_fim | hard | {
"lang": "rust",
"repo": "ivanceras/sauron",
"path": "/examples/progressive-rendering/server/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ivanceras/sauron path: /examples/progressive-rendering/server/src/main.rs
use warp::{Filter, http::Response};
use client::{App, Data};
use sauron::*;
use std::net::SocketAddr;
use std::collections::HashMap;
use percent_encoding::percent_decode_str;
mod page;
// path relative to the working dir... | code_fim | hard | {
"lang": "rust",
"repo": "ivanceras/sauron",
"path": "/examples/progressive-rendering/server/src/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: zhxiaogg/tfar path: /src/state_machine/states/internal.rs
use super::ServerId;
use std::collections::HashSet;
/// Represents a node in Raft cluster
#[derive(PartialEq)]
pub struct Server {
address: String,
port: u16,
}
/// Tracing the progress of an ongoing Vote event.
struct Voting... | code_fim | hard | {
"lang": "rust",
"repo": "zhxiaogg/tfar",
"path": "/src/state_machine/states/internal.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn has_leader(&self, leader: ServerId) -> bool {
self.leader.contains(&leader)
}
}
impl Voting {
/// create a new Voting by updating current one with an vote result
fn accept_vote(self, server: ServerId, agree: bool) -> Voting {
let Voting { mut agrees, mut rejects } =... | code_fim | hard | {
"lang": "rust",
"repo": "zhxiaogg/tfar",
"path": "/src/state_machine/states/internal.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tock/tock path: /kernel/src/platform/mpu.rs
/// The memory address where the region starts.
///
/// For maximum compatibility, we use a u8 pointer, however, note that many
/// memory protection units have very strict alignment requirements for the
/// memory regions protected ... | code_fim | hard | {
"lang": "rust",
"repo": "tock/tock",
"path": "/kernel/src/platform/mpu.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tock/tock path: /kernel/src/platform/mpu.rs
enum Permissions {
ReadWriteExecute,
ReadWriteOnly,
ReadExecuteOnly,
ReadOnly,
ExecuteOnly,
}
/// MPU region.
///
/// This is one contiguous address space protected by the MPU.
#[derive(Copy, Clone, PartialEq, Eq)]
pub struct Regio... | code_fim | hard | {
"lang": "rust",
"repo": "tock/tock",
"path": "/kernel/src/platform/mpu.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> "nop-preprocessor"
}
fn run(&self, _: &PreprocessorContext, book: Book) -> Result<Book, Error> {
Ok(book)
}
fn supports_renderer(&self, _: &str) -> bool {
true
}
}<|fim_prefix|>// repo: Matthewacon/mdbook-nop-preprocessor path: /src/main.rs
use clap::{App, Ar... | code_fim | hard | {
"lang": "rust",
"repo": "Matthewacon/mdbook-nop-preprocessor",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Matthewacon/mdbook-nop-preprocessor path: /src/main.rs
use clap::{App, Arg, ArgMatches, SubCommand};
use mdbook::book::Book;
use mdbook::errors::Error;
use mdbook::preprocess::{CmdPreprocessor, Preprocessor, PreprocessorContext};
use std::io;
pub fn make_app() -> App<'static, 'static> {
App... | code_fim | medium | {
"lang": "rust",
"repo": "Matthewacon/mdbook-nop-preprocessor",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> if let Err(_) = try_main() {
panic!("Failed to run nop-preprocessor");
}
}
impl Preprocessor for NopPreprocessor {
fn name(&self) -> &str {
"nop-preprocessor"
}
fn run(&self, _: &PreprocessorContext, book: Book) -> Result<Book, Error> {
Ok(book)
}
fn ... | code_fim | hard | {
"lang": "rust",
"repo": "Matthewacon/mdbook-nop-preprocessor",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: cbranch/aoc2018 path: /src/bin/day3.rs
extern crate aoc2018;
extern crate regex;
extern crate lazy_static;
use std::io::prelude::*;
use std::collections::HashMap;
use std::collections::hash_map::Entry;
use regex::Regex;
use lazy_static::lazy_static;
use aoc2018::get_input_file;
#[derive(Debug)... | code_fim | hard | {
"lang": "rust",
"repo": "cbranch/aoc2018",
"path": "/src/bin/day3.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let claims: Vec<_> = get_input_file().lines().map(|x| x.unwrap()).map(|x| parse_claim(&x)).collect();
let mut covered = HashMap::new();
for claim in claims.iter() {
for x in claim.left..claim.left + claim.width {
for y in claim.top..claim.top + claim.height {
... | code_fim | hard | {
"lang": "rust",
"repo": "cbranch/aoc2018",
"path": "/src/bin/day3.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>// Short problem description:
// Given a set of rectangles, find the total area covered by the intersection of at least any pair of rectangles
// i.e. length of the set {x: (x ∈ A && x ∈ B) ∀ {(A, B) ∈ X: A != B} }
//
// Because the total area is sufficiently small we can use a simple HashMap to track the... | code_fim | hard | {
"lang": "rust",
"repo": "cbranch/aoc2018",
"path": "/src/bin/day3.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: davidor/gebers path: /src/memory/mod.rs
use crate::interrupts::Interrupts;
use crate::interrupts::{ENABLED_INTERRUPTS_ADDR, PENDING_INTERRUPTS_ADDR};
pub const IO_PORTS_BEGIN: usize = 0xFF00;
const SERIAL_TRANSFER_DATA: usize = 0xFF01;
const SERIAL_TRANSFER_CONTROL: usize = 0xFF02;
const MEMOR... | code_fim | medium | {
"lang": "rust",
"repo": "davidor/gebers",
"path": "/src/memory/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Memory {
pub fn new() -> Memory {
Memory {
mem: [0; MEMORY_SIZE],
interrupts: Interrupts::new(),
}
}
pub fn read_byte(&self, address: u16) -> u8 {
if address == PENDING_INTERRUPTS_ADDR as u16 {
self.interrupts.if_value()
... | code_fim | medium | {
"lang": "rust",
"repo": "davidor/gebers",
"path": "/src/memory/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> chip8::arch::Chip8::print_listing(&listing);
} else {
println!("usage: dis <file-to-disassemble> [<start-offset>]");
}
}<|fim_prefix|>// repo: DealPete/static path: /chip8/recur.rs
mod recur;
pub mod defs;
pub mod chip8;
use defs::main::*;
fn main() {
use std::env;
use std::io... | code_fim | hard | {
"lang": "rust",
"repo": "DealPete/static",
"path": "/chip8/recur.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: DealPete/static path: /chip8/recur.rs
mod recur;
pub mod defs;
pub mod chip8;
use defs::main::*;
fn main() {
use std::env;
use std::io::Read;
use std::fs::File;
<|fim_suffix|> let listing = recur::recursive_descent(
&buffer,
chip8::arch::Chip8 {},
... | code_fim | hard | {
"lang": "rust",
"repo": "DealPete/static",
"path": "/chip8/recur.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>en (catch , method , structural , js_class = "Path2D" , js_name = roundRect)]
#[doc = "The `roundRect()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Path2D/roundRect)"]
#[doc = ""]
#[doc = "*This API requires the following crate f... | code_fim | hard | {
"lang": "rust",
"repo": "rustwasm/wasm-bindgen",
"path": "/crates/web-sys/src/features/gen_Path2d.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rustwasm/wasm-bindgen path: /crates/web-sys/src/features/gen_Path2d.rs
#![allow(unused_imports)]
#![allow(clippy::all)]
use super::*;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = Path2D , typescript_type = "Path2D")]
... | code_fim | hard | {
"lang": "rust",
"repo": "rustwasm/wasm-bindgen",
"path": "/crates/web-sys/src/features/gen_Path2d.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: zerodivisi0n/rust-nats path: /src/tls_config.rs
extern crate openssl;
use errors::*;
use std::fmt;
use self::openssl::ssl::{SslConnector, SslConnectorBuilder, SslMethod};
use self::openssl::x509::X509;
use self::openssl::pkey::PKey;
#[derive(Clone)]
pub struct TlsConfig(SslConnector);
pub str... | code_fim | hard | {
"lang": "rust",
"repo": "zerodivisi0n/rust-nats",
"path": "/src/tls_config.rs",
"mode": "psm",
"license": "ISC",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl fmt::Debug for TlsConfig {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "TlsConfig {{}}")
}
}<|fim_prefix|>// repo: zerodivisi0n/rust-nats path: /src/tls_config.rs
extern crate openssl;
use errors::*;
use std::fmt;
use self::openssl::ssl::{SslConnector, SslConnec... | code_fim | hard | {
"lang": "rust",
"repo": "zerodivisi0n/rust-nats",
"path": "/src/tls_config.rs",
"mode": "spm",
"license": "ISC",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn timestamp(address: Address) -> ZomeApiResult<Iso8601> {
let options = GetEntryOptions{status_request: StatusRequestKind::Initial, entry: false, headers: true, timeout: Timeout::new(10000)};
let entry_result = hdk::get_entry_result(&address, options)?;
match entry_result.result {
... | code_fim | hard | {
"lang": "rust",
"repo": "Qubeo/hcmin",
"path": "/zomes/core/code/src/pt_promise/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Qubeo/hcmin path: /zomes/core/code/src/pt_promise/mod.rs
use serde_derive::{ Deserialize, Serialize };
use holochain_json_derive::DefaultJson;
use hdk::{
self,
entry,
// from,
// link,
entry_definition::ValidatingEntryType,
holochain_core_types::{
dna::entry_types... | code_fim | hard | {
"lang": "rust",
"repo": "Qubeo/hcmin",
"path": "/zomes/core/code/src/pt_promise/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> Ok(PTPromise {
id: id.clone(),
created_at: timestamp(id)?,
title: pt_promise_entry.title,
content: pt_promise_entry.content,
context: "[Default context]".to_string(),
lifetime: 0,
location: ptloc,
})
}
... | code_fim | hard | {
"lang": "rust",
"repo": "Qubeo/hcmin",
"path": "/zomes/core/code/src/pt_promise/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> listener.accept_async(epoll.clone(), |stream| match stream {
Ok(stream) => {
serve(stream, vec![]);
Ok(())
}
Err(code) => {
println!("failed to accept; code = {}", code);
Err(())
}
});
println!("start epoll");
... | code_fim | hard | {
"lang": "rust",
"repo": "forkkit/wasmer",
"path": "/examples/http-server/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: forkkit/wasmer path: /examples/http-server/src/main.rs
#![feature(wasi_ext)]
use kernel_net::{schedule, Epoll, Tcp4Listener, TcpStream};
use std::sync::Arc;
fn serve(stream: Arc<TcpStream>, mut all: Vec<u8>) {
let stream2 = stream.clone();
stream.read_async(
Vec::with_capacity(... | code_fim | hard | {
"lang": "rust",
"repo": "forkkit/wasmer",
"path": "/examples/http-server/src/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> info!(Publisher, "HarperCollins Publishers Ltd");
}
#[test]
fn description() {
info!(Description, "<h3>From Library Journal</h3><p>New Line Cinema will be releasing \"The Lord of the Rings\" trilogy in three separate installments, and Houghton Mifflin Tolkie... | code_fim | hard | {
"lang": "rust",
"repo": "c0ding/mobi-rs",
"path": "/tests/exth.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: c0ding/mobi-rs path: /tests/exth.rs
// mod tests;
// use tests::BOOK;
mod book;
use book::BOOK;
mod exth_header {
use super::*;
use mobi::{BookInfo, ExtHeader, Header, HeaderData};
use std::collections::HashMap;
#[test]
fn parse() {
let records: HashMap<u32, String> =... | code_fim | hard | {
"lang": "rust",
"repo": "c0ding/mobi-rs",
"path": "/tests/exth.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> info!(Isbn, "9780261102316");
}
#[test]
fn publish_date() {
info!(PublishDate, "2010-12-21T00:00:00+00:00");
}
#[test]
fn contributor() {
info!(Contributor, "calibre (0.7.31) [http://calibre-ebook.com]");
}
... | code_fim | hard | {
"lang": "rust",
"repo": "c0ding/mobi-rs",
"path": "/tests/exth.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Ameobea/minutiae path: /minutiae/src/engine/iterator.rs
//! Defines an object that iterates over of a universe in some order.
use std::collections::HashSet;
use std::marker::PhantomData;
use cell::CellState;
use entity::{Entity, EntityState, MutEntityState};
/// Visits the entities of a unive... | code_fim | hard | {
"lang": "rust",
"repo": "Ameobea/minutiae",
"path": "/minutiae/src/engine/iterator.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // iterate over the remaining indexes of the universe and return the coordinates of the first found entity
while self.universe_index < self.universe_length {
self.universe_index += 1;
if access_entity(entity_meta, entities, self.universe_index, 0) {
... | code_fim | hard | {
"lang": "rust",
"repo": "Ameobea/minutiae",
"path": "/minutiae/src/engine/iterator.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>>(basic: B, updated: U) -> (Vec<K>, Vec<K>, Vec<K>)
where
K: Hash + Eq + Clone + 'a,
B: IntoIterator<Item = &'a K>,
U: IntoIterator<Item = &'a K>,
{
let basic: HashSet<_> = basic.into_iter().collect();
let updated: HashSet<_> = updated.into_iter().collect();
let to_add: Vec<_> = up... | code_fim | hard | {
"lang": "rust",
"repo": "rillrate-fossil/rillrate",
"path": "/pkg-core/rill-protocol/src/diff.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rillrate-fossil/rillrate path: /pkg-core/rill-protocol/src/diff.rs
use std::collections::HashSet;
use std::hash::Hash;
pub fn diff<'a, K, B, U>(basic: B, updated: U) -> (Vec<K>, Vec<K>)
where
K: Hash + Eq + Clone + 'a,
B: IntoIterator<Item = &'a K>,
U: IntoIterator<Item = &'a K>,
{
... | code_fim | hard | {
"lang": "rust",
"repo": "rillrate-fossil/rillrate",
"path": "/pkg-core/rill-protocol/src/diff.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>o_add: Vec<_> = updated.difference(&basic).map(|k| (*k).clone()).collect();
let to_remove: Vec<_> = basic.difference(&updated).map(|k| (*k).clone()).collect();
let to_check: Vec<_> = basic.intersection(&updated).map(|k| (*k).clone()).collect();
(to_add, to_remove, to_check)
}<|fim_prefix|>// r... | code_fim | hard | {
"lang": "rust",
"repo": "rillrate-fossil/rillrate",
"path": "/pkg-core/rill-protocol/src/diff.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: burrbull/nuc1xx-pac path: /src/pdma0/pdma_cdarx.rs
#[doc = "Reader of register PDMA_CDARx"]
pub type R = crate::R<u32, super::PDMA_CDARX>;
#[doc = "Reader of field `PDMA_C<|fim_suffix|>(always)]
pub fn pdma_cdar(&self) -> PDMA_CDAR_R {
PDMA_CDAR_R::new((self.bits & 0xffff_ffff) as u3... | code_fim | hard | {
"lang": "rust",
"repo": "burrbull/nuc1xx-pac",
"path": "/src/pdma0/pdma_cdarx.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>(always)]
pub fn pdma_cdar(&self) -> PDMA_CDAR_R {
PDMA_CDAR_R::new((self.bits & 0xffff_ffff) as u32)
}
}<|fim_prefix|>// repo: burrbull/nuc1xx-pac path: /src/pdma0/pdma_cdarx.rs
#[doc = "Reader of register PDMA_CDARx"]
pub type R = crate::R<u32, super::PDMA_CDARX>;
#[doc = "Reader of fie... | code_fim | medium | {
"lang": "rust",
"repo": "burrbull/nuc1xx-pac",
"path": "/src/pdma0/pdma_cdarx.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let endpoint =
syntax::segment("foo")
.or(syntax::segment("bar"))
.wrap(endpoint::wrapper::or_reject_with(|_err, _cx| {
bad_request(format_err!("custom rejection"))
}));
assert_matches!(local::get("/foo").apply(&endpoint), Ok(..));
... | code_fim | hard | {
"lang": "rust",
"repo": "eddyb/finchers",
"path": "/tests/endpoint/or.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: eddyb/finchers path: /tests/endpoint/or.rs
use failure::format_err;
use finchers::endpoint::syntax;
use finchers::error::bad_request;
use finchers::local;
use finchers::prelude::*;
use matches::assert_matches;
#[test]
fn test_or_1() {
let e1 = syntax::segment("foo").and(endpoint::value("foo... | code_fim | hard | {
"lang": "rust",
"repo": "eddyb/finchers",
"path": "/tests/endpoint/or.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let e1 = syntax::segment("foo").and(endpoint::value("foo"));
let e2 = syntax::segment("foo")
.and("bar")
.and(endpoint::value("foobar"));
let endpoint = e1.or(e2);
assert_matches!(local::get("/foo").apply(&endpoint), Ok(..));
assert_matches!(local::get("/foo/bar").app... | code_fim | medium | {
"lang": "rust",
"repo": "eddyb/finchers",
"path": "/tests/endpoint/or.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>
pub fn get_container(s: Option<String>) -> Result<container::Codec, Error> {
match s {
Some(s) => match try!(container::Codec::from_args(s.split(","))) {
(codec, mut rest) => {
match rest.next().is_some() {
false => {
Ok... | code_fim | hard | {
"lang": "rust",
"repo": "bjornua/transcode",
"path": "/src/codecs/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: bjornua/transcode path: /src/codecs/mod.rs
pub mod audio;
pub mod video;
pub mod container;
use std::ffi::OsString;
use std::error::Error as StdError;
use std::fmt;
#[derive(Debug)]
pub enum Error {
TooShort,
TooLong,
InvalidArg(String, &'static str)
}
<|fim_suffix|>pub fn get_con... | code_fim | hard | {
"lang": "rust",
"repo": "bjornua/transcode",
"path": "/src/codecs/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub trait Codec: Sized {
fn from_args<'a, T: Iterator<Item = &'a str>>(T) -> Result<(Self, T), Error>;
fn to_ffmpeg_args(&self) -> Vec<OsString>;
fn to_ffprobe_id(&self) -> (Option<&'static str>, Option<&'static str>);
fn to_examples() -> Vec<Vec<&'static str>>;
}
pub fn get_container(s... | code_fim | hard | {
"lang": "rust",
"repo": "bjornua/transcode",
"path": "/src/codecs/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: yoanlcq/lab path: /rust/nuke/src/clear.rs
use nuke_sys::*;
use context::*;
// NOT annotated with must_use, since it can safely be dropped.
pub struct ClearStep<'a> {
ctx: &'a mut Context<'a>
}
impl<'a> ClearStep<'a> {
pub fn clear(self) {
drop(self)
}
pub un... | code_fim | medium | {
"lang": "rust",
"repo": "yoanlcq/lab",
"path": "/rust/nuke/src/clear.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> unsafe {
nk_clear(&mut self.ctx.raw)
}
}
}<|fim_prefix|>// repo: yoanlcq/lab path: /rust/nuke/src/clear.rs
use nuke_sys::*;
use context::*;
// NOT annotated with must_use, since it can safely be dropped.
pub struct ClearStep<'a> {
ctx: &'a mut Context<'a>
}
... | code_fim | medium | {
"lang": "rust",
"repo": "yoanlcq/lab",
"path": "/rust/nuke/src/clear.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: lucab/lpc81x-pac path: /src/sct/ev2_ctrl.rs
IOCONDR::FALL => 2,
IOCONDR::HIGH => 3,
}
}
#[allow(missing_docs)]
#[doc(hidden)]
#[inline]
pub fn _from(value: u8) -> IOCONDR {
match value {
0 => IOCONDR::LOW,
1 => ... | code_fim | hard | {
"lang": "rust",
"repo": "lucab/lpc81x-pac",
"path": "/src/sct/ev2_ctrl.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: lucab/lpc81x-pac path: /src/sct/ev2_ctrl.rs
> true,
}
}
}
#[doc = r" Proxy"]
pub struct _OUTSELW<'a> {
w: &'a mut W,
}
impl<'a> _OUTSELW<'a> {
#[doc = r" Writes `variant` to the field"]
#[inline]
pub fn variant(self, variant: OUTSELW) -> &'a mut W {
{
... | code_fim | hard | {
"lang": "rust",
"repo": "lucab/lpc81x-pac",
"path": "/src/sct/ev2_ctrl.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>eld bit"]
pub fn set_bit(self) -> &'a mut W {
self.bit(true)
}
#[doc = r" Clears the field bit"]
pub fn clear_bit(self) -> &'a mut W {
self.bit(false)
}
#[doc = r" Writes raw bits to the field"]
#[inline]
pub fn bit(self, value: bool) -> &'a mut W {
... | code_fim | hard | {
"lang": "rust",
"repo": "lucab/lpc81x-pac",
"path": "/src/sct/ev2_ctrl.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let json = "[\"test\"]";
let parsed: HelloWorldRequest = serde_json::from_str(json).unwrap();
assert_eq!(HelloWorldRequest {name: Some("test".into()), message: None}, parsed);
let json = "[]";
let parsed: HelloWorldRequest = serde_json::from_str(json).unwrap();
... | code_fim | hard | {
"lang": "rust",
"repo": "jb55/clightning-plugin-api",
"path": "/examples/hello_world.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jb55/clightning-plugin-api path: /examples/hello_world.rs
extern crate clightning_plugin_api;
extern crate clightningrpc;
#[macro_use] extern crate serde_derive;
use clightning_plugin_api::{CmdOptionMeta, CmdOptionType, CmdOptions, Plugin, PluginContext, RpcMethod, RpcMethodParams};
#[derive(D... | code_fim | hard | {
"lang": "rust",
"repo": "jb55/clightning-plugin-api",
"path": "/examples/hello_world.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: szymon-solak/aoc-2020 path: /day-5-binary-boarding/src/main.rs
// https://adventofcode.com/2020/day/5
use std::str::FromStr;
#[derive(Debug)]
struct Seat {
row: usize,
column: usize,
}
impl Seat {
pub fn parse_from_binary_spec(spec: Vec<char>) -> Seat {
let (row, cols) = s... | code_fim | medium | {
"lang": "rust",
"repo": "szymon-solak/aoc-2020",
"path": "/day-5-binary-boarding/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let spec = s.chars().collect::<Vec<char>>();
Ok(Seat::parse_from_binary_spec(spec))
}
}
fn main() {
let args: Vec<String> = std::env::args().collect();
let path = args
.get(1)
.expect("The first argument should be the data file path");
let input_data = std... | code_fim | medium | {
"lang": "rust",
"repo": "szymon-solak/aoc-2020",
"path": "/day-5-binary-boarding/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: hnen/import-obj path: /src/obj_renderable.rs
use std::collections::HashMap;
use obj::*;
use error::*;
#[derive(Debug)]
pub struct ObjRenderable {
pub name : String,
pub mat_name : Option<String>,
pub v_pos : Vec<[f32;3]>,
pub v_norm : Vec<[f32;3]>,
pub v_tx : Vec<[f32;2]>,
... | code_fim | hard | {
"lang": "rust",
"repo": "hnen/import-obj",
"path": "/src/obj_renderable.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.