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 13:38
Code shared from the Rust Playground
fn main() {
println!("Hello, world!");
}
@rust-play
rust-play / playground.rs
Created January 24, 2020 13:33
Code shared from the Rust Playground
use serde::Serialize;
#[derive(Serialize)]
enum Token {
S(String),
_I(i32),
}
#[derive(Serialize)]
struct Foo {
@rust-play
rust-play / playground.rs
Created January 24, 2020 13:33
Code shared from the Rust Playground
fn identity<T: ?Sized, F>(f: F) -> F
where
F: for<'a> Fn(&'a T) -> &'a T,
{
f
}
fn foo(_f: impl for<'a> Fn(&'a str) -> &'a str) {}
fn main() {
@rust-play
rust-play / playground.rs
Created January 24, 2020 13:25
Code shared from the Rust Playground
fn main() {
let closure = |s: &str| s;
}
@rust-play
rust-play / playground.rs
Created January 24, 2020 13:25
Code shared from the Rust Playground
fn main() {
let closure = |s: &str| {
s
};
}
@rust-play
rust-play / playground.rs
Created January 24, 2020 13:23
Code shared from the Rust Playground
fn main() {
let bound = |s: Option<&'_ str>| -> &'_ str {
s.unwrap()
};
}
@rust-play
rust-play / playground.rs
Created January 24, 2020 13:20
Code shared from the Rust Playground
use std::net;
fn main() {
let ip: Result<net::IpAddr, _> = "::1".parse();
println!("{:?}", ip);
let addr = net::SocketAddr::new(ip.unwrap(), 9200);
println!("{:?}", addr);
println!("{}", addr);
println!("{}", addr.ip());
@rust-play
rust-play / playground.rs
Created January 24, 2020 13:20
Code shared from the Rust Playground
fn main() {
println!("Hello, world!");
}
@rust-play
rust-play / playground.rs
Created January 24, 2020 13:14
Code shared from the Rust Playground
struct Greeter {
name: String,
}
impl Greeter {
fn greet(&self) {
println!("Hey, {}!", self.name);
}
}
fn main() {
@rust-play
rust-play / playground.rs
Created January 24, 2020 13:14
Code shared from the Rust Playground
struct Greeter {
name: String,
}
impl Greeter {
fn greet(&self) {
println!("Hey, {}!", self.name);
}
}
fn main() {