Skip to content

Instantly share code, notes, and snippets.

The Rust Playground rust-play

View GitHub Profile
@rust-play
rust-play / playground.rs
Created Apr 23, 2019
Code shared from the Rust Playground
View playground.rs
#![feature(stmt_expr_attributes)]
type Value = u32;
#[derive(Debug)]
pub struct Error;
impl Error {
pub fn new() -> Self {
Error
@rust-play
rust-play / playground.rs
Created Apr 23, 2019
Code shared from the Rust Playground
View playground.rs
#![allow(dead_code)]
#![allow(unused_variables)]
struct IndiciesSource;
struct NoIndicies;
impl From<NoIndicies> for IndiciesSource {
fn from(_: NoIndicies) -> Self {
IndiciesSource
}
@rust-play
rust-play / playground.rs
Created Apr 23, 2019
Code shared from the Rust Playground
View playground.rs
#![allow(dead_code)]
#![allow(unused_variables)]
struct IndiciesSource;
struct NoIndicies;
impl From<NoIndicies> for IndiciesSource {
fn from(_: NoIndicies) -> Self {
IndiciesSource
}
@rust-play
rust-play / playground.rs
Created Apr 23, 2019
Code shared from the Rust Playground
View playground.rs
fn main() {
println!("Hello, world!");
}
@rust-play
rust-play / playground.rs
Created Apr 23, 2019
Code shared from the Rust Playground
View playground.rs
fn bitcoin_block_reward(height: u64) -> u64 {
let coin = 100000000.0;
let reward_base = 50.0 * coin;
let reward_halving = 210000.0;
let result = reward_base / (2.0 as f64).powf((height as f64 / reward_halving).floor());
result.floor() as u64
}
fn main() {
println!("{}", bitcoin_block_reward(1489218));
@rust-play
rust-play / playground.rs
Created Apr 23, 2019
Code shared from the Rust Playground
View playground.rs
// 事件绑定单例
struct Listener<T> {
name: String,
listener: fn(&T)
}
// 事件循环表
struct EventEmitter<T> {
listeners: Vec<Listener<T>>
@rust-play
rust-play / playground.rs
Created Apr 23, 2019
Code shared from the Rust Playground
View playground.rs
fn main() {
let A = 23;
let B = 16;
let C = 43;
match 23 {
A => println!("Input is equal to A"),
B => println!("Input is equal to B"),
C => println!("Input is equal to C"),
_ => println!("Input does not equal any value"),
@rust-play
rust-play / playground.rs
Created Apr 23, 2019
Code shared from the Rust Playground
View playground.rs
fn main() {
let A: i32 = 23;
let B: i32 = 16;
let C: i32 = 43;
match 23 {
A => println!("Input is equal to A"),
B => println!("Input is equal to B"),
C => println!("Input is equal to C"),
_ => println!("Input does not equal any value"),
@rust-play
rust-play / playground.rs
Created Apr 23, 2019
Code shared from the Rust Playground
View playground.rs
const A: i32 = 23;
const B: i32 = 16;
const C: i32 = 43;
fn main() {
match 23 {
A => println!("Input is equal to A"),
B => println!("Input is equal to B"),
C => println!("Input is equal to C"),
_ => println!("Input does not equal any value"),
@rust-play
rust-play / playground.rs
Created Apr 23, 2019
Code shared from the Rust Playground
View playground.rs
fn main() {
}
struct Bar<'a> {
x: fn(&'a str),
}
fn foo(x: Bar<'static>) {
You can’t perform that action at this time.