This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
Box::new("qwe".into()) as Box<std::error::Error>; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let _ = Box::<std::error::Error>::from("oh no"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn foo() -> Box<std::error::Error> { | |
"oh no".into() | |
} | |
fn main() { | |
let _ = foo(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(ptr_internals)] | |
use std::ptr::Unique; | |
fn main() { | |
let mut arr = [1u8, 2, 3]; | |
let slice = &mut arr[..]; | |
let unique : Unique<[u8]> = Unique::new(slice as *mut [u8]).unwrap(); | |
// Cast unique to an usize | |
let ptr = unsafe { (&(*unique.as_ptr())[0] as *const u8 as usize) }; | |
println!("{:?} {:x}", unique, ptr); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate futures; | |
extern crate tokio_core; | |
use futures::executor::spawn; | |
use futures::future::{FutureResult, ok, Future}; | |
use tokio_core::reactor::Core; | |
use std::fmt::Error; | |
fn main() { | |
let s = ok::<String, Error>(String::new()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashMap; | |
use std::cell::RefCell; | |
fn main() { | |
let mut cache = HashMap::new(); | |
cache.insert(0, 0); | |
let cache = RefCell::new(cache); | |
let x = if let Some(cached) = cache.borrow().get(&0).cloned() { | |
cached | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[feature(nll)] | |
use std::collections::HashMap; | |
use std::cell::RefCell; | |
fn main() { | |
let mut cache = HashMap::new(); | |
cache.insert(0, 0); | |
let cache = RefCell::new(cache); | |
let x = if let Some(cached) = cache.borrow().get(&1).cloned() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashMap; | |
use std::cell::RefCell; | |
fn main() { | |
let mut cache = HashMap::new(); | |
cache.insert(0, 0); | |
let cache = RefCell::new(cache); | |
let x = if let Some(cached) = {cache.borrow().get(&1).cloned()} { | |
cached | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashMap; | |
use std::cell::RefCell; | |
fn main() { | |
let mut cache = HashMap::new(); | |
cache.insert(0, 0); | |
let cache = RefCell::new(cache); | |
let x = if let Some(cached) = {let x = cache.borrow().get(&1).cloned(); x} { | |
cached | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let a = (1, 2, 3); | |
let mut b = 0; | |
println!("b: {} {:p}", b, &b); | |
let (x, b, y) = a; | |
println!("b: {} {:p}", b, &b); | |
} |