This file contains hidden or 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
| #![allow(mutable_transmutes)] | |
| use std::mem::transmute; | |
| fn main() { | |
| let a: Vec<u64> = Vec::new(); | |
| let r = &a; | |
| let r: &mut Vec<u64> = unsafe { transmute(r) }; | |
| r.push(1488); | |
| println!("{:?}", a); | |
This file contains hidden or 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
| trait Def<T> { | |
| fn def(&self, foo: T) -> bool; | |
| } | |
| impl<T, Func> Def<T> for Func | |
| where Func: Fn(T) -> bool | |
| { | |
| fn def(&self, foo: T) -> bool { | |
| (self)(foo) |
This file contains hidden or 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::hash_map::Entry; | |
| use std::collections::HashMap; | |
| trait EntryExt<'a, K, V>: 'a { | |
| fn or_insert_with2<F: FnOnce(&K) -> V>(self, f: F) -> &'a mut V; | |
| } | |
| impl<'a, K, V> EntryExt<'a, K, V> for Entry<'a, K, V> { | |
| fn or_insert_with2<F: FnOnce(&K) -> V>(self, f: F) -> &'a mut V { | |
| match self { |
This file contains hidden or 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(unboxed_closures, fn_traits)] | |
| fn main() { | |
| let add = |a: i32, b: i32| a + b; | |
| let sqr = |a: i32| a.pow(2); | |
| let add_two = |a: i32| a + 2; | |
| assert_eq!(chain(add, sqr)(2, 3), 25); | |
| assert_eq!( | |
| chain( |
This file contains hidden or 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
| /* | |
| Referenced from: | |
| http://web.archive.org/web/20120110153227/http://weegen.home.xs4all.nl/eelis/analogliterals.xhtml | |
| */ | |
| #ifndef ANALOGLITERALS_HPP | |
| #define ANALOGLITERALS_HPP | |
| namespace analog_literals { |
OlderNewer