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:26
Code shared from the Rust Playground
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 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 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 January 24, 2020 16:15
Code shared from the Rust Playground
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 January 24, 2020 16:09
Code shared from the Rust Playground
fn main() {
println!("Hello, world!");
}
@rust-play
rust-play / playground.rs
Created January 24, 2020 16:03
Code shared from the Rust Playground
fn main() {
println!("Hello, world!");
}
@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 January 24, 2020 16:02
Code shared from the Rust Playground
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 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");