Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(async_await, await_macro)]
- use {
- failure::Error,
- futures::future::BoxFuture,
- // futures::future::FutureObj,
- lazy_static::lazy_static,
- std::{collections::HashMap /*, convert::TryInto, sync::Arc */},
- };
- /*
- #[derive(Clone, Debug, Eq, Hash, PartialEq)]
- pub struct CapabilityPath {
- pub dirname: String,
- pub basename: String,
- }
- */
- pub struct Model {}
- pub enum ModelError {}
- pub struct AbsoluteMoniker {}
- pub struct Realm {}
- enum AmbientServiceArgument {
- Realm(Realm)
- }
- // TODO: Should be appropriate signature for async fn.
- type AmbientServiceFactory = Box<dyn Fn(&Model, &AbsoluteMoniker) -> BoxFuture<AmbientServiceArgument, ModelError>>;
- lazy_static! {
- static ref AMBIENT_SERVICES: HashMap<u8, AmbientServiceFactory> = {
- let mut map: HashMap<u8, AmbientServiceFactory> = HashMap::new();
- // TODO: Should be keyed on &'static CapabilityPath.
- map.insert(1, Box::new(realm_service_factory));
- map
- };
- }
- // TODO: Should be async fn.
- async fn realm_service_factory<'a>(model: &'a Model , abs_moniker: &'a AbsoluteMoniker) -> Result<AmbientServiceArgument, ModelError> {
- // TODO: Do async stuff.
- Ok(AmbientServiceArgument::Realm(/* From async stuff: */ Realm {}))
- }
- fn main() -> Result<(), Error> {
- let model = Model {};
- let abs_moniker = AbsoluteMoniker {};
- realm_service_factory(&model, &abs_moniker);
- Ok(())
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement