História do Rust
"Rust is Open"
type
é para áliases.
type Farenheit = i32;
type Celsius = i32;
fn is_it_hot(t: Farenheit) -> bool;
let temp: Celsius = 32;
is_it_hot(temp);
struct Celsius(i32);
struct Farenheit(i32);
impl Into<Celsius> for Farenheit {
fn into(c: Celsius) -> Self {
Self(((c.0 + 9) / 5) as i32 + 32);
}
}
is_it_hot(temp.into());
OS | How? |
---|---|
iOS | C integration |
Android | JNI |
Web | WASM |
mod common;
#[cfg(target_os = "android")]
mod android;
#[cfg(target_os = "ios")]
mod ios;
#[cfg(target_arch = "wasm32")]
mod wasm;
Service | Time |
---|---|
AWS Lambda | ~1.5s |
Google Cloud Functions | >2s |
Fastly Terrarium (WASM) | ~500ms |
$2.50 VPS + NGINX | ~30ms |
Autor do livro Programming WebAssembly with Rust
#[proc_macro]
pub fn println(input: TokenStream) -> TokenStream
{
// ???
}
"Don't start out very generic, refactor towards it!"
fn debug_iter<I>(iter: I)
where
I: Iterator,
I::Item: Debug
{
// ...
}
trait State { }
trait TerminalState { }
trait TransitionTo<S>
where S: State,
Self: State
{
fn transition(self) -> S;
}
trait Terminate
where Self: TerminalState
{
fn terminate(self);
}
struct Start;
impl State for Start {}
struct Loop;
impl State for Loop {}
struct Stop;
impl State for Stop {}
impl TerminalState for Stop {}
impl TransitionTo<Loop> for Start {
fn transition(self) -> Loop { ... }
}
impl TransitionTo<Loop> for Loop {
fn transition(self) -> Loop { ... }
}
impl TransitionTo<End> for Loop {
fn transition(self) -> End { ... }
}
impl Terminate for End {
fn terminate(self) { ... }
}
fn main() {
let initial = Start;
let next: Loop = initial.transition();
let next: Loop = next.transition();
let next: End = next.transition();
next.terminate();
}
Estado geral do async
em Rust.