Skip to content

Commit 97f0735

Browse files
committed
use raw code with scope type in RawBson
1 parent dd3d341 commit 97f0735

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/raw/elem.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,15 @@ impl<'a> RawBson<'a> {
209209

210210
/// Gets the BSON JavaScript code with scope that's referenced or returns an error if the value
211211
/// isn't BSON JavaScript code with scope.
212-
pub fn as_javascript_with_scope(self) -> RawResult<(&'a str, &'a RawDocumentRef)> {
212+
pub fn as_javascript_with_scope(self) -> RawResult<RawJavaScriptCodeWithScope<'a>> {
213213
if let ElementType::JavaScriptCodeWithScope = self.element_type {
214214
let length = i32_from_slice(&self.data[..4]);
215215
assert_eq!(self.data.len() as i32, length);
216216

217-
let js = read_lenencoded(&self.data[4..])?;
218-
let doc = RawDocumentRef::new(&self.data[9 + js.len()..])?;
217+
let code = read_lenencoded(&self.data[4..])?;
218+
let scope = RawDocumentRef::new(&self.data[9 + code.len()..])?;
219219

220-
Ok((js, doc))
220+
Ok(RawJavaScriptCodeWithScope { code, scope })
221221
} else {
222222
Err(RawError::UnexpectedType)
223223
}
@@ -318,9 +318,10 @@ impl<'a> TryFrom<RawBson<'a>> for Bson {
318318
ElementType::DbPointer => panic!("Uh oh. Maybe this should be a TryFrom"),
319319
ElementType::Symbol => Bson::Symbol(String::from(rawbson.as_symbol()?)),
320320
ElementType::JavaScriptCodeWithScope => {
321-
let (js, scope) = rawbson.as_javascript_with_scope()?;
321+
let RawJavaScriptCodeWithScope { code, scope } =
322+
rawbson.as_javascript_with_scope()?;
322323
Bson::JavaScriptCodeWithScope(crate::JavaScriptCodeWithScope {
323-
code: String::from(js),
324+
code: String::from(code),
324325
scope: scope.try_into()?,
325326
})
326327
}

0 commit comments

Comments
 (0)