Bson

Enum Bson 

Source
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

Source

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.

Source

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.

Source

pub fn element_type(&self) -> ElementType

Get the ElementType of this value.

Source§

impl Bson

Value helpers

Source

pub fn as_f64(&self) -> Option<f64>

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

Source

pub fn as_str(&self) -> Option<&str>

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

Source

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

Source

pub fn as_array(&self) -> Option<&Vec<Bson>>

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

Source

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

Source

pub fn as_document(&self) -> Option<&Document>

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

Source

pub fn as_document_mut(&mut self) -> Option<&mut Document>

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

Source

pub fn as_bool(&self) -> Option<bool>

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

Source

pub fn as_i32(&self) -> Option<i32>

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

Source

pub fn as_i64(&self) -> Option<i64>

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

Source

pub fn as_object_id(&self) -> Option<&ObjectId>

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

Source

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

Source

pub fn as_datetime(&self) -> Option<&DateTime<Utc>>

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

Source

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

Source

pub fn as_symbol(&self) -> Option<&str>

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

Source

pub fn as_symbol_mut(&mut self) -> Option<&mut str>

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

Source

pub fn as_timestamp(&self) -> Option<Timestamp>

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

Source

pub fn as_null(&self) -> Option<()>

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

Source

pub fn as_db_pointer(&self) -> Option<&DbPointer>

Trait Implementations§

Source§

impl Clone for Bson

Source§

fn clone(&self) -> Bson

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Bson

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Bson

Source§

fn default() -> Bson

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

impl<'de> Deserialize<'de> for Bson

Source§

fn deserialize<D>( deserializer: D, ) -> Result<Bson, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Bson

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> From<&[T]> for Bson
where T: Clone + Into<Bson>,

Source§

fn from(s: &[T]) -> Bson

Converts to this type from the input type.
Source§

impl<T> From<&T> for Bson
where T: Clone + Into<Bson>,

Source§

fn from(t: &T) -> Bson

Converts to this type from the input type.
Source§

impl From<&str> for Bson

Source§

fn from(s: &str) -> Bson

Converts to this type from the input type.
Source§

impl From<[u8; 12]> for Bson

Source§

fn from(a: [u8; 12]) -> Bson

Converts to this type from the input type.
Source§

impl From<Binary> for Bson

Source§

fn from(binary: Binary) -> Bson

Converts to this type from the input type.
Source§

impl From<ClientMetadata> for Bson

Source§

fn from(metadata: ClientMetadata) -> Bson

Converts to this type from the input type.
Source§

impl From<DateTime<Utc>> for Bson

Source§

fn from(a: DateTime<Utc>) -> Bson

Converts to this type from the input type.
Source§

impl From<DbPointer> for Bson

Source§

fn from(a: DbPointer) -> Bson

Converts to this type from the input type.
Source§

impl From<Document> for Bson

Source§

fn from(a: Document) -> Bson

Converts to this type from the input type.
Source§

impl From<JavaScriptCodeWithScope> for Bson

Source§

fn from(code_with_scope: JavaScriptCodeWithScope) -> Bson

Converts to this type from the input type.
Source§

impl From<ObjectId> for Bson

Source§

fn from(a: ObjectId) -> Bson

Converts to this type from the input type.
Source§

impl From<OsMetadata> for Bson

Source§

fn from(metadata: OsMetadata) -> Bson

Converts to this type from the input type.
Source§

impl From<Regex> for Bson

Source§

fn from(regex: Regex) -> Bson

Converts to this type from the input type.
Source§

impl From<String> for Bson

Source§

fn from(a: String) -> Bson

Converts to this type from the input type.
Source§

impl From<Timestamp> for Bson

Source§

fn from(ts: Timestamp) -> Bson

Converts to this type from the input type.
Source§

impl<T> From<Vec<T>> for Bson
where T: Into<Bson>,

Source§

fn from(v: Vec<T>) -> Bson

Converts to this type from the input type.
Source§

impl From<bool> for Bson

Source§

fn from(a: bool) -> Bson

Converts to this type from the input type.
Source§

impl From<f32> for Bson

Source§

fn from(a: f32) -> Bson

Converts to this type from the input type.
Source§

impl From<f64> for Bson

Source§

fn from(a: f64) -> Bson

Converts to this type from the input type.
Source§

impl From<i32> for Bson

Source§

fn from(a: i32) -> Bson

Converts to this type from the input type.
Source§

impl From<i64> for Bson

Source§

fn from(a: i64) -> Bson

Converts to this type from the input type.
Source§

impl From<u32> for Bson

Source§

fn from(a: u32) -> Bson

Converts to this type from the input type.
Source§

impl From<u64> for Bson

Source§

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
where T: Into<Bson>,

Source§

fn from_iter<I>(iter: I) -> Bson
where I: IntoIterator<Item = T>,

§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();
Source§

impl PartialEq for Bson

Source§

fn eq(&self, other: &Bson) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Bson

Source§

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
Source§

impl TryFrom<Map<String, Value>> for Bson

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

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(obj: Map<String, Value>) -> Result<Bson, Error>

Performs the conversion.
Source§

impl TryFrom<Value> for Bson

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

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Bson, Error>

Performs the conversion.
Source§

impl StructuralPartialEq for Bson

Auto Trait Implementations§

§

impl Freeze for Bson

§

impl RefUnwindSafe for Bson

§

impl Send for Bson

§

impl Sync for Bson

§

impl Unpin for Bson

§

impl UnwindSafe for Bson

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,