diff --git a/src/bson.rs b/src/bson.rs index 2004adfd..83f8b424 100644 --- a/src/bson.rs +++ b/src/bson.rs @@ -1130,7 +1130,8 @@ impl Binary { } } - pub(crate) fn as_raw_binary(&self) -> RawBinaryRef<'_> { + /// Borrow the contents as a `RawBinaryRef`. + pub fn as_raw_binary(&self) -> RawBinaryRef<'_> { RawBinaryRef { bytes: self.bytes.as_slice(), subtype: self.subtype, diff --git a/src/raw/bson_ref.rs b/src/raw/bson_ref.rs index c27ff939..a0668e01 100644 --- a/src/raw/bson_ref.rs +++ b/src/raw/bson_ref.rs @@ -460,6 +460,14 @@ pub struct RawBinaryRef<'a> { } impl<'a> RawBinaryRef<'a> { + /// Copy the contents into a `Binary`. + pub fn to_binary(&self) -> Binary { + Binary { + subtype: self.subtype, + bytes: self.bytes.to_owned(), + } + } + pub(crate) fn len(&self) -> i32 { match self.subtype { BinarySubtype::BinaryOld => self.bytes.len() as i32 + 4,