Browse Source

Fix new ServiceStack with_service and make it more explicit.

Kestrel 2 years ago
parent
commit
734781022e
2 changed files with 6 additions and 7 deletions
  1. 2 2
      fleck/src/fleck_core.rs
  2. 4 5
      fleck/src/service.rs

+ 2 - 2
fleck/src/fleck_core.rs

@@ -60,10 +60,10 @@ impl crate::service::DefaultService for CoreInitService {
                 .build(io);
         });
 
-        /*api.add_service::<msg::MessageService>();
+        api.add_service::<msg::MessageService>();
         api.add_service::<node::NodeService>();
         api.add_service::<discovery::LocalDiscovery>();
         api.add_service::<peer::PeerService>();
-        api.add_service::<crypto::SignPacket>();*/
+        api.add_service::<crypto::SignPacket>();
     }
 }

+ 4 - 5
fleck/src/service.rs

@@ -24,7 +24,7 @@ pub trait DefaultService: Default {
 }
 
 impl<T: 'static + DefaultService> Service for T {
-    fn new(api: Rc<crate::API>) -> Self {
+    fn new(_api: Rc<crate::API>) -> Self {
         Self::default()
     }
     fn setup(self: &Rc<Self>) {}
@@ -34,7 +34,6 @@ impl<T: 'static + DefaultService> Service for T {
     }
 }
 
-
 #[derive(Default)]
 pub struct ServiceStack {
     service_map: RefCell<HashMap<TypeId, Rc<dyn std::any::Any>>>,
@@ -71,10 +70,10 @@ impl ServiceStack {
         let svc = {
             let svcs = self.service_map.borrow();
             svcs.get(&id)
-                .expect("asked for service that doesn't exist!")
-                .downcast_ref::<Rc<S>>()
-                .unwrap()
+                .unwrap_or_else(|| panic!("asked for service {} that doesn't exist!", std::any::type_name::<S>()))
                 .clone()
+                .downcast::<S>()
+                .expect("internal inconsistency: wanted Rc<Service> but that wasn't what was in the map")
         };
 
         f(svc.as_ref())