Skip to content

Instantly share code, notes, and snippets.

View rust-play's full-sized avatar

The Rust Playground rust-play

View GitHub Profile
@rust-play
rust-play / playground.rs
Created January 24, 2020 16:26
Code shared from the Rust Playground
fn mock<T: Into<String>, I: IntoIterator<Item = T>>(_: I) {}
struct Merchant<'a> {
name: &'a str,
billing_portal: &'a str,
billing_period: &'a str,
stripe_id: Option<&'a str>,
}
fn merchant() -> Merchant { unimplemented!(); }
@rust-play
rust-play / playground.rs
Created January 24, 2020 16:19
Code shared from the Rust Playground
struct Inner {
a: A,
}
impl Inner {
fn fun(&mut self) {
self.a.something();
}
fn fun2(&mut self, outer: &Arc<Outer>) {
self.a.something2(outer.b);
@rust-play
rust-play / playground.rs
Created March 14, 2018 01:01
Code shared from the Rust Playground
#![feature(specialization)]
struct Baz;
trait Foo<T> {
fn bar();
}
default impl<T> Foo<Baz> for T {
fn bar() {
@rust-play
rust-play / playground.rs
Created January 24, 2020 16:02
Code shared from the Rust Playground
use std::net::SocketAddr;
use hyper::{Body, http, Request, Response, Server, StatusCode};
use hyper::service::{make_service_fn, service_fn};
#[tokio::main]
async fn main() {
let addr = SocketAddr::from(([127, 0, 0, 1], 3030));
let make_svc = make_service_fn(|_conn| async {
@rust-play
rust-play / playground.rs
Created December 28, 2018 10:15
Code shared from the Rust Playground
use std::thread;
struct Shitpointer(*mut i32);
unsafe impl Send for Shitpointer {}
fn main() {
let mut v: Vec<i32> = vec![1, 3, 3, 7];
let ptr_1 = Shitpointer(v.as_mut_ptr());
let ptr_2 = Shitpointer(v.as_mut_ptr());
@rust-play
rust-play / playground.rs
Created January 24, 2020 16:20
Code shared from the Rust Playground
#![allow(unused)]
use std::collections::HashMap;
use std::io;
struct PhoneEntry {
name: String,
phone: String,
}
impl PhoneEntry {
@rust-play
rust-play / playground.rs
Created July 31, 2019 20:59
Code shared from the Rust Playground
use serde::{Serialize, Deserialize}; // 1.0.97
use serde_json::{self, Value}; // 1.0.40
//use std::collections::HashMap;
#[derive(Serialize, Deserialize, Debug)]
struct Stuff {
a: i32,
#[serde(flatten)]
extra: Maybe,
@rust-play
rust-play / playground.rs
Created October 25, 2018 08:37
Code shared from the Rust Playground
#![feature(unsize)]
use std::alloc::Layout;
use std::marker::{PhantomData, Unsize};
use std::mem;
/// Assumes pointer-sized metadata
#[repr(C)]
struct DstPointerRepr {
data: *mut (),
@rust-play
rust-play / playground.rs
Created August 7, 2019 09:01
Code shared from the Rust Playground
struct Foo<T, C> where C: Fn() -> T {
make_t: C,
value: Option<T>,
}
impl<T, C> Foo<T, C> where C: Fn() -> T {
fn new(make_t: C) -> Foo<T, C> {
Foo {
make_t,
value: None
@rust-play
rust-play / playground.rs
Created January 24, 2020 16:01
Code shared from the Rust Playground
use std::process::{Command, Stdio};
fn main() {
let mut rev = Command::new("rev")
.stdin(Stdio::piped())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.spawn()
.expect("rev failed to spawn");