pub enum Bson {
Show 21 variants Double(f64), String(String), Array(Array), Document(Document), Boolean(bool), Null, RegularExpression(Regex), JavaScriptCode(String), JavaScriptCodeWithScope(JavaScriptCodeWithScope), Int32(i32), Int64(i64), Timestamp(Timestamp), Binary(Binary), ObjectId(ObjectId), DateTime(DateTime), Symbol(String), Decimal128(Decimal128), Undefined, MaxKey, MinKey, DbPointer(DbPointer),
}
Expand description

Possible BSON value types.

Variants

Double(f64)

64-bit binary floating point

String(String)

UTF-8 string

Array(Array)

Array

Document(Document)

Embedded document

Boolean(bool)

Boolean value

Null

Null value

RegularExpression(Regex)

Regular expression

JavaScriptCode(String)

JavaScript code

JavaScriptCodeWithScope(JavaScriptCodeWithScope)

JavaScript code w/ scope

Int32(i32)

32-bit signed integer

Int64(i64)

64-bit signed integer

Timestamp(Timestamp)

Timestamp

Binary(Binary)

Binary data

ObjectId(ObjectId)

DateTime(DateTime)

UTC datetime

Symbol(String)

Symbol (Deprecated)

Decimal128(Decimal128)

Undefined

Undefined value (Deprecated)

MaxKey

Max key

MinKey

Min key

DbPointer(DbPointer)

DBPointer (Deprecated)

Implementations

Converts the Bson value into its relaxed extended JSON representation.

Note: If this method is called on a case which contains a Decimal128 value, it will panic.

Converts the Bson value into its canonical extended JSON representation.

Note: extended json encoding for Decimal128 values is not supported. If this method is called on a case which contains a Decimal128 value, it will panic.

Get the ElementType of this value.

Value helpers

If Bson is Double, return its value as an f64. Returns None otherwise

If Bson is String, return its value as a &str. Returns None otherwise

If Bson is String, return a mutable reference to its value as a str. Returns None otherwise

If Bson is Array, return its value. Returns None otherwise

If Bson is Array, return a mutable reference to its value. Returns None otherwise

If Bson is Document, return its value. Returns None otherwise

If Bson is Document, return a mutable reference to its value. Returns None otherwise

If Bson is Bool, return its value. Returns None otherwise

If Bson is I32, return its value. Returns None otherwise

If Bson is I64, return its value. Returns None otherwise

If Bson is Objectid, return its value. Returns None otherwise

If Bson is Objectid, return a mutable reference to its value. Returns None otherwise

If Bson is DateTime, return its value. Returns None otherwise

If Bson is DateTime, return a mutable reference to its value. Returns None otherwise

If Bson is Symbol, return its value. Returns None otherwise

If Bson is Symbol, return a mutable reference to its value. Returns None otherwise

If Bson is Timestamp, return its value. Returns None otherwise

If Bson is Null, return its value. Returns None otherwise

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 from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

This will create the relaxed Extended JSON v2 representation of the provided Bson.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Examples
use std::iter::FromIterator;
use bson::Bson;

let x: Bson = Bson::from_iter(vec!["lorem", "ipsum", "dolor"]);
// or
let x: Bson = vec!["lorem", "ipsum", "dolor"].into_iter().collect();

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 object as if it were MongoDB Extended JSON v2.

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.

The type returned in the event of a conversion error.

Performs the conversion.

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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)

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.