Type Definition rbatis_sql::ops::Value
source · pub type Value = Bson;
Expand description
proxy rbson::Document struct,support Deserializer, Serializer use Cow Optimize unnecessary clones This structure has a certain amount of computing power
Trait Implementations
sourceimpl AsProxy for Value
impl AsProxy for Value
fn i32(&self) -> i32
fn i64(&self) -> i64
fn u32(&self) -> u32
fn u64(&self) -> u64
fn f64(&self) -> f64
fn str(&self) -> &str
fn string(&self) -> String
fn cast_string(&self) -> String
fn cast_i64(&self) -> i64
fn cast_u64(&self) -> u64
fn cast_f64(&self) -> f64
fn bool(&self) -> bool
fn is_empty(&self) -> bool
fn is_null(&self) -> bool
fn is_array(&self) -> bool
fn array(&self) -> Option<&Array>
fn is_document(&self) -> bool
fn is_object(&self) -> bool
fn object(&self) -> Option<&Document>
sourceimpl<I> OpsIndex<I> for Valuewhere
I: Index,
impl<I> OpsIndex<I> for Valuewhere
I: Index,
sourcefn index(&self, index: I) -> &Value
fn index(&self, index: I) -> &Value
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
sourceimpl<I> OpsIndexMut<I> for Valuewhere
I: Index,
impl<I> OpsIndexMut<I> for Valuewhere
I: Index,
sourcefn index_mut(&mut self, index: I) -> &mut Value
fn index_mut(&mut self, index: I) -> &mut Value
Write into a rbatis_sql::Value
using the syntax value[0] = ...
or
value["k"] = ...
.
If the index is a number, the value must be an array of length bigger than the index. Indexing into a value that is not an array or an array that is too small will panic.
If the index is a string, the value must be an object or null which is treated like an empty object. If the key is not already present in the object, it will be inserted with a value of null. Indexing into a value that is neither an object nor null will panic.
Examples
let mut data = bson!({ "x": 0 });
// replace an existing key
data["x"] = bson!(1);
// insert a new key
data["y"] = bson!([false, false, false]);
// replace an array value
data["y"][0] = bson!(true);
// inserted a deeply nested key
data["a"]["b"]["c"]["d"] = bson!(true);
println!("{}", data);