Skip to content

Commit c35ef6c

Browse files
griffdwrensha
authored andcommitted
Implement Clone for capnp::capability::Client
It is trivial to implement and codegen already does the same code snippet to clone the client. So I implemented Clone and changed codegen to use that instead.
1 parent 5206d4a commit c35ef6c

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

capnp/src/capability.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,15 @@ impl FromClientHook for Client {
413413
}
414414
}
415415

416+
#[cfg(feature = "alloc")]
417+
impl Clone for Client {
418+
fn clone(&self) -> Self {
419+
Self {
420+
hook: self.hook.add_ref(),
421+
}
422+
}
423+
}
424+
416425
/// The return value of Server::dispatch_call().
417426
#[cfg(feature = "alloc")]
418427
pub struct DispatchCallResult {

capnpc/src/codegen.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2810,13 +2810,18 @@ fn generate_node(
28102810
line("}"),
28112811
]));
28122812

2813-
mod_interior.push(
2814-
Branch(vec![
2815-
Line(format!("impl {bracketed_params} Clone for Client{bracketed_params} {{")),
2816-
indent(line("fn clone(&self) -> Self {")),
2817-
indent(indent(Line(fmt!(ctx,"Self {{ client: {capnp}::capability::Client::new(self.client.hook.add_ref()), {} }}", params.phantom_data_value)))),
2818-
indent(line("}")),
2819-
line("}")]));
2813+
mod_interior.push(Branch(vec![
2814+
Line(format!(
2815+
"impl {bracketed_params} Clone for Client{bracketed_params} {{"
2816+
)),
2817+
indent(line("fn clone(&self) -> Self {")),
2818+
indent(indent(Line(format!(
2819+
"Self {{ client: self.client.clone(), {} }}",
2820+
params.phantom_data_value
2821+
)))),
2822+
indent(line("}")),
2823+
line("}"),
2824+
]));
28202825

28212826
mod_interior.push(Branch(vec![
28222827
Line(format!(

0 commit comments

Comments
 (0)