repo
stringclasses
7 values
lang
stringclasses
2 values
aspect
stringclasses
7 values
file
stringlengths
5
48
content
stringlengths
283
144k
crossbeam
rust
concurrency
ready.rs
use std::{ any::Any, cell::Cell, error::Error, thread, time::{Duration, Instant}, }; use crossbeam_channel::{ Receiver, Select, TryRecvError, TrySendError, after, bounded, tick, unbounded, }; use crossbeam_utils::thread::scope; fn ms(ms: u64) -> Duration { Duration::from_millis(ms) } #[te...
crossbeam
rust
concurrency
thread_locals.rs
#![cfg(not(miri))] // Miri detects that this test is buggy: the destructor of `FOO` uses `std::thread::current()`! use std::{thread, time::Duration}; use crossbeam_channel::{select, unbounded}; use crossbeam_utils::thread::scope; fn ms(ms: u64) -> Duration { Duration::from_millis(ms) } #[test] #[cfg_attr(target...
crossbeam
rust
concurrency
fibonacci.rs
use std::thread; use crossbeam_channel::{Sender, bounded}; // Sends the Fibonacci sequence into the channel until it becomes disconnected. fn fibonacci(sender: Sender<u64>) { let (mut x, mut y) = (0, 1); while sender.send(x).is_ok() { let tmp = x; x = y; y += tmp; } } fn main() { ...
crossbeam
rust
concurrency
matching.rs
use crossbeam_channel::{bounded, select}; use crossbeam_utils::thread; fn main() { let people = vec!["Anna", "Bob", "Cody", "Dave", "Eva"]; let (s, r) = bounded(1); // Make room for one unmatched send. // Either send my name into the channel or receive someone else's, whatever happens first. let seek ...
crossbeam
rust
concurrency
stopwatch.rs
#[cfg(windows)] // signal_hook::iterator does not work on windows fn main() { println!("This example does not work on Windows"); } #[cfg(not(windows))] fn main() { use std::{ io, thread, time::{Duration, Instant}, }; use crossbeam_channel::{Receiver, bounded, select, tick}; use sig...
crossbeam
rust
concurrency
message.rs
use std::fmt; const LEN: usize = 1; #[derive(Clone, Copy)] pub(crate) struct Message(#[allow(dead_code)] [usize; LEN]); impl fmt::Debug for Message { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("Message") } } #[inline] pub(crate) fn new(num: usize) -> Message { Message([num;...
crossbeam
rust
concurrency
crossbeam-channel.rs
use crossbeam_channel::{Receiver, Select, Sender, bounded, unbounded}; mod message; const MESSAGES: usize = 5_000_000; const THREADS: usize = 4; fn new<T>(cap: Option<usize>) -> (Sender<T>, Receiver<T>) { match cap { None => unbounded(), Some(cap) => bounded(cap), } } fn seq(cap: Option<usiz...
crossbeam
rust
concurrency
lockfree.rs
use lockfree::channel; mod message; const MESSAGES: usize = 5_000_000; const THREADS: usize = 4; use std::thread; fn seq() { let (mut tx, mut rx) = channel::spsc::create(); for i in 0..MESSAGES { tx.send(message::new(i)).unwrap(); } for _ in 0..MESSAGES { while rx.recv().is_err() {...
crossbeam
rust
concurrency
mpsc.rs
use std::sync::mpsc; mod message; const MESSAGES: usize = 5_000_000; const THREADS: usize = 4; pub fn shuffle<T>(v: &mut [T]) { use std::{cell::Cell, num::Wrapping}; let len = v.len(); if len <= 1 { return; } thread_local! { static RNG: Cell<Wrapping<u32>> = const { Cell::new(Wr...
crossbeam
rust
concurrency
crossbeam-deque.rs
use std::thread; use crossbeam_deque::{Steal, Worker}; mod message; const MESSAGES: usize = 5_000_000; fn seq() { let tx = Worker::new_lifo(); let rx = tx.stealer(); for i in 0..MESSAGES { tx.push(message::new(i)); } for _ in 0..MESSAGES { match rx.steal() { Steal::...
crossbeam
rust
concurrency
atomicring.rs
use std::thread; use atomicring::AtomicRingBuffer; mod message; const MESSAGES: usize = 5_000_000; const THREADS: usize = 4; fn seq(cap: usize) { let q = AtomicRingBuffer::with_capacity(cap); for i in 0..MESSAGES { loop { if q.try_push(message::new(i)).is_ok() { break; ...
crossbeam
rust
concurrency
futures-channel.rs
use futures::{ SinkExt, StreamExt, channel::mpsc, executor::{ThreadPool, block_on}, future, stream, }; mod message; const MESSAGES: usize = 5_000_000; const THREADS: usize = 4; fn seq_unbounded() { block_on(async { let (tx, rx) = mpsc::unbounded(); for i in 0..MESSAGES { ...
crossbeam
rust
concurrency
flume.rs
mod message; const MESSAGES: usize = 5_000_000; const THREADS: usize = 4; pub fn shuffle<T>(v: &mut [T]) { use std::{cell::Cell, num::Wrapping}; let len = v.len(); if len <= 1 { return; } thread_local! { static RNG: Cell<Wrapping<u32>> = const { Cell::new(Wrapping(1)) }; } ...
crossbeam
rust
concurrency
mpmc.rs
use std::thread; mod message; const MESSAGES: usize = 5_000_000; const THREADS: usize = 4; fn seq(cap: usize) { let q = mpmc::Queue::with_capacity(cap); for i in 0..MESSAGES { loop { if q.push(message::new(i)).is_ok() { break; } else { thread::...
crossbeam
rust
concurrency
atomicringqueue.rs
use std::thread; use atomicring::AtomicRingQueue; mod message; const MESSAGES: usize = 5_000_000; const THREADS: usize = 4; fn seq(cap: usize) { let q = AtomicRingQueue::with_capacity(cap); for i in 0..MESSAGES { loop { if q.try_push(message::new(i)).is_ok() { break; ...
crossbeam
rust
concurrency
segqueue.rs
use std::thread; use crossbeam::queue::SegQueue; mod message; const MESSAGES: usize = 5_000_000; const THREADS: usize = 4; fn seq() { let q = SegQueue::new(); for i in 0..MESSAGES { q.push(message::new(i)); } for _ in 0..MESSAGES { q.pop().unwrap(); } } fn spsc() { let q =...
crossbeam
rust
concurrency
bus.rs
use bus::Bus; mod message; const MESSAGES: usize = 5_000_000; fn seq(cap: usize) { let mut tx = Bus::new(cap); let mut rx = tx.add_rx(); for i in 0..MESSAGES { tx.broadcast(message::new(i)); } for _ in 0..MESSAGES { rx.recv().unwrap(); } } fn spsc(cap: usize) { let mut ...
crossbeam
rust
concurrency
crossbeam.rs
#![feature(test)] extern crate test; use std::num::NonZeroUsize; use crossbeam_channel::{bounded, unbounded}; use crossbeam_utils::thread::scope; use test::Bencher; const TOTAL_STEPS: usize = 40_000; fn num_cpus() -> usize { std::thread::available_parallelism() .unwrap_or(NonZeroUsize::MIN) .in...
crossbeam
rust
concurrency
waker.rs
use alloc::vec::Vec; use core::{ ptr, sync::atomic::{AtomicBool, Ordering}, }; use std::thread::{self, ThreadId}; use crate::{ context::Context, select::{Operation, Selected}, utils::Mutex, }; /// Represents a thread blocked on a specific channel operation. pub(crate) struct Entry { /// The op...
crossbeam
rust
concurrency
channel.rs
use alloc::sync::Arc; use core::{ fmt, iter::FusedIterator, mem::{self, ManuallyDrop}, panic::{RefUnwindSafe, UnwindSafe}, time::Duration, }; use std::time::Instant; use crate::{ context::Context, counter, err::{RecvError, RecvTimeoutError, SendError, SendTimeoutError, TryRecvError, Try...
crossbeam
rust
concurrency
lib.rs
#![no_std] #![doc(test( no_crate_inject, attr(allow(dead_code, unused_assignments, unused_variables)) ))] #![warn( missing_docs, unsafe_op_in_unsafe_fn, clippy::alloc_instead_of_core, clippy::std_instead_of_alloc, clippy::std_instead_of_core )] #[cfg(feature = "std")] extern crate alloc; #[...
crossbeam
rust
concurrency
select_macro.rs
/// A helper macro for `select!` to hide the long list of macro patterns from the documentation. /// /// The macro consists of two stages: /// 1. Parsing /// 2. Code generation /// /// The parsing stage consists of these subparts: /// 1. `@list`: Turns a list of tokens into a list of cases. /// 2. `@list_errorN`: Diagn...
crossbeam
rust
concurrency
counter.rs
use alloc::boxed::Box; use core::{ ops, ptr::NonNull, sync::atomic::{AtomicBool, AtomicUsize, Ordering}, }; use std::process; /// Reference counter internals. struct Counter<C> { /// The number of senders associated with the channel. senders: AtomicUsize, /// The number of receivers associated...
crossbeam
rust
concurrency
err.rs
use core::fmt; use std::error; /// An error returned from the [`send`] method. /// /// The message could not be sent because the channel is disconnected. /// /// The error contains the message so it can be recovered. /// /// [`send`]: super::Sender::send #[derive(PartialEq, Eq, Clone, Copy)] pub struct SendError<T>(pu...
crossbeam
rust
concurrency
select.rs
use alloc::vec::Vec; use core::{fmt, marker::PhantomData, mem, time::Duration}; use std::time::Instant; use crossbeam_utils::Backoff; use crate::{ channel::{self, Receiver, Sender}, context::Context, err::{ ReadyTimeoutError, RecvError, SelectTimeoutError, SendError, TryReadyError, TrySelectError,...
crossbeam
rust
concurrency
alloc_helper.rs
use core::{alloc::Layout, ptr::NonNull}; // Based on unstable alloc::alloc::Global. // // Note: unlike alloc::alloc::Global that returns NonNull<[u8]>, // this returns NonNull<u8>. pub(crate) struct Global; #[allow(clippy::unused_self)] impl Global { #[inline] #[cfg_attr(miri, track_caller)] // even without pa...
crossbeam
rust
concurrency
utils.rs
use core::{cell::Cell, num::Wrapping, time::Duration}; use std::{thread, time::Instant}; /// Randomly shuffles a slice. pub(crate) fn shuffle<T>(v: &mut [T]) { let len = v.len(); if len <= 1 { return; } std::thread_local! { static RNG: Cell<Wrapping<u32>> = const { Cell::new(Wrapping(1...
crossbeam
rust
concurrency
context.rs
use alloc::sync::Arc; use core::{ cell::Cell, ptr, sync::atomic::{AtomicPtr, AtomicUsize, Ordering}, }; use std::{ thread::{self, Thread, ThreadId}, time::Instant, }; use crossbeam_utils::Backoff; use crate::select::Selected; /// Thread-local context used in select. // This is a private API that ...
crossbeam
rust
concurrency
at.rs
use core::sync::atomic::{AtomicBool, Ordering}; use std::{thread, time::Instant}; use crate::{ context::Context, err::{RecvTimeoutError, TryRecvError}, select::{Operation, SelectHandle, Token}, utils, }; /// Result of a receive operation. pub(crate) type AtToken = Option<Instant>; /// Channel that de...
crossbeam
rust
concurrency
zero.rs
use alloc::boxed::Box; use core::{ cell::UnsafeCell, fmt, marker::PhantomData, ptr, sync::atomic::{AtomicBool, Ordering}, }; use std::time::Instant; use crossbeam_utils::Backoff; use crate::{ context::Context, err::{RecvTimeoutError, SendTimeoutError, TryRecvError, TrySendError}, selec...
crossbeam
rust
concurrency
never.rs
use core::marker::PhantomData; use std::time::Instant; use crate::{ context::Context, err::{RecvTimeoutError, TryRecvError}, select::{Operation, SelectHandle, Token}, utils, }; /// This flavor doesn't need a token. pub(crate) type NeverToken = (); /// Channel that never delivers messages. pub(crate) ...
crossbeam
rust
concurrency
list.rs
use alloc::{alloc::handle_alloc_error, boxed::Box}; use core::{ alloc::Layout, cell::UnsafeCell, marker::PhantomData, mem::MaybeUninit, ptr, sync::atomic::{self, AtomicPtr, AtomicUsize, Ordering}, }; use std::time::Instant; use crossbeam_utils::{Backoff, CachePadded}; use crate::{ alloc_he...
crossbeam
rust
concurrency
array.rs
use alloc::boxed::Box; use core::{ cell::UnsafeCell, mem::MaybeUninit, ptr, sync::atomic::{self, Ordering}, }; use std::time::Instant; use crossbeam_utils::{Backoff, CachePadded}; use crate::{ context::Context, err::{RecvTimeoutError, SendTimeoutError, TryRecvError, TrySendError}, select::...
crossbeam
rust
concurrency
tick.rs
use core::time::Duration; use std::{thread, time::Instant}; use crossbeam_utils::atomic::AtomicCell; use crate::{ context::Context, err::{RecvTimeoutError, TryRecvError}, select::{Operation, SelectHandle, Token}, }; /// Result of a receive operation. pub(crate) type TickToken = Option<Instant>; #[derive...
crossbeam
rust
concurrency
base.rs
#![allow(clippy::redundant_clone, clippy::missing_spin_loop)] use std::{ ops::Bound, sync::atomic::{AtomicUsize, Ordering}, }; use crossbeam_epoch as epoch; use crossbeam_skiplist::{SkipList, base}; fn ref_entry<'a, K, V>(e: impl Into<Option<base::RefEntry<'a, K, V>>>) -> Entry<'a, K, V> { Entry(e.into()...
crossbeam
rust
concurrency
set.rs
use std::{ iter, ops::Bound, sync::{Arc, Barrier}, }; use crossbeam_skiplist::SkipSet; use crossbeam_utils::thread; #[test] fn smoke() { let m = SkipSet::new(); m.insert(1); m.insert(5); m.insert(7); } #[test] fn is_empty() { let s = SkipSet::new(); assert!(s.is_empty()); s.i...
crossbeam
rust
concurrency
map.rs
use std::{ borrow::Borrow, iter, ops::Bound, sync::{Arc, Barrier}, }; use crossbeam_skiplist::SkipMap; use crossbeam_utils::thread; #[test] fn smoke() { let m = SkipMap::new(); m.insert(1, 10); m.insert(5, 50); m.insert(7, 70); } #[test] fn is_empty() { let s = SkipMap::new(); ...
crossbeam
rust
concurrency
simple.rs
// use std::time::Instant; fn main() { // let map = crossbeam_skiplist::SkipMap::new(); // // let mut map = std::collections::BTreeMap::new(); // // let mut map = std::collections::HashMap::new(); // // let now = Instant::now(); // // let mut num = 0u64; // for _ in 0..1_000_000 { /...
crossbeam
rust
concurrency
btree.rs
#![feature(test)] extern crate test; use std::collections::BTreeMap as Map; use test::{Bencher, black_box}; #[bench] fn insert(b: &mut Bencher) { b.iter(|| { let mut map = Map::new(); let mut num = 0u64; for _ in 0..1_000 { num = num.wrapping_mul(17).wrapping_add(255); ...
crossbeam
rust
concurrency
skipmap.rs
#![feature(test)] extern crate test; use crossbeam_skiplist::SkipMap as Map; use test::{Bencher, black_box}; #[bench] fn insert(b: &mut Bencher) { b.iter(|| { let map = Map::new(); let mut num = 0u64; for _ in 0..1_000 { num = num.wrapping_mul(17).wrapping_add(255); ...
crossbeam
rust
concurrency
skiplist.rs
#![feature(test)] #![allow(clippy::unit_arg)] extern crate test; use crossbeam_epoch as epoch; use crossbeam_skiplist::SkipList; use test::{Bencher, black_box}; #[bench] fn insert(b: &mut Bencher) { let guard = &epoch::pin(); b.iter(|| { let map = SkipList::new(epoch::default_collector().clone()); ...
crossbeam
rust
concurrency
hash.rs
#![feature(test)] extern crate test; use std::collections::HashMap as Map; use test::{Bencher, black_box}; #[bench] fn insert(b: &mut Bencher) { b.iter(|| { let mut map = Map::new(); let mut num = 0u64; for _ in 0..1_000 { num = num.wrapping_mul(17).wrapping_add(255); ...
crossbeam
rust
concurrency
equivalent.rs
// These traits are based on `equivalent` crate, but `K` and `Q` are flipped to avoid type inference issues: // https://github.com/indexmap-rs/equivalent/issues/5 use core::{borrow::Borrow, cmp::Ordering}; /// Key equivalence trait. /// /// This trait allows hash table lookup to be customized. It has one blanket ///...
crossbeam
rust
concurrency
lib.rs
#![no_std] #![doc(test( no_crate_inject, attr(allow(dead_code, unused_assignments, unused_variables)) ))] #![warn( missing_docs, unsafe_op_in_unsafe_fn, clippy::alloc_instead_of_core, clippy::std_instead_of_alloc, clippy::std_instead_of_core )] #[cfg(all(feature = "alloc", target_has_atomic...
crossbeam
rust
concurrency
comparator.rs
use core::cmp::Ordering; use crate::equivalent::{Comparable, Equivalent}; /// Key equality trait. /// /// This trait allows for very flexible comparison of objects. You may /// borrow/dereference `L` and `R` using `Borrow` or another trait. The trait /// takes a `self` parameter, which you can use to change how the o...
crossbeam
rust
concurrency
base.rs
use alloc::alloc::handle_alloc_error; use core::{ alloc::Layout, cmp, fmt, marker::PhantomData, mem, ops::{Bound, Deref, RangeBounds}, ptr, ptr::NonNull, sync::atomic::{AtomicUsize, Ordering, fence}, }; use crossbeam_epoch::{self as epoch, Atomic, Collector, Guard, Shared}; use crossbea...
crossbeam
rust
concurrency
set.rs
use core::{ fmt, ops::{Bound, Deref, RangeBounds}, }; use crate::{ comparator::{BasicComparator, Comparator}, map, }; /// A set based on a lock-free skip list. /// /// This is an alternative to [`BTreeSet`] which supports /// concurrent access across multiple threads. /// /// A custom comparator may b...
crossbeam
rust
concurrency
alloc_helper.rs
use core::{alloc::Layout, ptr::NonNull}; // Based on unstable alloc::alloc::Global. // // Note: unlike alloc::alloc::Global that returns NonNull<[u8]>, // this returns NonNull<u8>. pub(crate) struct Global; #[allow(clippy::unused_self)] impl Global { #[inline] #[cfg_attr(miri, track_caller)] // even without pa...
crossbeam
rust
concurrency
map.rs
use core::{ fmt, mem::ManuallyDrop, ops::{Bound, RangeBounds}, ptr, }; use crossbeam_epoch as epoch; use crate::{ base::{self, try_pin_loop}, comparator::{BasicComparator, Comparator}, }; /// An ordered map based on a lock-free skip list. /// /// This is an alternative to [`BTreeMap`] which s...
crossbeam
rust
concurrency
subcrates.rs
use crossbeam::select; #[test] fn channel() { let (s, r) = crossbeam::channel::bounded(1); select! { send(s, 0) -> res => res.unwrap(), recv(r) -> res => assert!(res.is_ok()), } } #[test] fn deque() { let w = crossbeam::deque::Worker::new_fifo(); w.push(1); let _ = w.pop(); } ...
crossbeam
rust
concurrency
build.rs
// The rustc-cfg emitted by the build script are *not* public API. use std::env; fn main() { println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rustc-check-cfg=cfg(crossbeam_sanitize_thread)"); let target = &*env::var("TARGET").expect("TARGET not set"); // `cfg(sanitize = "..")` is not sta...
crossbeam
rust
concurrency
injector.rs
use std::sync::{ Arc, Mutex, atomic::{AtomicBool, AtomicUsize, Ordering::SeqCst}, }; use crossbeam_deque::{ Injector, Steal::{self, Empty, Success}, Worker, }; use crossbeam_utils::thread::scope; fn busy_retry<T>(mut f: impl FnMut() -> Steal<T>) -> Steal<T> { loop { let s = f(); ...
crossbeam
rust
concurrency
fifo.rs
use std::sync::{ Arc, Mutex, atomic::{AtomicBool, AtomicUsize, Ordering::SeqCst}, }; use crossbeam_deque::{ Steal::{Empty, Success}, Worker, }; use crossbeam_utils::thread::scope; #[test] fn smoke() { let w = Worker::new_fifo(); let s = w.stealer(); assert_eq!(w.pop(), None); assert_eq...
crossbeam
rust
concurrency
lifo.rs
use std::sync::{ Arc, Mutex, atomic::{AtomicBool, AtomicUsize, Ordering::SeqCst}, }; use crossbeam_deque::{ Steal::{Empty, Success}, Worker, }; use crossbeam_utils::thread::scope; #[test] fn smoke() { let w = Worker::new_lifo(); let s = w.stealer(); assert_eq!(w.pop(), None); assert_eq...
crossbeam
rust
concurrency
steal.rs
use crossbeam_deque::{ Injector, Steal::{self, Success}, Worker, }; fn busy_retry<T>(mut f: impl FnMut() -> Steal<T>) -> Steal<T> { loop { let s = f(); if !s.is_retry() { return s; } } } #[test] fn steal_fifo() { let w = Worker::new_fifo(); for i in 1..=...
crossbeam
rust
concurrency
deque.rs
use alloc::{alloc::handle_alloc_error, boxed::Box, sync::Arc}; use core::{ alloc::Layout, cell::{Cell, UnsafeCell}, cmp, fmt, marker::PhantomData, mem::{self, MaybeUninit}, ptr, sync::atomic::{self, AtomicPtr, AtomicUsize, Ordering}, }; use crossbeam_epoch::{self as epoch, Atomic, Owned}; u...
crossbeam
rust
concurrency
lib.rs
#![no_std] #![doc(test( no_crate_inject, attr(allow(dead_code, unused_assignments, unused_variables)) ))] #![warn( missing_docs, unsafe_op_in_unsafe_fn, clippy::alloc_instead_of_core, clippy::std_instead_of_alloc, clippy::std_instead_of_core )] #[cfg(feature = "std")] extern crate alloc; #[...
crossbeam
rust
concurrency
alloc_helper.rs
use core::{alloc::Layout, ptr::NonNull}; // Based on unstable alloc::alloc::Global. // // Note: unlike alloc::alloc::Global that returns NonNull<[u8]>, // this returns NonNull<u8>. pub(crate) struct Global; #[allow(clippy::unused_self)] impl Global { #[inline] #[cfg_attr(miri, track_caller)] // even without pa...
crossbeam
rust
concurrency
lib.rs
#![no_std] #![doc(test( no_crate_inject, attr(allow(dead_code, unused_assignments, unused_variables)) ))] #![warn( missing_docs, unsafe_op_in_unsafe_fn, clippy::alloc_instead_of_core, clippy::std_instead_of_alloc, clippy::std_instead_of_core )] #[cfg(feature = "std")] extern crate std; pub...
crossbeam
rust
concurrency
seg_queue.rs
use std::sync::atomic::{AtomicUsize, Ordering}; use crossbeam_queue::SegQueue; use crossbeam_utils::thread::scope; #[test] fn smoke() { let q = SegQueue::new(); q.push(7); assert_eq!(q.pop(), Some(7)); q.push(8); assert_eq!(q.pop(), Some(8)); assert!(q.pop().is_none()); } #[test] fn len_empt...
crossbeam
rust
concurrency
array_queue.rs
use std::sync::atomic::{AtomicUsize, Ordering}; use crossbeam_queue::ArrayQueue; use crossbeam_utils::thread::scope; #[test] fn smoke() { let q = ArrayQueue::new(1); q.push(7).unwrap(); assert_eq!(q.pop(), Some(7)); q.push(8).unwrap(); assert_eq!(q.pop(), Some(8)); assert!(q.pop().is_none())...
crossbeam
rust
concurrency
lib.rs
#![no_std] #![doc(test( no_crate_inject, attr(allow(dead_code, unused_assignments, unused_variables)) ))] #![warn( missing_docs, unsafe_op_in_unsafe_fn, clippy::alloc_instead_of_core, clippy::std_instead_of_alloc, clippy::std_instead_of_core )] #[cfg(all(feature = "alloc", target_has_atomic...
crossbeam
rust
concurrency
seg_queue.rs
use alloc::{alloc::handle_alloc_error, boxed::Box}; use core::{ alloc::Layout, cell::UnsafeCell, fmt, marker::PhantomData, mem::MaybeUninit, panic::{RefUnwindSafe, UnwindSafe}, ptr, sync::atomic::{self, AtomicPtr, AtomicUsize, Ordering}, }; use crossbeam_utils::{Backoff, CachePadded}; ...
crossbeam
rust
concurrency
array_queue.rs
use alloc::boxed::Box; use core::{ cell::UnsafeCell, fmt, mem::{self, MaybeUninit}, panic::{RefUnwindSafe, UnwindSafe}, sync::atomic::{self, Ordering}, }; use crossbeam_utils::{Backoff, CachePadded}; // Ideally, we want to always use AtomicU64, but since it is not available on all platforms, // we...
crossbeam
rust
concurrency
alloc_helper.rs
use core::{alloc::Layout, ptr::NonNull}; // Based on unstable alloc::alloc::Global. // // Note: unlike alloc::alloc::Global that returns NonNull<[u8]>, // this returns NonNull<u8>. pub(crate) struct Global; #[allow(clippy::unused_self)] impl Global { #[inline] #[cfg_attr(miri, track_caller)] // even without pa...
nom
rust
parsers
expression_ast.rs
use nom::{ branch::alt, bytes::complete::tag, character::complete::{alphanumeric1 as alphanumeric, digit1 as digit}, combinator::{map, map_res}, multi::separated_list0, sequence::delimited, IResult, Parser, }; use nom_language::precedence::{binary_op, precedence, unary_op, Assoc, Operation}; // Elements ...
nom
rust
parsers
overflow.rs
#![allow(clippy::unreadable_literal)] #![cfg(target_pointer_width = "64")] use nom::bytes::streaming::take; #[cfg(feature = "alloc")] use nom::multi::{length_data, many}; #[cfg(feature = "alloc")] use nom::number::streaming::be_u64; use nom::{Err, IResult, Needed, Parser}; // Parser definition // We request a length...
nom
rust
parsers
float.rs
use nom::branch::alt; use nom::bytes::complete::tag; use nom::character::streaming::digit1 as digit; use nom::combinator::{map, map_res, opt, recognize}; use nom::error::ErrorKind; use nom::number::complete::f32; use nom::number::complete::f64; use nom::number::Endianness; use nom::sequence::{delimited, pair}; use nom:...
nom
rust
parsers
ini_str.rs
use nom::{ bytes::complete::{is_a, tag, take_till, take_while}, character::complete::{alphanumeric1 as alphanumeric, char, space0 as space}, combinator::opt, multi::many, sequence::{delimited, pair, terminated}, IResult, Parser, }; use std::collections::HashMap; fn is_line_ending_or_comment(chr: char) -> ...
nom
rust
parsers
reborrow_fold.rs
#![allow(dead_code)] // #![allow(unused_variables)] use std::str; use nom::bytes::complete::is_not; use nom::character::complete::char; use nom::combinator::{map, map_res}; use nom::multi::fold; use nom::sequence::delimited; use nom::{IResult, Parser}; fn atom(_tomb: &mut ()) -> impl for<'a> FnMut(&'a [u8]) -> IResu...
nom
rust
parsers
custom_errors.rs
#![allow(dead_code)] use nom::bytes::streaming::tag; use nom::character::streaming::digit1 as digit; use nom::combinator::verify; use nom::error::{ErrorKind, ParseError}; #[cfg(feature = "alloc")] use nom::multi::count; use nom::sequence::terminated; use nom::{IResult, Parser}; #[derive(Debug)] pub struct CustomError...
nom
rust
parsers
arithmetic.rs
use nom::{ branch::alt, bytes::complete::tag, character::complete::char, character::complete::{digit1 as digit, space0 as space}, combinator::map_res, multi::fold, sequence::{delimited, pair}, IResult, Parser, }; // Parser definition use std::str::FromStr; // We parse any expr surrounded by parens, i...
nom
rust
parsers
issues.rs
//#![feature(trace_macros)] #![allow(dead_code)] #![allow(clippy::redundant_closure)] use nom::{error::ErrorKind, Err, IResult, Needed, Parser}; #[allow(dead_code)] struct Range { start: char, end: char, } pub fn take_char(input: &[u8]) -> IResult<&[u8], char> { if !input.is_empty() { Ok((&input[1..], inpu...
nom
rust
parsers
json.rs
#![cfg(feature = "alloc")] use nom::{ branch::alt, bytes::complete::{tag, take}, character::complete::{anychar, char, multispace0, none_of}, combinator::{map, map_opt, map_res, value, verify}, error::ParseError, multi::{fold, separated_list0}, number::complete::double, sequence::{delimited, preceded, s...
nom
rust
parsers
arithmetic_ast.rs
use std::fmt; use std::fmt::{Debug, Display, Formatter}; use std::str::FromStr; use nom::Parser; use nom::{ branch::alt, bytes::complete::tag, character::complete::{digit1 as digit, multispace0 as multispace}, combinator::{map, map_res}, multi::many, sequence::{delimited, preceded}, IResult, }; pub enu...
nom
rust
parsers
ini.rs
use nom::{ bytes::complete::take_while, character::complete::{ alphanumeric1 as alphanumeric, char, multispace0 as multispace, space0 as space, }, combinator::{map, map_res, opt}, multi::many, sequence::{delimited, pair, separated_pair, terminated}, IResult, Parser, }; use std::collections::HashMap; ...
nom
rust
parsers
mp4.rs
#![allow(dead_code)] use nom::{ branch::alt, bytes::streaming::{tag, take}, combinator::{map, map_res}, error::ErrorKind, multi::many, number::streaming::{be_f32, be_u16, be_u32, be_u64}, Err, IResult, Needed, Parser, }; use std::str; fn mp4_box(input: &[u8]) -> IResult<&[u8], &[u8]> { match be_u32(i...
nom
rust
parsers
escaped.rs
use nom::bytes::complete::escaped; use nom::character::complete::digit1; use nom::character::complete::one_of; use nom::{error::ErrorKind, Err, IResult}; fn esc(s: &str) -> IResult<&str, &str, (&str, ErrorKind)> { escaped(digit1, '\\', one_of("\"n\\"))(s) } #[cfg(feature = "alloc")] fn esc_trans(s: &str) -> IResult...
nom
rust
parsers
css.rs
use nom::bytes::complete::{tag, take_while_m_n}; use nom::combinator::map_res; use nom::{IResult, Parser}; #[derive(Debug, Eq, PartialEq)] pub struct Color { pub red: u8, pub green: u8, pub blue: u8, } fn from_hex(input: &str) -> Result<u8, std::num::ParseIntError> { u8::from_str_radix(input, 16) } fn is_hex...
nom
rust
parsers
multiline.rs
use nom::{ character::complete::{alphanumeric1 as alphanumeric, line_ending as eol}, multi::many, sequence::terminated, IResult, Parser, }; pub fn end_of_line(input: &str) -> IResult<&str, &str> { if input.is_empty() { Ok((input, input)) } else { eol(input) } } pub fn read_line(input: &str) -> I...
nom
rust
parsers
fnmut.rs
use nom::{ bytes::complete::tag, multi::{many, many0_count}, Parser, }; #[test] fn parse() { let mut counter = 0; let res = { let mut parser = many::<_, (), Vec<&str>, _, _>(0.., |i| { counter += 1; tag("abc")(i) }); parser.parse("abcabcabcabc").unwrap() }; println!("res: {:?}"...
nom
rust
parsers
error.rs
use std::fmt; use nom::{ error::{ContextError, ErrorKind, FromExternalError, ParseError}, ErrorConvert, }; /// This error type accumulates errors and their position when backtracking /// through a parse tree. With some post processing, /// it can be used to display user friendly error messages #[derive(Clone, Deb...
nom
rust
parsers
mod.rs
#[cfg(test)] mod tests; use nom::error::{ErrorKind, FromExternalError, ParseError}; use nom::{Check, Err, IResult, Input, Mode, OutputM, OutputMode, Parser}; /// An unary operator. pub struct Unary<V, Q: Ord + Copy> { value: V, precedence: Q, } /// A binary operator. pub struct Binary<V, Q: Ord + Copy> { value...
nom
rust
parsers
json2.rs
//#[global_allocator] //static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; use nom::{ branch::alt, bytes::{tag, take}, character::{anychar, char, multispace0, none_of}, combinator::{map, map_opt, map_res, value, verify}, error::{Error, ParseError}, multi::{fold, separated_list0}, number::doub...
nom
rust
parsers
custom_error.rs
extern crate nom; use nom::error::ErrorKind; use nom::error::ParseError; use nom::Err::Error; use nom::IResult; #[derive(Debug, PartialEq)] pub enum CustomError<I> { MyError, Nom(I, ErrorKind), } impl<I> ParseError<I> for CustomError<I> { fn from_error_kind(input: I, kind: ErrorKind) -> Self { CustomError:...
nom
rust
parsers
json.rs
#![cfg(feature = "alloc")] use nom::{ branch::alt, bytes::complete::{escaped, tag, take_while}, character::complete::{alphanumeric1 as alphanumeric, char, one_of}, combinator::{cut, map, opt, value}, error::{context, ContextError, ErrorKind, ParseError}, multi::separated_list0, number::complete::double, ...
nom
rust
parsers
string.rs
#![cfg(feature = "alloc")] use nom::branch::alt; use nom::bytes::streaming::{is_not, take_while_m_n}; use nom::character::streaming::{char, multispace1}; use nom::combinator::{map, map_opt, map_res, value, verify}; use nom::error::{FromExternalError, ParseError}; use nom::multi::fold; use nom::sequence::{delimited, pr...
nom
rust
parsers
s_expression.rs
#![cfg(feature = "alloc")] use nom::{ branch::alt, bytes::complete::tag, character::complete::{alpha1, char, digit1, multispace0, multispace1, one_of}, combinator::{cut, map, map_res, opt}, error::context, multi::many, sequence::{delimited, preceded, terminated}, IResult, Parser, }; use nom_language::e...
nom
rust
parsers
iterator.rs
use std::collections::HashMap; use std::iter::Iterator; use nom::bytes::complete::tag; use nom::character::complete::alphanumeric1; use nom::combinator::iterator; use nom::sequence::{separated_pair, terminated}; use nom::IResult; fn main() { let mut data = "abcabcabcabc"; fn parser(i: &str) -> IResult<&str, &str...
nom
rust
parsers
json_iterator.rs
#![cfg(feature = "alloc")] use nom::{ branch::alt, bytes::complete::{escaped, tag, take_while}, character::complete::{alphanumeric1 as alphanumeric, char, one_of}, combinator::{cut, map}, error::{context, ParseError}, multi::separated_list0, number::complete::double, sequence::{preceded, separated_pair...
nom
rust
parsers
number.rs
#[global_allocator] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; use codspeed_criterion_compat::*; use nom::number::complete; fn parser(i: &[u8]) -> nom::IResult<&[u8], u64> { complete::be_u64(i) } fn number(c: &mut Criterion) { let data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]; parser(&dat...
nom
rust
parsers
ini_str.rs
#[global_allocator] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; use codspeed_criterion_compat::*; use nom::{ bytes::complete::{is_a, tag, take_till, take_while}, character::complete::{alphanumeric1 as alphanumeric, char, not_line_ending, space0 as space}, combinator::opt, multi::many, seq...
nom
rust
parsers
arithmetic.rs
#[global_allocator] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion}; use nom::{ branch::alt, character::complete::{char, digit1, one_of, space0}, combinator::map_res, multi::fold, sequence::{delimited, pair}, IResult...
nom
rust
parsers
json.rs
#[global_allocator] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; use codspeed_criterion_compat::*; use nom::{ branch::alt, bytes::{tag, take}, character::{anychar, char, multispace0, none_of}, combinator::{map, map_opt, map_res, value, verify}, error::{Error, ErrorKind, FromExternalError, P...
nom
rust
parsers
ini.rs
#[global_allocator] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; use codspeed_criterion_compat::*; use nom::{ bytes::complete::take_while, character::complete::{ alphanumeric1 as alphanumeric, char, multispace1 as multispace, space1 as space, }, combinator::{map_res, opt}, multi::many,...
nom
rust
parsers
http.rs
#![cfg_attr(rustfmt, rustfmt_skip)] #[global_allocator] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; use codspeed_criterion_compat::*; use nom::{IResult, bytes::{tag, take_while1}, character:: char, multi::many, OutputMode, Parser, PResult, error::Error, Mode, sequence::{preceded, delimited, separat...
nom
rust
parsers
fuzz_arithmetic.rs
#![no_main] use libfuzzer_sys::fuzz_target; use std::str; extern crate nom; use nom::{ branch::alt, bytes::complete::tag, character::complete::char, character::complete::{digit1 as digit, space0 as space}, combinator::{map, map_res, verify}, multi::fold_many0, sequence::{delimited, pair, terminated}, ...
nom
rust
parsers
error.rs
use crate::internal::{Err, Mode, OutputMode, PResult, Parser}; use crate::lib::std::fmt; #[cfg(feature = "alloc")] use crate::alloc::borrow::ToOwned; #[cfg(feature = "std")] use crate::internal::IResult; /// This trait must be implemented by the error type of a nom parser. /// /// There are already implementations o...
nom
rust
parsers
lib.rs
#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(feature = "docsrs", feature(doc_cfg))] #![allow(clippy::doc_markdown)] #![deny(missing_docs)] #[cfg(feature = "alloc")] #[macro_use] extern crate alloc; #[cfg(doctest)] extern crate doc_comment; #[cfg(doctest)] doc_comment::doctest!("../README.md"); /// Lib modul...
nom
rust
parsers
str.rs
#[cfg(test)] mod test { #[cfg(feature = "alloc")] use crate::{branch::alt, bytes::complete::tag_no_case, combinator::recognize, multi::many}; use crate::{ bytes::complete::{is_a, is_not, tag, take, take_till, take_until}, error::{self, ErrorKind}, Err, IResult, }; #[test] fn tagtr_succeed() { ...