text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_prefix|>// repo: clumsy/rsrl path: /rsrl/src/control/gtd/greedy_gq.rs
use crate::{
OnlineLearner, Shared, make_shared,
control::Controller,
domains::Transition,
fa::{
Weights, WeightsView, WeightsViewMut, Parameterised,
StateFunction, StateActionFunction, EnumerableStateActionFunc... | code_fim | hard | {
"lang": "rust",
"repo": "clumsy/rsrl",
"path": "/rsrl/src/control/gtd/greedy_gq.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.fa_q.evaluate(s, a)
}
}
impl<S, Q, W, PB> Controller<S, PB::Action> for GreedyGQ<Q, W, PB>
where
Q: EnumerableStateActionFunction<S>,
PB: EnumerablePolicy<S>,
{
fn sample_target(&self, rng: &mut impl Rng, s: &S) -> PB::Action {
self.target_policy.sample(rng, s)
}
... | code_fim | hard | {
"lang": "rust",
"repo": "clumsy/rsrl",
"path": "/rsrl/src/control/gtd/greedy_gq.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: carbonatedcaffeine/zircon-rpi path: /src/sys/lib/topology_builder/src/lib.rs
le license that can be
// found in the LICENSE file.
use {
crate::error::*,
cm_rust::{self, NativeIntoFidl},
fidl::endpoints::create_proxy,
fidl_fuchsia_data as fdata, fidl_fuchsia_io as fio, fidl_fuchs... | code_fim | hard | {
"lang": "rust",
"repo": "carbonatedcaffeine/zircon-rpi",
"path": "/src/sys/lib/topology_builder/src/lib.rs",
"mode": "psm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Adds a new mocked component to the topology. When the component is supposed to run the
/// provided [`Mock`] is called with the component's handles.
pub async fn add_mocked_component(
&mut self,
moniker: Moniker,
mock: mock::Mock,
) -> Result<(), Error> {
... | code_fim | hard | {
"lang": "rust",
"repo": "carbonatedcaffeine/zircon-rpi",
"path": "/src/sys/lib/topology_builder/src/lib.rs",
"mode": "spm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> let root_decl = ComponentDecl {
offers: vec![OfferDecl::Protocol(OfferProtocolDecl {
source: OfferSource::Parent,
source_name: "fidl.examples.routing.echo.Echo".try_into().unwrap(),
target: OfferTarget::Child("a".to_string()),
... | code_fim | hard | {
"lang": "rust",
"repo": "carbonatedcaffeine/zircon-rpi",
"path": "/src/sys/lib/topology_builder/src/lib.rs",
"mode": "spm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> let meta_id = encode(&meta_id_digest);
(meta_id, title_trimmed, extra_trimmed)
}
/// Trim text such that its UTF-8 encoded byte representation does not exceed
/// 128-bytes each. Remove leading and trailing whitespace.
pub fn text_trim(text: &str) -> String {
let input_trim = text.len().min(I... | code_fim | hard | {
"lang": "rust",
"repo": "iscc/iscc-rs",
"path": "/src/mid.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: iscc/iscc-rs path: /src/mid.rs
//! Meta-ID
use crate::base58::encode;
use crate::hashes::{similarity_hash, sliding_window, xxhash64};
use crate::normalization::text_normalize;
const WINDOW_SIZE_MID: usize = 4;
const HEAD_MID: u8 = 0x00;
const INPUT_TRIM: usize = 128;
/// The Meta-ID component ... | code_fim | hard | {
"lang": "rust",
"repo": "iscc/iscc-rs",
"path": "/src/mid.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_trim_text() {
let multibyte_2 = "ü".repeat(128);
let trimmed = text_trim(&multibyte_2);
assert_eq!(trimmed.chars().count(), 64);
assert_eq!(trimmed.len(), 128);
let multibyte_3 = "驩".repeat(128);
... | code_fim | hard | {
"lang": "rust",
"repo": "iscc/iscc-rs",
"path": "/src/mid.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>async fn index(req: HttpRequest, stream: web::Payload) -> Result<HttpResponse, Error> {
let resp = ws::start(ClientSession::new(), &req, stream);
println!("{:?}", resp);
resp
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
... | code_fim | medium | {
"lang": "rust",
"repo": "atkak/toy-webrtc-signaling",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: atkak/toy-webrtc-signaling path: /src/main.rs
use actix_files::Files;
use actix_web::{web, App, Error, HttpRequest, HttpResponse, HttpServer};
use actix_web_actors::ws;
<|fim_suffix|>async fn index(req: HttpRequest, stream: web::Payload) -> Result<HttpResponse, Error> {
let resp = ws::start... | code_fim | medium | {
"lang": "rust",
"repo": "atkak/toy-webrtc-signaling",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: inact1v1ty/pathtracer-rs path: /src/camera.rs
use crate::ray::Ray;
use crate::vec3::Vec3;
use crate::util::local_rng;
use rand::Rng;
#[derive(Debug, Clone)]
pub struct Camera {
pub lower_left: Vec3,
pub horizontal: Vec3,
pub vertical: Vec3,
pub origin: Vec3,
pub lens_radius... | code_fim | hard | {
"lang": "rust",
"repo": "inact1v1ty/pathtracer-rs",
"path": "/src/camera.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn random_in_unit_disk() -> Vec3 {
let mut rng = local_rng();
let mut p: Vec3;
loop {
p = Vec3::new(rng.gen_range(-1.0..=1.0), rng.gen_range(-1.0..=1.0), 0.0);
if Vec3::dot(p, p) < 1.0 {
break;
}
}
p
}<|fim_prefix|>// repo: inact1v1ty/pathtracer-... | code_fim | hard | {
"lang": "rust",
"repo": "inact1v1ty/pathtracer-rs",
"path": "/src/camera.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>nk.capnp")
.file("carsales.capnp")
.run()
.expect("compiling schemas");
}<|fim_prefix|>// repo: capnproto/capnproto-rust path: /benchmark/build.rs
fn main() {
::capnpc::CompilerCommand::new()<|fim_middle|>
.file("eval.capnp")
.file("catra | code_fim | easy | {
"lang": "rust",
"repo": "capnproto/capnproto-rust",
"path": "/benchmark/build.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> .run()
.expect("compiling schemas");
}<|fim_prefix|>// repo: capnproto/capnproto-rust path: /benchmark/build.rs
fn main() {
::capnpc::CompilerCommand::new()<|fim_middle|>
.file("eval.capnp")
.file("catrank.capnp")
.file("carsales.capnp")
| code_fim | medium | {
"lang": "rust",
"repo": "capnproto/capnproto-rust",
"path": "/benchmark/build.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: capnproto/capnproto-rust path: /benchmark/build.rs
fn main() {
::capnpc::CompilerCommand::new()<|fim_suffix|>nk.capnp")
.file("carsales.capnp")
.run()
.expect("compiling schemas");
}<|fim_middle|>
.file("eval.capnp")
.file("catra | code_fim | easy | {
"lang": "rust",
"repo": "capnproto/capnproto-rust",
"path": "/benchmark/build.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>ypeRef
(
)
port_ref
.
as_mut_ptr
(
)
)
}
;
result_from_status
(
status
|
|
{
let
port_ref
=
unsafe
{
port_ref
.
assume_init
(
)
}
;
OutputPort
{
port
:
Port
{
object
:
Object
(
port_ref
)
}
}
}
)
}
/
/
/
Creates
an
input
port
through
which
the
client
may
receive
incoming
MIDI
messages
from
any
MIDI
source... | code_fim | hard | {
"lang": "rust",
"repo": "marco-c/gecko-dev-wordified",
"path": "/third_party/rust/coremidi/src/client.rs",
"mode": "spm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: marco-c/gecko-dev-wordified path: /third_party/rust/coremidi/src/client.rs
use
core_foundation
:
:
{
base
:
:
{
OSStatus
TCFType
}
string
:
:
CFString
}
;
use
coremidi_sys
:
:
{
MIDIClientCreate
MIDIClientDispose
MIDIDestinationCreate
MIDIInputPortCreate
MIDINotification
MIDIOutputPortCreate
MID... | code_fim | hard | {
"lang": "rust",
"repo": "marco-c/gecko-dev-wordified",
"path": "/third_party/rust/coremidi/src/client.rs",
"mode": "psm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_suffix|>)
}
}
}
)
}
/
/
/
Creates
a
virtual
destination
in
the
client
.
/
/
/
See
[
MIDIDestinationCreate
]
(
https
:
/
/
developer
.
apple
.
com
/
reference
/
coremidi
/
1495347
-
mididestinationcreate
)
.
/
/
/
pub
fn
virtual_destination
<
F
>
(
&
self
name
:
&
str
callback
:
F
)
-
>
Result
<
VirtualDestination... | code_fim | hard | {
"lang": "rust",
"repo": "marco-c/gecko-dev-wordified",
"path": "/third_party/rust/coremidi/src/client.rs",
"mode": "spm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_suffix|> counter!("processing_errors_total", 1, "error_type" => "failed_serialize");
}
}<|fim_prefix|>// repo: imorph/vector path: /src/internal_events/metric_to_log.rs
use super::InternalEvent;
use metrics::counter;
use serde_json::Error;
#[derive(Debug)]
pub(crate) struct MetricToLogFailedSerialize... | code_fim | medium | {
"lang": "rust",
"repo": "imorph/vector",
"path": "/src/internal_events/metric_to_log.rs",
"mode": "spm",
"license": "MPL-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: imorph/vector path: /src/internal_events/metric_to_log.rs
use super::InternalEvent;
use metrics::counter;
use serde_json::Error;
#[derive(Debug)]
pub(crate) struct MetricToLogFailedSerialize {
pub error: Error,
}
<|fim_suffix|> counter!("processing_errors_total", 1, "error_type" => ... | code_fim | hard | {
"lang": "rust",
"repo": "imorph/vector",
"path": "/src/internal_events/metric_to_log.rs",
"mode": "psm",
"license": "MPL-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rust-lang/rust path: /library/core/src/async_iter/async_iter.rs
use crate::ops::DerefMut;
use crate::pin::Pin;
use crate::task::{Context, Poll};
/// A trait for dealing with asynchronous iterators.
///
/// This is the main async iterator trait. For more about the concept of async iterators
/// ... | code_fim | hard | {
"lang": "rust",
"repo": "rust-lang/rust",
"path": "/library/core/src/async_iter/async_iter.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn size_hint(&self) -> (usize, Option<usize>) {
(**self).size_hint()
}
}
#[unstable(feature = "async_iterator", issue = "79024")]
impl<P> AsyncIterator for Pin<P>
where
P: DerefMut,
P::Target: AsyncIterator,
{
type Item = <P::Target as AsyncIterator>::Item;
fn poll_next(s... | code_fim | hard | {
"lang": "rust",
"repo": "rust-lang/rust",
"path": "/library/core/src/async_iter/async_iter.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: manuel-woelker/tantivy-server path: /src/errors.rs
error_chain! {
links {
}
foreign_links {
Io(::std::io::Error) #[doc = "Link to a `std::error::Error` type."];
EnvVar(::std::env::VarError) #[doc = "Link to a `std::env::VarError` type."];
Hyper(::hyper::Error)... | code_fim | medium | {
"lang": "rust",
"repo": "manuel-woelker/tantivy-server",
"path": "/src/errors.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> iron::IronError::new(self, iron::status::InternalServerError)
}
}<|fim_prefix|>// repo: manuel-woelker/tantivy-server path: /src/errors.rs
error_chain! {
links {
}
foreign_links {
Io(::std::io::Error) #[doc = "Link to a `std::error::Error` type."];
EnvVar(::std::en... | code_fim | medium | {
"lang": "rust",
"repo": "manuel-woelker/tantivy-server",
"path": "/src/errors.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl PrettyPrint for Expr {
fn to_doc(&self) -> RcDoc<()> {
match self {
Expr::Term(term) => term.to_doc(),
Expr::Tup(tup) => tup.to_doc().parens(),
}
}
}
impl PrettyPrint for OpCall {
fn to_doc(&self) -> RcDoc<()> {
RcDoc::as_string(self.op())
... | code_fim | hard | {
"lang": "rust",
"repo": "AnisHamadouche/reticle",
"path": "/src/langs/ir/src/pretty_print.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: AnisHamadouche/reticle path: /src/langs/ir/src/pretty_print.rs
use crate::ast::*;
use itertools::Itertools;
use prettyprint::{block_with_braces, intersperse, PrettyHelper, PrettyPrint, RcDoc};
fn term_names(term: &ExprTerm) -> RcDoc<()> {
match term {
ExprTerm::Any => RcDoc::text("_... | code_fim | hard | {
"lang": "rust",
"repo": "AnisHamadouche/reticle",
"path": "/src/langs/ir/src/pretty_print.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tillrohrmann/rust-challenges path: /aoc14/src/bin/main.rs
use aoc14::Recipes;
fn main() {
// solve_part_one();
solve_part_two();
}
fn solve_part_one() {
let mut recipes = Recipes::new();
println!("{:?}", recipes.find_recipes_after(236021, 10));
}
<|fim_suffix|> let mut recip... | code_fim | easy | {
"lang": "rust",
"repo": "tillrohrmann/rust-challenges",
"path": "/aoc14/src/bin/main.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut recipes = Recipes::new();
println!("{:?}", recipes.find_recipes_after(236021, 10));
}
fn solve_part_two() {
let mut recipes = Recipes::new();
println!("{}", recipes.number_recipes_until_sequence(&[2,3,6,0,2,1]));
}<|fim_prefix|>// repo: tillrohrmann/rust-challenges path: /aoc14/s... | code_fim | easy | {
"lang": "rust",
"repo": "tillrohrmann/rust-challenges",
"path": "/aoc14/src/bin/main.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut recipes = Recipes::new();
println!("{}", recipes.number_recipes_until_sequence(&[2,3,6,0,2,1]));
}<|fim_prefix|>// repo: tillrohrmann/rust-challenges path: /aoc14/src/bin/main.rs
use aoc14::Recipes;
fn main() {
// solve_part_one();
solve_part_two();
}
<|fim_middle|>fn solve_part_... | code_fim | medium | {
"lang": "rust",
"repo": "tillrohrmann/rust-challenges",
"path": "/aoc14/src/bin/main.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Applies a given block to the `BlockStorage`.
pub fn apply_to_block_storage(&self, block: &Block) {
// Write Block to BlockStorage
self.block_storage.write_block(block).unwrap();
}
/// Applies a given block to the `WorldState`.
pub async fn apply_to_worldstate(&self... | code_fim | hard | {
"lang": "rust",
"repo": "dfriedenberger/Prellblock",
"path": "/prellblock/src/consensus/transaction_applier.rs",
"mode": "spm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Applies a given to both the `world_state` and the `block_storage`.
pub async fn apply_block(&self, block: Block) {
// Write Block to BlockStorage
self.apply_to_block_storage(&block);
// Write Block to WorldState
self.apply_to_worldstate(block).await;
}
... | code_fim | hard | {
"lang": "rust",
"repo": "dfriedenberger/Prellblock",
"path": "/prellblock/src/consensus/transaction_applier.rs",
"mode": "spm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dfriedenberger/Prellblock path: /prellblock/src/consensus/transaction_applier.rs
//! Can be used by any consensus algorithm to apply blocks.
use super::Block;
use crate::{block_storage::BlockStorage, world_state::WorldStateService};
/// Helps to apply transactions onto the `BlockStorage` and `... | code_fim | hard | {
"lang": "rust",
"repo": "dfriedenberger/Prellblock",
"path": "/prellblock/src/consensus/transaction_applier.rs",
"mode": "psm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_suffix|>leTimelineMessagePortOperationType {
SerializeData = "serializeData",
DeserializeData = "deserializeData",
}<|fim_prefix|>// repo: rustwasm/wasm-bindgen path: /crates/web-sys/src/features/gen_ProfileTimelineMessagePortOperationType.rs
#![allow(unused_imports)]
#![allow(clippy::all)]
use wasm_bind... | code_fim | hard | {
"lang": "rust",
"repo": "rustwasm/wasm-bindgen",
"path": "/crates/web-sys/src/features/gen_ProfileTimelineMessagePortOperationType.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rustwasm/wasm-bindgen path: /crates/web-sys/src/features/gen_ProfileTimelineMessagePortOperationType.rs
#![allow(unused_imports)]
#![allow(clippy::all)]
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
#[doc = "The `Profile<|fim_suffix|> activated: `ProfileTimelineMessagePortOperationType`*"]
#[der... | code_fim | medium | {
"lang": "rust",
"repo": "rustwasm/wasm-bindgen",
"path": "/crates/web-sys/src/features/gen_ProfileTimelineMessagePortOperationType.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rnbwdsh/hashcode2020 path: /src/io.rs
extern crate bit_vec; //https://docs.rs/bit-vec/0.6.1/bit_vec/
use bit_vec::BitVec;
use crate::Library;
use crate::library::Count;
use std::fs;
use std::option::NoneError;
pub fn read_file(filename: &str) -> Result<(u32, u32, Vec<u32>, Vec<Library>), NoneEr... | code_fim | medium | {
"lang": "rust",
"repo": "rnbwdsh/hashcode2020",
"path": "/src/io.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn write_solution(score: u64, used_libs: Vec<usize>, used_books: Vec<BitVec>, filename: &str) {
fs::create_dir(format!("solutions/{}", filename)).ok(); // ignore if creating a directory fails
let path = format!("solutions/{}/{}.txt", filename, score.to_string());
let nr_books = used_libs.... | code_fim | hard | {
"lang": "rust",
"repo": "rnbwdsh/hashcode2020",
"path": "/src/io.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let nr_books = used_libs.len().to_string();
let rest = used_libs.iter().zip(used_books.iter()).map(| (lib, books)|
format!("{} {}\n{}", lib, books.count_ones(), books
.clone()
.to_vec()
.iter()
.map(|x| x.to_string())
.collect::<V... | code_fim | hard | {
"lang": "rust",
"repo": "rnbwdsh/hashcode2020",
"path": "/src/io.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let pod: Pod = pods.get(pod_name).await?;
if let Some(spec) = pod.spec {
Ok(format!("{:#?}", spec))
} else {
Ok(String::new())
}
}<|fim_prefix|>// repo: JonnyWalker81/ice-kube path: /src/util.rs
use anyhow::Result;
use k8s_openapi::api::core::v1::Pod;
use kube::{api::List... | code_fim | hard | {
"lang": "rust",
"repo": "JonnyWalker81/ice-kube",
"path": "/src/util.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let pods: Api<Pod> = Api::namespaced(client, namespace);
let pod: Pod = pods.get(pod_name).await?;
if let Some(spec) = pod.spec {
Ok(format!("{:#?}", spec))
} else {
Ok(String::new())
}
}<|fim_prefix|>// repo: JonnyWalker81/ice-kube path: /src/util.rs
use anyhow::Res... | code_fim | hard | {
"lang": "rust",
"repo": "JonnyWalker81/ice-kube",
"path": "/src/util.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: JonnyWalker81/ice-kube path: /src/util.rs
use anyhow::Result;
use k8s_openapi::api::core::v1::Pod;
use kube::{api::ListParams, config::Kubeconfig, Api, Client, Config};
pub trait OptionEx {
fn to_str(&self) -> String;
}
impl OptionEx for Option<String> {
fn to_str(&self) -> String {
... | code_fim | hard | {
"lang": "rust",
"repo": "JonnyWalker81/ice-kube",
"path": "/src/util.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let v1: Vec<i32> = vec![1, 2, 3];
let v2: Vec<_> = v1.iter().map(|x| x + 1).collect();
assert_eq!(v2, vec![2, 3, 4]);
}<|fim_prefix|>// repo: namtx-0867/reading-rust-programming path: /chapter_13/capture_env/src/main.rs
fn main() {
let x = 4;
let equal_to_x = |z| z == x;
let y = ... | code_fim | medium | {
"lang": "rust",
"repo": "namtx-0867/reading-rust-programming",
"path": "/chapter_13/capture_env/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: namtx-0867/reading-rust-programming path: /chapter_13/capture_env/src/main.rs
fn main() {
let x = 4;
let equal_to_x = |z| z == x;
let y = 4;
assert!(equal_to_x(y));
// x is captured
let v = vec![1, 2, 3];
let equal_to_v = move |z| z == v;
// println!("can't... | code_fim | medium | {
"lang": "rust",
"repo": "namtx-0867/reading-rust-programming",
"path": "/chapter_13/capture_env/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: williamtu/flow-rust path: /src/flow.rs
use crate::types::*;
use std::mem;
use std::slice;
pub const FLOW_TNL_F_UDPIF : u16 = (1 << 4);
/* Fragment bits, used for IPv4 and IPv6, always zero for non-IP flows. */
pub const FLOW_NW_FRAG_ANY: u8 = (1 << 0); /* Set for any IP frag. */
pub const FLO... | code_fim | hard | {
"lang": "rust",
"repo": "williamtu/flow-rust",
"path": "/src/flow.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl flow_tnl {
pub fn dst_is_set(&self) -> bool {
return self.ip_dst != 0 || self.ipv6_dst.ipv6_addr_is_set();
}
pub fn as_u64_slice(&self) -> &[u64] {
unsafe {
slice::from_raw_parts(self as *const Self as *const u64,
mem::size_of... | code_fim | hard | {
"lang": "rust",
"repo": "williamtu/flow-rust",
"path": "/src/flow.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut file_exists = false;
//If the file opens, it exists. If there is an error, it doesn't.
match File::open("iplog.bin"){
Ok(attr) => {file_exists = true;},
Err(_) => {}
};
if file_exists {
//Opens file and saves contents to string vector
let mut file = File::open("iplog.bin").unwrap();
... | code_fim | hard | {
"lang": "rust",
"repo": "tobywhughes/PieCoin",
"path": "/src/tcp.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tobywhughes/PieCoin path: /src/tcp.rs
extern crate serde;
extern crate bincode;
use bincode::{serialize, deserialize, deserialize_from, serialize_into, Infinite};
use std::io::prelude::*;
use std::net::{TcpListener, TcpStream, SocketAddrV4, Ipv4Addr};
use std::thread;
use std::fs::File;
use std... | code_fim | hard | {
"lang": "rust",
"repo": "tobywhughes/PieCoin",
"path": "/src/tcp.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dark64/zokrates_wasm_resolver_playground path: /src/lib.rs
use wasm_bindgen::prelude::*;
type Location = String;
// the path to a file, just for clarity here
type Path = String;
// some zokrates source, just for clarity
type Source = String;
#[wasm_bindgen]
pub struct ResolverResult {
so... | code_fim | hard | {
"lang": "rust",
"repo": "dark64/zokrates_wasm_resolver_playground",
"path": "/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> l: Location,
p: Path,
) -> Result<(Source, Location), zokrates_core::imports::Error> {
let res = resolve(l, p.to_string());
Ok((res.source, res.location))
};
// we call the zokrates compile function with our closure
compile_core::<FieldPrime, _>(
so... | code_fim | hard | {
"lang": "rust",
"repo": "dark64/zokrates_wasm_resolver_playground",
"path": "/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>// generic things, were in the template I used for this
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
// This is like the `main` function, except for JavaScript.
#[wasm_bindgen(start)]
pub fn main_js() -> Result<(), JsValue> {
// This... | code_fim | hard | {
"lang": "rust",
"repo": "dark64/zokrates_wasm_resolver_playground",
"path": "/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> Ok(Some(chapter))
}
#[allow(clippy::unnecessary_operation, clippy::unit_arg)]
#[tracing::instrument(level = "trace", skip(self, _pre, _main, _post), err)]
pub async fn update_chapter(
&self,
story_id: Cow<'static, str>,
chapter_number: i32,
_pre: Co... | code_fim | medium | {
"lang": "rust",
"repo": "Txuritan/stry",
"path": "/stry-backend-postgres/src/chapter.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Txuritan/stry path: /stry-backend-postgres/src/chapter.rs
use {crate::PostgresBackend, std::borrow::Cow, stry_models::Chapter};
/// Handles any and all queries that deal with a Story's Chapters.
#[cfg_attr(feature = "boxed-futures", stry_macros::box_async)]
impl PostgresBackend {
#[tracing:... | code_fim | hard | {
"lang": "rust",
"repo": "Txuritan/stry",
"path": "/stry-backend-postgres/src/chapter.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: theduke/printf-compat path: /src/output.rs
//! Various ways to output formatting data.
use core::cell::Cell;
use core::ffi::VaList;
use core::fmt;
use core::str::from_utf8;
use cty::*;
#[cfg(feature = "std")]
pub use yes_std::*;
use crate::{Argument, DoubleFormat, Flags, Specifier};
struct ... | code_fim | hard | {
"lang": "rust",
"repo": "theduke/printf-compat",
"path": "/src/output.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn write_bytes(
w: &mut impl io::Write,
flags: Flags,
width: c_int,
precision: Option<c_int>,
b: &[u8],
) -> io::Result<()> {
let precision = precision.unwrap_or(b.len() as c_int);
let b = b.get(..(b.len().min(precision as usize))).unwrap_or(... | code_fim | hard | {
"lang": "rust",
"repo": "theduke/printf-compat",
"path": "/src/output.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let m = Material::new();
let position = Tuple::point(0.0, 0.0, 0.0);
let eyev = Tuple::vector(0.0, 0.0, -1.0);
let normalv = Tuple::vector(0.0, 0.0, -1.0);
let light = PointLight::new(Tuple::point(0.0, 0.0, -10.0), Tuple::color(1.0, 1.0, 1.0));
let result = ... | code_fim | hard | {
"lang": "rust",
"repo": "isido/ray-tracer-challenge",
"path": "/src/material.rs",
"mode": "spm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: isido/ray-tracer-challenge path: /src/material.rs
use crate::lights::PointLight;
use crate::tuple;
use crate::tuple::Tuple;
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Material {
pub color: Tuple,
pub ambient: f64,
pub diffuse: f64,
pub specular: f64,
pub shininess: ... | code_fim | hard | {
"lang": "rust",
"repo": "isido/ray-tracer-challenge",
"path": "/src/material.rs",
"mode": "psm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(Tuple::color(0.7364, 0.7364, 0.7364), result);
}
#[test]
fn lightning_with_eye_in_path_of_reflection_vector() {
let m = Material::new();
let position = Tuple::point(0.0, 0.0, 0.0);
let eyev = Tuple::vector(0.0, -f64::sqrt(2.0) / 2.0, -f64::sqrt(2.0) ... | code_fim | hard | {
"lang": "rust",
"repo": "isido/ray-tracer-challenge",
"path": "/src/material.rs",
"mode": "spm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Emm54321/cancellable-timer path: /examples/example1.rs
use cancellable_timer::*;
use std::io;
use std::time::Duration;
fn main() {
let (mut timer, canceller) = Timer::new2().unwrap();
println!("Wait 2s, uninterrupted.");
let r = timer.sleep(Duration::from_secs(2));
println!("Do... | code_fim | hard | {
"lang": "rust",
"repo": "Emm54321/cancellable-timer",
"path": "/examples/example1.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> println!("Wait 10s, cancel after 2s");
let canceller2 = canceller.clone();
std::thread::spawn(move || {
std::thread::sleep(Duration::from_secs(2));
canceller2.cancel().unwrap();
});
match timer.sleep(Duration::from_secs(10)) {
Err(ref e) if e.kind() == io::Error... | code_fim | medium | {
"lang": "rust",
"repo": "Emm54321/cancellable-timer",
"path": "/examples/example1.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: erickt/lmath-rs path: /src/vec.rs
use core::cmp::Eq;
use std::cmp::FuzzyEq;
use numeric::types::angle::Radians;
use numeric::types::number::Number;
pub mod vec2;
pub mod vec3;
pub mod vec4;
pub use self::vec2::Vec2;
pub use self::vec3::Vec3;
pub use self::vec4::Vec4;
/**
* The base generi... | code_fim | hard | {
"lang": "rust",
"repo": "erickt/lmath-rs",
"path": "/src/vec.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> /**
* Set the vector to a specified length whilst preserving the direction
*/
fn normalize_self_to(&mut self, length: T);
/**
* Linearly intoperlate the vector towards `other`
*/
fn lerp_self(&mut self, other: &self, amount: T);
}
/**
* Component-wise vector comp... | code_fim | hard | {
"lang": "rust",
"repo": "erickt/lmath-rs",
"path": "/src/vec.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl nsIAccessibleEvent {
/* readonly attribute unsigned long eventType; */
#[inline]
pub unsafe fn get_eventType(&self, ) -> Result<libc::uint32_t, nsresult> {
let mut _retval: libc::uint32_t = ::std::mem::zeroed();
match ((*self.vtable).get_eventType)(self as *const _, &mut _... | code_fim | hard | {
"lang": "rust",
"repo": "mystor/dist-xprs-example",
"path": "/rt/nsIAccessibleEvent.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mystor/dist-xprs-example path: /rt/nsIAccessibleEvent.rs
//
// DO NOT EDIT. THIS FILE IS GENERATED FROM ../../../dist/idl/nsIAccessibleEvent.idl
//
pub mod nsIAccessibleEvent_consts {
pub const EVENT_SHOW: i64 = 1;
pub const EVENT_HIDE: i64 = 2;
pub const EVENT_REORDER: i64 = 3;
... | code_fim | hard | {
"lang": "rust",
"repo": "mystor/dist-xprs-example",
"path": "/rt/nsIAccessibleEvent.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: sccommunity/crates-sgx path: /crates/serde/test_suite/tests/test_de.rs
> btreemap![], 2 => btreemap![3 => 4, 5 => 6]] => &[
Token::Map { len: Some(2) },
Token::I32(1),
Token::Map { len: Some(0) },
Token::MapEnd,
Token::... | code_fim | hard | {
"lang": "rust",
"repo": "sccommunity/crates-sgx",
"path": "/crates/serde/test_suite/tests/test_de.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_de_tokens(&value, &tokens);
assert_de_tokens_ignore(&tokens);
}
#[test]
fn test_cstr() {
assert_de_tokens::<Box<CStr>>(
&CString::new("abc").unwrap().into_boxed_c_str(),
&[Token::Bytes(b"abc")],
);
}
#[test]
fn test_cstr_internal_null() {
assert_de_tokens_error... | code_fim | hard | {
"lang": "rust",
"repo": "sccommunity/crates-sgx",
"path": "/crates/serde/test_suite/tests/test_de.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: sccommunity/crates-sgx path: /crates/serde/test_suite/tests/test_de.rs
=> &[Token::Str("a")],
'a' => &[Token::String("a")],
}
test_string {
"abc".to_owned() => &[Token::Str("abc")],
"abc".to_owned() => &[Token::String("abc")],
"a".to_owned() => &[Token::C... | code_fim | hard | {
"lang": "rust",
"repo": "sccommunity/crates-sgx",
"path": "/crates/serde/test_suite/tests/test_de.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> // If this set of symbols has been whitelisted, then there's no error.
if self
.syntax_grammar
.expected_conflicts
.contains(&actual_conflict)
{
self.actual_conflicts.remove(&actual_conflict);
return Ok(());
}
... | code_fim | hard | {
"lang": "rust",
"repo": "tree-sitter/tree-sitter",
"path": "/cli/src/generate/build_tables/build_parse_table.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tree-sitter/tree-sitter path: /cli/src/generate/build_tables/build_parse_table.rs
// sorted out ahead of time in `add_actions`. But there can still be
// REDUCE-REDUCE conflicts where all actions have the *same*
// precedence, and there can still be SHIFT/REDUCE conflicts.
... | code_fim | hard | {
"lang": "rust",
"repo": "tree-sitter/tree-sitter",
"path": "/cli/src/generate/build_tables/build_parse_table.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Otherwise, insert a new parse state and add it to the queue of
// parse states to populate.
Entry::Vacant(v) => {
let core = v.key().core();
let core_count = self.core_ids_by_core.len();
let core_id = *self.core_ids_by_... | code_fim | hard | {
"lang": "rust",
"repo": "tree-sitter/tree-sitter",
"path": "/cli/src/generate/build_tables/build_parse_table.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl<T> MyBox<T> {
fn new(v: T) -> MyBox<T> {
MyBox(v)
}
}<|fim_prefix|>// repo: kuwana-kb/the-rust-programming-language path: /ch15/pointer.rs
fn main() {
let x = 5;
// let y = &x;
// let y = Box::new(x);
let y = MyBox::new(x);
assert_eq!(x, 5);
assert_eq!(*y, 5... | code_fim | easy | {
"lang": "rust",
"repo": "kuwana-kb/the-rust-programming-language",
"path": "/ch15/pointer.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: kuwana-kb/the-rust-programming-language path: /ch15/pointer.rs
fn main() {
let x = 5;
// let y = &x;
// let y = Box::new(x);
let y = MyBox::new(x);
<|fim_suffix|>struct MyBox<T>(T);
impl<T> MyBox<T> {
fn new(v: T) -> MyBox<T> {
MyBox(v)
}
}<|fim_middle|> ass... | code_fim | easy | {
"lang": "rust",
"repo": "kuwana-kb/the-rust-programming-language",
"path": "/ch15/pointer.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rje/aoc2020 path: /src/bin/day09.rs
use parsing::day09;
fn main() {
let data = day09::parse("data/day09/problem_1.txt");
println!("Data len: {}", data.len());
solve_problem_1(&data);
solve_problem_2(&data);
}
<|fim_suffix|>fn solve_problem_2(data: &Vec<u64>) {
let to_find:... | code_fim | hard | {
"lang": "rust",
"repo": "rje/aoc2020",
"path": "/src/bin/day09.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let to_find: u64 = 50047984;
for slice_size in 2..data.len() {
for i in 0..(data.len() - slice_size) {
let slice = &data[i..i + slice_size];
let sum: u64 = slice.iter().sum();
if sum == to_find {
let mut vec = slice.to_vec();
... | code_fim | hard | {
"lang": "rust",
"repo": "rje/aoc2020",
"path": "/src/bin/day09.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// Load a Numpy matrix as an mmap. This only consumes address space. (Part 1)
///
/// This is a two-step process because the Mmap needs to outlive the matrix.
pub fn open_matrix_mmap<P: AsRef<Path>>(path: P) -> Result<MatFile> {
let header_match = Regex::new(r"NUMPY\x01\x00(?s:..)\{'descr': ?'<f8', ?... | code_fim | hard | {
"lang": "rust",
"repo": "SeanTater/cabarrus",
"path": "/src/numpy.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: SeanTater/cabarrus path: /src/numpy.rs
//! Read and write NDArrays as Numpy arrays
use ndarray::prelude::*;
use ndarray as nd;
use std::fs::{OpenOptions, File};
use std::path::Path;
use std::ptr;
use std::str;
use std::io::{Read, Write};
use regex::bytes::Regex;
use byteorder::{LittleEndian, Bi... | code_fim | hard | {
"lang": "rust",
"repo": "SeanTater/cabarrus",
"path": "/src/numpy.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// Load a Numpy matrix as an mmap (Part 2)
///
/// You need to know the number of dimensions at compile time so for convenience, we assume you
/// need a matrix. Also, this method is even faster than read_matrix but only works for native byte
/// order.
///
/// This is different than you might expect. Th... | code_fim | hard | {
"lang": "rust",
"repo": "SeanTater/cabarrus",
"path": "/src/numpy.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: twking7/adventofcode2017 path: /src/day25.rs
use std::collections::HashMap;
enum State { A, B, C, D, E, F }
fn part1() -> usize {
let mut i = 0;
let mut ptr = 0isize;
let mut h: HashMap<isize, bool> = HashMap::new();
let mut state = State::A;
while i < 12_994_925 {
... | code_fim | hard | {
"lang": "rust",
"repo": "twking7/adventofcode2017",
"path": "/src/day25.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> = State::C;
} else {
h.insert(ptr, false);
ptr += 1;
state = State::A;
}
},
State::F => {
if val {
h.insert(ptr, true);
ptr += 1;
... | code_fim | hard | {
"lang": "rust",
"repo": "twking7/adventofcode2017",
"path": "/src/day25.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: nigaea/webp-rs path: /libwebp-sys/src/decode.rs
use std::os::raw::*;
use std::ptr;
pub use self::VP8StatusCode::*;
pub use self::WEBP_CSP_MODE::*;
cfg_if! {
if #[cfg(feature = "0.5")] {
pub const WEBP_DECODER_ABI_VERSION: c_int = 0x0208;
} else {
pub const WEBP_DECODER_... | code_fim | hard | {
"lang": "rust",
"repo": "nigaea/webp-rs",
"path": "/libwebp-sys/src/decode.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[repr(C)]
pub struct WebPDecBuffer {
pub colorspace: WEBP_CSP_MODE,
pub width: c_int,
pub height: c_int,
pub is_external_memory: c_int,
pub u: WebPDecBufferUnion,
pub pad: [u32; 4],
pub private_memory: *mut u8,
}
#[allow(non_snake_case)]
#[repr(C)]
pub union WebPDecBufferUnio... | code_fim | hard | {
"lang": "rust",
"repo": "nigaea/webp-rs",
"path": "/libwebp-sys/src/decode.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub enum InputValue {
InputString(String),
Esc,
Blank,
}
impl InputValue {
#[allow(dead_code)]
fn as_integer(&self) -> i32 {
match self {
InputValue::InputString(_) => 0,
InputValue::Esc => -1,
InputValue::Blank => 1,
}
}
}
/** ... | code_fim | hard | {
"lang": "rust",
"repo": "evanjpw/startrust",
"path": "/src/interaction.rs",
"mode": "spm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: evanjpw/startrust path: /src/interaction.rs
use std::io::{BufRead, Read};
use std::thread;
use std::time::Duration;
#[allow(unused_imports)]
use beep::beep as sound;
use dim::{dimensions::Frequency, si::Hertz};
#[allow(unused_imports)]
use log::{debug, info};
use num_enum::{FromPrimitive, IntoP... | code_fim | hard | {
"lang": "rust",
"repo": "evanjpw/startrust",
"path": "/src/interaction.rs",
"mode": "psm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[inline]
pub fn on_zero(&self) -> bool {
(self.Flags & 0b0100_0000) != 0
}
#[inline]
pub fn on_positive(&self) -> bool {
(self.Flags & 0b1000_0000) == 0
}
#[inline]
pub fn on_parity_even(&self) -> bool {
(self.Flags & 0b0000_0100) != 0
}
... | code_fim | hard | {
"lang": "rust",
"repo": "Rodrigodd/space-invaders-emu",
"path": "/intel8080/src/intel8080.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Rodrigodd/space-invaders-emu path: /intel8080/src/intel8080.rs
pub trait IODevices: Send {
fn read(&mut self, device: u8) -> u8;
fn write(&mut self, device: u8, value: u8);
}
pub trait Memory: Send {
fn read(&self, adress: u16) -> u8;
fn write(&mut self, adress: u16, value: u8);... | code_fim | hard | {
"lang": "rust",
"repo": "Rodrigodd/space-invaders-emu",
"path": "/intel8080/src/intel8080.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>
}
fn add(a:i32,b:i32)->i32{
println!("ADDING {} + {}",a,b);
a+b
}
fn subtract(a:i32,b:i32)->i32{
println!("SUBTRACTING {} - {}",a,b);
a-b
}
fn multiply(a:i32,b:i32)->i32{
println!("MULTIPLYING {} * {}",a,b);
a*b
}
fn divide(a:i32,b:i32)->i32{
println!("DIVIDING {} / {}",a,b);... | code_fim | medium | {
"lang": "rust",
"repo": "rcore-os-infohub/ossoc2020-nlxxh-daily",
"path": "/rust-code/rust-python/ex21/ex21.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rcore-os-infohub/ossoc2020-nlxxh-daily path: /rust-code/rust-python/ex21/ex21.rs
fn main(){
println!("Let's do some math with just functions:");
let age = add(30, 5);
let height = subtract(78, 4);
let weight = multiply(90, 2);
let iq = divide(100, 2);
println!("Age: {}, H... | code_fim | medium | {
"lang": "rust",
"repo": "rcore-os-infohub/ossoc2020-nlxxh-daily",
"path": "/rust-code/rust-python/ex21/ex21.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub use distance::{hamming_ascii, hamming_bytes, levenshtein_ascii, levenshtein_bytes, jaro_winkler_ascii, jaro_winkler_bytes};<|fim_prefix|>// repo: rapidclock/estahr path: /src/strings/mod.rs
//! This module has utility functions for strings.
//!
//! You can get different kind of distances between st... | code_fim | medium | {
"lang": "rust",
"repo": "rapidclock/estahr",
"path": "/src/strings/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rapidclock/estahr path: /src/strings/mod.rs
//! This module has utility functions for strings.
//!
//! You can get different kind of distances between strings.
//!
//! The string distances currently provided are:
//! 1. Hamming Distance [Wiki](https://en.wikipedia.org/wiki/Hamming_distance)... | code_fim | medium | {
"lang": "rust",
"repo": "rapidclock/estahr",
"path": "/src/strings/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // eprintln!("first neighbors: {:?}", frontier);
println!("Finding path...");
while let Some(node) = frontier.pop() {
let curr = node.curr();
if visited.contains(curr) {
continue;
} else {
visited.insert(curr.to_owned());
}
// e... | code_fim | hard | {
"lang": "rust",
"repo": "ruoshui-git/stuy-stat-ai",
"path": "/rust/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> for word in neighbors
.get(curr)
.expect("Error: intermediate word not in dict")
{
let mut new_words = node.words.clone();
new_words.push(word.to_string());
frontier.push(State {
words: new_words.clone(),
... | code_fim | hard | {
"lang": "rust",
"repo": "ruoshui-git/stuy-stat-ai",
"path": "/rust/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ruoshui-git/stuy-stat-ai path: /rust/src/main.rs
use std::{
collections::{BinaryHeap, HashSet},
env,
fs::File,
io::{self, BufRead, BufReader},
};
use stuy_ai::doublets::{State, WordGraph};
fn main() -> io::Result<()> {
let args: Vec<String> = env::args().collect();
let s... | code_fim | hard | {
"lang": "rust",
"repo": "ruoshui-git/stuy-stat-ai",
"path": "/rust/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: wgwoods/sallyport path: /src/syscall/network.rs
// SPDX-License-Identifier: Apache-2.0
//! network syscalls
use super::BaseSyscallHandler;
use crate::untrusted::{AddressValidator, UntrustedRef, UntrustedRefMut, Validate, ValidateSlice};
use crate::{request, Block, Result};
/// network syscall... | code_fim | hard | {
"lang": "rust",
"repo": "wgwoods/sallyport",
"path": "/src/syscall/network.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Limit the read to `Block::buf_capacity()`
let count = usize::min(count, Block::buf_capacity());
let addrlen = addrlen.validate(self);
let len = match addrlen {
None => 0,
Some(ref e) => **e,
};
if (count + (len as usize)) > Bloc... | code_fim | hard | {
"lang": "rust",
"repo": "wgwoods/sallyport",
"path": "/src/syscall/network.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let c = self.new_cursor();
let c = unsafe {
c.copy_into_slice(count, buf[..result_len].as_mut())
.or(Err(libc::EFAULT))?
};
unsafe {
let (c, addr_buf) = c.alloc::<u8>(*addrlen as _).or(Err(libc::EMSGSIZE))... | code_fim | hard | {
"lang": "rust",
"repo": "wgwoods/sallyport",
"path": "/src/syscall/network.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut m = Array::<u8>::new(16).unwrap();
let p = m.as_mut_ptr();
let (mut l, mut r) = m.split_at_mut(4);
assert_eq!(l.as_ptr(), p);
assert_eq!(l.as_mut_ptr(), p);
assert_eq!(l.len(), 4);
assert_eq!(r.as_ptr(), unsafe { p.offset(4) });
assert_eq!(r.as_mut_ptr(), unsafe { p... | code_fim | medium | {
"lang": "rust",
"repo": "Hakuyume/rust-cuda",
"path": "/cuda/src/memory/tests/split_at.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Hakuyume/rust-cuda path: /cuda/src/memory/tests/split_at.rs
use super::Array;
#[test]
fn split_at() {
let m = Array::<u8>::new(16).unwrap();
let (l, r) = m.split_at(4);
assert_eq!(l.as_ptr(), m.as_ptr());
assert_eq!(l.len(), 4);
assert_eq!(r.as_ptr(), unsafe { m.as_ptr().off... | code_fim | hard | {
"lang": "rust",
"repo": "Hakuyume/rust-cuda",
"path": "/cuda/src/memory/tests/split_at.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let m = Array::<u8>::new(16).unwrap();
m.split_at(24);
}
#[test]
fn split_at_mut() {
let mut m = Array::<u8>::new(16).unwrap();
let p = m.as_mut_ptr();
let (mut l, mut r) = m.split_at_mut(4);
assert_eq!(l.as_ptr(), p);
assert_eq!(l.as_mut_ptr(), p);
assert_eq!(l.len(), 4);... | code_fim | medium | {
"lang": "rust",
"repo": "Hakuyume/rust-cuda",
"path": "/cuda/src/memory/tests/split_at.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: MianSaleem/escpos-rs path: /src/instruction/escpos_image.rs
extern crate serde;
extern crate base64;
extern crate image;
extern crate log;
use log::warn;
use super::{Justification};
use crate::{Error, command::{Command}};
use image::{DynamicImage, GenericImageView, Pixel};
use serde::{Serialize... | code_fim | hard | {
"lang": "rust",
"repo": "MianSaleem/escpos-rs",
"path": "/src/instruction/escpos_image.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl<'de> serde::de::Visitor<'de> for EscposImageVisitor {
type Value = EscposImage;
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("a tuple containing as first element a base64 encoded image, as second a list of cached widths")
}
... | code_fim | hard | {
"lang": "rust",
"repo": "MianSaleem/escpos-rs",
"path": "/src/instruction/escpos_image.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let base = if is_interface {
None
} else {
from_extends(
alloc,
enum_type.is_some(),
is_enum_class,
is_abstract,
&ast_class.extends,
)
};
let base_is_closure = || {
base.as_ref().map_or(false, |cls... | code_fim | hard | {
"lang": "rust",
"repo": "facebook/hhvm",
"path": "/hphp/hack/src/hackc/emitter/emit_class.rs",
"mode": "spm",
"license": "PHP-3.01",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: facebook/hhvm path: /hphp/hack/src/hackc/emitter/emit_class.rs
;
let name = tc.name.1.to_string();
let (recognized, unrecognized) = match &tc.kind {
ClassTypeconst::TCAbstract(ast::ClassAbstractTypeconst { default: None, .. }) => {
(Slice::empty(), Slice::empty())
... | code_fim | hard | {
"lang": "rust",
"repo": "facebook/hhvm",
"path": "/hphp/hack/src/hackc/emitter/emit_class.rs",
"mode": "psm",
"license": "PHP-3.01",
"source": "the-stack-v2"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.