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 15:24
Code shared from the Rust Playground
use std::convert::Infallible;
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));
@rust-play
rust-play / playground.rs
Created January 24, 2020 15:11
Code shared from the Rust Playground
fn main() {
let val = Some(10);
//let val = None;
let z = maybe_add_four(val);
println!("{:?}", z)
}
fn maybe_add_four(y: Option<i32>) -> Option<i32> {
let ret = y.map(|x| x + 4);
assert_eq!(y, Some(10));
@rust-play
rust-play / playground.rs
Created January 24, 2020 15:08
Code shared from the Rust Playground
fn main() {
println!("Hello, world!");
}
@rust-play
rust-play / playground.rs
Created January 24, 2020 15:05
Code shared from the Rust Playground
struct A {
a: usize,
b: &'static str,
}
const LIST: [A; 2] = [
A { a: 1, b: "hello" }, A { a: 2, b: "w" },
];
@rust-play
rust-play / playground.rs
Created January 24, 2020 15:04
Code shared from the Rust Playground
struct A {
a: usize,
b: &'static str,
}
const LIST: [A; 1] = [
A { a: 1, b: "hello" }
];
@rust-play
rust-play / playground.rs
Created January 24, 2020 15:04
Code shared from the Rust Playground
#![feature(extern_prelude)]
extern crate serde; // 1.0.68
#[macro_use]
extern crate serde_derive; // 1.0.68
use std::collections::HashMap;
use serde::*;
use std::fmt::{Display, Formatter};
use serde::ser::{Serialize, Serializer, SerializeSeq, SerializeMap};
@rust-play
rust-play / playground.rs
Created January 24, 2020 14:56
Code shared from the Rust Playground
use std::os::raw::c_int;
use std::sync::mpsc::sync_channel;
use std::{cmp, slice};
use reqwest::{Client, Method, StatusCode};
use tokio::runtime::Handle;
pub struct Context<'a> {
client: &'a Client,
endpoint: &'a str,
@rust-play
rust-play / playground.rs
Created January 24, 2020 14:49
Code shared from the Rust Playground
use core::mem::MaybeUninit;
use core::ptr::NonNull;
use core::marker::PhantomData;
use core::cmp::Ordering;
const MAX_N: usize = 16;
struct InternalNode<T> {
leaf: LeafNode<T>,
children: [BoxedNode<T>; MAX_N],
@rust-play
rust-play / playground.rs
Created January 24, 2020 14:45
Code shared from the Rust Playground
fn main() {
println!("Hello, world!");
}
@rust-play
rust-play / playground.rs
Created January 24, 2020 14:39
Code shared from the Rust Playground
struct PrintInDrop(&'static str);
impl Drop for PrintInDrop {
fn drop(&mut self) {
println!("{}", self.0);
}
}
fn bar(_: &PrintInDrop) -> PrintInDrop {
PrintInDrop("ret")