Skip to content

Commit 3c7c60f

Browse files
committed
RUST-1385 Add binary/raw conversions
1 parent 20675ff commit 3c7c60f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/bson.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,8 @@ impl Binary {
11301130
}
11311131
}
11321132

1133-
pub(crate) fn as_raw_binary(&self) -> RawBinaryRef<'_> {
1133+
/// Borrow the contents as a `RawBinaryRef`.
1134+
pub fn as_raw_binary(&self) -> RawBinaryRef<'_> {
11341135
RawBinaryRef {
11351136
bytes: self.bytes.as_slice(),
11361137
subtype: self.subtype,

src/raw/bson_ref.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,14 @@ pub struct RawBinaryRef<'a> {
460460
}
461461

462462
impl<'a> RawBinaryRef<'a> {
463+
/// Copy the contents into a `Binary`.
464+
pub fn to_binary(&self) -> Binary {
465+
Binary {
466+
subtype: self.subtype,
467+
bytes: self.bytes.to_owned(),
468+
}
469+
}
470+
463471
pub(crate) fn len(&self) -> i32 {
464472
match self.subtype {
465473
BinarySubtype::BinaryOld => self.bytes.len() as i32 + 4,

0 commit comments

Comments
 (0)