pub enum Bson {
Show 21 variants
Double(f64),
String(String),
Array(Vec<Bson>),
Document(Document),
Boolean(bool),
Null,
RegularExpression(Regex),
JavaScriptCode(String),
JavaScriptCodeWithScope(JavaScriptCodeWithScope),
Int32(i32),
Int64(i64),
Timestamp(Timestamp),
Binary(Binary),
ObjectId(ObjectId),
DateTime(DateTime<Utc>),
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(Vec<Bson>)
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>)
UTC datetime
Symbol(String)
Symbol (Deprecated)
Decimal128(Decimal128)
Undefined
Undefined value (Deprecated)
MaxKey
Max key
MinKey
Min key
DbPointer(DbPointer)
DBPointer (Deprecated)
Implementations§
Source§impl Bson
impl Bson
Sourcepub fn into_relaxed_extjson(self) -> Value
pub fn into_relaxed_extjson(self) -> Value
Converts the Bson value into its relaxed extended JSON representation.
Note: extended json encoding for Decimal128
values is not supported without the
“decimal128” feature flag. If this method is called on a case which contains a
Decimal128
value, it will panic.
Sourcepub fn into_canonical_extjson(self) -> Value
pub fn into_canonical_extjson(self) -> Value
Converts the Bson value into its canonical extended JSON representation.
Note: extended json encoding for Decimal128
values is not supported without the
“decimal128” feature flag. If this method is called on a case which contains a
Decimal128
value, it will panic.
Sourcepub fn element_type(&self) -> ElementType
pub fn element_type(&self) -> ElementType
Get the ElementType
of this value.
Source§impl Bson
Value helpers
impl Bson
Value helpers
Sourcepub fn as_f64(&self) -> Option<f64>
pub fn as_f64(&self) -> Option<f64>
If Bson
is Double
, return its value as an f64
. Returns None
otherwise
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
If Bson
is String
, return its value as a &str
. Returns None
otherwise
Sourcepub fn as_str_mut(&mut self) -> Option<&mut str>
pub fn as_str_mut(&mut self) -> Option<&mut str>
If Bson
is String
, return a mutable reference to its value as a str
. Returns None
otherwise
Sourcepub fn as_array(&self) -> Option<&Vec<Bson>>
pub fn as_array(&self) -> Option<&Vec<Bson>>
If Bson
is Array
, return its value. Returns None
otherwise
Sourcepub fn as_array_mut(&mut self) -> Option<&mut Vec<Bson>>
pub fn as_array_mut(&mut self) -> Option<&mut Vec<Bson>>
If Bson
is Array
, return a mutable reference to its value. Returns None
otherwise
Sourcepub fn as_document(&self) -> Option<&Document>
pub fn as_document(&self) -> Option<&Document>
If Bson
is Document
, return its value. Returns None
otherwise
Sourcepub fn as_document_mut(&mut self) -> Option<&mut Document>
pub fn as_document_mut(&mut self) -> Option<&mut Document>
If Bson
is Document
, return a mutable reference to its value. Returns None
otherwise
Sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
If Bson
is Bool
, return its value. Returns None
otherwise
Sourcepub fn as_object_id(&self) -> Option<&ObjectId>
pub fn as_object_id(&self) -> Option<&ObjectId>
If Bson
is Objectid
, return its value. Returns None
otherwise
Sourcepub fn as_object_id_mut(&mut self) -> Option<&mut ObjectId>
pub fn as_object_id_mut(&mut self) -> Option<&mut ObjectId>
If Bson
is Objectid
, return a mutable reference to its value. Returns None
otherwise
Sourcepub fn as_datetime(&self) -> Option<&DateTime<Utc>>
pub fn as_datetime(&self) -> Option<&DateTime<Utc>>
If Bson
is DateTime
, return its value. Returns None
otherwise
Sourcepub fn as_datetime_mut(&mut self) -> Option<&mut DateTime<Utc>>
pub fn as_datetime_mut(&mut self) -> Option<&mut DateTime<Utc>>
If Bson
is DateTime
, return a mutable reference to its value. Returns None
otherwise
Sourcepub fn as_symbol(&self) -> Option<&str>
pub fn as_symbol(&self) -> Option<&str>
If Bson
is Symbol
, return its value. Returns None
otherwise
Sourcepub fn as_symbol_mut(&mut self) -> Option<&mut str>
pub fn as_symbol_mut(&mut self) -> Option<&mut str>
If Bson
is Symbol
, return a mutable reference to its value. Returns None
otherwise
Sourcepub fn as_timestamp(&self) -> Option<Timestamp>
pub fn as_timestamp(&self) -> Option<Timestamp>
If Bson
is Timestamp
, return its value. Returns None
otherwise
pub fn as_db_pointer(&self) -> Option<&DbPointer>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Bson
impl<'de> Deserialize<'de> for Bson
Source§fn deserialize<D>(
deserializer: D,
) -> Result<Bson, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Bson, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl From<JavaScriptCodeWithScope> for Bson
impl From<JavaScriptCodeWithScope> for Bson
Source§fn from(code_with_scope: JavaScriptCodeWithScope) -> Bson
fn from(code_with_scope: JavaScriptCodeWithScope) -> Bson
Source§impl From<u64> for Bson
impl From<u64> for Bson
Source§fn from(a: u64) -> Bson
fn from(a: u64) -> Bson
This conversion is lossy if the provided u64
is greater than i64::MAX
, which it will be
converted to. Using this From
implementation is highly discouraged and it will be
removed in the next major version.
Note: due to https://github.com/rust-lang/rust/issues/39935 we cannot deprecate this implementation.
Source§impl<T> FromIterator<T> for Bson
impl<T> FromIterator<T> for Bson
Source§impl Serialize for Bson
impl Serialize for Bson
Source§fn 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,
Source§impl TryFrom<Map<String, Value>> for Bson
This converts from the input JSON object as if it were MongoDB Extended JSON v2.
impl TryFrom<Map<String, Value>> for Bson
This converts from the input JSON object as if it were MongoDB Extended JSON v2.
Source§impl TryFrom<Value> for Bson
This converts from the input JSON as if it were MongoDB Extended JSON v2.
impl TryFrom<Value> for Bson
This converts from the input JSON as if it were MongoDB Extended JSON v2.