Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #![feature(async_await, await_macro)]
  2.  
  3. use {
  4. failure::Error,
  5. futures::future::BoxFuture,
  6. // futures::future::FutureObj,
  7. lazy_static::lazy_static,
  8. std::{collections::HashMap /*, convert::TryInto, sync::Arc */},
  9. };
  10.  
  11. /*
  12. #[derive(Clone, Debug, Eq, Hash, PartialEq)]
  13. pub struct CapabilityPath {
  14. pub dirname: String,
  15. pub basename: String,
  16. }
  17. */
  18.  
  19. pub struct Model {}
  20. pub enum ModelError {}
  21. pub struct AbsoluteMoniker {}
  22. pub struct Realm {}
  23. enum AmbientServiceArgument {
  24. Realm(Realm)
  25. }
  26.  
  27. // TODO: Should be appropriate signature for async fn.
  28. type AmbientServiceFactory = Box<dyn Fn(&Model, &AbsoluteMoniker) -> BoxFuture<AmbientServiceArgument, ModelError>>;
  29.  
  30. lazy_static! {
  31. static ref AMBIENT_SERVICES: HashMap<u8, AmbientServiceFactory> = {
  32. let mut map: HashMap<u8, AmbientServiceFactory> = HashMap::new();
  33. // TODO: Should be keyed on &'static CapabilityPath.
  34. map.insert(1, Box::new(realm_service_factory));
  35. map
  36. };
  37. }
  38.  
  39. // TODO: Should be async fn.
  40. async fn realm_service_factory<'a>(model: &'a Model , abs_moniker: &'a AbsoluteMoniker) -> Result<AmbientServiceArgument, ModelError> {
  41. // TODO: Do async stuff.
  42. Ok(AmbientServiceArgument::Realm(/* From async stuff: */ Realm {}))
  43. }
  44.  
  45. fn main() -> Result<(), Error> {
  46. let model = Model {};
  47. let abs_moniker = AbsoluteMoniker {};
  48. realm_service_factory(&model, &abs_moniker);
  49. Ok(())
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement