Skip to content

Instantly share code, notes, and snippets.

The Rust Playground rust-play

Block or report user

Report or block rust-play

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@rust-play
rust-play / playground.rs
Created Dec 5, 2019
Code shared from the Rust Playground
View playground.rs
pub struct Um {
gus: i64,
}
fn main() {
let u = Um{gus: 7};
let a: i64 = u.gus;
match 7 {
@rust-play
rust-play / playground.rs
Created Dec 5, 2019
Code shared from the Rust Playground
View playground.rs
fn func<T: ?Sized>() {
eprintln!("Size: {}", std::mem::size_of::<&T>());
}
trait Whatever {}
fn main() {
func::<usize>();
func::<[usize]>();
func::<dyn Whatever>();
@rust-play
rust-play / playground.rs
Created Dec 5, 2019
Code shared from the Rust Playground
View playground.rs
fn func<T: ?Sized>() {
eprintln!("Size: {}", std::mem::size_of::<&T>());
}
fn main() {
func::<usize>();
func::<[usize]>();
}
@rust-play
rust-play / playground.rs
Created Dec 5, 2019
Code shared from the Rust Playground
View playground.rs
macro_rules! test_cases {
(@ [ :: $variant:ident :: stream :: compress ]) => {
#[test] fn a() { }
};
(@ [ :: $variant:ident :: futures :: write :: compress ]) => {
#[test] fn b() { }
};
(@ [ :: $variant:ident :: futures :: write :: decompress ]) => {
@rust-play
rust-play / playground.rs
Created Dec 5, 2019
Code shared from the Rust Playground
View playground.rs
struct MyStruct<TCollection>
where
for<'a> &'a TCollection: IntoIterator<Item = &'a ()>,
{
references: TCollection,
}
impl<TCollection> Drop for MyStruct<TCollection>
where
for<'b> &'b TCollection: IntoIterator<Item = &'b ()>,
@rust-play
rust-play / playground.rs
Created Dec 5, 2019
Code shared from the Rust Playground
View playground.rs
pub mod zero_sized {
use std::marker::PhantomData;
pub struct ZeroSizeProof<T>(PhantomData<T>, ());
pub trait ZeroSized: Sized {
#[deny(const_err)]
const I_AM_ZERO_SIZED: ();
fn proof_zero_size(&self) -> ZeroSizeProof<Self>;
}
@rust-play
rust-play / playground.rs
Created Dec 5, 2019
Code shared from the Rust Playground
View playground.rs
struct MyStruct<TCollection>
where
for<'a> &'a TCollection: IntoIterator<Item = &'a ()>,
{
references: TCollection,
}
impl<TCollection> Drop for MyStruct<TCollection>
where
for<'b> &'b TCollection: IntoIterator<Item = &'b ()>,
@rust-play
rust-play / playground.rs
Created Dec 5, 2019
Code shared from the Rust Playground
View playground.rs
use std::collections::HashMap;
struct Foo {
d: HashMap<String, f32>
}
impl Foo {
fn get(&mut self, s: &str) -> Option<&f32> {
if !self.d.contains_key(s) {
self.d.insert(s.to_string(), 0.0);
@rust-play
rust-play / playground.rs
Created Dec 5, 2019
Code shared from the Rust Playground
View playground.rs
use std::iter::Peekable;
use std::str::Chars;
pub enum Token {
E,
Rest,
}
pub struct Lexer<'a> {
chars: Peekable<Chars<'a>>,
@rust-play
rust-play / playground.rs
Created Dec 5, 2019
Code shared from the Rust Playground
View playground.rs
struct Foo<F=()>(Vec<F>);
fn do_stuff() {
let foo = Foo();
}
You can’t perform that action at this time.