text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_suffix|> PathBuf::from(&str::from_utf8(&julia_home.stdout).unwrap()).to_path_buf()
}<|fim_prefix|>// repo: dovahcrow/julia-sys path: /src/lib.rs
#![feature(untagged_unions)]
extern crate libc;
<|fim_middle|>pub mod sys;
pub use sys::*;
use std::process::Command;
use std::path::PathBuf;
use std::str;
pub f... | code_fim | hard | {
"lang": "rust",
"repo": "dovahcrow/julia-sys",
"path": "/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn connection_id(&self) -> ConnectionId;
fn connection_type_id(&self) -> ConnectionTypeId;
}
#[derive(Copy, Clone)]
pub enum PortKind {
In,
Out,
InOut,
}
#[derive(Copy, Clone)]
pub struct Port {
pub id: PortId,
pub kind: PortKind,
pub conn_id: ConnectionId,
pub rcv_m... | code_fim | medium | {
"lang": "rust",
"repo": "KillingSpark/rs-event-sim",
"path": "/src/core/connection/connection.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>}
#[derive(Copy, Clone)]
pub enum PortKind {
In,
Out,
InOut,
}
#[derive(Copy, Clone)]
pub struct Port {
pub id: PortId,
pub kind: PortKind,
pub conn_id: ConnectionId,
pub rcv_mod: ModuleId,
pub rcv_gate: GateId,
pub rcv_port: PortId,
}<|fim_prefix|>// repo: KillingSp... | code_fim | medium | {
"lang": "rust",
"repo": "KillingSpark/rs-event-sim",
"path": "/src/core/connection/connection.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: KillingSpark/rs-event-sim path: /src/core/connection/connection.rs
use crate::core::contexts::SimulationContext;
use crate::core::id_mngmnt::id_types::{ConnectionId, ConnectionTypeId, GateId, ModuleId, PortId};
use crate::core::messages::message::Message;
pub trait Connection {
fn handle_me... | code_fim | medium | {
"lang": "rust",
"repo": "KillingSpark/rs-event-sim",
"path": "/src/core/connection/connection.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Spu7Nix/Numberlang path: /src/main.rs
mod parser;
use std::{collections::HashMap, env::args, fs};
pub type Number = i32;
fn main() {
let args: Vec<String> = args().collect();
let content = fs::read_to_string(&args[1]).unwrap();
let exprs = parser::parse(&content);
println!("{}"... | code_fim | hard | {
"lang": "rust",
"repo": "Spu7Nix/Numberlang",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> 30 => {
// define function
assert_eq!(args.len(), 3);
let func_id = eval(&args[0], state).unwrap_num();
if func_id < 100 {
panic!("invalid function name (must be over 100)")
}
let arguments = match eval(&args[1... | code_fim | hard | {
"lang": "rust",
"repo": "Spu7Nix/Numberlang",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> 44 => {
// append to tuple
assert_eq!(args.len(), 2);
let tuple = eval(&args[0], state);
let mut list = match tuple {
n @ Value::Number(_) => vec![n],
Value::Tuple(t) => t,
};
list.push(eval(&... | code_fim | hard | {
"lang": "rust",
"repo": "Spu7Nix/Numberlang",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> Ok(())
}
*/
pub fn generate(_instance: &PackageInstance, _out: LazyCreateBuilder) -> io::Result<()> {
//let out = out.set_header("#!/bin/bash\n\nset -e\n\n");
//let mut out = out.finalize();
// This is actually a bad idea because it could leave the dependency in a corrupt state
// bu... | code_fim | medium | {
"lang": "rust",
"repo": "Kixunil/debcrafter",
"path": "/src/bin/generator/preinst.rs",
"mode": "spm",
"license": "MITNFA",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn generate(_instance: &PackageInstance, _out: LazyCreateBuilder) -> io::Result<()> {
//let out = out.set_header("#!/bin/bash\n\nset -e\n\n");
//let mut out = out.finalize();
// This is actually a bad idea because it could leave the dependency in a corrupt state
// but maybe there's a... | code_fim | medium | {
"lang": "rust",
"repo": "Kixunil/debcrafter",
"path": "/src/bin/generator/preinst.rs",
"mode": "spm",
"license": "MITNFA",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Kixunil/debcrafter path: /src/bin/generator/preinst.rs
use std::io;
use debcrafter::im_repr::PackageInstance;
use crate::codegen::{LazyCreateBuilder};
/*
fn write_patches<W: io::Write>(mut out: W, instance: &PackageInstance) -> io::Result<()> {
<|fim_suffix|>pub fn generate(_instance: &PackageI... | code_fim | hard | {
"lang": "rust",
"repo": "Kixunil/debcrafter",
"path": "/src/bin/generator/preinst.rs",
"mode": "psm",
"license": "MITNFA",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rodrimati1992/abi_stable_crates path: /abi_stable/src/sabi_types/version.rs
//! Types representing the version number of a library.
use core_extensions::{SelfOps, StringExt};
use std::{
error,
fmt::{self, Display},
num::ParseIntError,
};
use crate::std_types::RStr;
/// The `<majo... | code_fim | hard | {
"lang": "rust",
"repo": "rodrimati1992/abi_stable_crates",
"path": "/abi_stable/src/sabi_types/version.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fmt::Display::fmt(&self.version, f)
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// Instantiates a [`VersionStrings`] with the
/// major.minor.patch version of the librar... | code_fim | hard | {
"lang": "rust",
"repo": "rodrimati1992/abi_stable_crates",
"path": "/abi_stable/src/sabi_types/version.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut state = self.state.lock();
// Check the device state to decide whether start a new worker thread.
// Note that this check cannot be done by the caller of this function because `self.state`
// can be modified by another thread technically.
match *state {
... | code_fim | hard | {
"lang": "rust",
"repo": "danielverkamp/crosvm",
"path": "/devices/src/virtio/vhost/user/proxy.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: danielverkamp/crosvm path: /devices/src/virtio/vhost/user/proxy.rs
])
.context("failed to create a wait context object")?;
// Represents if |slave_req_helper.endpoint| is being monitored for data
// from the Vhost-user sibling.
let mut sibling_socket_polling... | code_fim | hard | {
"lang": "rust",
"repo": "danielverkamp/crosvm",
"path": "/devices/src/virtio/vhost/user/proxy.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: danielverkamp/crosvm path: /devices/src/virtio/vhost/user/proxy.rs
structs consist of
// metadata about actual device related memory passed from the sibling. Ensure that the size
// of the payload is consistent with this structure.
let payload_size = payload.len();
... | code_fim | hard | {
"lang": "rust",
"repo": "danielverkamp/crosvm",
"path": "/devices/src/virtio/vhost/user/proxy.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> let front = (at - origin).normalize();
let right = front.cross(up).normalize();
let up = right.cross(&front);
let horizontal = right * focus_plane_width;
let vertical = up * focus_plane_height;
let direction = front * focus_distance;
Self {
... | code_fim | hard | {
"lang": "rust",
"repo": "tonyxty/raytracer",
"path": "/src/camera.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: tonyxty/raytracer path: /src/camera.rs
use nalgebra::Vector3;
use rand_distr::{Distribution, UnitDisc};
use crate::ray::Ray;
use crate::RNG;
pub struct Camera {
horizontal: Vector3<f64>,
vertical: Vector3<f64>,
origin: Vector3<f64>,
direction: Vector3<f64>,
right: Vector3<f... | code_fim | hard | {
"lang": "rust",
"repo": "tonyxty/raytracer",
"path": "/src/camera.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub struct Runner<ER, N>
where
ER: RaftEngine,
N: LogFetchedNotifier,
{
notifier: N,
raft_engine: ER,
}
impl<ER: RaftEngine, N: LogFetchedNotifier> Runner<ER, N> {
pub fn new(notifier: N, raft_engine: ER) -> Runner<ER, N> {
Runner {
notifier,
raft_engin... | code_fim | hard | {
"lang": "rust",
"repo": "iosmanthus/tikv",
"path": "/components/raftstore/src/store/worker/raftlog_fetch.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let hit_size_limit = res
.as_ref()
.map(|c| (*c as u64) != high - low)
.unwrap_or(false);
fail_point!("worker_async_fetch_raft_log");
self.notifier.notify(
region_id,
... | code_fim | hard | {
"lang": "rust",
"repo": "iosmanthus/tikv",
"path": "/components/raftstore/src/store/worker/raftlog_fetch.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: iosmanthus/tikv path: /components/raftstore/src/store/worker/raftlog_fetch.rs
// Copyright 2021 TiKV Project Authors. Licensed under Apache-2.0.
use std::fmt;
use engine_traits::RaftEngine;
use fail::fail_point;
use raft::GetEntriesContext;
use tikv_util::worker::Runnable;
use crate::store::{... | code_fim | hard | {
"lang": "rust",
"repo": "iosmanthus/tikv",
"path": "/components/raftstore/src/store/worker/raftlog_fetch.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: rylev/azure-functions-rs path: /azure-functions-sdk/src/commands/build.rs
use crate::util::{print_failure, print_running, print_success, read_crate_name};
use atty::Stream;
use clap::{App, Arg, ArgMatches, SubCommand};
use colored::Colorize;
use std::process::Command;
pub struct Build<'a> {
... | code_fim | hard | {
"lang": "rust",
"repo": "rylev/azure-functions-rs",
"path": "/azure-functions-sdk/src/commands/build.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> if !status.success() {
return Err(format!(
"docker failed with exit code {}.",
status.code().unwrap()
));
}
Ok(())
}
}
impl From<&'a ArgMatches<'a>> for Build<'a> {
fn from(args: &'a ArgMatches<'a>) -> Self {
... | code_fim | hard | {
"lang": "rust",
"repo": "rylev/azure-functions-rs",
"path": "/azure-functions-sdk/src/commands/build.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>qp_queue: String,
}
impl Settings {
pub fn new() -> Result<Self, config::ConfigError> {
let mut s = config::Config::new();
s.merge(config::Environment::with_prefix("shop"))?;
s.try_into()
}
}<|fim_prefix|>// repo: BigRedEye/dc-hw path: /shop/src/config.rs
use config;
#[d... | code_fim | medium | {
"lang": "rust",
"repo": "BigRedEye/dc-hw",
"path": "/shop/src/config.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> config::Config::new();
s.merge(config::Environment::with_prefix("shop"))?;
s.try_into()
}
}<|fim_prefix|>// repo: BigRedEye/dc-hw path: /shop/src/config.rs
use config;
#[derive(Debug, Clone, serde::Deserialize)]
pub struct Settings {
pub database_url: String,
pub bind_addres... | code_fim | medium | {
"lang": "rust",
"repo": "BigRedEye/dc-hw",
"path": "/shop/src/config.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: BigRedEye/dc-hw path: /shop/src/config.rs
use config;
#[derive(Debug, Clone, serde::Deserialize)]
pub struct Settings {
pub database_url: String,
pub bind_address: std::net::SocketAddr,
pub auth_address: String,
pub amqp_address: String,
pub am<|fim_suffix|> config::Config::... | code_fim | medium | {
"lang": "rust",
"repo": "BigRedEye/dc-hw",
"path": "/shop/src/config.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> simple_store(dynamic_arr[0]);
ref_store(&dynamic_arr); // borrows rather than owning
let dynamic_arr = store(dynamic_arr); // ownership returned
println!("{:?}", dynamic_arr); // will throw an error as ownership has been moved to store
println!("{:?}", &dynamic_arr[4..6]); // sli... | code_fim | hard | {
"lang": "rust",
"repo": "vijaysharmay/rust-session-part-1",
"path": "/src/lesson_4.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> println!("{:?}", dynamic_arr); // will throw an error as ownership has been moved to store
println!("{:?}", &dynamic_arr[4..6]); // slices allow you to get a subset of data without owning it
}
fn store(v: Vec<i32>) -> Vec<i32>{
println!("Stored {:?}", v);
v
}
fn ref_store(v: &Vec<i32>)... | code_fim | hard | {
"lang": "rust",
"repo": "vijaysharmay/rust-session-part-1",
"path": "/src/lesson_4.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: vijaysharmay/rust-session-part-1 path: /src/lesson_4.rs
///
/// Lession 4 - Ownership & Borrowing
///
#[path = "./common.rs"]
mod common;
pub fn exec(){
common::display_lesson_name(4);
lesson();
}
<|fim_suffix|> println!("{:?}", &dynamic_arr[4..6]); // slices allow you to get a su... | code_fim | hard | {
"lang": "rust",
"repo": "vijaysharmay/rust-session-part-1",
"path": "/src/lesson_4.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(
reverse_words("The quick brown fox jumps over the lazy dog."),
"ehT kciuq nworb xof spmuj revo eht yzal .god"
);
assert_eq!(reverse_words("apple"), "elppa");
assert_eq!(reverse_words("a b c d"), "a b c d");
assert_eq!(
... | code_fim | hard | {
"lang": "rust",
"repo": "mukundbhudia/rs-challenges",
"path": "/tests/reverse_words.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: mukundbhudia/rs-challenges path: /tests/reverse_words.rs
// From: https://www.codewars.com/kata/5259b20d6021e9e14c0010d4/train/rust
pub fn reverse_words(string_to_reverse: &str) -> String {
let mut output = String::new();
let mut temp_word_buffer = String::new();
<|fim_suffix|> let ... | code_fim | hard | {
"lang": "rust",
"repo": "mukundbhudia/rs-challenges",
"path": "/tests/reverse_words.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: n1t0/pyo3 path: /tests/test_text_signature.rs
use pyo3::prelude::*;
use pyo3::{types::PyType, wrap_pyfunction, wrap_pymodule, PyCell};
mod common;
#[test]
fn class_without_docs_or_signature() {
#[pyclass]
struct MyClass {}
let gil = Python::acquire_gil();
let py = gil.python()... | code_fim | hard | {
"lang": "rust",
"repo": "n1t0/pyo3",
"path": "/tests/test_text_signature.rs",
"mode": "psm",
"license": "Python-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[test]
fn test_pyfn() {
#[pymodule]
fn my_module(_py: Python, m: &PyModule) -> PyResult<()> {
#[pyfn(m, "my_function", a, b = "None", "*", c = 42)]
#[text_signature = "(a, b=None, *, c=42)"]
fn my_function(a: i32, b: Option<i32>, c: i32) {
let _ = (a, b, c);
... | code_fim | hard | {
"lang": "rust",
"repo": "n1t0/pyo3",
"path": "/tests/test_text_signature.rs",
"mode": "spm",
"license": "Python-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[pyfunction(a, b = "None", "*", c = 42)]
#[text_signature = "(a, b=None, *, c=42)"]
fn my_function(a: i32, b: Option<i32>, c: i32) {
let _ = (a, b, c);
}
let gil = Python::acquire_gil();
let py = gil.python();
let f = wrap_pyfunction!(my_function)(py).unwrap();
p... | code_fim | hard | {
"lang": "rust",
"repo": "n1t0/pyo3",
"path": "/tests/test_text_signature.rs",
"mode": "spm",
"license": "Python-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> c.execute_insn();
assert_eq!(c.v[5], 255);
assert_eq!(c.v[0xf], 0);
assert_eq!(c.pc, 2);
}
#[test]
fn test1_assign_vx_minus_vy_to_vx() {
let mut c = CPU::new(None);
c.pc = 0;
// Instruction: 0x89d5
// v[9] = v[9] - v[0xd]
c.v[9] = 100;
c.v[0xd] = 90; // No borrow... | code_fim | hard | {
"lang": "rust",
"repo": "pcein/trust-rust",
"path": "/code/chip8emu/src/cpu_test.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: pcein/trust-rust path: /code/chip8emu/src/cpu_test.rs
use super::*;
/// Tests all instructions except those doing I/O.
#[test]
fn test_jump(){
let mut c = CPU::new(None);
c.pc = 0;
// Instruction: 0x1055
// Jump to 0x55
c.mem[0] = 0x10;
c.mem[1] = 0x55;
c.execut... | code_fim | hard | {
"lang": "rust",
"repo": "pcein/trust-rust",
"path": "/code/chip8emu/src/cpu_test.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> c.execute_insn();
assert_eq!(c.pc, 0x126);
}
#[test]
fn test_assign_rand_bitand_const_to_vx() {
let mut c = CPU::new(None);
c.pc = 0;
// Instruction: 0xc75a
// v[7] = rand() & 0x5a
// When the test code is being executed,
// value of rand() will be 0xff.
c.mem[0] = 0x... | code_fim | hard | {
"lang": "rust",
"repo": "pcein/trust-rust",
"path": "/code/chip8emu/src/cpu_test.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: astral-sh/ruff path: /crates/ruff/src/rules/flake8_pyi/rules/exit_annotations.rs
use std::fmt::{Display, Formatter};
use ruff_python_ast::{
Expr, ExprBinOp, ExprSubscript, ExprTuple, Identifier, Operator, ParameterWithDefault,
Parameters, Ranged,
};
use smallvec::SmallVec;
use ruff_dia... | code_fim | hard | {
"lang": "rust",
"repo": "astral-sh/ruff",
"path": "/crates/ruff/src/rules/flake8_pyi/rules/exit_annotations.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|>/// Return `true` if the [`Expr`] is `BaseException`.
fn is_base_exception(expr: &Expr, model: &SemanticModel) -> bool {
model
.resolve_call_path(expr)
.as_ref()
.is_some_and(|call_path| matches!(call_path.as_slice(), ["" | "builtins", "BaseException"]))
}
/// Return `true` if... | code_fim | hard | {
"lang": "rust",
"repo": "astral-sh/ruff",
"path": "/crates/ruff/src/rules/flake8_pyi/rules/exit_annotations.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: thomastaylor312/krustlet path: /crates/kubelet/src/store/oci/client.rs
//! Client for fetching container modules from OCI
use async_trait::async_trait;
use oci_distribution::client::ImageData;
use oci_distribution::secrets::RegistryAuth;
use oci_distribution::Reference;
/// An image client cap... | code_fim | hard | {
"lang": "rust",
"repo": "thomastaylor312/krustlet",
"path": "/crates/kubelet/src/store/oci/client.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[async_trait]
impl Client for oci_distribution::Client {
async fn pull(&mut self, image: &Reference, auth: &RegistryAuth) -> anyhow::Result<ImageData> {
self.pull_image(image, auth).await
}
async fn fetch_digest(
&mut self,
image: &Reference,
auth: &RegistryAu... | code_fim | hard | {
"lang": "rust",
"repo": "thomastaylor312/krustlet",
"path": "/crates/kubelet/src/store/oci/client.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> buf).await {
if n == 0 {
break;
}
let mut stream = connection.open_uni().await?;
send(
&mut stream,
&bincode::serialize(&shared::ServerCommand::FilePart(
file_name.to_string(),
buf[0..n].to_vec(),
... | code_fim | hard | {
"lang": "rust",
"repo": "Bartixxx32/KISS-multiplayer",
"path": "/kissmp-server/src/file_transfer.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>ring(),
buf[0..n].to_vec(),
chunk_n,
file_length,
n as u32,
))
.unwrap(),
)
.await?;
stream.finish();
chunk_n += 1;
}
Ok(())
}<|fim_prefix|>// repo: Bartixxx32/KISS-multiplayer ... | code_fim | hard | {
"lang": "rust",
"repo": "Bartixxx32/KISS-multiplayer",
"path": "/kissmp-server/src/file_transfer.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Bartixxx32/KISS-multiplayer path: /kissmp-server/src/file_transfer.rs
use crate::*;
use tokio::io::AsyncReadExt;
const CHUNK_SIZE: usize = 65536;
// FIXME
pub async fn transfer_file(
connection: quinn::Connection,
path: &std::path::Path,
) -> anyhow::Result<()> {
let mut file = tok... | code_fim | hard | {
"lang": "rust",
"repo": "Bartixxx32/KISS-multiplayer",
"path": "/kissmp-server/src/file_transfer.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[test]
fn read_range_be() {
// let y_be: u32 = 0b00001010_01010000_11110000_00001111;
let y_arr = &[0b00001010u8, 0b01010000, 0b11110000, 0b00001111];
let r: u32 = y_arr.range_read_be(0..8);
assert_eq!(r, 0b00001111);
let r: u32 = y_arr.range_read_be(0..16);
assert_eq!(r, 0b1111... | code_fim | hard | {
"lang": "rust",
"repo": "placrosse/simple-bitrange-rs",
"path": "/src/tests.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: placrosse/simple-bitrange-rs path: /src/tests.rs
use crate::*;
#[test]
fn write_range_be() {
let y = &mut [0b11111111u8, 0b11111111, 0b11111111, 0b11111111];
let val = &[0b11111111u8, 0b11111111, 0b11110000, 0b00001111];
y.range_write_be(4..12, 0);
<|fim_suffix|>#[test]
fn endian_... | code_fim | hard | {
"lang": "rust",
"repo": "placrosse/simple-bitrange-rs",
"path": "/src/tests.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let r: u32 = y_arr.range_read_be(0..8);
assert_eq!(r, 0b00001111);
let r: u32 = y_arr.range_read_be(0..16);
assert_eq!(r, 0b11110000_00001111);
let r: u32 = y_arr.range_read_be(0..24);
assert_eq!(r, 0b01010000_11110000_00001111);
}
#[test]
fn read_range_le() {
// let y: u32... | code_fim | hard | {
"lang": "rust",
"repo": "placrosse/simple-bitrange-rs",
"path": "/src/tests.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: JohnHeitmann/fluent-rs path: /fluent/examples/selector.rs
extern crate fluent;
use fluent::bundle::FluentBundle;
use fluent::types::FluentValue;
use std::collections::HashMap;
<|fim_suffix|> match bundle.format("hello-world", None) {
Some((value, _)) => println!("{}", value),
... | code_fim | hard | {
"lang": "rust",
"repo": "JohnHeitmann/fluent-rs",
"path": "/fluent/examples/selector.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> match bundle.format("hello-world", None) {
Some((value, _)) => println!("{}", value),
_ => println!("None"),
}
let mut args = HashMap::new();
args.insert("name", FluentValue::from("moon"));
match bundle.format("hello-world2", Some(&args)) {
Some((value, _)) =>... | code_fim | hard | {
"lang": "rust",
"repo": "JohnHeitmann/fluent-rs",
"path": "/fluent/examples/selector.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: perlw/sandbox_rust path: /src/bedrock/kronos.rs
struct SystemState<T> {
name: String,
system: Box<System<T>>,
running: bool,
timing: f64,
since_update: f64,
}
pub trait System<T> {
fn start(&mut self) -> bool;
fn stop(&mut self) -> bool;
fn update(&mut self, delt... | code_fim | hard | {
"lang": "rust",
"repo": "perlw/sandbox_rust",
"path": "/src/bedrock/kronos.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn post_message(&mut self, system: &str, msg: &T) {
// Temp solution, should queue first then send
for s in &mut self.systems {
if s.running && s.name == system {
println!("System {} receiving message", s.name);
s.system.message(msg);
... | code_fim | hard | {
"lang": "rust",
"repo": "perlw/sandbox_rust",
"path": "/src/bedrock/kronos.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn start_system(&mut self, name: &str) {
for s in &mut self.systems {
if !s.running && s.name == name {
if s.system.start() {
s.running = true;
println!("System {} started", name);
} else {
... | code_fim | hard | {
"lang": "rust",
"repo": "perlw/sandbox_rust",
"path": "/src/bedrock/kronos.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn update(&mut self, msg: Self::Message) {
match msg {
Msg::Updating => {
info!("Tick...");
}
}
}
fn handle(&mut self, msg: Self::Input, who: HandlerId) {
info!("Request: {:?}", msg);
match msg {
Request::GetD... | code_fim | hard | {
"lang": "rust",
"repo": "carlosdp/plaster",
"path": "/examples/multi_thread/src/job.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> match msg {
Msg::Updating => {
info!("Tick...");
}
}
}
fn handle(&mut self, msg: Self::Input, who: HandlerId) {
info!("Request: {:?}", msg);
match msg {
Request::GetDataFromServer => {
self.link.re... | code_fim | hard | {
"lang": "rust",
"repo": "carlosdp/plaster",
"path": "/examples/multi_thread/src/job.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: carlosdp/plaster path: /examples/multi_thread/src/job.rs
use std::time::Duration;
use yew::prelude::worker::*;
// TODO use yew::services::{IntervalService, FetchService, Task};
use yew::services::Task;
use yew::services::interval::IntervalService;
use yew::services::fetch::FetchService;
<|fim_s... | code_fim | hard | {
"lang": "rust",
"repo": "carlosdp/plaster",
"path": "/examples/multi_thread/src/job.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: kellymclaughlin/pg-test path: /hierarchy-test/src/main.rs
#[macro_use]
extern crate clap;
extern crate histogram;
extern crate postgres;
extern crate rand;
extern crate uuid;
mod baseline;
mod common;
mod database;
mod opts;
mod schema;
mod table;
mod types;
use std::error::Error;
use std::pro... | code_fim | hard | {
"lang": "rust",
"repo": "kellymclaughlin/pg-test",
"path": "/hierarchy-test/src/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> database::delete_tables(url_arc.clone(), database_count);
},
Mode::Schema => {
let schema_count = value_t!(matches, "schemaCount", u32)
.unwrap_or(DEFAULT_HIERARCHY_COUNT);
let start = Instant::now();
schema::run_threads(url_a... | code_fim | hard | {
"lang": "rust",
"repo": "kellymclaughlin/pg-test",
"path": "/hierarchy-test/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // The url is guaranteed to be present if we make it here
let url = String::from(matches.value_of("url").unwrap());
let url_arc = Arc::new(url);
let thread_count = value_t!(matches, "threadCount", u32)
.unwrap_or(THREAD_COUNT);
let thread_iterations = value_t!(matches, "threadI... | code_fim | hard | {
"lang": "rust",
"repo": "kellymclaughlin/pg-test",
"path": "/hierarchy-test/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: slowli/jwt-compact path: /src/jwk.rs
g the [`TryFrom`] trait.
#[derive(Debug)]
#[non_exhaustive]
pub enum JwkError {
/// Required field is absent from JWK.
NoField(String),
/// Key type (the `kty` field) is not as expected.
UnexpectedKeyType {
/// Expected key type.
... | code_fim | hard | {
"lang": "rust",
"repo": "slowli/jwt-compact",
"path": "/src/jwk.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: slowli/jwt-compact path: /src/jwk.rs
er).map(SecretBytes::new)
}
}
/// Basic [JWK] functionality: (de)serialization and creating thumbprints.
///
/// See [RFC 7518] for the details about the fields for various key types.
///
/// [`Self::thumbprint()`] and the [`Display`](fmt::Display) imple... | code_fim | hard | {
"lang": "rust",
"repo": "slowli/jwt-compact",
"path": "/src/jwk.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut json_entries: Vec<_> = json_value.iter().collect();
json_entries.sort_unstable_by(|(x, _), (y, _)| x.cmp(y));
formatter.write_str("{")?;
let field_count = json_entries.len();
for (i, (name, value)) in json_entries.into_iter().enumerate() {
write... | code_fim | hard | {
"lang": "rust",
"repo": "slowli/jwt-compact",
"path": "/src/jwk.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: wraikny/object_system_rs path: /src/scene.rs
use std::{cell::RefCell, rc::Rc};
use super::{
object_system::{self, Component, CoreSystem, HasComponent, HasComponentInner, SceneInner},
system_2d::{layer::Layer2D, object::Object2D},
system_3d::{layer::Layer3D, object::Object3D},
};
//... | code_fim | medium | {
"lang": "rust",
"repo": "wraikny/object_system_rs",
"path": "/src/scene.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> &mut self.layers2d
}
}
impl object_system::Scene<Layer3D, Object3D> for Scene {
fn layers(&mut self) -> &mut Vec<Box<Layer3D>> {
&mut self.layers3d
}
}<|fim_prefix|>// repo: wraikny/object_system_rs path: /src/scene.rs
use std::{cell::RefCell, rc::Rc};
use super::{
objec... | code_fim | hard | {
"lang": "rust",
"repo": "wraikny/object_system_rs",
"path": "/src/scene.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let cumsum: Vec<f64> = w.iter().scan(0.0, |acc, &x| {
*acc = *acc + x;
Some(*acc)
}).collect();
let mut u: f64;
let mut u_rand:f64;
let mut res:Vec<usize> = vec![0; n];
for i in 0..n {
u_rand = rng.gen();
u =(i as f64 + u_rand)/( n as f... | code_fim | hard | {
"lang": "rust",
"repo": "niharikag/PGSampler",
"path": "/RustCode/src/utils.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> match location{
Ok(location) => res[i] = location,
Err(location) => res[i] = location,
}
}
res
}
// transfer function that takes input as vector of f64
#[inline]
pub fn transfer_func(x:&Vec<f64>)->Vec<f64> {
let out:Vec<f64> = x.iter().map(|x|
/... | code_fim | hard | {
"lang": "rust",
"repo": "niharikag/PGSampler",
"path": "/RustCode/src/utils.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: niharikag/PGSampler path: /RustCode/src/utils.rs
use rand::Rng;
use rand::rngs::StdRng;
use rand_distr::StandardNormal;
//use random_choice::random_choice;
//use rand::seq::index::sample;
//use rayon::prelude::*;
#[allow(dead_code)]
pub fn binary_search(arr: &[f64], target: &f64) -> usize
{
... | code_fim | hard | {
"lang": "rust",
"repo": "niharikag/PGSampler",
"path": "/RustCode/src/utils.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Cody-Duncan/rust_d3d12_sample_hello_tetrahedron path: /src/geometry.rs
use cgmath::*;
use crate::transforms;
#[derive(Debug, Copy, Clone)]
pub struct ColoredVertex
{
#[allow(dead_code)]
position : Vector3<f32>,
#[allow(dead_code)]
color : Vector4<f32>,
}
#[allow(dead_code)]
const SAMPLE_A... | code_fim | hard | {
"lang": "rust",
"repo": "Cody-Duncan/rust_d3d12_sample_hello_tetrahedron",
"path": "/src/geometry.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> return colored_vertices;
}
// Sample colored tetrahedron in Projection space.
#[allow(dead_code)]
pub fn sample_colored_tetrahedron_vertices() -> [ColoredVertex; 12]
{
// Vertices for a unit tetrahedron in world space, with center of the bottom
// face at the origin.
let sample_tetrahedron_vertices :... | code_fim | hard | {
"lang": "rust",
"repo": "Cody-Duncan/rust_d3d12_sample_hello_tetrahedron",
"path": "/src/geometry.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // trasform to projection space
let vleft = view_proj * sample_triangle_vertices[0].extend(1.0);
let vtop = view_proj * sample_triangle_vertices[1].extend(1.0);
let vright = view_proj * sample_triangle_vertices[2].extend(1.0);
// perspective divide (normally done by gpu pipeline)
let vvleft = vl... | code_fim | hard | {
"lang": "rust",
"repo": "Cody-Duncan/rust_d3d12_sample_hello_tetrahedron",
"path": "/src/geometry.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // we come back to the check we saved before
// we need to add +1 because we are adding an instruction
c.push(inst::jump(cmp - (c.len() + 1) as i64));
c
}
pub fn optimize(&self) -> super::Stmt {
super::r#for(&self.var, self.extent.optimize(), self.body.opti... | code_fim | hard | {
"lang": "rust",
"repo": "irevoire/stackvm",
"path": "/src/stmt/for.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: irevoire/stackvm path: /src/stmt/for.rs
use super::Stmt;
use crate::expr::Expr;
/// A for statement
///
/// for (loop_var = 0; loop_var < extent; ++loop_var) {
/// body
/// }
///
/// Parameters
/// ----------
/// loop_var : str
/// The loop variable.
///
/// Parameters
/// ----------
///... | code_fim | hard | {
"lang": "rust",
"repo": "irevoire/stackvm",
"path": "/src/stmt/for.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Liano/procmon path: /src/main.rs
extern crate procmon;
use std::{thread};
use std::path::PathBuf;
//static PROCESS_TO_KEEP: &'static str = "C:\\Users\\nmestaoui\\Desktop\\tester\\bin\\Debug\\tester.exe";
<|fim_suffix|>
fn main() {
let child = thread::spawn(|| {
let mut counter = 0;
... | code_fim | medium | {
"lang": "rust",
"repo": "Liano/procmon",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> if let Ok(mut processes) = Process::get_processes() {
println!("running processes {}", processes.len());
while let Some(process) = processes.pop() {
println!("{}: {} [{}]"
, process.get_process_id()
, process.get_name().unwrap()
, process.get_location().unwra... | code_fim | hard | {
"lang": "rust",
"repo": "Liano/procmon",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>
fn main() {
let child = thread::spawn(|| {
let mut counter = 0;
loop {
//show_process_running();
show_all_processes();
counter += 1;
if counter == 1 {
break;
}
thread::sleep_ms(10_000);
}
});
if child.join().is_err() {
println!("ligour oc... | code_fim | medium | {
"lang": "rust",
"repo": "Liano/procmon",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl MessageHandler for Handler {
fn on_message(&mut self, msg: Message) {
if let Some(callback) = self.callback.lock().take() {
(callback)();
}
msg.respond(Value::Null)
}
}<|fim_prefix|>// repo: hustxiaoc/rust-flutter path: /flutter-plugins/src/isolate.rs
//! ... | code_fim | hard | {
"lang": "rust",
"repo": "hustxiaoc/rust-flutter",
"path": "/flutter-plugins/src/isolate.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: hustxiaoc/rust-flutter path: /flutter-plugins/src/isolate.rs
//! Plugin to work with locales.
//! It handles flutter/localization type message.
use std::sync::{Arc, Weak};
use flutter_engine::{
channel::{MessageChannel, MessageHandler},
codec::STRING_CODEC,
plugins::Plugin,
Flut... | code_fim | hard | {
"lang": "rust",
"repo": "hustxiaoc/rust-flutter",
"path": "/flutter-plugins/src/isolate.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: myth/rust-ga path: /src/ea/population.rs
use super::individual::{Genotype, Individual, Phenotype};
use crate::Options;
use rand::{thread_rng, Rng};
use std::time::SystemTime;
use std::{cmp::Ordering, fmt};
use std::{fmt::Display, slice::IterMut};
use structopt::clap::arg_enum;
/// Interface for... | code_fim | hard | {
"lang": "rust",
"repo": "myth/rust-ga",
"path": "/src/ea/population.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut total_fitness = 0.0;
for i in &self.population {
if self.options.minimize {
total_fitness += 1.0 / i.fitness;
} else {
total_fitness += i.fitness
}
}
let mut new_generation = self.select_parents(to... | code_fim | hard | {
"lang": "rust",
"repo": "myth/rust-ga",
"path": "/src/ea/population.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // TODO: Optimize, move chosen selector to struct member
match self.options.parent_selection {
ParentSelection::RouletteWheel => {
while new_population.len() < self.options.population as usize {
let a = roulette_wheel_select(
... | code_fim | hard | {
"lang": "rust",
"repo": "myth/rust-ga",
"path": "/src/ea/population.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: solotzg/rs-hash-ord path: /src/hash_table.rs
use std::marker;
use std::mem;
use std::ptr;
use avl_node::{AVLNode, AVLNodePtr, AVLNodePtrBase, AVLRoot, AVLRootPtr};
use avl_node;
use list::{ListHead, ListHeadPtr, ListHeadPtrFn};
use std::hash::Hash;
use std::hash::BuildHasher;
use std::hash::Hash... | code_fim | hard | {
"lang": "rust",
"repo": "solotzg/rs-hash-ord",
"path": "/src/hash_table.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[inline]
pub fn rehash(&mut self, len: usize) {
let old_index_size = self.index_size;
let limit = calc_limit(len);
if old_index_size >= limit {
return;
}
let mut need = old_index_size;
while need < limit {
need = need.saturat... | code_fim | hard | {
"lang": "rust",
"repo": "solotzg/rs-hash-ord",
"path": "/src/hash_table.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: daniellockyer/passive-packet path: /src/client.rs
#![feature(ip)]
#[macro_use]
extern crate serde_derive;
extern crate serde;
extern crate serde_json;
extern crate peel_ip;
extern crate curl;
extern crate pnet;
mod common;
use common::{CommStore,Communication};
use curl::easy::Easy;
use std::... | code_fim | hard | {
"lang": "rust",
"repo": "daniellockyer/passive-packet",
"path": "/src/client.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> else { println!("{:?}", packet); }
}
if src == dst { continue; }
if src.is_multicast() { src_group = "broadcast"; }
if dst.is_multicast() { dst_group = "broadcast"; }
if src.is_global() { src_group = "internet"; }
if dst.is_global() { dst_group = "internet"; }
if src.i... | code_fim | hard | {
"lang": "rust",
"repo": "daniellockyer/passive-packet",
"path": "/src/client.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> matcher.advance();
let r_field = matcher.get_byte() as i8;
Instruction {
opcode,
l_field_mode,
l_field,
size,
r_field_mode,
r_field
}
}<|fim_prefix|>// repo: Jerald/daemon_vm path: /src/parser/custom.rs
use crate::types::... | code_fim | hard | {
"lang": "rust",
"repo": "Jerald/daemon_vm",
"path": "/src/parser/custom.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Jerald/daemon_vm path: /src/parser/custom.rs
use crate::types::{
Instruction,
Opcode,
AddressingMode,
OperationSize,
BytePattern,
};
const BYTE_MAX: u8 = 0xFF;
const BYTE_LEN: u8 = 8;
struct ByteMatcher
{
inner: Vec<u8>,
index: usize,
}
impl Byte... | code_fim | hard | {
"lang": "rust",
"repo": "Jerald/daemon_vm",
"path": "/src/parser/custom.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn advance(&mut self)
{
self.index += 1;
}
}
pub fn parse_instruction(input: &[u8]) -> Instruction
{
let mut matcher = ByteMatcher::new(Vec::from(input));
let opcode = matcher.match_byte::<Opcode>();
let l_field_mode = matcher.match_byte::<AddressingMode>()... | code_fim | hard | {
"lang": "rust",
"repo": "Jerald/daemon_vm",
"path": "/src/parser/custom.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> expect_args!(SIGNATURE, args, [
value => value,
]);
match value {
Value::String(ref value) => {
Return::Local(Value::Symbol(universe.intern_symbol(value.as_str())))
}
Value::Symbol(sym) => Return::Local(Value::Symbol(sym)),
_ => Return::Exce... | code_fim | hard | {
"lang": "rust",
"repo": "erde74/som-rs",
"path": "/som-interpreter-ast/src/primitives/string.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: erde74/som-rs path: /som-interpreter-ast/src/primitives/string.rs
use std::collections::hash_map::DefaultHasher;
use std::convert::TryFrom;
use std::hash::Hasher;
use std::rc::Rc;
use crate::expect_args;
use crate::invokable::Return;
use crate::primitives::PrimitiveFn;
use crate::universe::Univ... | code_fim | hard | {
"lang": "rust",
"repo": "erde74/som-rs",
"path": "/som-interpreter-ast/src/primitives/string.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl From<ControlMessage> for ArrowMessage {
fn from(cmsg: ControlMessage) -> Self {
Self::new(0, 0, cmsg)
}
}
impl Encode for ArrowMessage {
fn encode(&self, buf: &mut BytesMut) {
let header = ArrowMessageHeader::new(
self.header.service,
self.header.s... | code_fim | hard | {
"lang": "rust",
"repo": "angelcam/arrow-client",
"path": "/src/net/arrow/proto/msg/mod.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Get encoded message body.
pub fn payload(&self) -> &[u8] {
self.payload.as_ref()
}
}
impl From<ControlMessage> for ArrowMessage {
fn from(cmsg: ControlMessage) -> Self {
Self::new(0, 0, cmsg)
}
}
impl Encode for ArrowMessage {
fn encode(&self, buf: &mut BytesM... | code_fim | hard | {
"lang": "rust",
"repo": "angelcam/arrow-client",
"path": "/src/net/arrow/proto/msg/mod.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: angelcam/arrow-client path: /src/net/arrow/proto/msg/mod.rs
// Copyright 2017 click2stream, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://w... | code_fim | hard | {
"lang": "rust",
"repo": "angelcam/arrow-client",
"path": "/src/net/arrow/proto/msg/mod.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_example() -> Result<()> {
let bus_ids = vec![(0, 7), (1, 13), (4, 59), (6, 31), (7, 19)];
assert_eq!(part_a(&bus_ids, 939)?, 295);
assert_eq!(part_b(&bus_ids), 1068781);
Ok(())
}
}<|fim_prefix|>// repo:... | code_fim | hard | {
"lang": "rust",
"repo": "runfalk/advent-of-code-2020",
"path": "/src/day13.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn main(path: &Path) -> Result<(u64, Option<u64>)> {
let mut lines = read_lines(path)?;
let departure_time: u64 = lines
.next()
.transpose()?
.ok_or_else(|| anyhow!("Unable to read first line of input"))?
.parse()?;
let bus_ids = lines
.next()
... | code_fim | hard | {
"lang": "rust",
"repo": "runfalk/advent-of-code-2020",
"path": "/src/day13.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: runfalk/advent-of-code-2020 path: /src/day13.rs
use anyhow::{anyhow, Result};
use std::path::Path;
use crate::reader::read_lines;
fn part_a(bus_ids: &[(u64, u64)], departure_time: u64) -> Result<u64> {
let (delay, bus_id) = bus_ids
.iter()
.map(|(_, bus_id)| (bus_id - (depa... | code_fim | hard | {
"lang": "rust",
"repo": "runfalk/advent-of-code-2020",
"path": "/src/day13.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl LineStyle2 {
pub fn read<R: BitRead>(reader: &mut R) -> Result<Self> {
let width = reader.read_u16()?;
let start_cap_style = CapStyle::read(reader)?;
let join_style = reader.read_ub8(2)?;
let has_fill = reader.read_bit()?;
let no_h_scale = reader.read_bit()... | code_fim | hard | {
"lang": "rust",
"repo": "djcsdy/wildflower-codec",
"path": "/src/decode/tags/styles/line_style_2.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: djcsdy/wildflower-codec path: /src/decode/tags/styles/line_style_2.rs
use crate::decode::bit_read::BitRead;
use crate::decode::read_ext::SwfTypesReadExt;
use crate::decode::tags::common::fixed_8::Fixed8;
use crate::decode::tags::common::rgba::Rgba;
use crate::decode::tags::styles::cap_style::Cap... | code_fim | hard | {
"lang": "rust",
"repo": "djcsdy/wildflower-codec",
"path": "/src/decode/tags/styles/line_style_2.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn rasterize_triangle(&self, t: &Triangle) {
// find aabb
let mut lb = glm::vec2(self.width as f32, self.height as f32);
let mut rt = glm::vec2(0f32, 0f32);
for _v in &t.v {
lb.x = f32::max(f32::min(lb.x, _v.x), 0f32);
lb.y = f32::max(f32::min(l... | code_fim | hard | {
"lang": "rust",
"repo": "DarkTong/game101",
"path": "/src/rasterizer.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: DarkTong/game101 path: /src/rasterizer.rs
#![allow(dead_code)]
use std::{borrow::BorrowMut, collections::HashMap};
use std::cell::RefCell;
use std::default::Default;
use crate::{
triangle::*, utility,
shader::*,
shader_program::*
};
use crate::utility::to_vec4;
#[derive(Default, C... | code_fim | hard | {
"lang": "rust",
"repo": "DarkTong/game101",
"path": "/src/rasterizer.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: pixelbar/rustschool_gaia path: /libs/shared/src/lib.rs
#![feature(box_syntax)]
extern crate time;
extern crate image;
<|fim_suffix|>pub use gaia_entry::{AstrometricPrior, GaiaEntry};
pub use timer::Timer;
pub use generate_image::generate_image;<|fim_middle|>#[macro_use] mod macros;
mod gaia_en... | code_fim | medium | {
"lang": "rust",
"repo": "pixelbar/rustschool_gaia",
"path": "/libs/shared/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub use gaia_entry::{AstrometricPrior, GaiaEntry};
pub use timer::Timer;
pub use generate_image::generate_image;<|fim_prefix|>// repo: pixelbar/rustschool_gaia path: /libs/shared/src/lib.rs
#![feature(box_syntax)]
extern crate time;
extern crate image;
<|fim_middle|>#[macro_use] mod macros;
mod gaia_en... | code_fim | medium | {
"lang": "rust",
"repo": "pixelbar/rustschool_gaia",
"path": "/libs/shared/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: hikarine3/programming_language_comparison path: /examples/time/date_time/date_time.rs
extern crate chrono;
use chrono::{Local, DateTime};
<|fim_suffix|> let now: DateTime<Local> = Local::now();
println!("{}", now.format("%Y/%m/%d %H:%M:%S"))
}<|fim_middle|>fn main() {
| code_fim | easy | {
"lang": "rust",
"repo": "hikarine3/programming_language_comparison",
"path": "/examples/time/date_time/date_time.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.