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
// Author: Michael Hewson | |
// https://gist.github.com/mikeyhew/334122cd0104ad3509388074be4351ba | |
// released under the Unlicense <https://unlicense.org/> | |
use std::{ | |
borrow::Cow, | |
str, | |
char, | |
iter, | |
}; |
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
/// A number of lifetime and type parameters that a type is bound with | |
#[derive(Copy, Clone, Debug)] | |
pub struct Binder { | |
num_lifetimes: u32, | |
num_types: u32, | |
} | |
impl Binder { | |
pub fn bind<T>(self, value: T) -> Bound<T> { | |
Bound { |
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(arbitrary_self_types)] | |
use std::ptr; | |
type TypeId = String; | |
trait Any<'a>: 'a { | |
fn type_id(self: *const Self) -> TypeId; | |
} |
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(arbitrary_self_types, specialization)] | |
use std::{ | |
mem::{self, ManuallyDrop}, | |
ptr::{self, NonNull}, | |
marker::PhantomData, | |
ops::{Deref, DerefMut}, | |
}; | |
struct Move<'a, T: 'a + ?Sized> { |
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
extern crate crossbeam; | |
extern crate rand; | |
use rand::Rng; | |
#[allow(unused)] | |
use std::sync::{RwLock, Mutex}; | |
const ARRAY_LEN: usize = 1000; | |
const READS_PER_WRITE: u32 = 5; |
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
let gcd_42_55 = loop(a = 42, b = 45) { | |
if y == 0 { | |
break x | |
} else { | |
continue(b, a % b) | |
} | |
}; |
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
DEBUG:rustc_typeck::collect: convert: item with id 2 | |
DEBUG:rustc_typeck::collect: convert: item std with id 3 | |
DEBUG:rustc_typeck::collect: convert: item Foo with id 4 | |
DEBUG:rustc_typeck::astconv: ast_ty_to_ty(id=NodeId(9), ast_ty=type(&'a isize)) | |
DEBUG:rustc_typeck::astconv: ast_region_to_region(lifetime=lifetime(10: 'a)) yields ReEarlyBound(0, 'a) | |
DEBUG:rustc_typeck::astconv: TyRef r=ReEarlyBound(0, 'a) | |
DEBUG:rustc_typeck::astconv: ast_ty_to_ty(id=NodeId(11), ast_ty=type(isize)) | |
DEBUG:rustc_typeck::astconv: ast_ty_to_ty: maybe_qself=None path=path(isize) | |
DEBUG:rustc_typeck::astconv: base_def_to_ty(def=PrimTy(TyInt(isize)), opt_self_ty=None, path_segments=[PathSegment { name: isize(93), parameters: None, infer_types: false }]) | |
DEBUG:rustc_typeck::astconv: ast_ty_to_ty(id=NodeId(13), ast_ty=type(&'b isize)) |
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(arbitrary_self_types, unboxed_closures, fn_traits)] | |
use std::mem::{self, ManuallyDrop}; | |
use std::ptr; | |
use std::slice; | |
macro_rules! mk_move { | |
(let $name:ident = &move $expr:expr;) => { | |
mk_move!(let $name: _ = &move $expr;); | |
}; |
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::fmt; | |
pub trait Unwrap { | |
type Target; | |
type ErrorMessage: fmt::Display; | |
/// takes Self and either unwraps it into Target, | |
/// or returns an error message to panic with | |
fn unwrap(self) -> Result<Self::Target, Self::ErrorMessage>; |
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::cell::UnsafeCell; | |
#[repr(C)] | |
struct Channel; | |
extern { | |
fn foo(inputs: *mut *mut Channel); | |
} | |
fn call_foo(inputs: &mut [&mut [Channel]]) { |
NewerOlder