pub trait OpsIndex<Idx> where
Idx: ?Sized, {
type Output: ?Sized;
fn index(&self, index: Idx) -> &Self::Output;
}
Required Associated Types
Required Methods
Implementations on Foreign Types
sourceimpl<I> OpsIndex<I> for Bson where
I: Index,
impl<I> OpsIndex<I> for Bson where
I: Index,
sourcefn index(&self, index: I) -> &Bson
fn index(&self, index: I) -> &Bson
Index into a rbatis_sql::Value
using the syntax value[0]
or
value["k"]
.
Returns Value::Null
if the type of self
does not match the type of
the index, for example if the index is a string and self
is an array
or a number. Also returns Value::Null
if the given key does not exist
in the map or the given index is not within the bounds of the array.
For retrieving deeply nested values, you should have a look at the
Value::pointer
method.
Examples
let data = bson!({
"x": {
"y": ["z", "zz"]
}
});
assert_eq!(data["x"]["y"], bson!(["z", "zz"]));
assert_eq!(data["x"]["y"][0], bson!("z"));
assert_eq!(data["a"], bson!(null)); // returns null for undefined values
assert_eq!(data["a"]["b"], bson!(null)); // does not panic