[][src]Struct rawbson::Array

pub struct Array { /* fields omitted */ }

Implementations

impl Array[src]

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

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

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) };

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Trait Implementations

impl<'a> IntoIterator for &'a Array[src]

type IntoIter = ArrayIter<'a>

Which kind of iterator are we turning this into?

type Item = RawResult<Element<'a>>

The type of the elements being iterated over.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]