From 96b4f4d5acf673df777add1980344b4fd7a4ca05 Mon Sep 17 00:00:00 2001 From: anb Date: Mon, 9 Oct 2023 12:33:42 -0700 Subject: [PATCH] add Composer implementation for reference types 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. --- src/base/wire.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/base/wire.rs b/src/base/wire.rs index a1ef839e2..5e4f61bf4 100644 --- a/src/base/wire.rs +++ b/src/base/wire.rs @@ -46,6 +46,15 @@ impl Composer for bytes::BytesMut {} #[cfg(feature = "smallvec")] impl> Composer for smallvec::SmallVec {} +impl Composer for &mut T { + fn append_compressed_dname( + &mut self, + name: &N, + ) -> Result<(), Self::AppendError> { + Composer::append_compressed_dname(*self, name) + } +} + //------------ Compose ------------------------------------------------------- /// An extension trait to add composing to foreign types.