Enum sentry_contrib_native::Value
source · [−]pub enum Value {
Null,
Bool(bool),
Int(i32),
Double(f64),
String(String),
List(Vec<Value>),
Map(BTreeMap<String, Value>),
}
Expand description
Represents a Sentry protocol value.
Examples
assert!(Value::new(()).is_null());
assert!(Value::new(true).is_bool());
assert!(Value::new(10).is_int());
assert!(Value::new(10.).is_double());
assert!(Value::new("test").is_string());
assert!(Value::new(vec!["test 1", "test 2"]).is_list());
assert!(Value::new(vec![("test key 1", "test 1"), ("test key 2", "test 2")]).is_map());
Variants
Null
Null value.
Bool(bool)
Boolean.
Int(i32)
Integer.
Double(f64)
Double.
String(String)
String.
List(Vec<Value>)
List.
Map(BTreeMap<String, Value>)
Map.
Implementations
sourceimpl Value
impl Value
sourcepub fn into_null(self) -> Result<(), Error>
pub fn into_null(self) -> Result<(), Error>
Returns Ok
if self
is Value::Null
.
Errors
Fails with Error::TryConvert
if self
isn’t a Value::Null
;
Examples
assert_eq!(Ok(()), Value::new(()).into_null());
assert_eq!(
Err(Error::TryConvert(Value::new(false))),
Value::new(false).into_null()
);
sourcepub const fn as_bool(&self) -> Option<bool>
pub const fn as_bool(&self) -> Option<bool>
Returns Some
with the inner value if self
is Value::Bool
.
Examples
assert_eq!(Some(true), Value::new(true).as_bool());
sourcepub fn as_mut_bool(&mut self) -> Option<&mut bool>
pub fn as_mut_bool(&mut self) -> Option<&mut bool>
Returns Some
with the inner value if self
is Value::Bool
.
Examples
let mut value = Value::new(true);
value.as_mut_bool().map(|value| *value = false);
assert_eq!(Some(false), value.as_bool());
sourcepub fn into_bool(self) -> Result<bool, Error>
pub fn into_bool(self) -> Result<bool, Error>
Returns Ok
with the inner value if self
is Value::Bool
.
Errors
Fails with Error::TryConvert
if self
isn’t a Value::Bool
;
Examples
assert_eq!(Ok(true), Value::new(true).into_bool());
assert_eq!(
Err(Error::TryConvert(Value::new(()))),
Value::new(()).into_bool()
);
sourcepub const fn as_int(&self) -> Option<i32>
pub const fn as_int(&self) -> Option<i32>
Returns Some
with the inner value if self
is Value::Int
.
Examples
assert_eq!(Some(10), Value::new(10).as_int());
sourcepub fn as_mut_int(&mut self) -> Option<&mut i32>
pub fn as_mut_int(&mut self) -> Option<&mut i32>
Returns Some
with the inner value if self
is Value::Int
.
Examples
let mut value = Value::new(10);
value.as_mut_int().map(|value| *value = 5);
assert_eq!(Some(5), value.as_int());
sourcepub fn into_int(self) -> Result<i32, Error>
pub fn into_int(self) -> Result<i32, Error>
Returns Ok
with the inner value if self
is Value::Int
.
Errors
Fails with Error::TryConvert
if self
isn’t a Value::Int
;
Examples
assert_eq!(Ok(10), Value::new(10).into_int());
assert_eq!(
Err(Error::TryConvert(Value::new(false))),
Value::new(false).into_int()
);
sourcepub const fn as_double(&self) -> Option<f64>
pub const fn as_double(&self) -> Option<f64>
Returns Some
with the inner value if self
is Value::Double
.
Examples
assert_eq!(Some(10.), Value::new(10.).as_double());
sourcepub fn as_mut_double(&mut self) -> Option<&mut f64>
pub fn as_mut_double(&mut self) -> Option<&mut f64>
Returns Some
with the inner value if self
is Value::Double
.
Examples
let mut value = Value::new(10.);
value.as_mut_double().map(|value| *value = 5.);
assert_eq!(Some(5.), value.as_double());
sourcepub fn into_double(self) -> Result<f64, Error>
pub fn into_double(self) -> Result<f64, Error>
Returns Ok
with the inner value if self
is Value::Double
.
Errors
Fails with Error::TryConvert
if self
isn’t a Value::Double
;
Examples
assert_eq!(Ok(10.), Value::new(10.).into_double());
assert_eq!(
Err(Error::TryConvert(Value::new(false))),
Value::new(false).into_double()
);
sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Returns Some
with the inner value if self
is Value::String
.
Examples
assert_eq!(Some("test"), Value::new("test").as_str());
sourcepub fn as_mut_str(&mut self) -> Option<&mut str>
pub fn as_mut_str(&mut self) -> Option<&mut str>
Returns Some
with the inner value if self
is Value::String
.
Examples
let mut value = Value::new("test");
value
.as_mut_str()
.map(|value| value.get_mut(0..1).unwrap().make_ascii_uppercase());
assert_eq!(Some("Test"), value.as_str());
sourcepub fn into_string(self) -> Result<String, Error>
pub fn into_string(self) -> Result<String, Error>
Returns Ok
with the inner value if self
is Value::String
.
Errors
Fails with Error::TryConvert
if self
isn’t a Value::String
;
Examples
assert_eq!(Ok(String::from("test")), Value::new("test").into_string());
assert_eq!(
Err(Error::TryConvert(Value::new(false))),
Value::new(false).into_string()
);
sourcepub const fn is_list(&self) -> bool
pub const fn is_list(&self) -> bool
Returns true
if self
is Value::List
.
Examples
assert!(Value::new(vec!["test 1", "test 2"]).is_list());
sourcepub const fn as_list(&self) -> Option<&Vec<Self>>
pub const fn as_list(&self) -> Option<&Vec<Self>>
Returns Some
with the inner value if self
is Value::List
.
Examples
assert_eq!(
Some(&vec!["test 1".into(), "test 2".into()]),
Value::new(vec!["test 1", "test 2"]).as_list()
);
sourcepub fn as_mut_list(&mut self) -> Option<&mut Vec<Self>>
pub fn as_mut_list(&mut self) -> Option<&mut Vec<Self>>
Returns Some
with the inner value if self
is Value::List
.
Examples
let mut value = Value::new(vec!["test 1", "test 2"]);
value.as_mut_list().map(|value| value[0] = "test 3".into());
assert_eq!(Some("test 3"), value.into_list()?[0].as_str());
sourcepub fn into_list(self) -> Result<Vec<Self>, Error>
pub fn into_list(self) -> Result<Vec<Self>, Error>
Returns Ok
with the inner value if self
is Value::List
.
Errors
Fails with Error::TryConvert
if self
isn’t a Value::List
;
Examples
assert_eq!(
Ok(vec!["test 1".into(), "test 2".into()]),
Value::new(vec!["test 1", "test 2"]).into_list()
);
assert_eq!(
Err(Error::TryConvert(Value::new(false))),
Value::new(false).into_list()
);
sourcepub const fn is_map(&self) -> bool
pub const fn is_map(&self) -> bool
Returns true
if self
is Value::Map
.
Examples
assert!(Value::new(vec![("test key 1", "test 1"), ("test key 2", "test 2")]).is_map());
sourcepub const fn as_map(&self) -> Option<&BTreeMap<String, Self>>
pub const fn as_map(&self) -> Option<&BTreeMap<String, Self>>
Returns Some
with the inner value if self
is Value::Map
.
Examples
assert_eq!(
Some(&BTreeMap::from_iter(vec![
("test key 1".into(), "test 1".into()),
("test key 2".into(), "test 2".into())
])),
Value::new(vec![("test key 1", "test 1"), ("test key 2", "test 2")]).as_map()
);
sourcepub fn as_mut_map(&mut self) -> Option<&mut BTreeMap<String, Self>>
pub fn as_mut_map(&mut self) -> Option<&mut BTreeMap<String, Self>>
Returns Some
with the inner value if self
is Value::Map
.
Examples
let mut value = Value::new(vec![("test key 1", false), ("test key 2", false)]);
value
.as_mut_map()
.and_then(|value| value.get_mut("test key 1"))
.and_then(|value| value.as_mut_bool())
.map(|value| *value = true);
assert_eq!(Some(true), value.into_map()?["test key 1"].as_bool());
sourcepub fn into_map(self) -> Result<BTreeMap<String, Self>, Error>
pub fn into_map(self) -> Result<BTreeMap<String, Self>, Error>
Returns Ok
with the inner value if self
is Value::Map
.
Errors
Fails with Error::TryConvert
if self
isn’t a Value::Map
;
Examples
assert_eq!(
Ok(BTreeMap::from_iter(vec![
("test key 1".into(), "test 1".into()),
("test key 2".into(), "test 2".into())
])),
Value::new(vec![("test key 1", "test 1"), ("test key 2", "test 2")]).into_map()
);
assert_eq!(
Err(Error::TryConvert(Value::new(false))),
Value::new(false).into_map()
);
Trait Implementations
sourceimpl PartialOrd<Value> for Value
impl PartialOrd<Value> for Value
sourcefn partial_cmp(&self, other: &Value) -> Option<Ordering>
fn partial_cmp(&self, other: &Value) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl StructuralPartialEq for Value
Auto Trait Implementations
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnwindSafe for Value
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more