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 March 11, 2018 20:48
Code shared from the Rust Playground
This is only a test
@rust-play
rust-play / playground.rs
Created March 12, 2018 09:51
Code shared from the Rust Playground
struct t{
a: u32,
b: u32
}
fn main() {
let mut test: t;
test.a = 16;
test.b = 12;
let res: u32 = test.a*test.b;
@rust-play
rust-play / playground.rs
Created March 12, 2018 10:21
Code shared from the Rust Playground
struct Test {
a: u32,
b: u32,
}
impl Test {
fn new(a: u32, b: u32) -> Test {
Test { a, b }
}
}
@rust-play
rust-play / playground.rs
Created March 12, 2018 11:59
Code shared from the Rust Playground
#![feature(specialization)]
pub struct MemberBase {
id: u32,
}
impl MemberBase {
pub fn id(&self) -> u32 { self.id }
}
pub trait UiMemberSpecialization {
fn size(&self) -> (u32, u32);
@rust-play
rust-play / playground.rs
Created March 12, 2018 23:36
Code shared from the Rust Playground
struct Testing{
one: Option<String>
}
impl Testing {
/// redis://[:<passwd>@]<hostname>[:port][/<db>]
pub fn do_something(&self) {
let one = &self.one.unwrap_or_default();
println!("one is: {:?}", one);
@rust-play
rust-play / playground.rs
Created March 12, 2018 23:39
Code shared from the Rust Playground
struct Testing{
one: Option<String>
}
impl Testing {
/// redis://[:<passwd>@]<hostname>[:port][/<db>]
pub fn do_something(&self) {
let one = self.one.as_ref().unwrap();
println!("one is: {:?}", one);
@rust-play
rust-play / playground.rs
Created March 13, 2018 15:33
Code shared from the Rust Playground
fn main() {
let mut v = vec![1, 2, 3, 4, 5];
let first = &v[0];
v.push(6);
}
@rust-play
rust-play / playground.rs
Created March 13, 2018 22:51
Code shared from the Rust Playground
//play.rust-lang.org
fn main() {}
@rust-play
rust-play / playground.rs
Created March 13, 2018 22:56
Code shared from the Rust Playground
extern crate chrono;
use chrono::prelude::*;
fn main() {
let datetime = Utc.ymd(2020, 1, 1).and_hms(0, 0, 0);
let timestamp = datetime.timestamp();
let naive_datetime = NaiveDateTime::from_timestamp(timestamp, 0);
let datetime_again: DateTime<Utc> = DateTime::from_utc(naive_datetime, Utc);
println!("{}", datetime_again);
@rust-play
rust-play / playground.rs
Created March 13, 2018 23:49
Code shared from the Rust Playground
fn greet_world() {
println!("Hello, world!"); // our old friend.
let southern_germany = "Grüß Gott!";
let japan = "ハロー・ワールド";
let regions = [southern_germany, japan];
for region in &regions {
println!("{}", region);