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 Sep 20, 2019
Code shared from the Rust Playground
View playground.rs
#![feature(dropck_eyepatch)]
use std::{fmt, rc::Rc};
struct PeekOnDrop<T: fmt::Debug>(T);
unsafe impl<#[may_dangle] T: fmt::Debug> Drop for PeekOnDrop<T> {
fn drop(&mut self) {
println!("{:?}", self.0);
}
@rust-play
rust-play / playground.rs
Created Sep 20, 2019
Code shared from the Rust Playground
View playground.rs
#![feature(core_intrinsics)]
use std::intrinsics::discriminant_value;
use std::mem::size_of;
#[derive(Debug)]
#[allow(dead_code)]
enum E {
A = 0x1000_0000,
B = 0,
@rust-play
rust-play / playground.rs
Created Sep 20, 2019
Code shared from the Rust Playground
View playground.rs
#![allow(dead_code, unconditional_recursion)]
trait StringRep {
fn rep(&self) -> String;
}
#[derive(Debug)]
enum Token {
Add((Box<Token>, Box<Token>)),
Sub((Box<Token>, Box<Token>)),
@rust-play
rust-play / playground.rs
Created Sep 20, 2019
Code shared from the Rust Playground
View playground.rs
use core::ops::*;
fn main() {
let mut times_vec_updated = 0;
let mut vec = OnUpdate(vec![], |v| {
eprintln!("Vec updated: {:?}", v);
times_vec_updated += 1;
});
vec.borrow_mut().push(5);
@rust-play
rust-play / playground.rs
Created Sep 20, 2019
Code shared from the Rust Playground
View playground.rs
pub struct Foo;
mod private {
use super::*;
impl Foo {
pub fn bar(&self) {}
}
}
fn main() {
@rust-play
rust-play / playground.rs
Created Sep 20, 2019
Code shared from the Rust Playground
View playground.rs
use core::ops::*;
fn main() {
let mut vec = OnUpdate(vec![], |v| {
println!("Vec updated: {:?}", v);
});
vec.borrow_mut().push(5);
vec.borrow_mut().push(6);
vec.borrow_mut().push(7);
@rust-play
rust-play / playground.rs
Created Sep 20, 2019
Code shared from the Rust Playground
View playground.rs
fn main() {
foo("abc");
}
struct Value();
struct StrDeserializer<'a>(&'a str);
impl<'a> StrDeserializer<'a> {
fn new(s: &'a str) -> Self {
StrDeserializer(s)
@rust-play
rust-play / playground.rs
Created Sep 20, 2019
Code shared from the Rust Playground
View playground.rs
#![feature(const_generics)]
trait Foo {
const A: usize;
}
trait Aux<const A: usize> {}
impl<T: Foo> Aux<{ <T as Foo>::A }> for T where T: Foo {}
trait Trait {}
impl<T> Trait for T where T: Aux<{ 2 }> {}
@rust-play
rust-play / playground.rs
Created Sep 20, 2019
Code shared from the Rust Playground
View playground.rs
#![feature(const_generics)]
trait Foo {
const A: usize;
}
trait Aux<const A: usize> {}
impl<T: Foo> Aux<{ <T as Foo>::A }> for T where T: Foo {}
trait Trait {}
impl<T> Trait for T where T: Aux<{ 2 }> {}
@rust-play
rust-play / playground.rs
Last active Sep 20, 2019
Code shared from the Rust Playground
View playground.rs
#![feature(const_generics)]
trait Foo {
const A: usize;
}
trait Aux<const A: usize> {}
impl<T: Foo> Aux<{ <T as Foo>::A }> for T {}
trait Trait {}
impl<T> Trait for T where T: Aux<{ 2 }> {}
You can’t perform that action at this time.