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 Aug 21, 2019
Code shared from the Rust Playground
View playground.rs
fn main() {
let a = find_min(vec![-9, 1, 2, 3, 4]);
let b = find_min(vec![100, 10, 20, 30, 40]);
println!("{:?} {:?}", a, b);
}
fn find_min<T>(data: Vec<T>) -> Option<T> {
let mut it = data.into_iter();
let mut min = match it.next() {
Some(elem) => elem,
@rust-play
rust-play / playground.rs
Created Aug 21, 2019
Code shared from the Rust Playground
View playground.rs
use std::io;
use std::io::Read;
use std::fs::File;
use std::path::Path;
use std::num::ParseIntError;
use failure::Fail;
fn do_io_things(file: &Path) -> Result<i32, Error> {
let mut file = File::open(file)?;
let mut contents = String::new();
@rust-play
rust-play / playground.rs
Created Aug 21, 2019
Code shared from the Rust Playground
View playground.rs
struct S {
x: Box<[u8]>
}
fn main() {
let x = S {x: Box::new([0u8; 32])};
crossbeam::scope(|s| {
s.spawn(|_| {
println!("{:?}", x.x);
});
println!("{:?}", x.x);
@rust-play
rust-play / playground.rs
Created Aug 21, 2019
Code shared from the Rust Playground
View playground.rs
use std::io;
use std::io::Read;
use std::fmt;
use std::error::Error;
use std::fs::File;
use std::path::Path;
use std::num::ParseIntError;
fn do_io_things(file: &Path) -> Result<i32, MyError> {
let mut file = File::open(file)?;
@rust-play
rust-play / playground.rs
Created Aug 21, 2019
Code shared from the Rust Playground
View playground.rs
use std::collections::HashMap;
pub struct Selector {
pub networks: HashMap<u32, Vec<&'static str>>,
}
impl Selector {
pub fn new() -> Selector {
@rust-play
rust-play / playground.rs
Created Aug 20, 2019
Code shared from the Rust Playground
View playground.rs
use std::collections::HashMap;
pub type DidWork = bool;
pub type RequestId = String;
pub struct PsCore<'pscore, MOD, OUT, OUTR, INR, E> {
pending_outs: HashMap<RequestId, Box<dyn Fn(&mut MOD, OUTR) + 'pscore>>,
out_outbox: Vec<(Option<RequestId>, OUT)>,
in_outbox: Vec<(RequestId, INR)>,
phantom_error: std::marker::PhantomData<E>,
@rust-play
rust-play / playground.rs
Created Aug 20, 2019
Code shared from the Rust Playground
View playground.rs
type F = dyn FnMut();
pub fn g(_f: &mut F) {}
pub fn test(f: &mut F) {
g(&mut || f())
}
@rust-play
rust-play / playground.rs
Created Aug 20, 2019
Code shared from the Rust Playground
View playground.rs
use std::sync::Mutex;
#[macro_use]
extern crate lazy_static;
#[derive(Debug)]
struct MyDB {}
lazy_static! {
@rust-play
rust-play / playground.rs
Created Aug 20, 2019
Code shared from the Rust Playground
View playground.rs
struct Church<'a, T> {
runner: Box<dyn Fn(&'a dyn Fn(T) -> T) -> Box<dyn Fn(T) -> T + 'a> + 'a>
}
impl<'a, T> Church<'a, T>
{
fn succ(self) -> Self {
Church { runner: Box::new(move |f| {
Box::new(|x| (self.runner)(f)(x))
})}
@rust-play
rust-play / playground.rs
Created Aug 20, 2019
Code shared from the Rust Playground
View playground.rs
use bytes::Bytes;
fn main() {
let mut mem = Bytes::from(&b"Hello world"[..]);
println!("{}", std::str::from_utf8(&mem).unwrap());
}
You can’t perform that action at this time.