Struct bson::document::Document[][src]

pub struct Document { /* fields omitted */ }
Expand description

A BSON document represented as an associative HashMap with insertion ordering.

Implementations

Creates a new empty Document.

Gets an iterator over the entries of the map.

Clears the document, removing all values.

Returns a reference to the Bson corresponding to the key.

Gets a mutable reference to the Bson corresponding to the key

Get a floating point value for this key if it exists and has the correct type.

Get a mutable reference to a floating point value for this key if it exists and has the correct type.

Get a reference to a Decimal128 value for key, if it exists.

Get a mutable reference to a Decimal128 value for key, if it exists.

Get a string slice this key if it exists and has the correct type.

Get a mutable string slice this key if it exists and has the correct type.

Get a reference to an array for this key if it exists and has the correct type.

Get a mutable reference to an array for this key if it exists and has the correct type.

Get a reference to a document for this key if it exists and has the correct type.

Get a mutable reference to a document for this key if it exists and has the correct type.

Get a bool value for this key if it exists and has the correct type.

Get a mutable reference to a bool value for this key if it exists and has the correct type.

Returns wether this key has a null value

Get an i32 value for this key if it exists and has the correct type.

Get a mutable reference to an i32 value for this key if it exists and has the correct type.

Get an i64 value for this key if it exists and has the correct type.

Get a mutable reference to an i64 value for this key if it exists and has the correct type.

Get a time stamp value for this key if it exists and has the correct type.

Get a mutable reference to a time stamp value for this key if it exists and has the correct type.

Get a reference to a generic binary value for this key if it exists and has the correct type.

Get a mutable reference generic binary value for this key if it exists and has the correct type.

Get an object id value for this key if it exists and has the correct type.

Get a mutable reference to an object id value for this key if it exists and has the correct type.

Get a reference to a UTC datetime value for this key if it exists and has the correct type.

Get a mutable reference to a UTC datetime value for this key if it exists and has the correct type.

Returns true if the map contains a value for the specified key.

Gets a collection of all keys in the document.

Gets a collection of all values in the document.

Returns the number of elements in the document.

Returns true if the document contains no elements

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.

Takes the value of the entry out of the document, and returns it. Computes in O(n) time (average).

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)?;

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);

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Deserialize this value given this Deserializer.

Formats the value using the given formatter. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Performs the conversion.

Creates a value from an iterator. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

This converts from the input JSON as if it were MongoDB Extended JSON v2.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.