Skip to content

Commit e0bdf73

Browse files
committed
Manually implement Copy/Clone for generated readers.
The current `[derive(Copy,Clone)]` only triggers when all of the type parameters are `Copy` and `Clone`.
1 parent 06bdf01 commit e0bdf73

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

capnpc/src/codegen.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1727,7 +1727,6 @@ fn generate_node(
17271727
])
17281728
}),
17291729
BlankLine,
1730-
Line("#[derive(Clone, Copy)]".to_string()),
17311730
(if !is_generic {
17321731
Line("pub struct Reader<'a> { reader: ::capnp::private::layout::StructReader<'a> }".to_string())
17331732
} else {
@@ -1740,6 +1739,15 @@ fn generate_node(
17401739
Line("}".to_string())
17411740
])
17421741
}),
1742+
// Manually implement Copy/Clone because `derive` only kicks in if all of
1743+
// the parameters are known to implement Copy/Clone.
1744+
Branch(vec![
1745+
Line(format!("impl <'a,{0}> ::core::marker::Copy for Reader<'a,{0}> {1} {{}}",
1746+
params.params, params.where_clause)),
1747+
Line(format!("impl <'a,{0}> ::core::clone::Clone for Reader<'a,{0}> {1} {{",
1748+
params.params, params.where_clause)),
1749+
Indent(Box::new(Line("fn clone(&self) -> Self { *self }".into()))),
1750+
Line("}".into())]),
17431751
BlankLine,
17441752
Branch(vec![
17451753
Line(format!("impl <'a,{0}> ::capnp::traits::HasTypeId for Reader<'a,{0}> {1} {{",

0 commit comments

Comments
 (0)