Created
December 4, 2016 20:56
-
-
Save anonymous/af57f1ea1be5d7757e6f6adf83d89e9e to your computer and use it in GitHub Desktop.
Shared via Rust Playground
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(core_intrinsics)] | |
pub trait Deserialize: Sized { | |
fn deserialize(String) -> Self; | |
} | |
struct Position(i32, i32); | |
struct Velocity(i32, i32); | |
impl Deserialize for Position { | |
fn deserialize(s: String) -> Self { | |
Position(5, 5) | |
} | |
} | |
pub struct EntityBuilder; | |
impl EntityBuilder { | |
pub fn with<T>(self, v: T) { | |
println!("test"); | |
} | |
} | |
use std::collections::HashMap; | |
use std::intrinsics; | |
pub struct Deserializer { | |
pub map: HashMap<String, Box<Fn(EntityBuilder, String)>>, | |
} | |
fn main() { | |
let x = |e: EntityBuilder, s: String| { | |
e.with(Position::deserialize(s)); | |
}; | |
let mut deserializer = Deserializer { map: HashMap::new() }; | |
deserializer.map.insert("Test".to_string(), Box::new(x)); | |
let entity_builder = EntityBuilder; | |
let create = deserializer.map.get("Test").unwrap(); | |
create(entity_builder, "Test".to_string()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment