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::any::Any; | |
trait Schema { | |
fn eq(&self, other: &Schema) -> bool; | |
fn as_any(&self) -> &Any; | |
} | |
impl PartialEq<Schema> for Schema { | |
fn eq(&self, other: &Schema) -> bool { | |
Schema::eq(self, other) |
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::any::Any; | |
trait Schema { | |
fn eq(&self, other: &Schema) -> bool; | |
fn as_any(&self) -> &Any; | |
} | |
impl<'a, 'b> PartialEq<Schema+'b> for Schema+'a { | |
fn eq(&self, other: &(Schema+'b)) -> bool { | |
Schema::eq(self, other) |
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
fn old() -> Vec<u8> { | |
let mut hash = vec![0u8; 8]; // vec of u8 representing the bits and bytes of the hash computed for the image. | |
let raw: Vec<_> = (0..8).flat_map(|_| (0 .. 9).rev()).collect(); // vec of u8 representing gray pixels of an 9x8 image. | |
for x in 0..8 { | |
for y in 0..8 { | |
if raw[x*9+y] > raw[x*9+y+1] { | |
hash[x] |= 0x1 << y | |
} |
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
fn main() { | |
#![allow(unused)] | |
// A borrow can be moved out of the scope where it is created as long as the original value is | |
// known to live long enough. Here it is assigned to `out`. While `out` is in scope, `x` is | |
// inaccessible. When `out` goes out of scope, `x` becomes accessible again: | |
{ | |
fn bar<'a>(x: &'a mut u32) -> &'a mut u32 { x } | |
let mut x = 1; | |
{ |
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
fn old() -> Vec<u8> { | |
let mut hash = vec![0u8; 8]; // vec of u8 representing the bits and bytes of the hash computed for the image. | |
let raw: Vec<_> = (0..8).flat_map(|_| (0 .. 9).rev()).collect(); // vec of u8 representing gray pixels of an 9x8 image. | |
for x in 0..8 { | |
for y in 0..8 { | |
if raw[x*9+y] > raw[x*9+y+1] { | |
hash[x] |= 0x1 << y | |
} |
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::marker::PhantomData; | |
struct Nothing; | |
#[allow(dead_code)] | |
struct Neg; | |
struct Zero<T: Num>(PhantomData<T>); | |
struct One<T: Num>(PhantomData<T>); |
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 T<'a> { | |
type A; | |
type Iter: Iterator<Item=Self::A>; | |
fn new() -> Self; | |
fn iter(&self) -> Self::Iter; | |
fn test() where Self: Sized { | |
let a = <Self as T<'a>>::new(); | |
let _ = a.iter().map(|a| 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
use std::ops::Deref; | |
fn main() { | |
let s: &'static str = "hello"; | |
let x: &'static str = &*s; | |
let y: &'static str = s.deref(); // <-- lifetime error | |
} |
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
type RenderData = u32; | |
struct Manager { | |
render_data: Vec<Option<RenderData>> | |
} | |
pub fn main() { | |
let mut entity_manager = Manager { | |
render_data: vec![None, Some(5), None, Some(2), None] |
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
type RenderData = u32; | |
struct Manager { | |
#[allow(dead_code)] | |
num_entities: usize, | |
render_data: Vec<Option<RenderData>> | |
} | |
pub fn main() { |
NewerOlder