[−][src]Enum sentry_contrib_native::Value
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 value.
Bool(bool)
Boolean.
Int(i32)
Integer.
Double(f64)
Double.
String(String)
String.
List.
Map.
Implementations
impl Value
[src]
pub fn new<V: Into<Self>>(value: V) -> Self
[src]
Creates a new Sentry value.
Panics
Panics if value
contains any null bytes.
Examples
let value = Value::new("test");
#[must_use]pub fn is_null(&self) -> bool
[src]
#[must_use]pub fn as_null(&self) -> Option<()>
[src]
pub fn into_null(self) -> Result<(), Error>
[src]
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() );
#[must_use]pub fn is_bool(&self) -> bool
[src]
#[must_use]pub fn as_bool(&self) -> Option<bool>
[src]
Returns Some
with the inner value if self
is Value::Bool
.
Examples
assert_eq!(Some(true), Value::new(true).as_bool());
#[must_use]pub fn as_mut_bool(&mut self) -> Option<&mut bool>
[src]
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());
pub fn into_bool(self) -> Result<bool, Error>
[src]
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() );
#[must_use]pub fn is_int(&self) -> bool
[src]
#[must_use]pub fn as_int(&self) -> Option<i32>
[src]
Returns Some
with the inner value if self
is Value::Int
.
Examples
assert_eq!(Some(10), Value::new(10).as_int());
#[must_use]pub fn as_mut_int(&mut self) -> Option<&mut i32>
[src]
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());
pub fn into_int(self) -> Result<i32, Error>
[src]
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() );
#[must_use]pub fn is_double(&self) -> bool
[src]
#[must_use]pub fn as_double(&self) -> Option<f64>
[src]
Returns Some
with the inner value if self
is Value::Double
.
Examples
assert_eq!(Some(10.), Value::new(10.).as_double());
#[must_use]pub fn as_mut_double(&mut self) -> Option<&mut f64>
[src]
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());
pub fn into_double(self) -> Result<f64, Error>
[src]
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() );
#[must_use]pub fn is_string(&self) -> bool
[src]
#[must_use]pub fn as_str(&self) -> Option<&str>
[src]
Returns Some
with the inner value if self
is Value::String
.
Examples
assert_eq!(Some("test"), Value::new("test").as_str());
#[must_use]pub fn as_mut_str(&mut self) -> Option<&mut str>
[src]
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());
pub fn into_string(self) -> Result<String, Error>
[src]
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() );
#[must_use]pub fn is_list(&self) -> bool
[src]
Returns true
if self
is Value::List
.
Examples
assert!(Value::new(vec!["test 1", "test 2"]).is_list());
#[must_use]pub fn as_list(&self) -> Option<&Vec<Self>>
[src]
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() );
#[must_use]pub fn as_mut_list(&mut self) -> Option<&mut Vec<Self>>
[src]
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());
pub fn into_list(self) -> Result<Vec<Self>, Error>
[src]
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() );
#[must_use]pub fn is_map(&self) -> bool
[src]
Returns true
if self
is Value::Map
.
Examples
assert!(Value::new(vec![("test key 1", "test 1"), ("test key 2", "test 2")]).is_map());
#[must_use]pub fn as_map(&self) -> Option<&BTreeMap<String, Self>>
[src]
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() );
#[must_use]pub fn as_mut_map(&mut self) -> Option<&mut BTreeMap<String, Self>>
[src]
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());
pub fn into_map(self) -> Result<BTreeMap<String, Self>, Error>
[src]
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
impl Clone for Value
[src]
impl Debug for Value
[src]
impl Default for Value
[src]
impl<'_, V: Into<Self> + Copy> From<&'_ V> for Value
[src]
impl<'_> From<&'_ str> for Value
[src]
impl From<()> for Value
[src]
impl<K: Into<String>, V: Into<Value>> From<BTreeMap<K, V>> for Value
[src]
impl From<String> for Value
[src]
impl<K: Into<String>, V: Into<Value>> From<Vec<(K, V)>> for Value
[src]
impl<V: Into<Value>> From<Vec<V>> for Value
[src]
impl From<bool> for Value
[src]
impl From<f32> for Value
[src]
impl From<f64> for Value
[src]
impl From<i16> for Value
[src]
impl From<i32> for Value
[src]
impl From<i8> for Value
[src]
impl From<u16> for Value
[src]
impl From<u8> for Value
[src]
impl PartialEq<Value> for Value
[src]
impl PartialOrd<Value> for Value
[src]
fn partial_cmp(&self, other: &Value) -> Option<Ordering>
[src]
fn lt(&self, other: &Value) -> bool
[src]
fn le(&self, other: &Value) -> bool
[src]
fn gt(&self, other: &Value) -> bool
[src]
fn ge(&self, other: &Value) -> bool
[src]
impl StructuralPartialEq for Value
[src]
impl TryFrom<Value> for ()
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: Value) -> Result<Self, Error>
[src]
impl TryFrom<Value> for bool
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: Value) -> Result<Self, Error>
[src]
impl TryFrom<Value> for i32
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: Value) -> Result<Self, Error>
[src]
impl TryFrom<Value> for f64
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: Value) -> Result<Self, Error>
[src]
impl TryFrom<Value> for String
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: Value) -> Result<Self, Error>
[src]
impl TryFrom<Value> for Vec<Value>
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: Value) -> Result<Self, Error>
[src]
impl TryFrom<Value> for BTreeMap<String, Value>
[src]
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
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,