This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use core::{ | |
mem::{self, MaybeUninit}, | |
ptr, | |
}; | |
/// This struct is a simple wrapper around `[MaybeUninit<T>; N]`. | |
/// It provides some convenience methods for working with arrays that may have uninitialized items. | |
pub(crate) struct MaybeArray<T, const N: usize> { | |
array: [MaybeUninit<T>; N] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn helper<'a, 'b, T: ?Sized>(_: &'a &'b (), v: &'b T) -> &'a T { v } | |
fn helper_mut<'a, 'b, T: ?Sized>(_: &'a &'b (), v: &'b mut T) -> &'a mut T { v } | |
/// Use black magic fuckery to turn any `&T` into a `&'static T`. | |
/// May introduce undefined behavior. | |
pub fn make_static<'a, T: ?Sized>(input: &'a T) -> &'static T { | |
let f: fn(_, &'a T) -> &'static T = helper; | |
f(&&(), input) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub(crate) struct MaybeArray<T, const N: usize> { | |
array: [MaybeUninit<T>; N], | |
} | |
impl<T, const N: usize> Default for MaybeArray<T, { N }> { | |
#[inline(always)] | |
fn default() -> Self { | |
Self { | |
array: unsafe { MaybeUninit::<_>::uninit().assume_init() }, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(async_await)] | |
extern crate structopt; | |
use structopt::StructOpt; | |
use std::{ | |
future::Future as StdFuture, | |
net::{IpAddr, SocketAddr}, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub inline fn MaybeUninit(comptime T: type) type { | |
return packed union { | |
value: T, | |
uninit: void, | |
const Self = @This(); | |
inline fn init(value: T) Self { | |
return Self { .value = value }; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct __<'__, ___: '__ = &'__ [()]> { | |
__: &'__ [__<'__, &'__ [___]>], | |
___: ___, | |
} | |
fn main() { | |
'__: while break '__ | |
== (|___: __<()>| -> () { ___.___ })(__::<()> { | |
__: &[][..], | |
___: (), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![no_std] | |
/// Fakes a value of type `T`. | |
#[inline] | |
pub const unsafe fn fake_type<T>() -> T { | |
cold(); | |
unreachable() | |
} | |
/// Tells the compiler this code is unreachable. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(const_mut_refs)] | |
#![feature(const_fn)] | |
#![feature(const_if_match)] | |
#![feature(const_loop)] | |
#![feature(const_raw_ptr_deref)] | |
#![feature(const_fn_union)] | |
#![feature(const_raw_ptr_to_usize_cast)] | |
#![feature(const_saturating_int_methods)] | |
use std::marker::PhantomData; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::{ | |
ops::{Generator, GeneratorState}, | |
pin::Pin, | |
}; | |
/// A wrapper struct around Generators, | |
/// providing a safe implementation of the [`Iterator`] trait. | |
pub struct GenIter<G>(Option<G>); | |
impl<G: Generator + Unpin> GenIter<G> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mod simd { | |
use core::arch::x86_64::{ | |
__m128i, _mm_add_epi32, _mm_and_si128, _mm_cmpeq_epi32, _mm_mullo_epi32, _mm_set1_epi32, | |
_mm_setzero_si128, _mm_sllv_epi32, _mm_srlv_epi32, _mm_sub_epi32, _mm_test_all_ones, | |
_mm_xor_si128, | |
}; | |
/// Maps from an array to its corresponding Simd type. | |
pub unsafe trait SimdArray: Copy { | |
type Lane: Copy; |