From 3c7c60f6dd51b79e9f0661d51ab5b62ed89c3e83 Mon Sep 17 00:00:00 2001 From: Abraham Egnor Date: Fri, 12 Aug 2022 15:39:18 -0400 Subject: [PATCH] RUST-1385 Add binary/raw conversions --- src/bson.rs | 3 ++- src/raw/bson_ref.rs | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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,