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
sourceimpl 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: 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. 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.
sourceimpl Bson
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<&Array>
pub fn as_array(&self) -> Option<&Array>
If Bson
is Array
, return its value. Returns None
otherwise
sourcepub fn as_array_mut(&mut self) -> Option<&mut Array>
pub fn as_array_mut(&mut self) -> Option<&mut Array>
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>
pub fn as_datetime(&self) -> Option<&DateTime>
If Bson
is DateTime
, return its value. Returns None
otherwise
sourcepub fn as_datetime_mut(&mut self) -> Option<&mut DateTime>
pub fn as_datetime_mut(&mut self) -> Option<&mut DateTime>
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
sourceimpl<'de> Deserialize<'de> for Bson
impl<'de> Deserialize<'de> for Bson
sourcefn deserialize<D>(deserializer: D) -> Result<Bson, D::Error> where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Bson, D::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl From<Bson> for Value
impl From<Bson> for Value
This will create the relaxed Extended JSON v2 representation of the provided Bson
.
sourceimpl<T: TimeZone> From<DateTime<T>> for Bson
This is supported on crate feature chrono-0_4
only.
impl<T: TimeZone> From<DateTime<T>> for Bson
chrono-0_4
only.sourceimpl From<Decimal128> for Bson
impl From<Decimal128> for Bson
sourcefn from(d: Decimal128) -> Self
fn from(d: Decimal128) -> Self
Converts to this type from the input type.
sourceimpl From<JavaScriptCodeWithScope> for Bson
impl From<JavaScriptCodeWithScope> for Bson
sourcefn from(code_with_scope: JavaScriptCodeWithScope) -> Bson
fn from(code_with_scope: JavaScriptCodeWithScope) -> Bson
Converts to this type from the input type.
sourceimpl<T: Into<Bson>> FromIterator<T> for Bson
impl<T: Into<Bson>> FromIterator<T> for Bson
sourcefn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
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();
sourceimpl TryFrom<Map<String, Value>> for Bson
impl TryFrom<Map<String, Value>> for Bson
This converts from the input JSON object as if it were MongoDB Extended JSON v2.
sourceimpl<'a> TryFrom<RawBsonRef<'a>> for Bson
impl<'a> TryFrom<RawBsonRef<'a>> for Bson
sourceimpl TryFrom<Value> for Bson
impl TryFrom<Value> for Bson
This converts from the input JSON as if it were MongoDB Extended JSON v2.
impl StructuralPartialEq for Bson
Auto Trait Implementations
impl RefUnwindSafe for Bson
impl Send for Bson
impl Sync for Bson
impl Unpin for Bson
impl UnwindSafe for Bson
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
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more