Struct Array

Source
pub struct Array { /* private fields */ }

Implementations§

Source§

impl Array

Source

pub fn new(data: &[u8]) -> RawResult<&Array>

Source

pub unsafe fn new_unchecked(data: &[u8]) -> &Array

Return a new Array from the provided bytes.

§Safety

The provided bytes must start with a valid length indicator and end with a NUL terminator, as described in the bson spec.

The following is valid:

// Represents the array [null, 514i32], which is the same as the document
// {"0": null, "1": 514}
let bson = b"\x0f\0\0\0\x0A0\0\x101\0\x02\x02\0\0\0";
let arr = unsafe { Array::new_unchecked(bson) };
let mut arriter = arr.into_iter();
assert!(arriter.next().unwrap().and_then(|b| b.as_null()).is_ok());
assert_eq!(arriter.next().unwrap().and_then(|b| b.as_i32()).unwrap(), 514);

And so is this, even though the provided document is not an array, because the errors will be caught during decode.

// Represents the document {"0": null, "X": 514}
let bson = b"\x0f\0\0\0\x0A0\0\x10X\0\x02\x02\0\0\0";
let arr = unsafe { Array::new_unchecked(bson) };
let mut arriter = arr.into_iter();
assert!(arriter.next().unwrap().and_then(|b| b.as_null()).is_ok());
assert!(arriter.next().unwrap().is_err());
assert!(arriter.next().is_none());
§Bad:

The following, however, indicates the wrong size for the document, and is therefore unsound.

// Contains a length indicator, that is longer than the array
let invalid = b"\x06\0\0\0\0";
let arr: &Array = unsafe { Array::new_unchecked(invalid) };
Source

pub fn from_doc(doc: &Doc) -> &Array

Source

pub fn get(&self, index: usize) -> RawResult<Option<Element<'_>>>

Source

pub fn get_f64(&self, index: usize) -> RawResult<Option<f64>>

Source

pub fn get_str(&self, index: usize) -> RawResult<Option<&str>>

Source

pub fn get_document(&self, index: usize) -> RawResult<Option<&Doc>>

Source

pub fn get_array(&self, index: usize) -> RawResult<Option<&Array>>

Source

pub fn get_binary(&self, index: usize) -> RawResult<Option<RawBsonBinary<'_>>>

Source

pub fn get_object_id(&self, index: usize) -> RawResult<Option<ObjectId>>

Source

pub fn get_bool(&self, index: usize) -> RawResult<Option<bool>>

Source

pub fn get_datetime(&self, index: usize) -> RawResult<Option<DateTime<Utc>>>

Source

pub fn get_null(&self, index: usize) -> RawResult<Option<()>>

Source

pub fn get_regex(&self, index: usize) -> RawResult<Option<RawBsonRegex<'_>>>

Source

pub fn get_javascript(&self, index: usize) -> RawResult<Option<&str>>

Source

pub fn get_symbol(&self, index: usize) -> RawResult<Option<&str>>

Source

pub fn get_javascript_with_scope( &self, index: usize, ) -> RawResult<Option<(&str, &Doc)>>

Source

pub fn get_i32(&self, index: usize) -> RawResult<Option<i32>>

Source

pub fn get_timestamp( &self, index: usize, ) -> RawResult<Option<RawBsonTimestamp<'_>>>

Source

pub fn get_i64(&self, index: usize) -> RawResult<Option<i64>>

Source

pub fn to_vec(&self) -> RawResult<Vec<Element<'_>>>

Source

pub fn as_bytes(&self) -> &[u8]

Trait Implementations§

Source§

impl<'a> IntoIterator for &'a Array

Source§

type IntoIter = ArrayIter<'a>

Which kind of iterator are we turning this into?
Source§

type Item = Result<Element<'a>, RawError>

The type of the elements being iterated over.
Source§

fn into_iter(self) -> ArrayIter<'a>

Creates an iterator from a value. Read more
Source§

impl TryFrom<&Array> for Vec<Bson>

Source§

type Error = RawError

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

fn try_from(arr: &Array) -> RawResult<Vec<Bson>>

Performs the conversion.

Auto Trait Implementations§

§

impl Freeze for Array

§

impl RefUnwindSafe for Array

§

impl Send for Array

§

impl !Sized for Array

§

impl Sync for Array

§

impl Unpin for Array

§

impl UnwindSafe for Array

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