Skip to content

Commit

Permalink
add Composer implementation for reference types
Browse files Browse the repository at this point in the history
The use case is to share the underlying Composer buffer between
builders to avoid allocation, via a thread local variable for example.
Without the reference type implements, the ownership could be
transferred by memory swap operation, but that's not quite ideal. Plus
some methods like MessageBuilder::from_target would drop the Composer
on error, which makes it even difficult to share.
  • Loading branch information
xofyarg committed Oct 17, 2023
1 parent 97bf460 commit 96b4f4d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/base/wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ impl Composer for bytes::BytesMut {}
#[cfg(feature = "smallvec")]
impl<A: smallvec::Array<Item = u8>> Composer for smallvec::SmallVec<A> {}

impl<T: Composer> Composer for &mut T {
fn append_compressed_dname<N: ToDname + ?Sized>(
&mut self,
name: &N,
) -> Result<(), Self::AppendError> {
Composer::append_compressed_dname(*self, name)
}
}

//------------ Compose -------------------------------------------------------

/// An extension trait to add composing to foreign types.
Expand Down

0 comments on commit 96b4f4d

Please sign in to comment.