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

Creates a new Sentry value.

Examples
let value = Value::new("test");

Returns true if self is Value::Null.

Examples
assert!(Value::new(()).is_null());

Returns Some if self is Value::Null.

Examples
assert_eq!(Some(()), Value::new(()).as_null());

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

Returns true if self is Value::Bool.

Examples
assert!(Value::new(true).is_bool());

Returns Some with the inner value if self is Value::Bool.

Examples
assert_eq!(Some(true), Value::new(true).as_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());

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

Returns true if self is Value::Int.

Examples
assert!(Value::new(10).is_int());

Returns Some with the inner value if self is Value::Int.

Examples
assert_eq!(Some(10), Value::new(10).as_int());

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

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

Returns true if self is Value::Double.

Examples
assert!(Value::new(10.).is_double());

Returns Some with the inner value if self is Value::Double.

Examples
assert_eq!(Some(10.), Value::new(10.).as_double());

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

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

Returns true if self is Value::String.

Examples
assert!(Value::new("test").is_string());

Returns Some with the inner value if self is Value::String.

Examples
assert_eq!(Some("test"), Value::new("test").as_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());

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

Returns true if self is Value::List.

Examples
assert!(Value::new(vec!["test 1", "test 2"]).is_list());

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

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

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

Returns true if self is Value::Map.

Examples
assert!(Value::new(vec![("test key 1", "test 1"), ("test key 2", "test 2")]).is_map());

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

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

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.