Skip to content

Commit f1717d7

Browse files
griffdwrensha
authored andcommitted
Add trivial implementations of FromClientHook
Sometimes it is nice to be able to return a `Box<dyn ClientHook>` or and untyped `Client` from the functions that use FromClientHook like `bootstrap`. This commit simply adds trivial implementations of `FromClientHook` for `Box<dyn ClientHook>` and `Client`.
1 parent 01b0056 commit f1717d7

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

capnp/src/capability.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,21 @@ pub trait FromClientHook {
335335
}
336336
}
337337

338+
#[cfg(feature = "alloc")]
339+
impl FromClientHook for alloc::boxed::Box<dyn ClientHook> {
340+
fn new(hook: alloc::boxed::Box<dyn ClientHook>) -> Self {
341+
hook
342+
}
343+
344+
fn into_client_hook(self) -> alloc::boxed::Box<dyn ClientHook> {
345+
self
346+
}
347+
348+
fn as_client_hook(&self) -> &dyn ClientHook {
349+
self.as_ref()
350+
}
351+
}
352+
338353
/// An untyped client.
339354
#[cfg(feature = "alloc")]
340355
pub struct Client {
@@ -383,6 +398,21 @@ impl Client {
383398
}
384399
}
385400

401+
#[cfg(feature = "alloc")]
402+
impl FromClientHook for Client {
403+
fn new(hook: alloc::boxed::Box<dyn ClientHook>) -> Self {
404+
Client::new(hook)
405+
}
406+
407+
fn into_client_hook(self) -> alloc::boxed::Box<dyn ClientHook> {
408+
self.hook
409+
}
410+
411+
fn as_client_hook(&self) -> &dyn ClientHook {
412+
self.hook.as_ref()
413+
}
414+
}
415+
386416
/// The return value of Server::dispatch_call().
387417
#[cfg(feature = "alloc")]
388418
pub struct DispatchCallResult {

0 commit comments

Comments
 (0)