Skip to content

Instantly share code, notes, and snippets.

The Rust Playground rust-play

View GitHub Profile
@rust-play
rust-play / playground.rs
Created Apr 21, 2019
Code shared from the Rust Playground
View playground.rs
#![feature(box_into_pin)]
use std::pin::Pin;
trait T {
fn test(&self) -> usize;
}
struct X {
_n: i32
}
@rust-play
rust-play / playground.rs
Created Apr 21, 2019
Code shared from the Rust Playground
View playground.rs
use std::ops::Index;
#[derive(Debug)]
struct Image<P> {
width: usize,
pixels: Vec<P>,
}
impl<P: Default + Copy> Image<P> {
/// Create a new image of the given size.
@rust-play
rust-play / playground.rs
Created Apr 21, 2019
Code shared from the Rust Playground
View playground.rs
use std::rc::Rc;
fn main() {
let mut thingy = Rc::new(0u32);
let _share = thingy.clone();
let thingy_ref = Rc::get_mut(&mut thingy).expect("got nothing");
*thingy_ref = 1;
println!("{}", *thingy);
}
@rust-play
rust-play / playground.rs
Created Apr 21, 2019
Code shared from the Rust Playground
View playground.rs
extern crate termion; // 1.5.1
use std::io;
use termion::input::TermRead;
use termion::raw::IntoRawMode;
use termion::screen::AlternateScreen;
pub fn main() {
let stdin = io::stdin();
let stdout = io::stdout();
@rust-play
rust-play / playground.rs
Created Apr 21, 2019
Code shared from the Rust Playground
View playground.rs
use std::collections::HashSet;
#[derive(Hash, Eq, Debug)]
struct Test {
a: i32,
b: String,
c: bool
}
impl PartialEq for Test {
@rust-play
rust-play / playground.rs
Created Apr 21, 2019
Code shared from the Rust Playground
View playground.rs
pub struct Foo<'a> {
a: &'a str,
}
trait Bar {
type Baz;
fn default() -> Self;
}
@rust-play
rust-play / playground.rs
Created Apr 21, 2019
Code shared from the Rust Playground
View playground.rs
fn derive_switch_int(&mut self, generator: NodeId, discr: Operand<'tcx>, switch_ty: Ty, values: Cow<'tcx,[u128]>, targets: Vec<BasicBlock>, sir: &mut Sir) -> Vec<Frame<'tcx>> {
let new_memory = self.current_memory.clone();
let compare_to = self.process_operand(discr, generator, sir);
let otherwise_target = targets.pop().unwrap();
let all_other = targets.iter();
let (expressions, frames): (Vec<Expr>, Vec<Option<Frame>>) = values.iter().zip(all_other).map(|(desired_val, target)| {
let comp = Expr::Value(SymTy::from_scalar(*desired_val, switch_ty));
let prec = Expr::BinOp(Rator::Eq, Box::new(comp), Box::new(compare_to));
(prec, self.block_to_frame(generator, *target, Some(prec)))
}).unzip();
@rust-play
rust-play / playground.rs
Created Apr 21, 2019
Code shared from the Rust Playground
View playground.rs
pub struct Foo<'a> {
a: &'a str,
}
impl<'a, 'b> Default for Foo<'a> {
fn default() -> Self {
Self { a: "hello" }
}
}
@rust-play
rust-play / playground.rs
Created Apr 21, 2019
Code shared from the Rust Playground
View playground.rs
#[allow(dead_code)]
struct Foo<'a> {
a: std::marker::PhantomData<&'a ()>
}
trait Bar {}
impl Bar for Foo<'_> {}
@rust-play
rust-play / playground.rs
Created Apr 21, 2019
Code shared from the Rust Playground
View playground.rs
mod some_module {
pub fn some_function() {
println!("Hello, World!")
}
}
fn main() {
use crate::some_module::some_function;
some_function()
You can’t perform that action at this time.