@@ -379,7 +379,7 @@ where
379379 C : capnp:: capability:: FromServer < S > ,
380380{
381381 capnp:: capability:: FromClientHook :: new ( Box :: new ( local:: Client :: new (
382- <C as capnp:: capability:: FromServer < S > >:: from_server ( s ) ,
382+ <C as capnp:: capability:: FromServer < S > >:: from_server ( Rc :: new ( s ) ) ,
383383 ) ) )
384384}
385385
@@ -393,7 +393,8 @@ pub struct CapabilityServerSet<S, C>
393393where
394394 C : capnp:: capability:: FromServer < S > ,
395395{
396- caps : std:: collections:: HashMap < usize , Weak < C :: Dispatch > > ,
396+ caps : std:: collections:: HashMap < usize , Weak < S > > ,
397+ marker : std:: marker:: PhantomData < C > ,
397398}
398399
399400impl < S , C > Default for CapabilityServerSet < S , C >
@@ -403,6 +404,7 @@ where
403404 fn default ( ) -> Self {
404405 Self {
405406 caps : std:: default:: Default :: default ( ) ,
407+ marker : std:: marker:: PhantomData ,
406408 }
407409 }
408410}
@@ -417,16 +419,18 @@ where
417419
418420 /// Adds a new capability to the set and returns a client backed by it.
419421 pub fn new_client ( & mut self , s : S ) -> C {
420- let dispatch = <C as capnp:: capability:: FromServer < S > >:: from_server ( s) ;
421- let wrapped = Rc :: new ( dispatch) ;
422- let ptr = Rc :: as_ptr ( & wrapped) as usize ;
423- self . caps . insert ( ptr, Rc :: downgrade ( & wrapped) ) ;
424- capnp:: capability:: FromClientHook :: new ( Box :: new ( local:: Client :: from_rc ( wrapped) ) )
422+ let rc = Rc :: new ( s) ;
423+ let weak = Rc :: downgrade ( & rc) ;
424+ let ptr = Rc :: as_ptr ( & rc) as usize ;
425+ self . caps . insert ( ptr, weak) ;
426+
427+ let dispatch = <C as capnp:: capability:: FromServer < S > >:: from_server ( rc) ;
428+ capnp:: capability:: FromClientHook :: new ( Box :: new ( local:: Client :: new ( dispatch) ) )
425429 }
426430
427431 /// Looks up a capability and returns its underlying server object, if found.
428432 /// Fully resolves the capability before looking it up.
429- pub async fn get_local_server ( & self , client : & C ) -> Option < Rc < C :: Dispatch > >
433+ pub async fn get_local_server ( & self , client : & C ) -> Option < Rc < S > >
430434 where
431435 C : capnp:: capability:: FromClientHook ,
432436 {
@@ -444,7 +448,7 @@ where
444448 /// to call `get_resolved_cap()` before calling this. The advantage of this method
445449 /// over `get_local_server()` is that this one is synchronous and borrows `self`
446450 /// over a shorter span (which can be very important if `self` is inside a `RefCell`).
447- pub fn get_local_server_of_resolved ( & self , client : & C ) -> Option < Rc < C :: Dispatch > >
451+ pub fn get_local_server_of_resolved ( & self , client : & C ) -> Option < Rc < S > >
448452 where
449453 C : capnp:: capability:: FromClientHook ,
450454 {
0 commit comments