Skip to content

Commit f7c86be

Browse files
committed
WeakCapabilityServerSet -> CapabilityServerSet
1 parent f54ea4c commit f7c86be

File tree

2 files changed

+10
-81
lines changed

2 files changed

+10
-81
lines changed

capnp-rpc/src/lib.rs

+5-76
Original file line numberDiff line numberDiff line change
@@ -316,92 +316,21 @@ where
316316
)))
317317
}
318318

319-
/// Allows a server to recognize its own capabilities when passed back to it, and obtain the
320-
/// underlying Server objects associated with them.
321-
/// Note that `CapabilityServerSet` holds references to every `Server` passed to it,
322-
/// and the only way to drop them is to drop the entire `CapabilityServerSet`.
323-
/// The `WeakCapabilityServerSet` struct below is a (better) alternative that only holds
324-
/// weak references. Its semantics match the capnproto-c++ version of `CapabilityServerSet`.
325-
///
326-
/// TODO(v0.17): remove this `CapabilityServerSet` implementation and rename
327-
/// `WeakCapabilityServerSet` to `CapabilityServerSet`.
328-
pub struct CapabilityServerSet<S, C>
329-
where
330-
C: capnp::capability::FromServer<S>,
331-
{
332-
caps: std::collections::HashMap<usize, Rc<RefCell<C::Dispatch>>>,
333-
}
334-
335-
impl<S, C> Default for CapabilityServerSet<S, C>
336-
where
337-
C: capnp::capability::FromServer<S>,
338-
{
339-
fn default() -> Self {
340-
Self {
341-
caps: std::default::Default::default(),
342-
}
343-
}
344-
}
345-
346-
impl<S, C> CapabilityServerSet<S, C>
347-
where
348-
C: capnp::capability::FromServer<S>,
349-
{
350-
pub fn new() -> Self {
351-
Self::default()
352-
}
353-
354-
/// Adds a new capability to the set and returns a client backed by it.
355-
pub fn new_client(&mut self, s: S) -> C {
356-
let dispatch = <C as capnp::capability::FromServer<S>>::from_server(s);
357-
let wrapped = Rc::new(RefCell::new(dispatch));
358-
let ptr = wrapped.as_ptr() as usize;
359-
self.caps.insert(ptr, wrapped.clone());
360-
capnp::capability::FromClientHook::new(Box::new(local::Client::from_rc(wrapped)))
361-
}
362-
363-
/// Looks up a capability and returns its underlying server object, if found.
364-
/// Fully resolves the capability before looking it up.
365-
pub async fn get_local_server(&self, client: &C) -> Option<&Rc<RefCell<C::Dispatch>>>
366-
where
367-
C: capnp::capability::FromClientHook,
368-
{
369-
let resolved: C = capnp::capability::get_resolved_cap(
370-
capnp::capability::FromClientHook::new(client.as_client_hook().add_ref()),
371-
)
372-
.await;
373-
let hook = resolved.into_client_hook();
374-
let ptr = hook.get_ptr();
375-
self.caps.get(&ptr)
376-
}
377-
378-
/// Looks up a capability and returns its underlying server object, if found.
379-
/// Does *not* attempt to resolve the capability first, so you will usually want
380-
/// to call `get_resolved_cap()` before calling this. The advantage of this method
381-
/// over `get_local_server()` is that this one is synchronous and borrows `self`
382-
/// over a shorter span (which can be very important if `self` is inside a `RefCell`).
383-
pub fn get_local_server_of_resolved(&self, client: &C) -> Option<&Rc<RefCell<C::Dispatch>>>
384-
where
385-
C: capnp::capability::FromClientHook,
386-
{
387-
let hook = client.as_client_hook();
388-
let ptr = hook.get_ptr();
389-
self.caps.get(&ptr)
390-
}
391-
}
319+
#[deprecated(since = "0.17.0", note = "use CapabilityServerSet instead")]
320+
pub type WeakCapabilityServerSet<S, C> = CapabilityServerSet<S, C>;
392321

393322
/// Allows a server to recognize its own capabilities when passed back to it, and obtain the
394323
/// underlying Server objects associated with them. Holds only weak references to Server objects
395324
/// allowing Server objects to be dropped when dropped by the remote client. Call the `gc` method
396325
/// to reclaim memory used for Server objects that have been dropped.
397-
pub struct WeakCapabilityServerSet<S, C>
326+
pub struct CapabilityServerSet<S, C>
398327
where
399328
C: capnp::capability::FromServer<S>,
400329
{
401330
caps: std::collections::HashMap<usize, Weak<RefCell<C::Dispatch>>>,
402331
}
403332

404-
impl<S, C> Default for WeakCapabilityServerSet<S, C>
333+
impl<S, C> Default for CapabilityServerSet<S, C>
405334
where
406335
C: capnp::capability::FromServer<S>,
407336
{
@@ -412,7 +341,7 @@ where
412341
}
413342
}
414343

415-
impl<S, C> WeakCapabilityServerSet<S, C>
344+
impl<S, C> CapabilityServerSet<S, C>
416345
where
417346
C: capnp::capability::FromServer<S>,
418347
{

capnp-rpc/test/test.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -916,11 +916,11 @@ fn capability_list() {
916916
fn capability_server_set() {
917917
use crate::impls;
918918
use crate::test_capnp::test_interface;
919-
use capnp_rpc::WeakCapabilityServerSet;
920-
let mut set1: WeakCapabilityServerSet<impls::TestInterface, test_interface::Client> =
921-
WeakCapabilityServerSet::new();
922-
let mut set2: WeakCapabilityServerSet<impls::TestInterface, test_interface::Client> =
923-
WeakCapabilityServerSet::new();
919+
use capnp_rpc::CapabilityServerSet;
920+
let mut set1: CapabilityServerSet<impls::TestInterface, test_interface::Client> =
921+
CapabilityServerSet::new();
922+
let mut set2: CapabilityServerSet<impls::TestInterface, test_interface::Client> =
923+
CapabilityServerSet::new();
924924

925925
let client_standalone = capnp_rpc::new_client(impls::TestInterface::new());
926926

0 commit comments

Comments
 (0)