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 18, 2019
Code shared from the Rust Playground
View playground.rs
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug)]
struct Point {
x: i32,
y: i32,
}
fn main() {
let point = Point { x: 1, y: 2 };
@rust-play
rust-play / playground.rs
Created Aug 7, 2019
Code shared from the Rust Playground
View playground.rs
use libc::{mkfifo, c_char};
use serde::{Serialize, Deserialize};
use std::fs::{File, OpenOptions};
use std::path::{Path, PathBuf};
use std::env::args;
use std::os::unix::ffi::OsStrExt;
use std::io::{Result, Error, Read, Write};
fn main() -> Result<()> {
let mut args = args();
@rust-play
rust-play / playground.rs
Created Jan 24, 2020
Code shared from the Rust Playground
View playground.rs
use std::ops::Index;
struct Foo<T> {
val: T,
}
impl<T> Index<usize> for (&Foo<T>, &str) {
type Output = T;
fn index(&self, _: usize) -> &T {
@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");
@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
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 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
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);
You can’t perform that action at this time.