Created
February 23, 2016 08:02
-
-
Save julienw/f9b04309172e91ad786d to your computer and use it in GitHub Desktop.
Interface factory
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 value_classes::value_id::{ ValueType, ValueID }; | |
trait Value<T> { | |
fn get() -> Result<T, ()>; | |
fn set(value: T) -> Result<(), ()>; | |
} | |
struct ValueBool { | |
value_id: ValueID | |
} | |
impl Value<bool> for ValueBool { | |
fn get() -> Result<bool, ()> { | |
unimplemented!() | |
} | |
fn set(value: bool) -> Result<(), ()> { | |
unimplemented!() | |
} | |
} | |
struct ValueFloat { | |
value_id: ValueID | |
} | |
impl Value<f32> for ValueFloat { | |
fn get() -> Result<f32, ()> { | |
unimplemented!() | |
} | |
fn set(value: f32) -> Result<(), ()> { | |
unimplemented!() | |
} | |
} | |
pub fn instance_for<T>(value_id: ValueID) -> Value<T> { | |
match value_id.get_type() { | |
ValueType::ValueType_Bool => { | |
ValueBool { | |
value_id: value_id | |
} | |
}, | |
ValueType::ValueType_Decimal => { | |
ValueFloat { | |
value_id: value_id | |
} | |
}, | |
_ => unimplemented!() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment