text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_suffix|> &mut self,
peer_id: &PeerId,
_: &ConnectionId,
old: &ConnectedPoint,
new: &ConnectedPoint,
) {
let old = (*peer_id, old.get_remote_address().clone());
let new = (*peer_id, new.get_remote_address().clone());
self.connections.remove(&old);
... | code_fim | hard | {
"lang": "rust",
"repo": "dvc94ch/ipfs-embed",
"path": "/net/src/peers.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dvc94ch/ipfs-embed path: /net/src/peers.rs
use fnv::{FnvHashMap, FnvHashSet};
use libp2p::core::connection::{ConnectedPoint, ConnectionId};
use libp2p::identify::IdentifyInfo;
use libp2p::swarm::protocols_handler::DummyProtocolsHandler;
use libp2p::swarm::{NetworkBehaviour, NetworkBehaviourActio... | code_fim | hard | {
"lang": "rust",
"repo": "dvc94ch/ipfs-embed",
"path": "/net/src/peers.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut print_img;
let (width, height) = img.dimensions();
let (mut print_width, mut print_height) = img.dimensions();
if conf.is_width_present {
print_width = conf.width.unwrap();
}
if conf.is_height_present {
//since 2 pixels are printed per terminal cell, an ima... | code_fim | hard | {
"lang": "rust",
"repo": "wapm-packages/viu-archived",
"path": "/viu-0.2.1/src/app.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: wapm-packages/viu-archived path: /viu-0.2.1/src/app.rs
use clap::{value_t, ArgMatches};
use gif::SetParameter;
use image::{DynamicImage, GenericImageView, ImageBuffer, ImageRgba8};
use std::fs::File;
use std::io::{self, BufReader, Read};
use std::sync::mpsc;
use std::{thread, time::Duration};
u... | code_fim | hard | {
"lang": "rust",
"repo": "wapm-packages/viu-archived",
"path": "/viu-0.2.1/src/app.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let file_in = match file_in {
Err(e) => {
error_and_quit(filename, e.to_string());
panic!();
}
Ok(f) => f,
};
if try_print_gif(&conf, BufReader::new(file_in), &tx_print, &rx_print).is_err() {
//the pro... | code_fim | hard | {
"lang": "rust",
"repo": "wapm-packages/viu-archived",
"path": "/viu-0.2.1/src/app.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn exp(self) -> Self { self.exp() }
fn exp2(self) -> Self { self.exp2() }
fn ln(self) -> Self { self.ln() }
fn log(self,base: Self) -> Self { self.log(base) }
fn log2(self) -> Self { self.log2() }
fn log10(self... | code_fim | hard | {
"lang": "rust",
"repo": "des256/e",
"path": "/src/base/real.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn cos(self) -> Self { self.cos() }
fn tan(self) -> Self { self.tan() }
fn asin(self) -> Self { self.asin() }
fn acos(self) -> Self { self.acos() }
fn atan(self) -> Self { self.atan() }
fn atan2(self,other: Sel... | code_fim | hard | {
"lang": "rust",
"repo": "des256/e",
"path": "/src/base/real.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: des256/e path: /src/base/real.rs
use crate::*;
/// real number trait
pub trait Real: Signed {
const PI: Self;
fn floor(self) -> Self;
fn ceil(self) -> Self;
fn round(self) -> Self;
fn trunc(self) -> Self;
fn fract(self) -> Self;
fn powf(self,n: Self) -> Self;
fn ... | code_fim | hard | {
"lang": "rust",
"repo": "des256/e",
"path": "/src/base/real.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[derive(Serialize, Deserialize)]
struct TimelineRecord {
datetime: String,
rate: f64,
}
impl From<Moer> for TimelineRecord {
fn from(m: Moer) -> TimelineRecord {
TimelineRecord {
rate: m.rate,
datetime: m.start.with_timezone(&Pacific).to_rfc3339(),
}
... | code_fim | hard | {
"lang": "rust",
"repo": "hdevalence/sgip-signal",
"path": "/examples/fetch.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: hdevalence/sgip-signal path: /examples/fetch.rs
use chrono::{Duration, Utc};
use chrono_tz::US::Pacific;
use hdrhistogram::Histogram;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use structopt::StructOpt;
use sgip_signal::{GridRegion, Moer, SgipSignal};
#[derive(Debug, ... | code_fim | hard | {
"lang": "rust",
"repo": "hdevalence/sgip-signal",
"path": "/examples/fetch.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> by_time
.into_iter()
.map(|(time, rates)| {
let min = rates.min() as f64 / 1000.;
let max = rates.max() as f64 / 1000.;
let mean = rates.mean() as f64 / 1000.;
let p10 = rates.value_at_quantile(0.1) as f64 / 1000.;
let p25 = r... | code_fim | hard | {
"lang": "rust",
"repo": "hdevalence/sgip-signal",
"path": "/examples/fetch.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>DIV_35_5 : u32 = 0xD1800000; // Processor clock is pll / 35.5
pub const SYSCTL_SYSDIV_36_5 : u32 = 0xD2000000; // Processor clock is pll / 36.5
pub const SYSCTL_SYSDIV_37_5 : u32 = 0xD2800000; // Processor clock is pll / 37.5
pub const SYSCTL_SYSDIV_38_5 : u32 = 0xD3000000; // Proc... | code_fim | hard | {
"lang": "rust",
"repo": "wfrisby/rust-demo-cortex-m4",
"path": "/sysctl.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: wfrisby/rust-demo-cortex-m4 path: /sysctl.rs
= 0x00000000; // PWM clock is processor clock /1
pub const SYSCTL_PWMDIV_2 : u32 = 0x00100000; // PWM clock is processor clock /2
pub const SYSCTL_PWMDIV_4 : u32 = 0x00120000; // PWM clock is processor clock /4
pub const SYSCTL_PWMD... | code_fim | hard | {
"lang": "rust",
"repo": "wfrisby/rust-demo-cortex-m4",
"path": "/sysctl.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: wfrisby/rust-demo-cortex-m4 path: /sysctl.rs
rnate reset
pub const SYSCTL_CAUSE_WDOG1 : u32 = 0x00000020; // Watchdog 1 reset
pub const SYSCTL_CAUSE_SW : u32 = 0x00000010; // Software reset
pub const SYSCTL_CAUSE_WDOG0 : u32 = 0x00000008; // Watchdog 0 reset
pub const SYSCTL... | code_fim | hard | {
"lang": "rust",
"repo": "wfrisby/rust-demo-cortex-m4",
"path": "/sysctl.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|>
/// number of bytes in key for this cipher
fn key_len(&self) -> usize;
/// number of bytes in tag
fn tag_len(&self) -> usize;
/// return nonce as slice
fn get_nonce(&self) -> &[u8];
}
/// Trait for cipher that can import keys
#[async_trait]
pub trait Import: Cipher + Sized {
... | code_fim | hard | {
"lang": "rust",
"repo": "stevelr/secret-keeper",
"path": "/core/src/ciphers/cipher.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>struct CipherKindVisitor;
impl<'de> serde::de::Visitor<'de> for CipherKindVisitor {
type Value = CipherKind;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("u8 from 1 to 3")
}
fn visit_u8<E>(self, n: u8) -> Result<Self::Value, E>
wher... | code_fim | hard | {
"lang": "rust",
"repo": "stevelr/secret-keeper",
"path": "/core/src/ciphers/cipher.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: stevelr/secret-keeper path: /core/src/ciphers/cipher.rs
use crate::{
error::{Error, Result},
keepers::SecretKeeper,
AuthTag, WrappedKey,
};
use async_trait::async_trait;
use bytes::Bytes;
// use serde_repr::{Deserialize_repr, Serialize_repr};
use std::fmt;
use strum_macros::{Display,... | code_fim | hard | {
"lang": "rust",
"repo": "stevelr/secret-keeper",
"path": "/core/src/ciphers/cipher.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>esource
}
;
use
std
:
:
rc
:
:
Rc
;
pub
type
FluentBundle
=
FluentBundleBase
<
Rc
<
FluentResource
>
>
;<|fim_prefix|>// repo: marco-c/gecko-dev-wordified path: /intl/l10n/rust/l10nregistry-rs/src/fluent.rs
use
fluent_bundle
:
:
FluentBundle
as
FluentBundleBa<|fim_middle|>se
;
pub
use
fluent_bundle
:
:
{... | code_fim | easy | {
"lang": "rust",
"repo": "marco-c/gecko-dev-wordified",
"path": "/intl/l10n/rust/l10nregistry-rs/src/fluent.rs",
"mode": "spm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: marco-c/gecko-dev-wordified path: /intl/l10n/rust/l10nregistry-rs/src/fluent.rs
use
fluent_bundle
:
:
FluentBundle
as
FluentBundleBa<|fim_suffix|>esource
}
;
use
std
:
:
rc
:
:
Rc
;
pub
type
FluentBundle
=
FluentBundleBase
<
Rc
<
FluentResource
>
>
;<|fim_middle|>se
;
pub
use
fluent_bundle
:
:
{... | code_fim | easy | {
"lang": "rust",
"repo": "marco-c/gecko-dev-wordified",
"path": "/intl/l10n/rust/l10nregistry-rs/src/fluent.rs",
"mode": "psm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: timyates/crafting-interpreters-rust path: /src/lox/scanner.rs
mod token;
pub struct Scanner<'a> {
source: &'a str,
tokens: Vec<token::Token>,
line: u32,
start: usize,
current: usize,
}
#[derive(Debug, Clone)]
pub struct LoxError;
pub fn init(source: &str) -> Scanner {
... | code_fim | hard | {
"lang": "rust",
"repo": "timyates/crafting-interpreters-rust",
"path": "/src/lox/scanner.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn peek_next(&mut self) -> char {
if self.current + 1 >= self.source.len() {
return '\0';
}
self.source.chars().nth(self.current + 1).unwrap()
}
fn lookahead(&mut self, target: char) -> bool {
if self.at_end() || self.source.chars().nth(self.current... | code_fim | hard | {
"lang": "rust",
"repo": "timyates/crafting-interpreters-rust",
"path": "/src/lox/scanner.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> if self.peek() == '.' && digit(self.peek_next()) {
self.advance();
}
while digit(self.peek()) {
self.advance();
}
let slice = self.source.get(self.start..self.current);
self.add_token_type(token::TokenType::Number(
slice... | code_fim | hard | {
"lang": "rust",
"repo": "timyates/crafting-interpreters-rust",
"path": "/src/lox/scanner.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: minterest-finance/minterest-chain-node path: /service/src/chain_spec.rs
{
let mut properties = Map::new();
properties.insert("tokenDecimals".into(), 18.into());
properties
}),
Extensions {
relay_chain: "rococo-local".into(),
para_id: id.into(),
},
)
}
pub fn get_standalone... | code_fim | hard | {
"lang": "rust",
"repo": "minterest-finance/minterest-chain-node",
"path": "/service/src/chain_spec.rs",
"mode": "psm",
"license": "LicenseRef-scancode-warranty-disclaimer",
"source": "the-stack-v2"
} |
<|fim_suffix|> root_key: AccountId,
initial_authorities: Vec<(AuraId, GrandpaId)>,
endowed_accounts: Vec<AccountId>,
) -> standalone_runtime::GenesisConfig {
standalone_runtime::GenesisConfig {
system: standalone_runtime::SystemConfig {
code: standalone_runtime::WASM_BINARY
.expect("WASM binary was not buil... | code_fim | hard | {
"lang": "rust",
"repo": "minterest-finance/minterest-chain-node",
"path": "/service/src/chain_spec.rs",
"mode": "spm",
"license": "LicenseRef-scancode-warranty-disclaimer",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Calculation existential balance for the pallets accounts and sudo account.
let existential_balances: Vec<(AccountId, Balance)> = ed_accounts
.into_iter()
.map(|account_id| (account_id, existential_deposit))
.collect();
let total_existential = existential_balances.iter().map(|(_, x)| x).sum::<u... | code_fim | hard | {
"lang": "rust",
"repo": "minterest-finance/minterest-chain-node",
"path": "/service/src/chain_spec.rs",
"mode": "spm",
"license": "LicenseRef-scancode-warranty-disclaimer",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: coreos/coreos-installer path: /src/s390x/zipl.rs
// Copyright 2020 CoreOS, 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://www.apache.org/lic... | code_fim | hard | {
"lang": "rust",
"repo": "coreos/coreos-installer",
"path": "/src/s390x/zipl.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let initrd = new_initrd.as_ref().map(|v| v.path()).unwrap_or(&initrd);
// during cosa-build we override hostkey(s) with a universal one
let hostkeys = if let Some(hostkey) = hostkey {
vec![PathBuf::from(hostkey)]
} else {
find_files("/etc/se-hostkeys", |e: &DirEntry| {
... | code_fim | hard | {
"lang": "rust",
"repo": "coreos/coreos-installer",
"path": "/src/s390x/zipl.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[allow(clippy::type_complexity, non_snake_case)]
pub fn deser_list_port_overrides<'a, I>(
tokens: &mut std::iter::Peekable<I>,
) -> Result<Option<std::vec::Vec<crate::model::PortOverride>>, smithy_json::deserialize::Error>
where
I: Iterator<
Item = Result<smithy_json::deserialize::Token<'... | code_fim | hard | {
"lang": "rust",
"repo": "JesseWright/aws-sdk-rust",
"path": "/sdk/globalaccelerator/src/json_deser.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: JesseWright/aws-sdk-rust path: /sdk/globalaccelerator/src/json_deser.rs
lder.set_listener(
crate::json_deser::deser_structure_custom_routing_listener(tokens)?,
);
}
_ => smithy_json::deserialize::token::s... | code_fim | hard | {
"lang": "rust",
"repo": "JesseWright/aws-sdk-rust",
"path": "/sdk/globalaccelerator/src/json_deser.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn deser_structure_port_mapping<'a, I>(
tokens: &mut std::iter::Peekable<I>,
) -> Result<Option<crate::model::PortMapping>, smithy_json::deserialize::Error>
where
I: Iterator<
Item = Result<smithy_json::deserialize::Token<'a>, smithy_json::deserialize::Error>,
>,
{
match tokens... | code_fim | hard | {
"lang": "rust",
"repo": "JesseWright/aws-sdk-rust",
"path": "/sdk/globalaccelerator/src/json_deser.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: serabis-solutions/serabis path: /alerter/src/tables/conditions.rs
use super::Table;
use r2d2_postgres::{PostgresConnectionManager};
use r2d2::{Pool};
//Table
#[derive(Debug)]
pub struct Conditions {
pool: Pool<PostgresConnectionManager>,
}
#[derive(Debug)]
pub struct TriggerContact {
p... | code_fim | hard | {
"lang": "rust",
"repo": "serabis-solutions/serabis",
"path": "/alerter/src/tables/conditions.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let conn = match self.pool.clone().get() {
Ok(v) => v,
Err(e) => {
info!("Failed to clone connection pool: {:?}\nTrying again...", e);
match self.pool.clone().get() {
Ok(v) => v,
Err(e) => panic!("Faile... | code_fim | hard | {
"lang": "rust",
"repo": "serabis-solutions/serabis",
"path": "/alerter/src/tables/conditions.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut contacts = vec![];
let conn = match self.pool.clone().get() {
Ok(v) => v,
Err(e) => {
info!("Failed to clone connection pool: {:?}\nTrying again...", e);
match self.pool.clone().get() {
Ok(v) => v,
... | code_fim | hard | {
"lang": "rust",
"repo": "serabis-solutions/serabis",
"path": "/alerter/src/tables/conditions.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl From<KafkaError> for Error {
fn from(ke: KafkaError) -> Self {
Error::KafkaError(ke)
}
}
impl From<(KafkaError, OwnedMessage)> for Error {
fn from(e: (KafkaError, OwnedMessage)) -> Self {
Error::ProducerError(e)
}
}<|fim_prefix|>// repo: divinerapier/manggis path: /m... | code_fim | medium | {
"lang": "rust",
"repo": "divinerapier/manggis",
"path": "/manggis/src/error/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl From<(KafkaError, OwnedMessage)> for Error {
fn from(e: (KafkaError, OwnedMessage)) -> Self {
Error::ProducerError(e)
}
}<|fim_prefix|>// repo: divinerapier/manggis path: /manggis/src/error/mod.rs
use rdkafka::error::KafkaError;
use rdkafka::message::OwnedMessage;
<|fim_middle|>#[de... | code_fim | hard | {
"lang": "rust",
"repo": "divinerapier/manggis",
"path": "/manggis/src/error/mod.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: divinerapier/manggis path: /manggis/src/error/mod.rs
use rdkafka::error::KafkaError;
use rdkafka::message::OwnedMessage;
<|fim_suffix|>impl From<KafkaError> for Error {
fn from(ke: KafkaError) -> Self {
Error::KafkaError(ke)
}
}
impl From<(KafkaError, OwnedMessage)> for Error {... | code_fim | medium | {
"lang": "rust",
"repo": "divinerapier/manggis",
"path": "/manggis/src/error/mod.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: lyuben-todorov/piko path: /node/src/semaphore.rs
use std::cmp::{Ordering, Reverse};
use std::collections::BinaryHeap;
/// The goal of this data structure is to provide an explicit ordering of async events in a multi-threaded
/// process. It holds a sequence of event handles with a defined total... | code_fim | hard | {
"lang": "rust",
"repo": "lyuben-todorov/piko",
"path": "/node/src/semaphore.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let i = Inner {
done: false.into(),
done_mutex: Mutex::new(false),
cv: Condvar::new(),
};
let client = Client(Arc::new(i));
let watcher = Watcher(client.0.clone());
(client, watcher)
}
}
#[derive(Clone)]
struct Watcher(Arc<In... | code_fim | hard | {
"lang": "rust",
"repo": "lyuben-todorov/piko",
"path": "/node/src/semaphore.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: hunterlester/rusting_leetcode path: /src/matrices.rs
use std::collections::HashSet;
fn is_valid_sudoku(board: Vec<Vec<&str>>) -> bool {
const BOARD_INDICES: [(usize, usize); 9] = [(0,0), (0,3), (0, 6), (3, 0), (3, 3), (3, 6), (6, 0), (6, 3), (6, 6)];
let mut row_set: HashSet<&str> = Has... | code_fim | hard | {
"lang": "rust",
"repo": "hunterlester/rusting_leetcode",
"path": "/src/matrices.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn test_valid_sudoku() {
let board = vec![
vec!["5","3",".",".","7",".",".",".","."],
vec!["6",".",".","1","9","5",".",".","."],
vec![".","9","8",".",".",".",".","6","."],
vec!["8",".",".",".","6",".",".",".","3"],
vec!["4",".",".",... | code_fim | hard | {
"lang": "rust",
"repo": "hunterlester/rusting_leetcode",
"path": "/src/matrices.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn log_deserialization() {
let s = r#"{
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"bloom" : "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000... | code_fim | hard | {
"lang": "rust",
"repo": "yijie37/DaQiao",
"path": "/bridge/parity-ethereum/json/src/state/log.rs",
"mode": "spm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: yijie37/DaQiao path: /bridge/parity-ethereum/json/src/state/log.rs
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity Ethereum.
// Parity Ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as ... | code_fim | hard | {
"lang": "rust",
"repo": "yijie37/DaQiao",
"path": "/bridge/parity-ethereum/json/src/state/log.rs",
"mode": "psm",
"license": "Unlicense",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: huangjj27/leetcode-SAO path: /src/offer/offer20.rs
//! 请实现一个函数用来判断字符串是否表示数值(包括整数和小数)。
//! 例如,字符串"+100"、"5e2"、"-123"、"3.1416"、"-1E-16"、"0123"都表示数值,
//! 但"12e"、"1a3.14"、"1.2.3"、"+-5"及"12e+5.4"都不是。
pub fn is_number(s: String) -> bool {
let s = s.trim();
return s.parse::<i32>().is_ok() || s... | code_fim | hard | {
"lang": "rust",
"repo": "huangjj27/leetcode-SAO",
"path": "/src/offer/offer20.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn test_signs() {
assert!(is_number("+100".to_string()));
assert!(is_number("-123".to_string()));
assert!(!is_number("+-5".to_string()));
}
#[test]
fn test_exponent() {
assert!(is_number("1e0".to_string()));
assert!(is_number("1e1".to_st... | code_fim | hard | {
"lang": "rust",
"repo": "huangjj27/leetcode-SAO",
"path": "/src/offer/offer20.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: dylanmckay/readterm path: /src/os/unix.rs
use crate::{
core::Settings,
event,
os,
Color,
};
use std::process::Command;
use std::{env, io, mem};
/// A Unix terminal driver.
pub struct Driver {
/// The settings.
settings: Settings,
/// The underlying shell background p... | code_fim | hard | {
"lang": "rust",
"repo": "dylanmckay/readterm",
"path": "/src/os/unix.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> -> rexpect::session::PtySession {
let mut cmd = Command::new(&settings.shell);
// FIXME: this won't exist if binaries are redistributed.
let dir = format!("{}/../", env!("CARGO_MANIFEST_DIR"));
cmd.current_dir(dir);
rexpect::session::spawn_command(cmd, None)
.expect("fai... | code_fim | hard | {
"lang": "rust",
"repo": "dylanmckay/readterm",
"path": "/src/os/unix.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[error("Failed to recover ed25519 public key from its base58 representation - {0}")]
MalformedEd25519IdentityKey(String),
#[error("Failed to recover ed25519 signature from its base58 representation - {0}")]
MalformedEd25519Signature(String),
#[error("Provided ed25519 signature did n... | code_fim | hard | {
"lang": "rust",
"repo": "nymtech/nym",
"path": "/common/cosmwasm-smart-contracts/service-provider-directory/src/error.rs",
"mode": "spm",
"license": "CC0-1.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[error("deposit too large: {funds}, required: {deposit_required}")]
TooLargeDeposit {
funds: cosmwasm_std::Uint128,
deposit_required: cosmwasm_std::Uint128,
},
#[error("reached the max number of providers ({max_providers}) for announcer {announcer}")]
ReachedMaxProvid... | code_fim | hard | {
"lang": "rust",
"repo": "nymtech/nym",
"path": "/common/cosmwasm-smart-contracts/service-provider-directory/src/error.rs",
"mode": "spm",
"license": "CC0-1.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: nymtech/nym path: /common/cosmwasm-smart-contracts/service-provider-directory/src/error.rs
use cosmwasm_std::{Addr, StdError};
use cw_controllers::AdminError;
use nym_contracts_common::signing::verifier::ApiVerifierError;
use thiserror::Error;
use crate::{NymAddress, ServiceId};
#[derive(Error... | code_fim | hard | {
"lang": "rust",
"repo": "nymtech/nym",
"path": "/common/cosmwasm-smart-contracts/service-provider-directory/src/error.rs",
"mode": "psm",
"license": "CC0-1.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: CBenoit/nushell path: /crates/nu-command/src/math/sqrt.rs
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Span, Value};
#[derive(Clone)]
pub struct SubCommand;
impl Command for SubComm... | code_fim | hard | {
"lang": "rust",
"repo": "CBenoit/nushell",
"path": "/crates/nu-command/src/math/sqrt.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> Signature::build("math sqrt").category(Category::Math)
}
fn usage(&self) -> &str {
"Applies the square root function to a list of numbers"
}
fn search_terms(&self) -> Vec<&str> {
vec!["square", "root"]
}
fn run(
&self,
engine_state: &Engin... | code_fim | hard | {
"lang": "rust",
"repo": "CBenoit/nushell",
"path": "/crates/nu-command/src/math/sqrt.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: frxstrem/pretty-log path: /src/format/style.rs
use std::io::{self, Write};
use crate::message::Severity;
pub trait Style: Into<AnyStyle> {
fn reset<W: Write + ?Sized>(&self, writer: &mut W) -> io::Result<()>;
fn severity<W: Write + ?Sized>(&self, writer: &mut W, severity: Severity) -> ... | code_fim | hard | {
"lang": "rust",
"repo": "frxstrem/pretty-log",
"path": "/src/format/style.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> Ok(())
}
fn strong<W: Write + ?Sized>(&self, _writer: &mut W) -> io::Result<()> {
Ok(())
}
}
pub struct ColoredStyle;
impl From<ColoredStyle> for AnyStyle {
fn from(style: ColoredStyle) -> AnyStyle {
AnyStyle::Colored(style)
}
}
impl Style for ColoredStyle {... | code_fim | hard | {
"lang": "rust",
"repo": "frxstrem/pretty-log",
"path": "/src/format/style.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: MahanthMohan/Rust-Projects path: /guessing-game/src/main.rs
// Declaring rand as an external crate
extern crate rand;
// io library
use std::io;
// Ordering - Greater/Lesser/Equal
use std::cmp::Ordering;
// Random Generator trait
use rand::Rng;
fn main() {
// Usage of the println!() macro
... | code_fim | medium | {
"lang": "rust",
"repo": "MahanthMohan/Rust-Projects",
"path": "/guessing-game/src/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> match guess.cmp(&target) {
Ordering::Less => println!("Too small!\n{}", endl),
Ordering::Greater => println!("Too big!\n{}", endl),
Ordering::Equal => break,
}
}
println!("Congragulations!");
println!("Your Guess: {}Actual: {}", guess, target);
}<|fim_prefix|>//... | code_fim | hard | {
"lang": "rust",
"repo": "MahanthMohan/Rust-Projects",
"path": "/guessing-game/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>)?;
println!("channel '{}': {}", msg.get_channel_name(), payload);
}
}
fn main() {
pub_sub();
}<|fim_prefix|>// repo: joaopedro5g/RustNodeRedis path: /rust/src/main.rs
extern crate redis;
fn pub_sub() -> redis::RedisResult<()> {
let client = redis::Client::open("redis://127.<|fim_mid... | code_fim | hard | {
"lang": "rust",
"repo": "joaopedro5g/RustNodeRedis",
"path": "/rust/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: joaopedro5g/RustNodeRedis path: /rust/src/main.rs
extern crate redis;
fn pub_sub() -> redis::RedisResult<()> {
let client = redis::Client::open("redis://127.<|fim_suffix|>be("rust")?;
loop {
let msg = pubsub.get_message()?;
let payload: String = msg.get_payload()?;
... | code_fim | medium | {
"lang": "rust",
"repo": "joaopedro5g/RustNodeRedis",
"path": "/rust/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: simlay/uikit-sys path: /examples/rect.rs
#[macro_use]
extern crate objc;
use log::trace;
use objc::{
declare::ClassDecl,
runtime::{Class, Object, Sel},
};
use winit::event_loop::EventLoopProxy;
use winit::{
event::{Event, StartCause, WindowEvent},
event_loop::{ControlFlow, Event... | code_fim | hard | {
"lang": "rust",
"repo": "simlay/uikit-sys",
"path": "/examples/rect.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[derive(PartialEq, Clone, Debug)]
pub struct WidgetEvent {
pub widget_id: u64,
pub id: usize,
}
#[derive(Debug)]
pub struct EventHandler {
pub id: id,
pub widget_id: u64,
}
static mut PROXY: Option<EventLoopProxy<WidgetEvent>> = None;
static mut COUNTER: Option<u64> = None;
impl EventHa... | code_fim | hard | {
"lang": "rust",
"repo": "simlay/uikit-sys",
"path": "/examples/rect.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: linkerd/linkerd2 path: /policy-controller/k8s/index/src/inbound/server.rs
use crate::ClusterInfo;
use linkerd_policy_controller_core::inbound::ProxyProtocol;
use linkerd_policy_controller_k8s_api::{self as k8s, policy::server::Port};
/// The parts of a `Server` resource that can change.
#[deriv... | code_fim | hard | {
"lang": "rust",
"repo": "linkerd/linkerd2",
"path": "/policy-controller/k8s/index/src/inbound/server.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> p: Option<k8s::policy::server::ProxyProtocol>,
cluster: &ClusterInfo,
) -> ProxyProtocol {
match p {
None | Some(k8s::policy::server::ProxyProtocol::Unknown) => ProxyProtocol::Detect {
timeout: cluster.default_detect_timeout,
},
Some(k8s::policy::server::Pro... | code_fim | hard | {
"lang": "rust",
"repo": "linkerd/linkerd2",
"path": "/policy-controller/k8s/index/src/inbound/server.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Server {
pub(crate) fn from_resource(srv: k8s::policy::Server, cluster: &ClusterInfo) -> Self {
Self {
labels: srv.metadata.labels.into(),
pod_selector: srv.spec.pod_selector,
port_ref: srv.spec.port,
protocol: proxy_protocol(srv.spec.proxy_... | code_fim | hard | {
"lang": "rust",
"repo": "linkerd/linkerd2",
"path": "/policy-controller/k8s/index/src/inbound/server.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: denbeigh2000/slack-blocks path: /src/elements/mod.rs
// Reference: https://api.slack.com/reference/block-kit/block-elements
mod button;
mod datepicker;
mod menus;
pub use crate::elements::button::{Button, ButtonBuilder, ButtonStyle};
pub use crate::elements::datepicker::{DatePicker, DatePickerB... | code_fim | hard | {
"lang": "rust",
"repo": "denbeigh2000/slack-blocks",
"path": "/src/elements/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn set_placeholder(mut self, ph: Text) -> Self {
self.placeholder = Some(ph);
self
}
pub fn set_initial_value<S: Into<String>>(mut self, value: S) -> Self {
self.initial_value = Some(value.into());
self
}
pub fn set_multiline(mut self, ml: bool) ->... | code_fim | hard | {
"lang": "rust",
"repo": "denbeigh2000/slack-blocks",
"path": "/src/elements/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> ReaderContext {
context: context,
peer: peer,
}
}
fn dispatch(&self, msg: FabricMsg) {
let msg_type = msg.get_type();
if let Some(handler) = self
.context
.msg_handlers
.read()
.unwrap()
... | code_fim | hard | {
"lang": "rust",
"repo": "arthurprs/sucredb",
"path": "/src/fabric.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: arthurprs/sucredb path: /src/fabric.rs
code payload
struct FramedBincodeCodec;
impl codec::Decoder for FramedBincodeCodec {
type Item = FabricMsg;
type Error = io::Error;
fn decode(&mut self, src: &mut BytesMut) -> io::Result<Option<Self::Item>> {
let (consumed, result) = {... | code_fim | hard | {
"lang": "rust",
"repo": "arthurprs/sucredb",
"path": "/src/fabric.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn steady_connection(
socket: tokio::net::TcpStream,
peer: NodeId,
context: Arc<SharedContext>,
) -> Box<Future<Item = (), Error = io::Error>> {
let (socket_rx, socket_tx) = socket.split();
let socket_tx = codec::FramedWrite::new(socket_tx, FramedBincodeCode... | code_fim | hard | {
"lang": "rust",
"repo": "arthurprs/sucredb",
"path": "/src/fabric.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>async fn notify_shutdown(mut tx: tokio::sync::mpsc::Sender<()>) {
let _ = signal(SignalKind::terminate())
.expect("bind SIGTERM")
.into_future()
.await;
tx.send(()).await.expect("notify");
}<|fim_prefix|>// repo: xDarksome/img-storage path: /src/main.rs
mod api;
mod libvip... | code_fim | hard | {
"lang": "rust",
"repo": "xDarksome/img-storage",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: xDarksome/img-storage path: /src/main.rs
mod api;
mod libvips;
mod service;
mod tests;
#[macro_use]
extern crate log;
#[macro_use]
extern crate lazy_static;
<|fim_suffix|> let (tx, mut rx) = tokio::sync::mpsc::channel::<()>(1);
tokio_executor::spawn(notify_shutdown(tx));
let port: ... | code_fim | hard | {
"lang": "rust",
"repo": "xDarksome/img-storage",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: museun/alto_logger path: /src/options/time.rs
/// How the timestamp should be displayed
///
/// Several helper methods for constructing this type are provided
/// * [`Relative`](enum.TimeConfig.html#variant.Relative) timestamp style
/// * use [`TimeConfig::relative_now`](enum.TimeConfig.html... | code_fim | hard | {
"lang": "rust",
"repo": "museun/alto_logger",
"path": "/src/options/time.rs",
"mode": "psm",
"license": "0BSD",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[cfg(feature = "time")]
/// Create a DateTime format
///
/// See the formatting description [here](https://time-rs.github.io/book/api/format-description.html)
///
/// This requires you to use a statically-parsed `format_description`.
///
/// you can get one via [`format_de... | code_fim | hard | {
"lang": "rust",
"repo": "museun/alto_logger",
"path": "/src/options/time.rs",
"mode": "spm",
"license": "0BSD",
"source": "the-stack-v2"
} |
<|fim_suffix|> match self {
Self::None => Self::None,
Self::Unix => Self::Unix,
Self::Relative(inner) => Self::Relative(*inner),
Self::Timing(_) => Self::Timing(Default::default()),
#[cfg(feature = "time")]
Self::DateTime(inner) => Self::Dat... | code_fim | hard | {
"lang": "rust",
"repo": "museun/alto_logger",
"path": "/src/options/time.rs",
"mode": "spm",
"license": "0BSD",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: srplab/starcore_for_rust path: /src/lib.rs
if let Some(fdata) = Obj.downcast_ref::<u16>() {
return (*fdata as u32, true);
} else if let Some(fdata) = Obj.downcast_ref::<i32>() {
return (*fdata as u32, true);
} else if let Some(fdata) = Obj.downcast_ref::<u32>() {
... | code_fim | hard | {
"lang": "rust",
"repo": "srplab/starcore_for_rust",
"path": "/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: srplab/starcore_for_rust path: /src/lib.rs
ObjData.ObjData.RefItem = G_WEAKTABLE_REFCOUNT;
}else{
ObjData.ObjData.RefItem = RefCount;
}
}
item.RefCount = 0 as usize;
item.ObjType = OBJECTTYPE_STARSERVICE;
item.ObjData_S... | code_fim | hard | {
"lang": "rust",
"repo": "srplab/starcore_for_rust",
"path": "/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> unsafe{
if StarRust_SRPControlInterface == 0 as *mut c_void {
return;
}
let PostObjData : StarObjectBody;
{
let mut In_ObjData = STARGETRCMUT_STAROBJECT!(self);
if let Some(ObjData) = In_ObjData.as_mut() {
... | code_fim | hard | {
"lang": "rust",
"repo": "srplab/starcore_for_rust",
"path": "/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: x7c1/plus path: /apps/s3api/src/serialize.rs
use crate::S3ApiResult;
use serde::Serialize;
pub trait AwsJsonSerialize: Serialize {
/// generate JSON String which has indents with 4 spaces
/// according to the behavior of AWS CLI.
fn to_aws_json(&self) -> S3ApiResult<String> {
... | code_fim | medium | {
"lang": "rust",
"repo": "x7c1/plus",
"path": "/apps/s3api/src/serialize.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>serialize(&mut serializer)?;
String::from_utf8(serializer.into_inner())?
};
Ok(json)
}
}
impl<A> AwsJsonSerialize for A where A: Serialize {}<|fim_prefix|>// repo: x7c1/plus path: /apps/s3api/src/serialize.rs
use crate::S3ApiResult;
use serde::Serialize;
pub trait AwsJso... | code_fim | hard | {
"lang": "rust",
"repo": "x7c1/plus",
"path": "/apps/s3api/src/serialize.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ytitov/grpc-rust-dart-demo path: /sy-server/src/messages/messages.rs
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct NewMessageParms {
#[prost(string, tag = "1")]
pub username: std::string::String,
#[prost(string, tag = "2")]
pub message_text: std::string::String,
#[... | code_fim | hard | {
"lang": "rust",
"repo": "ytitov/grpc-rust-dart-demo",
"path": "/sy-server/src/messages/messages.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let inner = self.inner.clone();
match req.uri().path() {
"/messages.Messages/NewMessage" => {
#[allow(non_camel_case_types)]
struct NewMessageSvc<T: Messages>(pub Arc<T>);
impl<T: Messages> tonic::server::U... | code_fim | hard | {
"lang": "rust",
"repo": "ytitov/grpc-rust-dart-demo",
"path": "/sy-server/src/messages/messages.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl RecommendationsRequest {
pub fn for_track(id: TrackId) -> Self {
Self {
seed_tracks: vector![id],
..Self::default()
}
}
}
#[derive(Clone, Copy, Debug, Default, Data, PartialEq, Eq, Hash)]
pub struct Range<T> {
pub min: Option<T>,
pub max: Optio... | code_fim | hard | {
"lang": "rust",
"repo": "KonstantinDjairo/psst",
"path": "/psst-gui/src/data/recommend.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: KonstantinDjairo/psst path: /psst-gui/src/data/recommend.rs
use std::sync::Arc;
use druid::{
im::{vector, Vector},
Data, Lens,
};
use serde::Deserialize;
use super::{ArtistLink, Promise, Track, TrackId};
#[derive(Clone, Data, Lens)]
pub struct Recommend {
pub results: Promise<Reco... | code_fim | hard | {
"lang": "rust",
"repo": "KonstantinDjairo/psst",
"path": "/psst-gui/src/data/recommend.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Sk3pz/mittere path: /mittere-server/src/main.rs
// Mittere server
use std::net::{TcpListener, TcpStream};
use mittere_lib::logger::Logger;
use mittere_lib::{make_logger, unwrap_or_default};
use std::sync::mpsc::{Sender, Receiver, channel};
use crate::command::command_processor;
use crate::clien... | code_fim | hard | {
"lang": "rust",
"repo": "Sk3pz/mittere",
"path": "/mittere-server/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> global_logger.lock().unwrap().warn(format!("A connection was attempted by {} but was refused: server is full.", ip));
drop(s);
continue;
}
global_logger.lock().unwrap().verbose(format!("Accepted connection: {}.", ip));
le... | code_fim | hard | {
"lang": "rust",
"repo": "Sk3pz/mittere",
"path": "/mittere-server/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // open the listener on the address
let listener_result = TcpListener::bind(address.clone());
if listener_result.is_err() {
// TODO: give a better explanation as to what happened with more info to help the user fix the issue?
global_logger.lock().unwrap().failure(format!("Could... | code_fim | hard | {
"lang": "rust",
"repo": "Sk3pz/mittere",
"path": "/mittere-server/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let strs = vec![String::from("s1"),String::from("s2")];
let ref_strs = & strs;
let longest = & ref_strs[0];
let l1 = strs[0];
}<|fim_prefix|>// repo: wmmxk/OOP_Rust path: /vector/index/main.rs
// This code is to show you can not move out of indexed content
<|fim_middle|>fn main() {
| code_fim | easy | {
"lang": "rust",
"repo": "wmmxk/OOP_Rust",
"path": "/vector/index/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: wmmxk/OOP_Rust path: /vector/index/main.rs
// This code is to show you can not move out of indexed content
<|fim_suffix|> let strs = vec![String::from("s1"),String::from("s2")];
let ref_strs = & strs;
let longest = & ref_strs[0];
let l1 = strs[0];
}<|fim_middle|>fn main() {
| code_fim | easy | {
"lang": "rust",
"repo": "wmmxk/OOP_Rust",
"path": "/vector/index/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: aoprisan/func path: /src/semigroup.rs
pub trait Semigroup {
type T;
fn add_and_own(self, t2: Self::T) -> Self::T;
}
///Macro to implement semigroup for numerics
#[macro_export]
macro_rules! semigroup_num {
($t:ident) => {
impl Semigroup for $t {
type T = $t;
... | code_fim | hard | {
"lang": "rust",
"repo": "aoprisan/func",
"path": "/src/semigroup.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> assert_eq!(Box::new(1).add_and_own(Box::new(2)), Box::new(3));
}
#[test]
fn test_option_semigroup(){
assert_eq!(Some(1).add_and_own(Some(2)), Some(3));
assert_eq!(Some(1).add_and_own(None), None);
assert_eq!(None.add_and_own(Some(2)), None);
}<|fim_prefix|>// repo: aoprisan/func path: /s... | code_fim | hard | {
"lang": "rust",
"repo": "aoprisan/func",
"path": "/src/semigroup.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn add_and_own(self, t2: Self::T) -> Self::T {
let x = *self as A;
let y = *t2 as A;
let r = x.add_and_own(y);
Box::new(r)
}
}
#[test]
fn test_num_semigroup(){
assert_eq!(1.add_and_own(2), 3);
}
#[test]
fn test_box_semigroup(){
assert_eq!(Box::new(1).add_a... | code_fim | hard | {
"lang": "rust",
"repo": "aoprisan/func",
"path": "/src/semigroup.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> Box::new(self.clone())
}
}
impl Clone for Box<dyn Symbol> {
fn clone(&self) -> Box<dyn Symbol> {
self.clone_box()
}
}<|fim_prefix|>// repo: lnds/Ogu path: /ogu-lang/src/backend/scopes/symbol.rs
#![allow(clippy::transmute_ptr_to_ref)]
use std::fmt::Debug;
use anyhow::Result;... | code_fim | hard | {
"lang": "rust",
"repo": "lnds/Ogu",
"path": "/ogu-lang/src/backend/scopes/symbol.rs",
"mode": "spm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: lnds/Ogu path: /ogu-lang/src/backend/scopes/symbol.rs
#![allow(clippy::transmute_ptr_to_ref)]
use std::fmt::Debug;
use anyhow::Result;
use crate::backend::scopes::types::Type;
use crate::backend::scopes::Scope;
pub(crate) trait Symbol: SymbolClone + Debug + mopa::Any {
fn get_name(&self)... | code_fim | hard | {
"lang": "rust",
"repo": "lnds/Ogu",
"path": "/ogu-lang/src/backend/scopes/symbol.rs",
"mode": "psm",
"license": "LicenseRef-scancode-unknown-license-reference",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: Konard/links-rs path: /src/linksdb/sbt_link.rs
pub struct Link <T> {
source: T,
target: T,
root_as_source: T,
left_as_source: T,
right_as_source:<|fim_suffix|>s_target: T,
right_as_target: T,
size_as_target: T
}<|fim_middle|> T,
size_as_soucre: T,
root_as_ta... | code_fim | medium | {
"lang": "rust",
"repo": "Konard/links-rs",
"path": "/src/linksdb/sbt_link.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>s_target: T,
right_as_target: T,
size_as_target: T
}<|fim_prefix|>// repo: Konard/links-rs path: /src/linksdb/sbt_link.rs
pub struct Link <T> {
source: T,
target: T,
root_as_source: T,
left_as_source: T,
right_as_source:<|fim_middle|> T,
size_as_soucre: T,
root_as_ta... | code_fim | medium | {
"lang": "rust",
"repo": "Konard/links-rs",
"path": "/src/linksdb/sbt_link.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: eisen-oxid/thermit path: /server/src/user/routes.rs
use crate::errors::ServiceError;
use crate::user::model::{User, UserData};
use crate::Pool;
use actix_web::error::BlockingError;
use actix_web::{delete, get, post, put, web, HttpResponse};
use serde_json::json;
use uuid::Uuid;
#[get("/users")]... | code_fim | hard | {
"lang": "rust",
"repo": "eisen-oxid/thermit",
"path": "/server/src/user/routes.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> if let Some(user) = user {
Ok(HttpResponse::Ok().json(user))
} else {
Err(ServiceError::NotFound)
}
}
#[post("/users")]
async fn create(
pool: web::Data<Pool>,
user_data: web::Json<UserData>,
) -> Result<HttpResponse, ServiceError> {
let conn = pool.get().expect("c... | code_fim | hard | {
"lang": "rust",
"repo": "eisen-oxid/thermit",
"path": "/server/src/user/routes.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[delete("/users/{id}")]
pub async fn delete(
pool: web::Data<Pool>,
user_id: web::Path<Uuid>,
) -> Result<HttpResponse, ServiceError> {
let conn = pool.get().expect("couldn't get db connection from pool");
let count = web::block(move || User::destroy(&conn, user_id.into_inner()))
... | code_fim | hard | {
"lang": "rust",
"repo": "eisen-oxid/thermit",
"path": "/server/src/user/routes.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: NyxCode/ublocks-ascii-art path: /src/raster.rs
use bit_vec::BitVec;
pub trait Raster {
fn new(width: usize, height: usize) -> Self;
fn width(&self) -> usize;
fn height(&self) -> usize;
fn set_pixel(&mut self, x: usize, y: usize);
fn render(&self) -> String;
}
pub struct Si... | code_fim | hard | {
"lang": "rust",
"repo": "NyxCode/ublocks-ascii-art",
"path": "/src/raster.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> for block_y in 0..height_in_blocks {
for block_x in 0..width_in_blocks {
let subpixel = (
self.storage[block_y * 2 * self.width + block_x * 2],
self.storage[block_y * 2 * self.width + block_x * 2 + 1],
self.sto... | code_fim | hard | {
"lang": "rust",
"repo": "NyxCode/ublocks-ascii-art",
"path": "/src/raster.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mass_contrib = weight * p.mass;
let cell_idx = cell_x.x as usize * CELL_DIM + cell_x.y as usize;
if cell_idx >= self.cells.len() {
continue;
}
let cell = &mut self.cells[cell_i... | code_fim | hard | {
"lang": "rust",
"repo": "medakk/learn-mpm",
"path": "/src/lib.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: medakk/learn-mpm path: /src/lib.rs
#![allow(non_snake_case)]
extern crate rand;
extern crate nalgebra_glm as glm;
const CELL_DIM: usize = 64;
const GRAVITY: f32 = 0.4;
const REST_DENSITY: f32 = 9.0;
const DYNAMIC_VISCOSITY: f32 = 0.11;
const EOS_STIFFNESS: f32 = 13.1;
const EOS_POWER: f32 = 7.... | code_fim | hard | {
"lang": "rust",
"repo": "medakk/learn-mpm",
"path": "/src/lib.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.