-
-
Save flukejones/1b5b860d046f569a95a03ead45bc4f54 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