Skip to content

Instantly share code, notes, and snippets.

Avatar

The Rust Playground rust-play

View GitHub Profile
@rust-play
rust-play / playground.rs
Created Jan 24, 2020
Code shared from the Rust Playground
View playground.rs
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 Jan 24, 2020
Code shared from the Rust Playground
View playground.rs
use std::fmt::Display;
fn do_things<T>(a: T, b: T) where
T: IntoIterator,
T::Item: Display {
for (e,f) in a.into_iter().zip(b.into_iter()) {
println!("{} {}", e, f);
}
}
@rust-play
rust-play / playground.rs
Created Jan 24, 2020
Code shared from the Rust Playground
View playground.rs
#![allow(unused)]
use std::collections::HashMap;
use std::io;
struct PhoneEntry {
name: String,
phone: String,
}
impl PhoneEntry {
@rust-play
rust-play / playground.rs
Created Jan 24, 2020
Code shared from the Rust Playground
View playground.rs
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 Jan 24, 2020
Code shared from the Rust Playground
View playground.rs
use rusqlite::{Connection, Result};
fn main() -> Result<()> {
let conn = Connection::open("data.sqlite")?;
let name = "";
let stripe_id = None;
conn.execute(
"INSERT INTO merchants (name, stripe_id) VALUES (?, ?)",
@rust-play
rust-play / playground.rs
Created Jan 24, 2020
Code shared from the Rust Playground
View playground.rs
fn main() {
println!("Hello, world!");
}
@rust-play
rust-play / playground.rs
Created Jan 24, 2020
Code shared from the Rust Playground
View playground.rs
fn main() {
println!("Hello, world!");
}
@rust-play
rust-play / playground.rs
Created Jan 24, 2020
Code shared from the Rust Playground
View playground.rs
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 Jan 24, 2020
Code shared from the Rust Playground
View playground.rs
use lazy_static; // 1.4.0
use std::collections::HashMap;
#[derive(Copy, Clone, Debug)]
pub struct Server {}
lazy_static::lazy_static! {
static ref SERVER1: Server = Server {};
static ref SERVER2: Server = Server {};
@rust-play
rust-play / playground.rs
Created Jan 24, 2020
Code shared from the Rust Playground
View playground.rs
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");
You can’t perform that action at this time.