text stringlengths 232 16.3k | domain stringclasses 1
value | difficulty stringclasses 3
values | meta dict |
|---|---|---|---|
<|fim_prefix|>// repo: yugen-sec/OffensiveRust path: /tcp_ssl_client/src/main.rs
use std::io::{Read, Write};
use std::net;
use std::net::{Ipv4Addr, TcpStream, SocketAddr};
use std::process::{Command, Stdio};
use std::str;
use std::thread;
use std::path::Path;
use openssl::ssl::{SslMethod, SslConnector};
use std::ffi::... | code_fim | medium | {
"lang": "rust",
"repo": "yugen-sec/OffensiveRust",
"path": "/tcp_ssl_client/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut build = SslConnector::builder(SslMethod::tls()).unwrap();
build.set_verify(openssl::ssl::SslVerifyMode::NONE);
let connector = build.build();
let addr = Ipv4Addr::new(127,0,0,1);
let sockettest = SocketAddr::from((addr,4443));
let convertsocket = sockettest.to_string();
let convert... | code_fim | medium | {
"lang": "rust",
"repo": "yugen-sec/OffensiveRust",
"path": "/tcp_ssl_client/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: KevinKelley/oui-rs path: /examples/pistonic/src/ui.rs
hemedContext;
use blendish::themed_draw::ThemedDraw;
use blendish::lowlevel_draw::LowLevelDraw;
use oui;
use oui::*;
// FIXME need Some<iconid> apparently (seems to use -1 for no-icon)
fn icon_id(x:u8, y:u8) -> i32 { ICONID(x, y) as i32 }
... | code_fim | hard | {
"lang": "rust",
"repo": "KevinKelley/oui-rs",
"path": "/examples/pistonic/src/ui.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: KevinKelley/oui-rs path: /examples/pistonic/src/ui.rs
ared refs to ui-updatable data
use blendish;
use blendish::*;
use blendish::ThemedContext;
use blendish::themed_draw::ThemedDraw;
use blendish::lowlevel_draw::LowLevelDraw;
use oui;
use oui::*;
// FIXME need Some<iconid> apparently (seems... | code_fim | hard | {
"lang": "rust",
"repo": "KevinKelley/oui-rs",
"path": "/examples/pistonic/src/ui.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let item = ui.last_child(parent);
let last = ui.prev_sibling(item);
// mark the new item as positioned under the previous item
ui.set_rel_to_top(item, last);
// fill parent horizontally, anchor to previous item vertically
ui.set_layout(item, HFILL|TOP);
// if not the first item... | code_fim | hard | {
"lang": "rust",
"repo": "KevinKelley/oui-rs",
"path": "/examples/pistonic/src/ui.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn new() -> Memory{
Memory {
mem: [0; 4096]
}
}
pub fn write_byte(&mut self, address: u16, value: u8) {
}
pub fn read_byte(&mut self, address: u16, value: u8) {
}
}<|fim_prefix|>// repo: carcharo/Chip8Emulator-Rust path: /src/memory.rs
... | code_fim | medium | {
"lang": "rust",
"repo": "carcharo/Chip8Emulator-Rust",
"path": "/src/memory.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: carcharo/Chip8Emulator-Rust path: /src/memory.rs
/* Most Chip-8 programs start at location 0x200 (512), but some begin at 0x600 (1536). Programs beginning at 0x600 are intended for the ETI 660 computer.
Memory Map:
+---------------+= 0xFFF (4095) End of Chip-8 RAM
| |
| ... | code_fim | medium | {
"lang": "rust",
"repo": "carcharo/Chip8Emulator-Rust",
"path": "/src/memory.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>unsafe extern "C" fn print_me(
_type_: std::os::raw::c_int,
_module_number: std::os::raw::c_int,
) -> std::os::raw::c_int {
BACKUP = sys::zend_execute_ex;
sys::zend_execute_ex = Some(execute);
0
}
pub fn create_module() -> anyhow::Result<Box<sys::zend_module_entry>> {
let x: sys::... | code_fim | medium | {
"lang": "rust",
"repo": "pawelchcki/php_bindings_rust",
"path": "/php-5x/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: pawelchcki/php_bindings_rust path: /php-5x/src/lib.rs
use std::ffi::{CStr, CString};
use std::{mem::size_of, option, ptr};
pub mod cstr;
pub mod php56;
pub mod php_info;
use php_all_sys::php56 as sys;
type Exec = unsafe extern "C" fn(execute_data: *mut sys::zend_execute_data);
static mut BAC... | code_fim | hard | {
"lang": "rust",
"repo": "pawelchcki/php_bindings_rust",
"path": "/php-5x/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub fn create_module() -> anyhow::Result<Box<sys::zend_module_entry>> {
let x: sys::zend_module_entry = sys::zend_module_entry {
size: size_of::<sys::zend_module_entry>() as u16,
zend_api: sys::ZEND_MODULE_API_NO,
zend_debug: sys::DEBUG_ZEND as u8,
zts: sys::USING_ZTS a... | code_fim | hard | {
"lang": "rust",
"repo": "pawelchcki/php_bindings_rust",
"path": "/php-5x/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: ngortheone/swayipc-command-builder path: /src/commands/title_align.rs
use super::*;
impl Command<TitleAlign> {
pub fn left(self) -> Command<Valid> {
self.push_str("left").transmute()
}
<|fim_suffix|> pub fn right(self) -> Command<Valid> {
self.push_str("right").trans... | code_fim | medium | {
"lang": "rust",
"repo": "ngortheone/swayipc-command-builder",
"path": "/src/commands/title_align.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn right(self) -> Command<Valid> {
self.push_str("right").transmute()
}
}<|fim_prefix|>// repo: ngortheone/swayipc-command-builder path: /src/commands/title_align.rs
use super::*;
impl Command<TitleAlign> {
pub fn left(self) -> Command<Valid> {
self.push_str("left").trans... | code_fim | medium | {
"lang": "rust",
"repo": "ngortheone/swayipc-command-builder",
"path": "/src/commands/title_align.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn find_minimum(a: &[f64]) -> usize {
let mut min_index = std::usize::MAX;
let mut min_value = std::f64::MAX;
for i in 0..a.len() {
let v = a[i];
if v < min_value {
min_value = v;
min_index = i;
}
}
min_index
}
#[cfg(test)]
mod tests {
... | code_fim | medium | {
"lang": "rust",
"repo": "svenschmidt75/Rust",
"path": "/DSandAlg/SelectionSort/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: svenschmidt75/Rust path: /DSandAlg/SelectionSort/src/lib.rs
fn selection_sort(a: &mut [f64]) {
// SS: Selection sort, ascending, an O(N^2) sorting algorithm,
// in-place
// SS: splits array in sorted and unsorted part
// [0..partition_index] = sorted
// [partition_index..] ... | code_fim | hard | {
"lang": "rust",
"repo": "svenschmidt75/Rust",
"path": "/DSandAlg/SelectionSort/src/lib.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Arrange
let mut a = [64.0, 25.0, 12.0, 22.0, 11.0];
// Act
selection_sort(&mut a);
// Assert
assert_eq!(a[0], 11.0);
assert_eq!(a[1], 12.0);
assert_eq!(a[2], 22.0);
assert_eq!(a[3], 25.0);
assert_eq!(a[4], 64.0);
}
}<... | code_fim | hard | {
"lang": "rust",
"repo": "svenschmidt75/Rust",
"path": "/DSandAlg/SelectionSort/src/lib.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: kevin01001101/hello_rust path: /src/main.rs
use std::mem;
mod pm;
pub use crate::pm::pattern_matching;
struct Point {
x: f64,
y: f64
}
fn origin() -> Point {
Point {x: 0.0, y: 0.0}
}
pub fn stack_and_heap()
{
}
fn add() -> i32
{
let a = 2 + 3;
return a;
}
fn main()
{
patter... | code_fim | hard | {
"lang": "rust",
"repo": "kevin01001101/hello_rust",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> match result
{
Some(z) => println!("{} / {} = {}", x, y, z),
_ => println!("cannot divide")
}
}
fn points()
{
let p = My3dPoint { x: 3.0, y: 4.0, z: 5.0};
println!("Point is {}", p.x);
}
struct My3dPoint {
x: f64,
y: f64,
z: f64
}
enum Color
{
Red,
Green,
Blue,... | code_fim | hard | {
"lang": "rust",
"repo": "kevin01001101/hello_rust",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: slazicoicr/noodles path: /noodles-vcf/src/header/record/value.rs
use std::fmt;
/// A VCF header record value.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Value {
/// A string.
String(String),
/// A structure.
Struct(Vec<(String, String)>),
}
impl fmt::Display for Value {
... | code_fim | hard | {
"lang": "rust",
"repo": "slazicoicr/noodles",
"path": "/noodles-vcf/src/header/record/value.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> match self {
Self::String(value) => f.write_str(value),
Self::Struct(fields) => {
for (i, (key, value)) in fields.iter().enumerate() {
if i > 0 {
f.write_str(",")?;
}
write!... | code_fim | hard | {
"lang": "rust",
"repo": "slazicoicr/noodles",
"path": "/noodles-vcf/src/header/record/value.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> Instance::new(light_client, state)
}
struct TestEvidenceReporter;
#[contracts::contract_trait]
impl EvidenceReporter for TestEvidenceReporter {
fn report(&self, evidence: Evidence, peer: PeerId) -> Result<TransactionHash, IoError> {
panic!(
"unexpected fork detected for peer ... | code_fim | hard | {
"lang": "rust",
"repo": "yihuang/tendermint-rs",
"path": "/light-client/tests/integration.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: yihuang/tendermint-rs path: /light-client/tests/integration.rs
//! Light Client integration tests.
//!
//! These are all ignored by default, since they test against running
//! `tendermint node --proxy_app=kvstore`. They can be run using:
//!
//! ```
//! cargo test -- --ignored
//! ```
use tend... | code_fim | hard | {
"lang": "rust",
"repo": "yihuang/tendermint-rs",
"path": "/light-client/tests/integration.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// send writes data out in chunks, like so:
///
/// u32: payload_size
/// [u8] payload
///
pub fn send(&mut self, event: T) {
let mut syn = self.fs_lock.lock().expect("Sender fs_lock poisoned");
let fslock = &mut (*syn);
if fslock.sender_idx < fslock.in_... | code_fim | hard | {
"lang": "rust",
"repo": "elsin-r/hopper",
"path": "/src/sender.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: elsin-r/hopper path: /src/sender.rs
use bincode::{serialize_into, Infinite};
use private;
use serde::{Deserialize, Serialize};
use std::fmt;
use std::fs;
use std::io::{BufWriter, Write};
use std::marker::PhantomData;
use std::path::{Path, PathBuf};
#[inline]
fn u32tou8abe(v: u32) -> [u8; 4] {
... | code_fim | hard | {
"lang": "rust",
"repo": "elsin-r/hopper",
"path": "/src/sender.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> let request = GitHubRequestBuilder::build(req, self.auth)?;
// --
let github_response = crate::adapters::fetch_async(request).await?;
// --
if github_response.is_success() {
Ok(crate::adapters::to_json_async(github_response).await?)
} else {
... | code_fim | hard | {
"lang": "rust",
"repo": "jondot/roctogen",
"path": "/src/endpoints/activity.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Only show notifications updated after the given time. This is a timestamp in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format: `YYYY-MM-DDTHH:MM:SSZ`.
pub fn since(self, since: chrono::DateTime<chrono::Utc>) -> Self {
Self {
all: self.all,
participati... | code_fim | hard | {
"lang": "rust",
"repo": "jondot/roctogen",
"path": "/src/endpoints/activity.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jondot/roctogen path: /src/endpoints/activity.rs
serParams = params.into();
request_uri.push_str(&serde_urlencoded::to_string(qp)?);
}
let req = GitHubRequest {
uri: request_uri,
body: None,
method: "GET",
headers: vec!... | code_fim | hard | {
"lang": "rust",
"repo": "jondot/roctogen",
"path": "/src/endpoints/activity.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> where
Self::VocabType: Borrow<Q>,
Q: Hash + ?Sized + Eq,
{
self.index
.get(key)
.cloned()
.map(|idx| SingleIdx::from_word_idx(idx as u64))
}
fn discard(&self, idx: usize) -> f32 {
self.discards[idx]
}
fn n_input_... | code_fim | hard | {
"lang": "rust",
"repo": "finalfusion/finalfrontier",
"path": "/src/vocab/simple.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: finalfusion/finalfrontier path: /src/vocab/simple.rs
use std::borrow::Borrow;
use std::collections::HashMap;
use std::hash::Hash;
use finalfusion::vocab::{SimpleVocab as FiFuSimpleVocab, VocabWrap};
use crate::idx::{SingleIdx, WordIdx};
use crate::vocab::{create_discards, create_indices};
use ... | code_fim | hard | {
"lang": "rust",
"repo": "finalfusion/finalfrontier",
"path": "/src/vocab/simple.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: jdm/rust-stb-image path: /image.rs
import stb_image::*;
import stb_image::bindgen::*;
import libc::types::os::arch::c95::c_int;
import ptr::{addr_of, is_null};
import str::as_c_str;
import vec::as_buf;
import vec::unsafe::from_buf;
struct image {
let width: uint;
let height: uint;
l... | code_fim | medium | {
"lang": "rust",
"repo": "jdm/rust-stb-image",
"path": "/image.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // FIXME: Shouldn't copy; instead we should use a sendable resource. They
// aren't particularly safe yet though.
let data = from_buf(buffer, (width * height * depth) as uint);
return some(image(width as uint, height as uint, depth as uint, data));
}<|fim_prefix|>// repo: jdm/rust-stb-imag... | code_fim | hard | {
"lang": "rust",
"repo": "jdm/rust-stb-image",
"path": "/image.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let c = s.chars().next().unwrap();
if let Some(next) = self.chars.get(&c) {
next.borrow_mut().search(&s[1..])
} else {
false
}
}
}<|fim_prefix|>// repo: nsaeki/atcoder path: /lib/trie.rs
use std::collections::HashMap;
use std::rc::Rc;
use std::c... | code_fim | hard | {
"lang": "rust",
"repo": "nsaeki/atcoder",
"path": "/lib/trie.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn search(&self, s: &str) -> bool {
if s.is_empty() && self.term {
return true;
}
let c = s.chars().next().unwrap();
if let Some(next) = self.chars.get(&c) {
next.borrow_mut().search(&s[1..])
} else {
false
... | code_fim | hard | {
"lang": "rust",
"repo": "nsaeki/atcoder",
"path": "/lib/trie.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: nsaeki/atcoder path: /lib/trie.rs
use std::collections::HashMap;
use std::rc::Rc;
use std::cell::RefCell;
#[derive(Debug)]
struct Trie {
root: Rc<RefCell<TrieNode>>,
}
impl Trie {
fn new() -> Self {
Self{
root: Rc::new(RefCell::new(TrieNode::new())),
}
}... | code_fim | medium | {
"lang": "rust",
"repo": "nsaeki/atcoder",
"path": "/lib/trie.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[test]
fn test_exist() {
let haystack = "hello".to_owned();
let needle = "ll".to_owned();
let expected = 2;
assert_eq!(Solution::str_str(haystack, needle), expected);
}
#[test]
fn test_not_exist() {
let haystack = "aabaa".to_owned();
le... | code_fim | hard | {
"lang": "rust",
"repo": "hhwyt/leetcode-rs",
"path": "/00028.ImplementstrStr-Sunday.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_suffix|> let haystack = "".to_owned();
let needle = "a".to_owned();
let expected = -1;
assert_eq!(Solution::str_str(haystack, needle), expected);
}
#[test]
fn test_needle_is_empty() {
let haystack = "".to_owned();
let needle = "".to_owned();
let ... | code_fim | hard | {
"lang": "rust",
"repo": "hhwyt/leetcode-rs",
"path": "/00028.ImplementstrStr-Sunday.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: hhwyt/leetcode-rs path: /00028.ImplementstrStr-Sunday.rs
use std::collections::HashMap;
struct Solution;
// Sunday algorithm: http://wiki.jikexueyuan.com/project/kmp-algorithm/sunday.html
// Time Complexity: best case is O(n/m), worst case is O(nm)
// Space Complexity: O(m)
impl Solution {
... | code_fim | hard | {
"lang": "rust",
"repo": "hhwyt/leetcode-rs",
"path": "/00028.ImplementstrStr-Sunday.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: richmans/webos path: /src/task/network.rs
use x86_64::instructions::port::Port;
use conquer_once::spin::OnceCell;
use crossbeam_queue::ArrayQueue;
use core::{pin::Pin, task::{Poll, Context}};
use futures_util::stream::Stream;
use crate::println;
use futures_util::task::AtomicWaker;
use futures_u... | code_fim | hard | {
"lang": "rust",
"repo": "richmans/webos",
"path": "/src/task/network.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let queue = PACKET_QUEUE
.try_get()
.expect("packet queue not initialized");
// fast path
if let Ok(packet) = queue.pop() {
return Poll::Ready(Some(packet));
}
WAKER.register(&cx.waker());
match queue.pop() {
Ok(packet) => {
WAKER.take(... | code_fim | hard | {
"lang": "rust",
"repo": "richmans/webos",
"path": "/src/task/network.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn ack_interrupt() {
let mut isr_port = Port::<u16>::new(*INTERRUPT_STATUS_PORT.get().expect("Interrupt status port not found"));
unsafe {
let isr_value = 5;
isr_port.write(isr_value);
}
}
/// Called by the network interrupt handler
pub(crate) fn add_packet(packet: u16) {
if... | code_fim | hard | {
"lang": "rust",
"repo": "richmans/webos",
"path": "/src/task/network.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: isgasho/snafu path: /src/guide/attributes.rs
//! # Attributes understood by the `Snafu` macro
//!
//! ## Controlling `Display`
//!
//! There are a number of ways you can specify how the `Display` trait
//! will be implemented for each variant:
//!
//! - `#[snafu(display("a format string with arg... | code_fim | hard | {
"lang": "rust",
"repo": "isgasho/snafu",
"path": "/src/guide/attributes.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>c context selectors.
//!
//! There are a number of forms of the attribute:
//!
//! - `#[snafu(visibility(X))]`
//!
//! `X` is a normal Rust visibility modifier (`pub`, `pub(crate)`,
//! `pub(in some::path)`, etc.). Supported in Rust 1.34.
//!
//! - `#[snafu(visibility = "X")]`
//!
//! The same argum... | code_fim | hard | {
"lang": "rust",
"repo": "isgasho/snafu",
"path": "/src/guide/attributes.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> #[snafu(visibility)]
//! IsPrivate, // Will be private
//! }
//! ```
//!
//! ## Controlling backtraces
//!
//! If your error contains other SNAFU errors which can report
//! backtraces, you may wish to delegate returning a backtrace to
//! those errors. Use `#[snafu(backtrace(delegate))]` to specif... | code_fim | hard | {
"lang": "rust",
"repo": "isgasho/snafu",
"path": "/src/guide/attributes.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: PoiScript/orgize path: /examples/custom.rs
use std::convert::From;
use std::env::args;
use std::fs;
use std::io::{Error as IOError, Write};
use std::result::Result;
use std::string::FromUtf8Error;
use orgize::export::{DefaultHtmlHandler, HtmlHandler};
use orgize::{Element, Org};
use slugify::sl... | code_fim | hard | {
"lang": "rust",
"repo": "PoiScript/orgize",
"path": "/examples/custom.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> MyError::Utf8(err)
}
}
#[derive(Default)]
struct MyHtmlHandler(DefaultHtmlHandler);
impl HtmlHandler<MyError> for MyHtmlHandler {
fn start<W: Write>(&mut self, mut w: W, element: &Element) -> Result<(), MyError> {
if let Element::Title(title) = element {
if title.leve... | code_fim | hard | {
"lang": "rust",
"repo": "PoiScript/orgize",
"path": "/examples/custom.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> full_frame.vec.reserve_exact(total_len);
full_frame.vec.extend(&raw_header);
full_frame.vec.resize(total_len, 0);
full_frame.pos = 9;
read_exact(read, full_frame)
});
let frame = frame_buf.map(|(read, frame_buf)| {
(read, RawFrame::from(frame_buf.ve... | code_fim | hard | {
"lang": "rust",
"repo": "erickt/grpc-rust",
"path": "/src/http2_async.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let write_preface = write_all(conn, preface).map_err(|_| GrpcError::Other);
let settings = write_preface.and_then(|(conn, _)| {
recv_raw_frame(conn)
});
let done = settings.map(|(conn, settings_raw)| {
match HttpFrame::from_raw(&settings_raw).unwrap() {
HttpFr... | code_fim | hard | {
"lang": "rust",
"repo": "erickt/grpc-rust",
"path": "/src/http2_async.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: erickt/grpc-rust path: /src/http2_async.rs
use std::io;
use std::io::Read;
use futures::Future;
use futures::failed;
use futures::stream::Stream;
use futures_io::read_exact;
use futures_io::write_all;
use futures_mio::TcpStream;
use solicit::http::frame::RawFrame;
use solicit::http::connecti... | code_fim | hard | {
"lang": "rust",
"repo": "erickt/grpc-rust",
"path": "/src/http2_async.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn main() {
let arg = env::args().skip(1).next();
let days: Vec<for<'r> fn(&'r str) -> u128> = days_vec!(23);
if arg == Some(String::from("-a")) {
println!(
"\n{}",
&format!(
"Total run time: {}",
format_duration(
... | code_fim | medium | {
"lang": "rust",
"repo": "vtheuer/aoc-2020",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: vtheuer/aoc-2020 path: /src/main.rs
#![allow(unused_imports, dead_code)]
extern crate macros;
use std::env;
use std::fs::{read_dir, read_to_string};
use crate::day::Day;
use crate::util::format_duration;
use colored::*;
use macros::days_vec;
<|fim_suffix|>fn main() {
let arg = env::args(... | code_fim | hard | {
"lang": "rust",
"repo": "vtheuer/aoc-2020",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> if arg == Some(String::from("-a")) {
println!(
"\n{}",
&format!(
"Total run time: {}",
format_duration(
(1..=days.len() as u8)
.map(|n| run_day(&days, n))
.sum::<u128>()
... | code_fim | hard | {
"lang": "rust",
"repo": "vtheuer/aoc-2020",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> match value_type {
ValueType::HexColour(_) => {
let (_red, _green, _blue): (u8, u8, u8) = (
u8::from_str_radix(&matched[1..3], 16).unwrap(),
u8::from_str_radix(&matched[3..5], 16).unwrap(),
u8::from_str_radix(&matched[5..7], 16).unwra... | code_fim | hard | {
"lang": "rust",
"repo": "KirilMihaylov/Legio-Parser",
"path": "/src/tests/match_mapped_alternatives.rs",
"mode": "spm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: KirilMihaylov/Legio-Parser path: /src/tests/match_mapped_alternatives.rs
use crate::{result::TransformMappedMatch, traits::*};
fn match_mapped_alternatives_str_test(data: &str) {
enum HexColourType {
ThreeDigit,
SixDigit,
}
enum ValueType {
HexColour(HexColo... | code_fim | hard | {
"lang": "rust",
"repo": "KirilMihaylov/Legio-Parser",
"path": "/src/tests/match_mapped_alternatives.rs",
"mode": "psm",
"license": "Apache-2.0",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: isabella232/ratsio path: /src/net/mod.rs
pub(crate) use self::connection::{NatsConnSinkStream, NatsConnection};
use futures::sync::mpsc::UnboundedSender;
use std::sync::Arc;
<|fim_suffix|>pub(crate) type ReconnectHandler = UnboundedSender<Arc<NatsConnection>>;<|fim_middle|>pub(crate) mod connec... | code_fim | easy | {
"lang": "rust",
"repo": "isabella232/ratsio",
"path": "/src/net/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>pub(crate) type ReconnectHandler = UnboundedSender<Arc<NatsConnection>>;<|fim_prefix|>// repo: isabella232/ratsio path: /src/net/mod.rs
pub(crate) use self::connection::{NatsConnSinkStream, NatsConnection};
use futures::sync::mpsc::UnboundedSender;
use std::sync::Arc;
<|fim_middle|>pub(crate) mod connec... | code_fim | easy | {
"lang": "rust",
"repo": "isabella232/ratsio",
"path": "/src/net/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: EarthEngineering/keyphrase path: /src/seed.rs
use crate::crypto::pbkdf2;
use crate::keyphrase::KeyPhrase;
use std::fmt;
/// The secret value used to derive HD wallet addresses from a [`KeyPhrase`][KeyPhrase] phrase.
///
/// Because it is not possible to create a [`KeyPhrase`][KeyPhrase] instanc... | code_fim | hard | {
"lang": "rust",
"repo": "EarthEngineering/keyphrase",
"path": "/src/seed.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>#[cfg(test)]
mod test {
use super::*;
#[test]
fn should_print_upper_hex_correctly() {
let seed = Seed {
bytes: vec![1, 10, 16, 255],
};
let hex = format!("{:?}", seed);
assert_eq!(hex, "0x010A10FF")
}
#[test]
fn should_print_lower_hex_c... | code_fim | hard | {
"lang": "rust",
"repo": "EarthEngineering/keyphrase",
"path": "/src/seed.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> for byte in &self.bytes {
write!(f, "{:02X}", byte)?;
}
Ok(())
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn should_print_upper_hex_correctly() {
let seed = Seed {
bytes: vec![1, 10, 16, 255],
};
let hex = for... | code_fim | hard | {
"lang": "rust",
"repo": "EarthEngineering/keyphrase",
"path": "/src/seed.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn group_metro_criterion(c: &mut Criterion) {
let seq: Vec<i32> = (1..=10).cycle().take(1000).collect();
c.bench_function("GroupBy Metro Hash", move |b| b.iter(|| group_metro(&seq)));
}
criterion_group!(
benches,
group_default_criterion,
group_fnv_criterion,
group_fx_criterion,
... | code_fim | hard | {
"lang": "rust",
"repo": "archer884/groupby",
"path": "/benches/hash_performance.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: archer884/groupby path: /benches/hash_performance.rs
#[macro_use]
extern crate criterion;
extern crate fnv;
extern crate fxhash;
extern crate groupby;
extern crate metrohash;
use criterion::Criterion;
use groupby::GroupBy;
use std::collections::{hash_map::RandomState, HashMap};
type Grouping<... | code_fim | hard | {
"lang": "rust",
"repo": "archer884/groupby",
"path": "/benches/hash_performance.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: poljar/rust-weechat path: /crates/weechat/src/hooks/bar.rs
//! Bar items are used to display status information in Weechat.
use core::ptr;
use std::os::raw::c_void;
use libc::c_char;
use weechat_sys::{t_gui_bar_item, t_gui_buffer, t_gui_window, t_hashtable, t_weechat_plugin};
use crate::{buffe... | code_fim | hard | {
"lang": "rust",
"repo": "poljar/rust-weechat",
"path": "/crates/weechat/src/hooks/bar.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl Drop for BarItem {
fn drop(&mut self) {
let weechat = Weechat::from_ptr(self.weechat);
let bar_item_remove = weechat.get().bar_item_remove.unwrap();
unsafe { bar_item_remove(self.ptr) };
}
}
impl BarItem {
/// Create a new bar item that can be added by a user.
... | code_fim | hard | {
"lang": "rust",
"repo": "poljar/rust-weechat",
"path": "/crates/weechat/src/hooks/bar.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: stkent/AdventOfCode2020 path: /src/day10.rs
pub fn solve_part_1(input: &[u8]) -> u16 {
let mut input_copy: Vec<u8> = input.to_vec();
input_copy.sort_unstable();
let jumps: Vec<u8> =
input_copy
.iter()
.zip(input_copy.iter().skip(1))
.map(|... | code_fim | hard | {
"lang": "rust",
"repo": "stkent/AdventOfCode2020",
"path": "/src/day10.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let input: Vec<u8> =
vec![
16,
10,
15,
5,
1,
11,
7,
19,
6,
12,
4,
];
assert_eq!(day10::so... | code_fim | hard | {
"lang": "rust",
"repo": "stkent/AdventOfCode2020",
"path": "/src/day10.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: MFAshby/ucms-experiment path: /rust/src/main.rs
#![feature(proc_macro_hygiene,decl_macro)]
#[macro_use] extern crate rocket;
use rocket_contrib::serve::StaticFiles;
#[get("/")]
fn index() -> &'static str {
<|fim_suffix|>fn main() {
rocket::ignite()
.mount("/static", StaticFiles::f... | code_fim | easy | {
"lang": "rust",
"repo": "MFAshby/ucms-experiment",
"path": "/rust/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> rocket::ignite()
.mount("/static", StaticFiles::from("static"))
.mount("/", routes![index]).launch();
}<|fim_prefix|>// repo: MFAshby/ucms-experiment path: /rust/src/main.rs
#![feature(proc_macro_hygiene,decl_macro)]
<|fim_middle|>#[macro_use] extern crate rocket;
use rocket_contrib... | code_fim | medium | {
"lang": "rust",
"repo": "MFAshby/ucms-experiment",
"path": "/rust/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> "Hello world!"
}
fn main() {
rocket::ignite()
.mount("/static", StaticFiles::from("static"))
.mount("/", routes![index]).launch();
}<|fim_prefix|>// repo: MFAshby/ucms-experiment path: /rust/src/main.rs
#![feature(proc_macro_hygiene,decl_macro)]
<|fim_middle|>#[macro_use] extern... | code_fim | medium | {
"lang": "rust",
"repo": "MFAshby/ucms-experiment",
"path": "/rust/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> for x in &GREEK_LEGACY[0] {
for bit in 0..8 {
match *x & 1 << bit {
0 => print!(" "),
_ => print!("█"),
}
}
println!()
}
}<|fim_prefix|>// repo: thejpster/font8x8-rs path: /examples/legacy.rs
extern crate font8x8;
us... | code_fim | medium | {
"lang": "rust",
"repo": "thejpster/font8x8-rs",
"path": "/examples/legacy.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: thejpster/font8x8-rs path: /examples/legacy.rs
extern crate font8x8;
use font8x8::legacy::GREEK_LEGACY;
<|fim_suffix|> for x in &GREEK_LEGACY[0] {
for bit in 0..8 {
match *x & 1 << bit {
0 => print!(" "),
_ => print!("█"),
}
... | code_fim | medium | {
"lang": "rust",
"repo": "thejpster/font8x8-rs",
"path": "/examples/legacy.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> use TypedTerm::*;
match self {
Abs(a) => Abs(Box::new(a.subst(s))),
App(a, b) => App(Box::new(a.subst(s)), Box::new(b.subst(s))),
Let(a, b) => Let(Box::new(a.subst(s)), Box::new(b.subst(s))),
If(a, b, c) => If(Box::new(a.subst(s)), Box::new(b... | code_fim | hard | {
"lang": "rust",
"repo": "lazear/types-and-programming-languages",
"path": "/05_recon/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: lazear/types-and-programming-languages path: /05_recon/src/main.rs
use std::collections::{HashMap, HashSet};
pub mod disjoint;
pub mod mutation;
pub mod naive;
pub mod parser;
pub mod types;
use types::*;
#[derive(Debug)]
pub enum Term {
Unit,
Bool(bool),
Int(usize),
Var(usize,... | code_fim | hard | {
"lang": "rust",
"repo": "lazear/types-and-programming-languages",
"path": "/05_recon/src/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> // Decode-bytes
'decode_loop: for c in to_decode.chars() {
match state {
// Expect any char
State::Char => {
// Check for percent-char
if c == '%' { state = State::Percent1 }
else { decoded.push(c) }
},
// Add the higher-percent-encoded-nibble
State::Percent1 => ... | code_fim | hard | {
"lang": "rust",
"repo": "KizzyCode/http_file",
"path": "/src/uri.rs",
"mode": "spm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: KizzyCode/http_file path: /src/uri.rs
use super::error::{Error, ErrorType};
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct URI {
pub protocol: String,
pub server: String,
pub resource: String,
pub name: String
}
impl URI {
pub fn parse(uri_string: &str) -> Result<Self, Error> {
use st... | code_fim | hard | {
"lang": "rust",
"repo": "KizzyCode/http_file",
"path": "/src/uri.rs",
"mode": "psm",
"license": "BSD-2-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: occlum/occlum path: /src/libos/src/util/mem_util.rs
use super::*;
use std::ffi::{CStr, CString};
use std::mem::size_of;
use std::ptr;
use vm::VMRange;
/// Memory utilities that deals with primitive types passed from user process
/// running inside enclave
pub mod from_user {
use super::*;
... | code_fim | hard | {
"lang": "rust",
"repo": "occlum/occlum",
"path": "/src/libos/src/util/mem_util.rs",
"mode": "psm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> /// Clone a C-string array (const char*[]) from outside the enclave
///
/// This array must be ended with a NULL pointer.
pub fn clone_cstrings_safely(out_ptr: *const *const c_char) -> Result<Vec<CString>> {
let mut cstrings = Vec::new();
if out_ptr == ptr::null() {
... | code_fim | hard | {
"lang": "rust",
"repo": "occlum/occlum",
"path": "/src/libos/src/util/mem_util.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_suffix|> let cstr = unsafe { CStr::from_ptr(out_ptr) };
let cstring = CString::from(cstr);
if !sgx_trts::trts::rsgx_raw_is_outside_enclave(
out_ptr as *const u8,
cstring.as_bytes_with_nul().len(),
) {
return_errno!(EFAULT, "the string is not outsi... | code_fim | hard | {
"lang": "rust",
"repo": "occlum/occlum",
"path": "/src/libos/src/util/mem_util.rs",
"mode": "spm",
"license": "BSD-3-Clause",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: aiden0z/snippets path: /lang/rust/generics/src/main.rs
fn largest_i32(list: &[i32]) -> i32 {
let mut largest = list[0];
for &item in list.iter() {
if item > largest {
largest = item;
}
}
largest
}
<|fim_suffix|>// largest
// }
// 还可以使用泛型来定义结构体, 而... | code_fim | hard | {
"lang": "rust",
"repo": "aiden0z/snippets",
"path": "/lang/rust/generics/src/main.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> largest
}
// 使用泛型
// fn largest<T>(list: &[T]) -> T {
// let mut largest = list[0];
// for &item in list.iter() {
// // 由于 item 的 T 类型可能未实现大小比较操作
// // 所以下面的代码会编译失败
// if item > largest {
// largest = item;
// }
// }
// largest
// }
// 还可... | code_fim | medium | {
"lang": "rust",
"repo": "aiden0z/snippets",
"path": "/lang/rust/generics/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>// 还可以使用泛型来定义结构体, 而且只使用了一个泛型
struct Point<T> {
x: T,
y: T,
}
// 还可以定义使用多个类型的泛型
struct PointT<T, U> {
x: T,
y: U,
}
fn main() {
let number_list = vec![34, 50, 25, 25, 100, 65];
let result = largest_i32(&number_list);
println!("The largest number is {}", result);
let char... | code_fim | hard | {
"lang": "rust",
"repo": "aiden0z/snippets",
"path": "/lang/rust/generics/src/main.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: glopez3008/vit-testing path: /iapyx/src/backend/mod.rs
mod node;
mod proxy;
mod vit_station;
use crate::Fund;
use crate::Proposal;
use crate::SimpleVoteStatus;
use chain_core::mempack::Readable;
use chain_core::{mempack::ReadBuf, property::Fragment as _};
use chain_impl_mockchain::{
block::... | code_fim | hard | {
"lang": "rust",
"repo": "glopez3008/vit-testing",
"path": "/iapyx/src/backend/mod.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub fn enable_logs(&mut self) {
self.node_client.enable_logs();
self.vit_client.enable_logs();
self.proxy_client.enable_debug();
}
pub fn are_fragments_in_blockchain(
&self,
fragment_ids: Vec<FragmentId>,
) -> Result<bool, WalletBackendError> {
... | code_fim | hard | {
"lang": "rust",
"repo": "glopez3008/vit-testing",
"path": "/iapyx/src/backend/mod.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: iceiix/openssl-test path: /src/main.rs
extern crate openssl;
use openssl::rand::rand_bytes;
use openssl::rsa::{Rsa, Padding};
extern crate num;
use num::bigint::{BigInt};
extern crate simple_asn1;
use simple_asn1::{from_der, ASN1Block};
//use num::bigint::ToBigInt;
#[macro_use]
extern crate h... | code_fim | hard | {
"lang": "rust",
"repo": "iceiix/openssl-test",
"path": "/src/main.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> let mut encoded_m = vec![0x00, 0x02];
encoded_m.append(&mut padding.to_vec());
encoded_m.append(&mut vec![0x00]);
encoded_m.extend_from_slice(&message);
println!("encoded_m = {:?}", encoded_m);
// TODO: ensure this is OS2IP https://tools.ietf.org/html/rfc8017#section-4.2
let m... | code_fim | hard | {
"lang": "rust",
"repo": "iceiix/openssl-test",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>
let rsa = Rsa::public_key_from_der(&packet_public_key_data).unwrap();
let mut shared = [0; 16];
rand_bytes(&mut shared).unwrap();
println!("shared = {:?}!", shared);
//let shared = [180, 233, 250, 239, 186, 185, 101, 205, 175, 174, 26, 1, 88, 93, 213, 250];
let packet_verify_token... | code_fim | hard | {
"lang": "rust",
"repo": "iceiix/openssl-test",
"path": "/src/main.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: doyoubi/mylint-rs path: /src/lint/utils.rs
use crate::{Filter, NodeIterator, SourceCode, ValidationError, Validator};
use tree_sitter::Node;
#[allow(unused_macros)]
macro_rules! assert_some {
($expression:expr) => {
match $expression {
Some(item) => item,
Non... | code_fim | medium | {
"lang": "rust",
"repo": "doyoubi/mylint-rs",
"path": "/src/lint/utils.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>fn get_text<'a>(node_kind: &str, node: &Node, source: &'a str) -> Option<&'a str> {
if node.kind() == node_kind {
let ident = match node.utf8_text(source.as_bytes()) {
Ok(ident) => ident,
Err(err) => {
error!("failed to get identifier: {:?}", err);
... | code_fim | hard | {
"lang": "rust",
"repo": "doyoubi/mylint-rs",
"path": "/src/lint/utils.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: hkazuakey/yoin path: /yoin-core/src/dic/unknown.rs
use std::io::{self, Write};
use std::collections::HashMap;
use byteorder::{ByteOrder, WriteBytesExt, NativeEndian};
pub type CategoryId = u8;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Category {
pub invoke: bool,
pub gro... | code_fim | hard | {
"lang": "rust",
"repo": "hkazuakey/yoin",
"path": "/yoin-core/src/dic/unknown.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn category_id(&self, ch: char) -> CategoryId {
self.categories.category_id(ch)
}
}
impl<'a> UnknownDic for CompiledUnkDic<'a> {
fn fetch_entries<'b>(&'b self, cate: CategoryId) -> Vec<Entry<'b>> {
let count = self.counts[cate as usize] as usize;
let index = self.indic... | code_fim | hard | {
"lang": "rust",
"repo": "hkazuakey/yoin",
"path": "/yoin-core/src/dic/unknown.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> self.categories.categorize(ch)
}
fn category_id(&self, ch: char) -> CategoryId {
self.categories.category_id(ch)
}
}
impl UnknownDic for UnkDic {
fn fetch_entries<'a>(&'a self, cate: CategoryId) -> Vec<Entry<'a>> {
let count = self.counts[cate as usize] as usize;
... | code_fim | hard | {
"lang": "rust",
"repo": "hkazuakey/yoin",
"path": "/yoin-core/src/dic/unknown.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: zowens/commitlog path: /src/reader.rs
//! Custom log reading.
use super::message::{MessageBuf, MessageError};
use std::fs::File;
/// Trait that allows reading from a slice of the log.
pub trait LogSliceReader {
/// Result type of this reader.
type Result: 'static;
<|fim_suffix|>#[cfg(u... | code_fim | hard | {
"lang": "rust",
"repo": "zowens/commitlog",
"path": "/src/reader.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> fn read_from(
&mut self,
file: &File,
file_position: u32,
bytes: usize,
) -> Result<Self::Result, MessageError> {
use std::os::unix::fs::FileExt;
let mut vec = vec![0; bytes];
file.read_at(&mut vec, u64::from(file_position))?;
Messag... | code_fim | medium | {
"lang": "rust",
"repo": "zowens/commitlog",
"path": "/src/reader.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|>impl LogSliceReader for MessageBufReader {
type Result = MessageBuf;
fn read_from(
&mut self,
file: &File,
file_position: u32,
bytes: usize,
) -> Result<Self::Result, MessageError> {
use std::os::unix::fs::FileExt;
let mut vec = vec![0; bytes];... | code_fim | medium | {
"lang": "rust",
"repo": "zowens/commitlog",
"path": "/src/reader.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> for (x, y) in xs.iter_mut().zip(ys.iter()) {
*x = $bound::$method(*x, *y);
// *x = x.$method(*y);
}
}
};
}
// 实现 `add_assign`、`mul_assign` 和 `sub_assign` 等函数。
op!(add_assign, Add, +=, add);
op!(mul... | code_fim | hard | {
"lang": "rust",
"repo": "weiyinfu/learnRust",
"path": "/src/clMacro.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> macro_rules! op {
($func:ident, $bound:ident, $op:tt, $method:ident) => {
fn $func<T: $bound<T, Output = T> + Copy>(xs: &mut Vec<T>, ys: &Vec<T>) {
assert_equal_len!(xs, ys, $func, $op);
for (x, y) in xs.iter_mut().zip(ys.iter()) {
... | code_fim | hard | {
"lang": "rust",
"repo": "weiyinfu/learnRust",
"path": "/src/clMacro.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: weiyinfu/learnRust path: /src/clMacro.rs
/**
宏指示符种类:
* block
* expr 用于表达式
* ident 用于变量名或函数名
* item
* pat (模式 pattern)
* path
* stmt (语句 statement)
* tt (标记树 token tree)
* ty (类型 type)
*/
#[test]
fn newVec() {
//宏的定义,既可以使用中括号,又可以使用小括号
#[allow(unused_macros)]
macro_rules! newVec {
... | code_fim | hard | {
"lang": "rust",
"repo": "weiyinfu/learnRust",
"path": "/src/clMacro.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|>_R {
RDATA2_R::new(((self.bits >> 16) & 0xffff) as u16)
}
}
#[doc = "SDADC1 and SDADC2 regular data register\n\nYou can [`read`](crate::generic::Reg::read) this register and get [`rdata12r::R`](R). See [API](https://docs.rs/svd2rust/#read--modify--write-api)."]
pub struct RDATA12R_SPEC;
impl ... | code_fim | hard | {
"lang": "rust",
"repo": "stm32-rs/stm32-rs-nightlies",
"path": "/stm32f3/src/stm32f301/sdadc1/rdata12r.rs",
"mode": "spm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: stm32-rs/stm32-rs-nightlies path: /stm32f3/src/stm32f301/sdadc1/rdata12r.rs
#[doc = "Register `RDATA12R` reader"]
pub type R = crate::R<RDATA12R_SPEC>;
#[doc = "Field `RDATA1` reader - Regular conversion data for SDADC1"]
pub type RDATA1_R = crate::FieldReader<u16>;
#[doc = "Field `RDATA2` reade... | code_fim | hard | {
"lang": "rust",
"repo": "stm32-rs/stm32-rs-nightlies",
"path": "/stm32f3/src/stm32f301/sdadc1/rdata12r.rs",
"mode": "psm",
"license": "unknown",
"source": "the-stack-v2"
} |
<|fim_suffix|> // non-alpha chars indicate word terminated
if !char.is_alphabetic() && char != '-' {
word_terminated = true;
suffix.push(char);
continue
}
result.push(char);
}
result.push_str(&suffix);
}... | code_fim | hard | {
"lang": "rust",
"repo": "gregl83/rust-lang-book",
"path": "/ch08_03_hash_maps/src/languages/english.rs",
"mode": "spm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: gregl83/rust-lang-book path: /ch08_03_hash_maps/src/languages/english.rs
pub fn to_pig_latin(text: &str) -> String {
let vowels = ['A', 'a', 'E', 'e', 'I', 'i', 'O', 'o', 'U', 'u'];
let mut result = String::new();
for word in text.split_whitespace() {
result.push(' ');
... | code_fim | hard | {
"lang": "rust",
"repo": "gregl83/rust-lang-book",
"path": "/ch08_03_hash_maps/src/languages/english.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_prefix|>// repo: aDotInTheVoid/noria path: /server/dataflow/src/state/single_state.rs
use super::mk_key::MakeKey;
use crate::prelude::*;
use crate::state::keyed_state::KeyedState;
use common::SizeOf;
use rand::prelude::*;
use std::rc::Rc;
pub(super) struct SingleState {
key: Vec<usize>,
state: KeyedStat... | code_fim | hard | {
"lang": "rust",
"repo": "aDotInTheVoid/noria",
"path": "/server/dataflow/src/state/single_state.rs",
"mode": "psm",
"license": "MIT",
"source": "the-stack-v2"
} |
<|fim_suffix|> pub(super) fn values<'a>(&'a self) -> Box<dyn Iterator<Item = &'a Rows> + 'a> {
match self.state {
KeyedState::Single(ref map) => Box::new(map.values()),
KeyedState::Double(ref map) => Box::new(map.values()),
KeyedState::Tri(ref map) => Box::new(map.values()... | code_fim | hard | {
"lang": "rust",
"repo": "aDotInTheVoid/noria",
"path": "/server/dataflow/src/state/single_state.rs",
"mode": "spm",
"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.