pub struct Document { /* private fields */ }
Expand description
A BSON document represented as an associative HashMap with insertion ordering.
Implementations
sourceimpl Document
impl Document
sourcepub fn get(&self, key: impl AsRef<str>) -> Option<&Bson>
pub fn get(&self, key: impl AsRef<str>) -> Option<&Bson>
Returns a reference to the Bson corresponding to the key.
sourcepub fn get_mut(&mut self, key: impl AsRef<str>) -> Option<&mut Bson>
pub fn get_mut(&mut self, key: impl AsRef<str>) -> Option<&mut Bson>
Gets a mutable reference to the Bson corresponding to the key
sourcepub fn get_f64(&self, key: impl AsRef<str>) -> Result<f64, ValueAccessError>
pub fn get_f64(&self, key: impl AsRef<str>) -> Result<f64, ValueAccessError>
Get a floating point value for this key if it exists and has the correct type.
sourcepub fn get_f64_mut(
&mut self,
key: impl AsRef<str>
) -> Result<&mut f64, ValueAccessError>
pub fn get_f64_mut(
&mut self,
key: impl AsRef<str>
) -> Result<&mut f64, ValueAccessError>
Get a mutable reference to a floating point value for this key if it exists and has the correct type.
sourcepub fn get_decimal128(
&self,
key: impl AsRef<str>
) -> Result<&Decimal128, ValueAccessError>
pub fn get_decimal128(
&self,
key: impl AsRef<str>
) -> Result<&Decimal128, ValueAccessError>
Get a reference to a Decimal128 value for key, if it exists.
sourcepub fn get_decimal128_mut(
&mut self,
key: impl AsRef<str>
) -> Result<&mut Decimal128, ValueAccessError>
pub fn get_decimal128_mut(
&mut self,
key: impl AsRef<str>
) -> Result<&mut Decimal128, ValueAccessError>
Get a mutable reference to a Decimal128 value for key, if it exists.
sourcepub fn get_str(&self, key: impl AsRef<str>) -> Result<&str, ValueAccessError>
pub fn get_str(&self, key: impl AsRef<str>) -> Result<&str, ValueAccessError>
Get a string slice this key if it exists and has the correct type.
sourcepub fn get_str_mut(
&mut self,
key: impl AsRef<str>
) -> Result<&mut str, ValueAccessError>
pub fn get_str_mut(
&mut self,
key: impl AsRef<str>
) -> Result<&mut str, ValueAccessError>
Get a mutable string slice this key if it exists and has the correct type.
sourcepub fn get_array(
&self,
key: impl AsRef<str>
) -> Result<&Vec<Bson, Global>, ValueAccessError>
pub fn get_array(
&self,
key: impl AsRef<str>
) -> Result<&Vec<Bson, Global>, ValueAccessError>
Get a reference to an array for this key if it exists and has the correct type.
sourcepub fn get_array_mut(
&mut self,
key: impl AsRef<str>
) -> Result<&mut Vec<Bson, Global>, ValueAccessError>
pub fn get_array_mut(
&mut self,
key: impl AsRef<str>
) -> Result<&mut Vec<Bson, Global>, ValueAccessError>
Get a mutable reference to an array for this key if it exists and has the correct type.
sourcepub fn get_document(
&self,
key: impl AsRef<str>
) -> Result<&Document, ValueAccessError>
pub fn get_document(
&self,
key: impl AsRef<str>
) -> Result<&Document, ValueAccessError>
Get a reference to a document for this key if it exists and has the correct type.
sourcepub fn get_document_mut(
&mut self,
key: impl AsRef<str>
) -> Result<&mut Document, ValueAccessError>
pub fn get_document_mut(
&mut self,
key: impl AsRef<str>
) -> Result<&mut Document, ValueAccessError>
Get a mutable reference to a document for this key if it exists and has the correct type.
sourcepub fn get_bool(&self, key: impl AsRef<str>) -> Result<bool, ValueAccessError>
pub fn get_bool(&self, key: impl AsRef<str>) -> Result<bool, ValueAccessError>
Get a bool value for this key if it exists and has the correct type.
sourcepub fn get_bool_mut(
&mut self,
key: impl AsRef<str>
) -> Result<&mut bool, ValueAccessError>
pub fn get_bool_mut(
&mut self,
key: impl AsRef<str>
) -> Result<&mut bool, ValueAccessError>
Get a mutable reference to a bool value for this key if it exists and has the correct type.
sourcepub fn get_i32(&self, key: impl AsRef<str>) -> Result<i32, ValueAccessError>
pub fn get_i32(&self, key: impl AsRef<str>) -> Result<i32, ValueAccessError>
Get an i32 value for this key if it exists and has the correct type.
sourcepub fn get_i32_mut(
&mut self,
key: impl AsRef<str>
) -> Result<&mut i32, ValueAccessError>
pub fn get_i32_mut(
&mut self,
key: impl AsRef<str>
) -> Result<&mut i32, ValueAccessError>
Get a mutable reference to an i32 value for this key if it exists and has the correct type.
sourcepub fn get_i64(&self, key: impl AsRef<str>) -> Result<i64, ValueAccessError>
pub fn get_i64(&self, key: impl AsRef<str>) -> Result<i64, ValueAccessError>
Get an i64 value for this key if it exists and has the correct type.
sourcepub fn get_i64_mut(
&mut self,
key: impl AsRef<str>
) -> Result<&mut i64, ValueAccessError>
pub fn get_i64_mut(
&mut self,
key: impl AsRef<str>
) -> Result<&mut i64, ValueAccessError>
Get a mutable reference to an i64 value for this key if it exists and has the correct type.
sourcepub fn get_timestamp(
&self,
key: impl AsRef<str>
) -> Result<Timestamp, ValueAccessError>
pub fn get_timestamp(
&self,
key: impl AsRef<str>
) -> Result<Timestamp, ValueAccessError>
Get a time stamp value for this key if it exists and has the correct type.
sourcepub fn get_timestamp_mut(
&mut self,
key: impl AsRef<str>
) -> Result<&mut Timestamp, ValueAccessError>
pub fn get_timestamp_mut(
&mut self,
key: impl AsRef<str>
) -> Result<&mut Timestamp, ValueAccessError>
Get a mutable reference to a time stamp value for this key if it exists and has the correct type.
sourcepub fn get_binary_generic(
&self,
key: impl AsRef<str>
) -> Result<&Vec<u8, Global>, ValueAccessError>
pub fn get_binary_generic(
&self,
key: impl AsRef<str>
) -> Result<&Vec<u8, Global>, ValueAccessError>
Get a reference to a generic binary value for this key if it exists and has the correct type.
sourcepub fn get_binary_generic_mut(
&mut self,
key: impl AsRef<str>
) -> Result<&mut Vec<u8, Global>, ValueAccessError>
pub fn get_binary_generic_mut(
&mut self,
key: impl AsRef<str>
) -> Result<&mut Vec<u8, Global>, ValueAccessError>
Get a mutable reference generic binary value for this key if it exists and has the correct type.
sourcepub fn get_object_id(
&self,
key: impl AsRef<str>
) -> Result<ObjectId, ValueAccessError>
pub fn get_object_id(
&self,
key: impl AsRef<str>
) -> Result<ObjectId, ValueAccessError>
Get an object id value for this key if it exists and has the correct type.
sourcepub fn get_object_id_mut(
&mut self,
key: impl AsRef<str>
) -> Result<&mut ObjectId, ValueAccessError>
pub fn get_object_id_mut(
&mut self,
key: impl AsRef<str>
) -> Result<&mut ObjectId, ValueAccessError>
Get a mutable reference to an object id value for this key if it exists and has the correct type.
sourcepub fn get_datetime(
&self,
key: impl AsRef<str>
) -> Result<&DateTime, ValueAccessError>
pub fn get_datetime(
&self,
key: impl AsRef<str>
) -> Result<&DateTime, ValueAccessError>
Get a reference to a UTC datetime value for this key if it exists and has the correct type.
sourcepub fn get_datetime_mut(
&mut self,
key: impl AsRef<str>
) -> Result<&mut DateTime, ValueAccessError>
pub fn get_datetime_mut(
&mut self,
key: impl AsRef<str>
) -> Result<&mut DateTime, ValueAccessError>
Get a mutable reference to a UTC datetime value for this key if it exists and has the correct type.
sourcepub fn contains_key(&self, key: impl AsRef<str>) -> bool
pub fn contains_key(&self, key: impl AsRef<str>) -> bool
Returns true if the map contains a value for the specified key.
sourcepub fn insert<KT, BT>(&mut self, key: KT, val: BT) -> Option<Bson> where
KT: Into<String>,
BT: Into<Bson>,
pub fn insert<KT, BT>(&mut self, key: KT, val: BT) -> Option<Bson> where
KT: Into<String>,
BT: Into<Bson>,
Sets the value of the entry with the OccupiedEntry’s key, and returns the entry’s old value. Accepts any type that can be converted into Bson.
sourcepub fn remove(&mut self, key: impl AsRef<str>) -> Option<Bson>
pub fn remove(&mut self, key: impl AsRef<str>) -> Option<Bson>
Takes the value of the entry out of the document, and returns it. Computes in O(n) time (average).
pub fn entry(&mut self, k: String) -> Entry<'_>
sourcepub fn to_writer<W>(&self, writer: W) -> Result<(), Error> where
W: Write,
pub fn to_writer<W>(&self, writer: W) -> Result<(), Error> where
W: Write,
Attempts to serialize the Document
into a byte stream.
While the method signature indicates an owned writer must be passed in, a mutable reference
may also be passed in due to blanket implementations of Write
provided in the standard
library.
use bson::doc;
let mut v: Vec<u8> = Vec::new();
let doc = doc! { "x" : 1 };
doc.to_writer(&mut v)?;
sourcepub fn from_reader<R>(reader: R) -> Result<Document, Error> where
R: Read,
pub fn from_reader<R>(reader: R) -> Result<Document, Error> where
R: Read,
Attempts to deserialize a Document
from a byte stream.
While the method signature indicates an owned reader must be passed in, a mutable reference
may also be passed in due to blanket implementations of Read
provided in the standard
library.
use bson::{doc, Document};
use std::io::Cursor;
let mut v: Vec<u8> = Vec::new();
let doc = doc! { "x" : 1 };
doc.to_writer(&mut v)?;
// read from mutable reference
let mut reader = Cursor::new(v.clone());
let doc1 = Document::from_reader(&mut reader)?;
// read from owned value
let doc2 = Document::from_reader(Cursor::new(v))?;
assert_eq!(doc, doc1);
assert_eq!(doc, doc2);
sourcepub fn from_reader_utf8_lossy<R>(reader: R) -> Result<Document, Error> where
R: Read,
pub fn from_reader_utf8_lossy<R>(reader: R) -> Result<Document, Error> where
R: Read,
Attempt to deserialize a Document
that may contain invalid UTF-8 strings from a byte
stream.
This is mainly useful when reading raw BSON returned from a MongoDB server, which
in rare cases can contain invalidly truncated strings (https://jira.mongodb.org/browse/SERVER-24007).
For most use cases, Document::from_reader
can be used instead.
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Document
impl<'de> Deserialize<'de> for Document
sourcefn deserialize<D>(
deserializer: D
) -> Result<Document, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D
) -> Result<Document, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
Deserialize this value given this Deserializer
.
sourceimpl Extend<(String, Bson)> for Document
impl Extend<(String, Bson)> for Document
sourcefn extend<T>(&mut self, iter: T) where
T: IntoIterator<Item = (String, Bson)>,
fn extend<T>(&mut self, iter: T) where
T: IntoIterator<Item = (String, Bson)>,
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl From<Document> for UpdateModifications
impl From<Document> for UpdateModifications
sourcefn from(item: Document) -> UpdateModifications
fn from(item: Document) -> UpdateModifications
Converts to this type from the input type.
sourceimpl FromIterator<(String, Bson)> for Document
impl FromIterator<(String, Bson)> for Document
sourceimpl<'a> IntoIterator for &'a Document
impl<'a> IntoIterator for &'a Document
sourceimpl IntoIterator for Document
impl IntoIterator for Document
sourceimpl Serialize for Document
impl Serialize for Document
sourcefn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
sourceimpl TryFrom<&RawDocument> for Document
impl TryFrom<&RawDocument> for Document
sourceimpl TryFrom<Map<String, Value>> for Document
impl TryFrom<Map<String, Value>> for Document
This converts from the input JSON as if it were MongoDB Extended JSON v2.
sourceimpl TryFrom<RawDocumentBuf> for Document
impl TryFrom<RawDocumentBuf> for Document
impl StructuralPartialEq for Document
Auto Trait Implementations
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnwindSafe for Document
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more