text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_prefix|>// repo: KatsuyaKikuchi/programming_contest_rust path: /src/VirtualContest/dp/041.rs
use proconio::input;
use std::collections::VecDeque;
fn main()
{
input! {
n:usize,
v:[usize;n]
}
let mut ans = vec![0; n];
let mx = v.iter().max().unwrap().clone();
let mut stack = VecDeque:... | code_fim | hard | {
"lang": "rust",
"repo": "KatsuyaKikuchi/programming_contest_rust",
"path": "/src/VirtualContest/dp/041.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> - idx;
}
stack.push_front((v[i], i + 1));
}
let mut stack = VecDeque::new();
stack.push_front((mx + 1, n));
for i in (0..n).rev() {
while let Some(&(val, _)) = stack.front() {
if val > v[i] {
break;
}
stack.pop_fr... | code_fim | hard | {
"lang": "rust",
"repo": "KatsuyaKikuchi/programming_contest_rust",
"path": "/src/VirtualContest/dp/041.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> unsafe {
let app: *mut Object = msg_send![class!(UIApplication), sharedApplication];
if app.is_null() {
return Err(Error::new(
ErrorKind::Other,
"UIApplication is null, can't open url",
));
}
let url_cstr = std::ff... | code_fim | medium | {
"lang": "rust",
"repo": "amodm/webbrowser-rs",
"path": "/src/ios.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: amodm/webbrowser-rs path: /src/ios.rs
use crate::{Browser, BrowserOptions, Error, ErrorKind, Result, TargetType};
use objc::{class, msg_send, runtime::Object, sel, sel_impl};
<|fim_suffix|> // always return true for a dry run
if options.dry_run {
return Ok(());
}
unsafe ... | code_fim | hard | {
"lang": "rust",
"repo": "amodm/webbrowser-rs",
"path": "/src/ios.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// A type representing user ID.
#[allow(non_camel_case_types)]
pub type gid_t = u32;
/// A type representing group ID.
#[allow(non_camel_case_types)]
pub type pid_t = i32;<|fim_prefix|>// repo: tokio-rs/tokio path: /tokio/src/net/unix/mod.rs
//! Unix specific network types.
// This module does not curr... | code_fim | hard | {
"lang": "rust",
"repo": "tokio-rs/tokio",
"path": "/tokio/src/net/unix/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tokio-rs/tokio path: /tokio/src/net/unix/mod.rs
//! Unix specific network types.
// This module does not currently provide any public API, but it was
// unintentionally defined as a public module. Hide it from the documentation
// instead of changing it to a private module to avoid breakage.
#[d... | code_fim | hard | {
"lang": "rust",
"repo": "tokio-rs/tokio",
"path": "/tokio/src/net/unix/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: elisvathi/rustracer path: /src/main.rs
// Main File
use rustracer::{
gen_random_sphere, get_color, get_metal, Float, ImageBuilder, PixelData, Scene, Sphere, Hittable,
ThreadPool, Vec3,
};
use std::cell::RefCell;
use std::rc::Rc;
use std::sync::{mpsc, Arc, Mutex};
fn get_final_color(
... | code_fim | medium | {
"lang": "rust",
"repo": "elisvathi/rustracer",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let width = 640;
let height = 480;
let sphere_plane = Rc::new(Sphere::new(get_metal(), 100.0, Vec3::new(0.0, -100.0, 5.0)));
let mut scene = Scene::new();
scene.add_object(sphere_plane);
for _ in 0..10 {
let obj = gen_random_sphere();
scene.add_object(obj);
}
... | code_fim | medium | {
"lang": "rust",
"repo": "elisvathi/rustracer",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: GrossBetruger/RustPlaygound path: /matchers_and_patterns/src/main.rs
fn print_point(&(x, y): &(i32, i32)) { // the parameter is a pattern!
println!("x coord: '{}'", x);
println!("y coord: '{}'", y);
}
fn main() {
<|fim_suffix|>// let Some(x) = Some(3); // won't compile because 'l... | code_fim | hard | {
"lang": "rust",
"repo": "GrossBetruger/RustPlaygound",
"path": "/matchers_and_patterns/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> if let Some(_x) = Some(3) {
println!("this definitely compile because 'if let' requires a refutable pattern")
}
// if let x = 44 { } // no way... the pattern '44' is irrefutable
}<|fim_prefix|>// repo: GrossBetruger/RustPlaygound path: /matchers_and_patterns/src/main.rs
fn print... | code_fim | hard | {
"lang": "rust",
"repo": "GrossBetruger/RustPlaygound",
"path": "/matchers_and_patterns/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: minalear/minmarkdown path: /src/lib.rs
#[macro_use]
extern crate lazy_static;
mod parser;
pub fn to_html(markdown: &str) -> String {
parser::parse(markdown)
/*let bold_re = Regex::new(r"\*\*(.*?)*\*\*").unwrap();
let italic_re = Regex::new(r"\*(.*?)*\*").unwrap();
let strike_re = Rege... | code_fim | hard | {
"lang": "rust",
"repo": "minalear/minmarkdown",
"path": "/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // MD Tags
if line.begins_with("```") { // code section
group_type = GroupedTypes::Code;
}
else if line.begins_with("# ") { // H1 header
html.push_str(&format!("<h1>{}</h1>\n", line.replace("# ", "")));
} else if line.begins_with("#... | code_fim | hard | {
"lang": "rust",
"repo": "minalear/minmarkdown",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let rick_pathbuf : path::PathBuf = target_path
.join("debug")
.join(&format!("{}{}", env!("CARGO_PKG_NAME"), tinyrick::binary_suffix()));
let rick_path : &str = rick_pathbuf
.to_str()
.unwrap();
if list_tasks {
tinyrick::exec!(ric... | code_fim | hard | {
"lang": "rust",
"repo": "mcandre/tinyrick_extras",
"path": "/vendor/tinyrick/src/tinyrick.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mcandre/tinyrick_extras path: /vendor/tinyrick/src/tinyrick.rs
//! CLI tinyrick tool
extern crate getopts;
extern crate tinyrick;
use std::env;
use std::path;
use std::process;
// Show short CLI spec
fn usage(brief : &str, opts : &getopts::Options) {
println!("{}", (*opts).usage(brief));
... | code_fim | hard | {
"lang": "rust",
"repo": "mcandre/tinyrick_extras",
"path": "/vendor/tinyrick/src/tinyrick.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: potocpav/lv2 path: /src/ontology/classes/extui.rs
use std;
use rome::graph;
use rome::resource;
use rome::ontology_adapter;
use ontology;
class!(
/// **extui:Widget**
:"http://kxstudio.sf.net/ns/lv2ext/external-ui#Widget", Widget,
1);
impl<'g, G: 'g> ontology::<|fim_suffix|>gy::properties::ui::... | code_fim | medium | {
"lang": "rust",
"repo": "potocpav/lv2",
"path": "/src/ontology/classes/extui.rs",
"mode": "psm",
"license": "LicenseRef-scancode-warranty-disclaimer",
"source": "the-stack-v2"
} |
<|fim_suffix|>gy::properties::ui::PortNotification<'g> for resource::IRI<'g, Widget<'g, G>> where G: graph::Graph<'g> {}<|fim_prefix|>// repo: potocpav/lv2 path: /src/ontology/classes/extui.rs
use std;
use rome::graph;
use rome::resource;
use rome::ontology_adapter;
use ontology;
class!(
/// **extui:Widget**
:"http:/... | code_fim | medium | {
"lang": "rust",
"repo": "potocpav/lv2",
"path": "/src/ontology/classes/extui.rs",
"mode": "spm",
"license": "LicenseRef-scancode-warranty-disclaimer",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Daedalus359/proxygen path: /src/card/mod.rs
use super::error::ProxygenError;
use super::maud::PreEscaped;
use super::regex::Regex;
mod database;
use self::database::DATABASE;
#[derive(Deserialize, Debug)]
pub enum Card {
Creature {
name: String,
manacost: String,
... | code_fim | hard | {
"lang": "rust",
"repo": "Daedalus359/proxygen",
"path": "/src/card/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> ORACLE_RE.replace_all(text, "<i>$reminder</i>")
.lines()
.map(|line| format!("<p class=\"oracle_p\">{}</p>", line))
.collect()
}
fn break_manacost(manacost: &str) -> String {
MANACOST_RE.replace_all(manacost, "$symbol<wbr>")
}
fn base_inner_html(name: &str, manacost: &str... | code_fim | hard | {
"lang": "rust",
"repo": "Daedalus359/proxygen",
"path": "/src/card/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: clpi/dlog path: /src/cmd/record.rs
use crate::{
models::{
Entry, record::Record
}, cmd::Cmd,
};
use clap::{ArgMatches, FromArgMatches, Subcommand};
use colored::{Color, Colorize, Style, Styles};
#[derive(Debug)]
pub enum RecordCmd {
New(Option<Record>),
List
}
impl Defa... | code_fim | hard | {
"lang": "rust",
"repo": "clpi/dlog",
"path": "/src/cmd/record.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl RecordCmd {
fn new_cmd() -> clap::App<'static> {
clap::App::new("new")
.about("Create a new record")
.long_flag("new")
.short_flag('n')
.aliases(&["create", "init"])
.args(&[
clap::Arg::new("path")
... | code_fim | hard | {
"lang": "rust",
"repo": "clpi/dlog",
"path": "/src/cmd/record.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn prune(nodes: &mut [Node]) {
unsafe {
for meidx in 0..nodes.iter().len() {
let me = take_force(nodes, meidx);
if me.dist == 0 { continue; }
let expect = me.dist - 1;
me.edges.retain(|&x| take_force(nodes, x).dist == expect);
if !me.... | code_fim | hard | {
"lang": "rust",
"repo": "danielzgtg/hackerrank-university-codesprint-5-solutions",
"path": "/trip/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn main() {
let nodes: Vec<Node>;
let s: usize;
let f: usize;
{
let mut read = String::new();
let stdin_ = io::stdin();
let mut stdin = stdin_.lock();
stdin.read_line(&mut read).unwrap();
let graphsize: usize;
let numedges: usize;
{
... | code_fim | hard | {
"lang": "rust",
"repo": "danielzgtg/hackerrank-university-codesprint-5-solutions",
"path": "/trip/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: danielzgtg/hackerrank-university-codesprint-5-solutions path: /trip/src/main.rs
use std::io::{self, BufRead};
#[derive(Debug)]
struct Node {
edges: Vec<usize>,
revedges: Vec<usize>,
dist: usize,
name: char,
}
impl Node {
fn new(name: char) -> Node {
Node {
... | code_fim | hard | {
"lang": "rust",
"repo": "danielzgtg/hackerrank-university-codesprint-5-solutions",
"path": "/trip/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> gl::DrawElements(
gl::TRIANGLES,
count as _,
idx_size,
(idx_offset * mem::size_of::<DrawIdx>()) as _,
);
... | code_fim | hard | {
"lang": "rust",
"repo": "rsbm/fere",
"path": "/window/src/imgui_renderer.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rsbm/fere path: /window/src/imgui_renderer.rs
use imgui::{Context, Ui};
use std::mem;
/*
mod gl {
#![cfg_attr(feature = "cargo-clippy", allow(clippy::unreadable_literal, clippy::too_many_arguments, clippy::unused_unit))]
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
}
*/
use gl::typ... | code_fim | hard | {
"lang": "rust",
"repo": "rsbm/fere",
"path": "/window/src/imgui_renderer.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: lineCode/orizuru path: /examples/bench.rs
use orizuru::{Consumer, Producer};
use serde::{Deserialize, Serialize};
use std::process::Command;
use std::str::FromStr;
use std::time::{Duration, Instant};
use std::{process, thread};
#[derive(Deserialize, Serialize, Debug)]
struct Job {
id: usize... | code_fim | hard | {
"lang": "rust",
"repo": "lineCode/orizuru",
"path": "/examples/bench.rs",
"mode": "psm",
"license": "ISC",
"source": "the-stack-v2"
} |
<|fim_suffix|> thread::spawn(move || {
let pid = process::id();
let queue_name = "oppgave:default";
let client = redis::Client::open("redis://127.0.0.1/").unwrap();
let mut con = client.get_connection().unwrap();
let now = Instant::now();
loop {
let count... | code_fim | hard | {
"lang": "rust",
"repo": "lineCode/orizuru",
"path": "/examples/bench.rs",
"mode": "spm",
"license": "ISC",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn build(self, processor: Processor) -> DistanceField {
let input_field = self.input.source_field().unwrap(); // dangerous !
processor.processor.process(&input_field)
}
}
// TODO. this must be DistanceInput I guess and not PngInput
impl From<PngInput> for DistanceFieldBuilder {
fn from(input: ... | code_fim | medium | {
"lang": "rust",
"repo": "Karuma303/rs_sdf",
"path": "/src/data/builder.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>// TODO. this must be DistanceInput I guess and not PngInput
impl From<PngInput> for DistanceFieldBuilder {
fn from(input: PngInput) -> Self {
Self::new(Box::new(input))
}
}<|fim_prefix|>// repo: Karuma303/rs_sdf path: /src/data/builder.rs
use crate::data::DistanceField;
use crate::input::DistanceInp... | code_fim | hard | {
"lang": "rust",
"repo": "Karuma303/rs_sdf",
"path": "/src/data/builder.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Karuma303/rs_sdf path: /src/data/builder.rs
use crate::data::DistanceField;
use crate::input::DistanceInput;
use crate::processor::{Processor};
use crate::input::image::PngInput;
pub struct DistanceFieldBuilder {
input: Box<dyn DistanceInput>,
}
<|fim_suffix|> pub fn build(self, processor: Pr... | code_fim | medium | {
"lang": "rust",
"repo": "Karuma303/rs_sdf",
"path": "/src/data/builder.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl CliArgs {
pub fn book_dir(&self) -> &Path {
&self.book_dir
}
}<|fim_prefix|>// repo: poetry-book/poetry-book-cli path: /src/input/cli/cli_args.rs
use std::path::{Path, PathBuf};
<|fim_middle|>use structopt::StructOpt;
#[derive(StructOpt, Debug)]
pub struct CliArgs {
/// The pat... | code_fim | medium | {
"lang": "rust",
"repo": "poetry-book/poetry-book-cli",
"path": "/src/input/cli/cli_args.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: poetry-book/poetry-book-cli path: /src/input/cli/cli_args.rs
use std::path::{Path, PathBuf};
use structopt::StructOpt;
<|fim_suffix|>impl CliArgs {
pub fn book_dir(&self) -> &Path {
&self.book_dir
}
}<|fim_middle|>#[derive(StructOpt, Debug)]
pub struct CliArgs {
/// The pat... | code_fim | medium | {
"lang": "rust",
"repo": "poetry-book/poetry-book-cli",
"path": "/src/input/cli/cli_args.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: MarcusDunn/AoC-2020 path: /src/timer.rs
#[macro_use]
pub mod time {
#[macro_export]
macro_rules! timed {
($expr:expr) => {{
use std::time::System<|fim_suffix|>pr:expr, $message:literal) => {{
print!($message);
print!(" ");
timed!($e... | code_fim | hard | {
"lang": "rust",
"repo": "MarcusDunn/AoC-2020",
"path": "/src/timer.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> SystemTime::now().duration_since(start).unwrap().as_nanos()
);
result
}};
($expr:expr, $message:literal) => {{
print!($message);
print!(" ");
timed!($expr)
}};
}
}<|fim_prefix|>// repo: MarcusDunn/AoC-20... | code_fim | hard | {
"lang": "rust",
"repo": "MarcusDunn/AoC-2020",
"path": "/src/timer.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> client.batch_execute(
"
insert into practice_summary values (2, 'Trumpet', 60, '2020-11-24');
commit;
",
)?;
Ok(())
}<|fim_prefix|>// repo: alexei-ozerov/postgres-dev-setup path: /rust-postgres/src/main.rs
use postgres::{Client, Error, NoTls};
fn main() -> Result<(), Error> ... | code_fim | medium | {
"lang": "rust",
"repo": "alexei-ozerov/postgres-dev-setup",
"path": "/rust-postgres/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: alexei-ozerov/postgres-dev-setup path: /rust-postgres/src/main.rs
use postgres::{Client, Error, NoTls};
<|fim_suffix|> let mut client = Client::connect("postgresql://aozerov:0112@localhost/aozerov", NoTls)?;
client.batch_execute(
"
insert into practice_summary values (2, 'Trump... | code_fim | easy | {
"lang": "rust",
"repo": "alexei-ozerov/postgres-dev-setup",
"path": "/rust-postgres/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: gnoliyil/fuchsia path: /src/ui/testing/puppet/src/main.rs
// Copyright 2022 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use {
anyhow::{Error, Result},
fuchsia_component::server::Service... | code_fim | hard | {
"lang": "rust",
"repo": "gnoliyil/fuchsia",
"path": "/src/ui/testing/puppet/src/main.rs",
"mode": "psm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> fs.dir("svc").add_fidl_service(std::convert::identity);
fs.take_and_serve_directory_handle()?;
fs.for_each_concurrent(None, ui_puppet_lib::run_puppet_factory).await;
Ok(())
}<|fim_prefix|>// repo: gnoliyil/fuchsia path: /src/ui/testing/puppet/src/main.rs
// Copyright 2022 The Fuchsia Aut... | code_fim | hard | {
"lang": "rust",
"repo": "gnoliyil/fuchsia",
"path": "/src/ui/testing/puppet/src/main.rs",
"mode": "spm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut fs = ServiceFs::new_local();
fs.dir("svc").add_fidl_service(std::convert::identity);
fs.take_and_serve_directory_handle()?;
fs.for_each_concurrent(None, ui_puppet_lib::run_puppet_factory).await;
Ok(())
}<|fim_prefix|>// repo: gnoliyil/fuchsia path: /src/ui/testing/puppet/src... | code_fim | hard | {
"lang": "rust",
"repo": "gnoliyil/fuchsia",
"path": "/src/ui/testing/puppet/src/main.rs",
"mode": "spm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub(crate) fn decode(field: &FieldsUnnamed, ed: &Endin) -> (Vec<TokenStream>, Vec<TokenStream>) {
let mut values = Vec::new();
let mut fields = Vec::new();
for (i, field) in field.unnamed.iter().enumerate() {
let t = field::decode(field, ed);
values.push(t);
let f: Toke... | code_fim | hard | {
"lang": "rust",
"repo": "ywzjackal/bin_codec.rs",
"path": "/bin_codec_derive/src/codec/unnamed.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ywzjackal/bin_codec.rs path: /bin_codec_derive/src/codec/unnamed.rs
use super::field;
use crate::Endin;
use proc_macro2::TokenStream;
use quote::*;
use syn::*;
pub(crate) fn encode(field: &FieldsUnnamed, ed: &Endin) -> TokenStream {
let mut tokens = quote!();
for (i, field) in field.unn... | code_fim | hard | {
"lang": "rust",
"repo": "ywzjackal/bin_codec.rs",
"path": "/bin_codec_derive/src/codec/unnamed.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn i(&'a self::S: &S) {} //~ ERROR unexpected lifetime `'a` in pattern
}
fn main() {}<|fim_prefix|>// repo: IThawk/rust-project path: /rust-master/src/test/ui/self/self-vs-path-ambiguity.rs
// Check that `self::foo` is parsed as a general pattern and not a self argument.
<|fim_middle|>struct S;
im... | code_fim | medium | {
"lang": "rust",
"repo": "IThawk/rust-project",
"path": "/rust-master/src/test/ui/self/self-vs-path-ambiguity.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: IThawk/rust-project path: /rust-master/src/test/ui/self/self-vs-path-ambiguity.rs
// Check that `self::foo` is parsed as a general pattern and not a self argument.
struct S;
<|fim_suffix|> fn g(&self::S: &S) {}
fn h(&mut self::S: &mut S) {}
fn i(&'a self::S: &S) {} //~ ERROR unexpec... | code_fim | easy | {
"lang": "rust",
"repo": "IThawk/rust-project",
"path": "/rust-master/src/test/ui/self/self-vs-path-ambiguity.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub struct IR {
pub name: String,
pub instructions: Vec<Box<Instruction>>,
script_type: ScriptType,
state: LocalContext,
}
impl IR {
pub fn print(self, global_context: &GlobalContext) {
let mut f = fs::File::create(get_out_file_name(&self.name)).unwrap();
for inst in s... | code_fim | hard | {
"lang": "rust",
"repo": "x87/crust",
"path": "/src/disassembler/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: x87/crust path: /src/disassembler/mod.rs
pub mod scanner;
use crate::library::Command;
use crate::types;
use crate::types::*;
use std::collections::HashMap;
use std::convert::TryInto;
use std::io::prelude::*;
use std::{collections, fs, path};
use slugify::slugify;
#[derive(Default)]
pub stru... | code_fim | hard | {
"lang": "rust",
"repo": "x87/crust",
"path": "/src/disassembler/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Awpteamoose/ggj2021 path: /src/systems/item_move.rs
use crate::prelude::*;
#[system]
pub fn system(
mut drawers: Query<(Entity, &mut cmp::Drawer)>,
cursor_pos: Res<res::CursorPos>,
btns: Res<Input<MouseButton>>,
selected_drawer: Res<res::SelectedDrawer>,
sprites: Query<(Entity, &GlobalTran... | code_fim | hard | {
"lang": "rust",
"repo": "Awpteamoose/ggj2021",
"path": "/src/systems/item_move.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut transferred = false;
for (entity, mut drawer) in drawers.iter_mut() {
if let Some(selected_drawer_entity) = selected_drawer.0 {
if selected_drawer_entity == entity { continue; }
}
let (_, global_transform, sprite) = sprites.get(entity).unwrap();
if collide(*cursor_pos.a... | code_fim | hard | {
"lang": "rust",
"repo": "Awpteamoose/ggj2021",
"path": "/src/systems/item_move.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> if lost_items.1.is_empty() && item_request.0 == item.description && collide(*cursor_pos.as_ref(), vec2(0., -0.150625), vec2(0.18, 0.135)) {
commands.despawn_recursive(selected_item_entity);
transferred = true;
item_request.1 = true;
}
if !transferred {
if let Some((old_parent, co... | code_fim | hard | {
"lang": "rust",
"repo": "Awpteamoose/ggj2021",
"path": "/src/systems/item_move.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: pinkdevelops/fluvio-connectors path: /mqtt/src/error.rs
use fluvio::FluvioError;
use paho_mqtt::Error as MqttError;
use structopt::clap::Error as ClapError;
use thiserror::Error;
<|fim_suffix|> #[error("Clap Error: `{0:#?}`.")]
Clap(#[from] ClapError),
}<|fim_middle|>#[derive(Error, Debu... | code_fim | medium | {
"lang": "rust",
"repo": "pinkdevelops/fluvio-connectors",
"path": "/mqtt/src/error.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[error("Clap Error: `{0:#?}`.")]
Clap(#[from] ClapError),
}<|fim_prefix|>// repo: pinkdevelops/fluvio-connectors path: /mqtt/src/error.rs
use fluvio::FluvioError;
use paho_mqtt::Error as MqttError;
use structopt::clap::Error as ClapError;
use thiserror::Error;
<|fim_middle|>#[derive(Error, Debu... | code_fim | medium | {
"lang": "rust",
"repo": "pinkdevelops/fluvio-connectors",
"path": "/mqtt/src/error.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ramuuns/aoc path: /2018/23-1.rs
use std::fs::File;
use std::io::prelude::*;
//use std::collections::HashMap;
const NEW_LINE : u8 = 10;
/*
Read a file given by a filename and parse it to a vector of
whatever we need given a line_transform function
*/
fn get_input<T>(filename : &str, l... | code_fim | hard | {
"lang": "rust",
"repo": "ramuuns/aoc",
"path": "/2018/23-1.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut maxr_point = Point::new(0,0,0,0);
for point in input.clone() {
if point.r > maxr_point.r {
maxr_point = point;
}
}
let mut cnt = 0;
for point in input {
if distance(point,maxr_point) <= maxr_point.r {
cnt+=1;
}
}
... | code_fim | hard | {
"lang": "rust",
"repo": "ramuuns/aoc",
"path": "/2018/23-1.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let input = get_input("input-23", parse );
let mut maxr_point = Point::new(0,0,0,0);
for point in input.clone() {
if point.r > maxr_point.r {
maxr_point = point;
}
}
let mut cnt = 0;
for point in input {
if distance(point,maxr_point) <= maxr_... | code_fim | hard | {
"lang": "rust",
"repo": "ramuuns/aoc",
"path": "/2018/23-1.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: platonist0/club_coding path: /src/email.rs
use reqwest::header::{CONTENT_TYPE, HeaderName};
use std::io::{Error, ErrorKind};
/// URL for the Postmark email endpoint.
/// Should not change in the future,
/// but make sure it is updated if the
/// library does not work.
static URL: &'static str =... | code_fim | hard | {
"lang": "rust",
"repo": "platonist0/club_coding",
"path": "/src/email.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let client = reqwest::Client::new();
let mut res = match client.post(URL)
.header(CONTENT_TYPE, "application/json")
.header(HeaderName::from_static(POSTMARK_HEADER), self.postmark_token.clone())
.body(json)
.send() {
... | code_fim | hard | {
"lang": "rust",
"repo": "platonist0/club_coding",
"path": "/src/email.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub struct VertexBufferLayout {
pub elements: Vec<VertexBufferElement>,
pub stride: u32,
}
impl VertexBufferLayout {
pub fn new() -> Self {
VertexBufferLayout {
elements: Vec::new(),
stride: 0
}
}
pub fn push(&mut self, count: u32, e_type: GLenu... | code_fim | hard | {
"lang": "rust",
"repo": "ChristopherLR/gl-playground",
"path": "/src/buffer.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl VertexBufferElement {
pub fn get_size(&self) -> u32 {
match self.element_type {
gl::FLOAT => mem::size_of::<GLfloat>().try_into().unwrap(),
gl::BYTE => mem::size_of::<GLbyte>().try_into().unwrap(),
gl::INT => mem::size_of::<GLuint>().try_into().unwrap()... | code_fim | hard | {
"lang": "rust",
"repo": "ChristopherLR/gl-playground",
"path": "/src/buffer.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ChristopherLR/gl-playground path: /src/buffer.rs
use gl::{self, types::{ GLuint, GLfloat, GLbyte, GLenum, GLboolean }};
use std::mem;
use core::convert::TryInto;
use crate::Vertex;
pub trait BufferType {
fn buffer_type(&self) -> GLenum;
}
impl BufferType for f32 {
fn buffer_type(&self... | code_fim | hard | {
"lang": "rust",
"repo": "ChristopherLR/gl-playground",
"path": "/src/buffer.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: facundoolano/exercism path: /rust/clock/src/lib.rs
use std::fmt;
#[derive(Debug, PartialEq)]
pub struct Clock {
pub hours: i32,
pub minutes: i32,
}
impl Clock {
pub fn new(hours: i32, minutes: i32) -> Self {
Self {
hours: normalized_hours(hours, minutes),
... | code_fim | hard | {
"lang": "rust",
"repo": "facundoolano/exercism",
"path": "/rust/clock/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> write!(f, "{:02}:{:02}", self.hours, self.minutes)
}
}
fn normalized_hours(hours: i32, minutes: i32) -> i32 {
let hour_diff = if minutes < 0 && minutes % 60 != 0 {
-1 + minutes / 60
} else {
minutes / 60
};
modulo(hours + hour_diff, 24)
}
fn modulo(n: i32, div... | code_fim | hard | {
"lang": "rust",
"repo": "facundoolano/exercism",
"path": "/rust/clock/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> queue.insert(0,left.clone())
}
if let Some(right) = &root.right {
queue.insert(0,right.clone())
}
}
}
let v = (sum as f64) / (size as ... | code_fim | hard | {
"lang": "rust",
"repo": "haskell-monad/rust_algorithm",
"path": "/src/637.average-of-levels-in-binary-tree.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: haskell-monad/rust_algorithm path: /src/637.average-of-levels-in-binary-tree.rs
/*
* @lc app=leetcode id=637 lang=rust
*
* [637] Average of Levels in Binary Tree
*/
// @lc code=start
// Definition for a binary tree node.
// #[derive(Debug, PartialEq, Eq)]
// pub struct TreeNode {
// pub v... | code_fim | hard | {
"lang": "rust",
"repo": "haskell-monad/rust_algorithm",
"path": "/src/637.average-of-levels-in-binary-tree.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Example: http://localhost:8000/test2
pub fn listenurl(&self) -> &Option<String> {
&self.listenurl
}
/// Example: Unspecified description
pub fn server_description(&self) -> &Option<String> {
&self.server_description
}
/// Example: Unspecified name
pub ... | code_fim | hard | {
"lang": "rust",
"repo": "segler-alex/icecast-stats",
"path": "/src/icecast_source.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Example: 2021-04-09T21:49:52+0200
#[cfg(not(feature = "chrono"))]
pub fn stream_start_iso8601(&self) -> &Option<String> {
&self.stream_start_iso8601
}
/// HTTP user agent string as sent by the source client.
pub fn user_agent(&self) -> &Option<String> {
&self.u... | code_fim | hard | {
"lang": "rust",
"repo": "segler-alex/icecast-stats",
"path": "/src/icecast_source.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: segler-alex/icecast-stats path: /src/icecast_source.rs
#[cfg(feature = "chrono")]
use chrono::DateTime;
#[cfg(feature = "chrono")]
use chrono::Utc;
use serde::{Deserialize, Serialize};
/// A streaming source
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct IcecastStatsSource {
art... | code_fim | hard | {
"lang": "rust",
"repo": "segler-alex/icecast-stats",
"path": "/src/icecast_source.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.edge_list[src].clone()
}
pub fn bfs_traverse(&self, src: VertexId) -> Vec<VertexId> {
use queue::Queue;
use std::iter;
let mut visited: Vec<_> = iter::repeat(false).
take(self.vertices.len()).collect();
let mut queue = Queue::new();
... | code_fim | hard | {
"lang": "rust",
"repo": "Zach41/rust-algorithm-club",
"path": "/src/graph/list_graph.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Zach41/rust-algorithm-club path: /src/graph/list_graph.rs
use std::clone::Clone;
use std::fmt;
use super::{Vertex, Edge, VertexId};
pub struct AdjacencyListGraph<T> {
vertices: Vec<Vertex<T>>,
edge_list: Vec<Vec<Edge>>,
}
impl<T> fmt::Display for AdjacencyListGraph<T> {
fn fmt(&se... | code_fim | hard | {
"lang": "rust",
"repo": "Zach41/rust-algorithm-club",
"path": "/src/graph/list_graph.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> iyr:2010 hgt:158cm hcl:#b6652a ecl:blu byr:1944 eyr:2021 pid:093154719
";
assert_eq!(Solver::run_on(input).1, 4);
}
#[test]
fn invalid_part2() {
let input = "eyr:1972 cid:100
hcl:#18171d ecl:amb hgt:170 pid:186cm iyr:2018 byr:192... | code_fim | hard | {
"lang": "rust",
"repo": "knutwalker/aoc2020",
"path": "/src/day04.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: knutwalker/aoc2020 path: /src/day04.rs
use std::{
collections::HashMap,
ops::{Deref, DerefMut},
};
register!(
"input/day4.txt";
run(input: chunk String) -> usize {
run(input)
}
);
#[derive(Default, Debug)]
struct Passport(HashMap<String, String>);
impl Deref for Pa... | code_fim | hard | {
"lang": "rust",
"repo": "knutwalker/aoc2020",
"path": "/src/day04.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let input = "eyr:1972 cid:100
hcl:#18171d ecl:amb hgt:170 pid:186cm iyr:2018 byr:1926
iyr:2019
hcl:#602927 eyr:1967 hgt:170cm
ecl:grn pid:012533040 byr:1946
hcl:dab227 iyr:2012
... | code_fim | hard | {
"lang": "rust",
"repo": "knutwalker/aoc2020",
"path": "/src/day04.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>34cc6, 0x70d3d61, 0xeadac62, 0x12093dd0, 0x9add67d, 0x87200d6,
0x175bcbb, 0xb29b49f, 0x1806b79c, 0x12fb61f, 0x170b3a10, 0x3aaf1cf, 0xa224085, 0x79d26af, 0x97759e2,
0x92e19f1, 0xb32714d, 0x1f00d9f1, 0xc728619, 0x9e6f627, 0xe745e24, 0x18ea4ace, 0xfc60a41, 0x125f5b2,
0xc3cf512, 0x39ed486, 0xf4d15... | code_fim | hard | {
"lang": "rust",
"repo": "nfjBill/rust-gmsm",
"path": "/src/g2/consts.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: nfjBill/rust-gmsm path: /src/g2/consts.rs
pub const BOTTOM28BITS: u32 = 0xFFFFFFF;
pub const BOTTOM29BITS: u32 = 0x1FFFFFFF;
pub const BITSIZE: usize = 256;
pub const KEYBYTES: usize = (BITSIZE + 7) / 8;
pub const UNCOMPRESS: u8 = 0x04;
pub const DEFAULT_UID: [u8; 16] = [0x31, 0x32, 0x33, 0x34, ... | code_fim | hard | {
"lang": "rust",
"repo": "nfjBill/rust-gmsm",
"path": "/src/g2/consts.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: 0x28/aoc_2020 path: /src/bin/day18.rs
use aoc_2020::input_file;
use std::{fs, iter::Peekable, str::Chars};
fn eval_expr(stream: &mut Peekable<Chars>) -> u64 {
let mut result = 0;
let mut is_add = false;
let mut is_mul = false;
while let Some(c) = stream.peek() {
match c... | code_fim | hard | {
"lang": "rust",
"repo": "0x28/aoc_2020",
"path": "/src/bin/day18.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(eval_prec("1 + (2 * 3) + (4 * (5 + 6))"), 51);
assert_eq!(eval_prec("2 * 3 + (4 * 5)"), 46);
assert_eq!(eval_prec("5 + (8 * 3 + 9 + 3 * 4 * 3)"), 1445);
assert_eq!(
eval_prec("5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))"),
669060
);
assert_eq!(
eval... | code_fim | hard | {
"lang": "rust",
"repo": "0x28/aoc_2020",
"path": "/src/bin/day18.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut result = eval_add(stream);
while let Some(c) = stream.peek() {
match c {
'*' => {
stream.next();
}
')' => {
stream.next();
break;
}
_ => {
result *= eval_add... | code_fim | hard | {
"lang": "rust",
"repo": "0x28/aoc_2020",
"path": "/src/bin/day18.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn resize(&mut self) {
let mut buf = Self::allocate(max(2 * self.size(), 1));
unsafe {
ptr::copy_nonoverlapping(self.heap.as_mut_ptr(), buf.as_mut_ptr(), self.size());
}
self.j = 0;
self.heap = buf;
}
}
#[cfg(test)]
#[test]
fn array_deque_rotate... | code_fim | hard | {
"lang": "rust",
"repo": "cipepser/minna-data",
"path": "/chap2_Array-Based_Lists/q2_6/src/array_deque.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: cipepser/minna-data path: /chap2_Array-Based_Lists/q2_6/src/array_deque.rs
use common::traits::List;
use std::cmp::max;
use std::iter::repeat;
use std::ptr;
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ArrayDeque<T: Clone + PartialEq + Eq + Default + std::fmt::Debug> {
j: usiz... | code_fim | hard | {
"lang": "rust",
"repo": "cipepser/minna-data",
"path": "/chap2_Array-Based_Lists/q2_6/src/array_deque.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> Self::Inline
}
}
impl From<&str> for Display {
fn from(val: &str) -> Self {
match val {
"none" => Display::None,
"inherit" => Display::Inherit,
_ => Display::Inline,
}
}
}<|fim_prefix|>// repo: fredlim/canvas path: /packages/canvas/... | code_fim | easy | {
"lang": "rust",
"repo": "fredlim/canvas",
"path": "/packages/canvas/src-native/canvas-native/canvas-core/src/common/svg/enums/display.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: fredlim/canvas path: /packages/canvas/src-native/canvas-native/canvas-core/src/common/svg/enums/display.rs
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Display {
None,
Inline,
Inherit,
}
<|fim_suffix|> Self::Inline
}
}
impl From<&str> for Display {
fn from(val: ... | code_fim | easy | {
"lang": "rust",
"repo": "fredlim/canvas",
"path": "/packages/canvas/src-native/canvas-native/canvas-core/src/common/svg/enums/display.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> match val {
"none" => Display::None,
"inherit" => Display::Inherit,
_ => Display::Inline,
}
}
}<|fim_prefix|>// repo: fredlim/canvas path: /packages/canvas/src-native/canvas-native/canvas-core/src/common/svg/enums/display.rs
#[derive(Copy, Clone, De... | code_fim | medium | {
"lang": "rust",
"repo": "fredlim/canvas",
"path": "/packages/canvas/src-native/canvas-native/canvas-core/src/common/svg/enums/display.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: aixelent/rust-playground path: /http/src/main.rs
extern crate reqwest;
<|fim_suffix|> let req = reqwest::get("https://google.com").expect("").text().expect("");
println!("Response from google.com:\n{}", req);
}<|fim_middle|>// http://rosettacode.org/wiki/HTTP
fn main() {
| code_fim | easy | {
"lang": "rust",
"repo": "aixelent/rust-playground",
"path": "/http/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let req = reqwest::get("https://google.com").expect("").text().expect("");
println!("Response from google.com:\n{}", req);
}<|fim_prefix|>// repo: aixelent/rust-playground path: /http/src/main.rs
extern crate reqwest;
// http://rosettacode.org/wiki/HTTP
<|fim_middle|>fn main() {
| code_fim | easy | {
"lang": "rust",
"repo": "aixelent/rust-playground",
"path": "/http/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: TheLeonsver1/grand_strategy path: /src/game_world/settlements/marker_components.rs
//settlement markers
#[derive(Default)]
pub struct VillageMa<|fim_suffix|>uct DuchyMarker;
#[derive(Default)]
pub struct KingdomMarker;<|fim_middle|>rker;
#[derive(Default)]
pub struct BaronyMarker;
#[derive(Defau... | code_fim | medium | {
"lang": "rust",
"repo": "TheLeonsver1/grand_strategy",
"path": "/src/game_world/settlements/marker_components.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>efault)]
pub struct CountyMarker;
#[derive(Default)]
pub struct DuchyMarker;
#[derive(Default)]
pub struct KingdomMarker;<|fim_prefix|>// repo: TheLeonsver1/grand_strategy path: /src/game_world/settlements/marker_components.rs
//settlement markers
#[derive(Default)]
pub struct VillageMa<|fim_middle|>rker... | code_fim | medium | {
"lang": "rust",
"repo": "TheLeonsver1/grand_strategy",
"path": "/src/game_world/settlements/marker_components.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> println!("re-register event");
self.socket.reregister(poll, token, interest, opts)
}
fn deregister(&self, poll: &Poll) -> io::Result<()> {
println!("de-register event");
self.socket.deregister(poll)
}
}<|fim_prefix|>// repo: yukinagae/chat path: /src/server.rs... | code_fim | hard | {
"lang": "rust",
"repo": "yukinagae/chat",
"path": "/src/server.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: yukinagae/chat path: /src/server.rs
use std::io;
use mio::*;
use mio::tcp::{TcpListener, TcpStream};
use std::collections::HashMap;
use client::WebSocketClient;
//
// config
//
pub const SERVER: Token = Token(0);
//
// server
//
pub struct WebSocketServer {
pub socket: TcpListener,
pu... | code_fim | hard | {
"lang": "rust",
"repo": "yukinagae/chat",
"path": "/src/server.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> println!("register event");
self.socket.register(poll, token, interest, opts)
}
fn reregister(&self, poll: &Poll, token: Token, interest: Ready, opts: PollOpt) -> io::Result<()> {
println!("re-register event");
self.socket.reregister(poll, token, interest, opts)
... | code_fim | hard | {
"lang": "rust",
"repo": "yukinagae/chat",
"path": "/src/server.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mbillingr/lisp-in-small-pieces path: /07-compilation/vm/src/types/opaque.rs
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct OpaquePointer(usize);
<|fim_suffix|>}
impl OpaqueCast for usize {
unsafe fn from_op(op: OpaquePointer) -> Self {
op.0
}
fn as_op(&self) -> Opaque... | code_fim | hard | {
"lang": "rust",
"repo": "mbillingr/lisp-in-small-pieces",
"path": "/07-compilation/vm/src/types/opaque.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn as_op(&self) -> OpaquePointer {
OpaquePointer(*self)
}
}<|fim_prefix|>// repo: mbillingr/lisp-in-small-pieces path: /07-compilation/vm/src/types/opaque.rs
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct OpaquePointer(usize);
impl OpaquePointer {
pub fn new(addr: usize) -> Self... | code_fim | hard | {
"lang": "rust",
"repo": "mbillingr/lisp-in-small-pieces",
"path": "/07-compilation/vm/src/types/opaque.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: saghm/sea-canal path: /src/stepper.rs
pub struct Stepper {
start: usize,
end: usize,
step: usize
}
impl Stepper {
pub fn new(start: usize, end: usize, step: usize) -> Self {
Stepper { start: start, end: end, step: step }
}
}
<|fim_suffix|>#[macro_export]
macro_rules... | code_fim | hard | {
"lang": "rust",
"repo": "saghm/sea-canal",
"path": "/src/stepper.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let next = self.start;
self.start += self.step;
Some(next)
}
}
#[macro_export]
macro_rules! step {
($start:expr => $end:expr; $step:expr) => { Stepper::new($start, $end, $step).into_iter() }
}<|fim_prefix|>// repo: saghm/sea-canal path: /src/stepper.rs
pub struct Stepper... | code_fim | medium | {
"lang": "rust",
"repo": "saghm/sea-canal",
"path": "/src/stepper.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mid = low + ((high - low) >> 1);
if nums[mid] == value { return mid as i32; }
if nums[mid] < value {
return _recursion(nums, mid+1, high, value);
} else {
return _recursion(nums, low, mid-1, value);
}
}
fn main() {
let nums1 = vec![8,11,19,23,27,33,45,55,67,98... | code_fim | medium | {
"lang": "rust",
"repo": "kongqiwei/algo",
"path": "/rust/15_binary_search/binary_search.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: kongqiwei/algo path: /rust/15_binary_search/binary_search.rs
// 二分查找
pub fn binary_search(nums: Vec<i32>, value: i32) -> i32 {
if nums.is_empty() { return -1; }
let mut low = 0;
let mut high = nums.len() - 1;
while low <= high {
let mid = low + ((high - low) >> 1);
... | code_fim | hard | {
"lang": "rust",
"repo": "kongqiwei/algo",
"path": "/rust/15_binary_search/binary_search.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: lsearl-thumpdataworks/datcom path: /src/utility/quad.rs
/// -----
/// File: /src/utility/quad.rs
/// Project: datcon
/// File Created: Wednesday, 14th Nov 182018 10:58:34 pm
/// Author: Leon S. Searl
///
/// Last Modified: Wednesday, 14th November 2018 10:58:36 pm
/// Modified By: Leon ... | code_fim | hard | {
"lang": "rust",
"repo": "lsearl-thumpdataworks/datcom",
"path": "/src/utility/quad.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let (y, slope) = utility::quad::quad(x, &xa, &ya);
//println!("y={}", y);
//println!("slope={}", slope);
assert!(y == 1.5f32);
assert!(slope == 1.0f32);
}
#[test]
fn line_between_upper_2points() {
let xa: Vec<f32> = vec![2.0f32, 3.0f32, 4.0f32];
... | code_fim | hard | {
"lang": "rust",
"repo": "lsearl-thumpdataworks/datcom",
"path": "/src/utility/quad.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn entity_color(entity_status: &EntityStatus) -> Color {
let mut color = Color::RGB(100, 100, 100);
if let Awareness::Aware(_) = entity_status.is_aware {
color = Color::RGB(0, 0, 170);
}
if entity_status.is_infected {
color = Color::RGB(170, 0, 0);
}
return colo... | code_fim | hard | {
"lang": "rust",
"repo": "JunkuiZhang/covid_rust",
"path": "/src/game/game_systems.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: JunkuiZhang/covid_rust path: /src/game/game_systems.rs
use rand::prelude::ThreadRng;
use rand::Rng;
use sdl2::pixels::Color;
use crate::game::game_data::Vector;
use crate::settings::AWARE_RADIUS;
use crate::settings::INFECTION_CHANCE;
use crate::settings::NOT_AWARE_ENTITY_MOVE_MUL;
use crate::s... | code_fim | hard | {
"lang": "rust",
"repo": "JunkuiZhang/covid_rust",
"path": "/src/game/game_systems.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: nushell/nushell path: /crates/nu-protocol/src/engine/overlay.rs
use crate::{DeclId, ModuleId, OverlayId, VarId};
use std::collections::HashMap;
pub static DEFAULT_OVERLAY_NAME: &str = "zero";
/// Tells whether a decl is visible or not
#[derive(Debug, Clone)]
pub struct Visibility {
decl_id... | code_fim | hard | {
"lang": "rust",
"repo": "nushell/nushell",
"path": "/crates/nu-protocol/src/engine/overlay.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.active_overlays
.iter()
.filter(|id| !removed_overlays.contains(self.get_overlay_name(**id)))
.copied()
.collect()
}
pub fn active_overlays<'a, 'b>(
&'b self,
removed_overlays: &'a mut Vec<Vec<u8>>,
) -> impl DoubleE... | code_fim | hard | {
"lang": "rust",
"repo": "nushell/nushell",
"path": "/crates/nu-protocol/src/engine/overlay.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: TrustedDataFramework/smart-contract-rust-exmaple path: /wbi/src/db.rs
use alloc::vec::Vec;
use crate::{forget, remember};
use alloc::string::*;
use core::marker::PhantomData;
pub struct Store<K, V> {
prefix: String,
phantom_0: PhantomData<K>,
phantom_1: PhantomData<V>,
}
macro_rule... | code_fim | hard | {
"lang": "rust",
"repo": "TrustedDataFramework/smart-contract-rust-exmaple",
"path": "/wbi/src/db.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.