Enum vector_core::event::Value
pub enum Value {
Bytes(Bytes),
Regex(ValueRegex),
Integer(i64),
Float(NotNan<f64>),
Boolean(bool),
Timestamp(DateTime<Utc>),
Object(BTreeMap<KeyString, Value>),
Array(Vec<Value>),
Null,
}
Expand description
The main value type used in Vector events, and VRL.
Variants§
Bytes(Bytes)
Bytes - usually representing a UTF8 String.
Regex(ValueRegex)
Regex. When used in the context of Vector this is treated identically to Bytes. It has additional meaning in the context of VRL.
Integer(i64)
Integer.
Float(NotNan<f64>)
Float - not NaN.
Boolean(bool)
Boolean.
Timestamp(DateTime<Utc>)
Timestamp (UTC).
Object(BTreeMap<KeyString, Value>)
Object.
Array(Vec<Value>)
Array.
Null
Null.
Implementations§
§impl Value
impl Value
pub fn as_float(&self) -> Option<NotNan<f64>>
pub fn as_float(&self) -> Option<NotNan<f64>>
Returns self as NotNan<f64>
, only if self is Value::Float
.
pub fn into_object(self) -> Option<BTreeMap<KeyString, Value>>
pub fn into_object(self) -> Option<BTreeMap<KeyString, Value>>
Returns self as ObjectMap
, only if self is Value::Object
.
pub fn as_timestamp(&self) -> Option<&DateTime<Utc>>
pub fn as_timestamp(&self) -> Option<&DateTime<Utc>>
Returns self as &DateTime<Utc>
, only if self is Value::Timestamp
.
pub fn as_timestamp_unwrap(&self) -> &DateTime<Utc>
pub fn as_timestamp_unwrap(&self) -> &DateTime<Utc>
Returns self as a DateTime<Utc>
.
§Panics
This function will panic if self is anything other than Value::Timestamp
.
pub fn as_object_mut_unwrap(&mut self) -> &mut BTreeMap<KeyString, Value>
pub fn as_object_mut_unwrap(&mut self) -> &mut BTreeMap<KeyString, Value>
Returns self as a mutable ObjectMap
.
§Panics
This function will panic if self is anything other than Value::Object
.
pub fn as_array_unwrap(&self) -> &[Value]
pub fn as_array_unwrap(&self) -> &[Value]
Returns self as a Vec<Value>
.
§Panics
This function will panic if self is anything other than Value::Array
.
pub fn as_array_mut_unwrap(&mut self) -> &mut Vec<Value>
pub fn as_array_mut_unwrap(&mut self) -> &mut Vec<Value>
Returns self as a mutable Vec<Value>
.
§Panics
This function will panic if self is anything other than Value::Array
.
pub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Returns true if self is Value::Integer
.
pub fn as_integer(&self) -> Option<i64>
pub fn as_integer(&self) -> Option<i64>
Returns self as f64
, only if self is Value::Integer
.
pub fn from_f64_or_zero(value: f64) -> Value
pub fn from_f64_or_zero(value: f64) -> Value
Creates a Value from an f64. If the value is Nan, it is converted to 0.0
§Panics
If NaN is used as a default value.
pub fn encode_as_bytes(&self) -> Result<Bytes, String>
pub fn encode_as_bytes(&self) -> Result<Bytes, String>
Converts the Value into a byte representation regardless of its original type. Object and Array are currently not supported, although technically there’s no reason why it couldn’t in future should the need arise.
§Errors
If the type is Object or Array, and string error description will be returned
pub fn is_boolean(&self) -> bool
pub fn is_boolean(&self) -> bool
Returns true if self is Value::Boolean
.
pub fn as_boolean(&self) -> Option<bool>
pub fn as_boolean(&self) -> Option<bool>
Returns self as bool
, only if self is Value::Boolean
.
pub fn as_array_mut(&mut self) -> Option<&mut Vec<Value>>
pub fn as_array_mut(&mut self) -> Option<&mut Vec<Value>>
Returns self as &mut Vec<Value>
, only if self is Value::Array
.
pub fn as_object(&self) -> Option<&BTreeMap<KeyString, Value>>
pub fn as_object(&self) -> Option<&BTreeMap<KeyString, Value>>
Returns self as &ObjectMap
, only if self is Value::Object
.
pub fn as_object_mut(&mut self) -> Option<&mut BTreeMap<KeyString, Value>>
pub fn as_object_mut(&mut self) -> Option<&mut BTreeMap<KeyString, Value>>
Returns self as &mut ObjectMap
, only if self is Value::Object
.
pub fn is_timestamp(&self) -> bool
pub fn is_timestamp(&self) -> bool
Returns true if self is Value::Timestamp
.
pub fn kind(&self) -> Kind
pub fn kind(&self) -> Kind
Returns the Kind
of this Value
§impl Value
impl Value
pub fn into_iter<'a>(self, recursive: bool) -> ValueIter<'a>
pub fn into_iter<'a>(self, recursive: bool) -> ValueIter<'a>
Create an iterator over the Value
.
For non-collection types, this returns a single-item iterator similar to
Option
’s iterator implementation.
For collection types, it returns all elements in the collection.
The resulting item is an [IterItem
], which contains either a mutable
Value
for non-collection types, a (&mut KeyString
, &mut Value
) pair for
object-type collections, or an immutable/mutable (usize
, &mut Value
)
pair for array-type collections.
§Recursion
If recursion
is set to true
, the iterator recurses into nested
collection types.
Recursion follows these rules:
- When a collection type is found, that type is first returned as-is.
That is, if we’re iterating over an object, and within that object is
a field “foo” containing an array, then we first return
IterItem::KeyValue
, which contains the key “foo”, and the array as the value. - After returning the collection type, the iterator recurses into the
nested collection itself. Using the previous example, we now go into
the array, and start returning
IterItem::IndexValue
variants for the elements within the array. - Any mutations done to the array before recursing into it are preserved, meaning once recursion starts, the mutations done on the object itself are preserved.
§impl Value
impl Value
pub fn coerce_to_bytes(&self) -> Bytes
pub fn coerce_to_bytes(&self) -> Bytes
pub fn to_string_lossy(&self) -> Cow<'_, str>
pub fn to_string_lossy(&self) -> Cow<'_, str>
Converts self into a String
representation, using JSON for Map
/Array
.
§Panics
If map or array serialization fails.
§impl Value
impl Value
pub fn merge(&mut self, incoming: Value)
pub fn merge(&mut self, incoming: Value)
Merges incoming
value into self.
Will concatenate Bytes
and overwrite the rest value kinds.
pub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Return if the node is empty, that is, it is an array or map with no items.
use vrl::value::Value;
use std::collections::BTreeMap;
use vrl::path;
let val = Value::from(1);
assert_eq!(val.is_empty(), false);
let mut val = Value::from(Vec::<Value>::default());
assert_eq!(val.is_empty(), true);
val.insert(path!(0), 1);
assert_eq!(val.is_empty(), false);
val.insert(path!(3), 1);
assert_eq!(val.is_empty(), false);
let mut val = Value::from(BTreeMap::default());
assert_eq!(val.is_empty(), true);
val.insert(path!("foo"), 1);
assert_eq!(val.is_empty(), false);
val.insert(path!("bar"), 2);
assert_eq!(val.is_empty(), false);
pub fn insert<'a>(
&mut self,
path: impl ValuePath<'a>,
insert_value: impl Into<Value>,
) -> Option<Value>
pub fn insert<'a>( &mut self, path: impl ValuePath<'a>, insert_value: impl Into<Value>, ) -> Option<Value>
Returns a reference to a field value specified by a path iter.
pub fn remove<'a>(
&mut self,
path: impl ValuePath<'a>,
prune: bool,
) -> Option<Value>
pub fn remove<'a>( &mut self, path: impl ValuePath<'a>, prune: bool, ) -> Option<Value>
Removes field value specified by the given path and return its value.
A special case worth mentioning: if there is a nested array and an item is removed
from the middle of this array, then it is just replaced by Value::Null
.
pub fn get<'a>(&self, path: impl ValuePath<'a>) -> Option<&Value>
pub fn get<'a>(&self, path: impl ValuePath<'a>) -> Option<&Value>
Returns a reference to a field value specified by a path iter.
Trait Implementations§
§impl<'de> Deserialize<'de> for Value
impl<'de> Deserialize<'de> for Value
§fn deserialize<D>(
deserializer: D,
) -> Result<Value, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Value, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
source§impl EstimatedJsonEncodedSizeOf for Value
impl EstimatedJsonEncodedSizeOf for Value
fn estimated_json_encoded_size_of(&self) -> JsonSize
source§impl From<MetricKind> for Value
impl From<MetricKind> for Value
source§fn from(kind: MetricKind) -> Self
fn from(kind: MetricKind) -> Self
source§impl From<MetricSketch> for Value
impl From<MetricSketch> for Value
source§fn from(value: MetricSketch) -> Self
fn from(value: MetricSketch) -> Self
source§impl From<MetricValue> for Value
impl From<MetricValue> for Value
source§fn from(value: MetricValue) -> Self
fn from(value: MetricValue) -> Self
§impl FromIterator<(KeyString, Value)> for Value
impl FromIterator<(KeyString, Value)> for Value
§impl FromIterator<(String, Value)> for Value
impl FromIterator<(String, Value)> for Value
§impl FromIterator<Value> for Value
impl FromIterator<Value> for Value
§impl PartialOrd for Value
impl PartialOrd for Value
§impl SecretTarget for Value
impl SecretTarget for Value
fn get_secret(&self, _key: &str) -> Option<&str>
fn insert_secret(&mut self, _key: &str, _value: &str)
fn remove_secret(&mut self, _key: &str)
§impl Serialize for Value
impl Serialize for Value
§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
§impl Target for Value
impl Target for Value
§fn target_get(
&self,
target_path: &OwnedTargetPath,
) -> Result<Option<&Value>, String>
fn target_get( &self, target_path: &OwnedTargetPath, ) -> Result<Option<&Value>, String>
None
if no value is found. Read more§impl TryFrom<Expr> for Value
impl TryFrom<Expr> for Value
Converts from an Expr
into a Value
. This is only possible if the expression represents
static values - Literal
s and Container
s containing Literal
s.
The error returns the expression back so it can be used in the error report.
source§impl TryFrom<Value> for MetricKind
impl TryFrom<Value> for MetricKind
§impl VrlValueArithmetic for Value
impl VrlValueArithmetic for Value
§fn try_mul(self, rhs: Value) -> Result<Value, ValueError>
fn try_mul(self, rhs: Value) -> Result<Value, ValueError>
Similar to std::ops::Mul
, but fallible (e.g. TryMul
).
§fn try_div(self, rhs: Value) -> Result<Value, ValueError>
fn try_div(self, rhs: Value) -> Result<Value, ValueError>
Similar to std::ops::Div
, but fallible (e.g. TryDiv
).
§fn try_add(self, rhs: Value) -> Result<Value, ValueError>
fn try_add(self, rhs: Value) -> Result<Value, ValueError>
Similar to std::ops::Add
, but fallible (e.g. TryAdd
).
§fn try_sub(self, rhs: Value) -> Result<Value, ValueError>
fn try_sub(self, rhs: Value) -> Result<Value, ValueError>
Similar to std::ops::Sub
, but fallible (e.g. TrySub
).
§fn try_or(
self,
rhs: impl FnMut() -> Result<Value, ExpressionError>,
) -> Result<Value, ValueError>
fn try_or( self, rhs: impl FnMut() -> Result<Value, ExpressionError>, ) -> Result<Value, ValueError>
Try to “OR” (||
) two values types.
If the lhs value is null
or false
, the rhs is evaluated and
returned. The rhs is a closure that can return an error, and thus this
method can return an error as well.
§fn try_and(self, rhs: Value) -> Result<Value, ValueError>
fn try_and(self, rhs: Value) -> Result<Value, ValueError>
Try to “AND” (&&
) two values types.
A lhs or rhs value of Null
returns false
.
§fn try_rem(self, rhs: Value) -> Result<Value, ValueError>
fn try_rem(self, rhs: Value) -> Result<Value, ValueError>
Similar to std::ops::Rem
, but fallible (e.g. TryRem
).
§fn try_gt(self, rhs: Value) -> Result<Value, ValueError>
fn try_gt(self, rhs: Value) -> Result<Value, ValueError>
Similar to std::cmp::Ord
, but fallible (e.g. TryOrd
).
§fn try_ge(self, rhs: Value) -> Result<Value, ValueError>
fn try_ge(self, rhs: Value) -> Result<Value, ValueError>
Similar to std::cmp::Ord
, but fallible (e.g. TryOrd
).
§fn try_lt(self, rhs: Value) -> Result<Value, ValueError>
fn try_lt(self, rhs: Value) -> Result<Value, ValueError>
Similar to std::cmp::Ord
, but fallible (e.g. TryOrd
).
§fn try_le(self, rhs: Value) -> Result<Value, ValueError>
fn try_le(self, rhs: Value) -> Result<Value, ValueError>
Similar to std::cmp::Ord
, but fallible (e.g. TryOrd
).
§fn eq_lossy(&self, rhs: &Value) -> bool
fn eq_lossy(&self, rhs: &Value) -> bool
Similar to std::cmp::Eq
, but does a lossless comparison for integers
and floats.
fn try_merge(self, rhs: Value) -> Result<Value, ValueError>
§impl VrlValueConvert for Value
impl VrlValueConvert for Value
§fn into_expression(self) -> Box<dyn Expression>
fn into_expression(self) -> Box<dyn Expression>
Convert a given Value
into a [Expression
] trait object.
fn try_integer(self) -> Result<i64, ValueError>
fn try_into_i64(&self) -> Result<i64, ValueError>
fn try_float(self) -> Result<f64, ValueError>
fn try_into_f64(&self) -> Result<f64, ValueError>
fn try_bytes(self) -> Result<Bytes, ValueError>
fn try_bytes_utf8_lossy(&self) -> Result<Cow<'_, str>, ValueError>
fn try_boolean(self) -> Result<bool, ValueError>
fn try_regex(self) -> Result<ValueRegex, ValueError>
fn try_null(self) -> Result<(), ValueError>
fn try_array(self) -> Result<Vec<Value>, ValueError>
fn try_object(self) -> Result<BTreeMap<KeyString, Value>, ValueError>
fn try_timestamp(self) -> Result<DateTime<Utc>, ValueError>
impl Eq for Value
impl StructuralPartialEq for Value
Auto Trait Implementations§
impl !Freeze for Value
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnwindSafe for Value
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CallHasher for T
impl<T> CallHasher for T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
§fn deserialize(
&self,
deserializer: &mut D,
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> FromLuaMulti for Twhere
T: FromLua,
impl<T> FromLuaMulti for Twhere
T: FromLua,
§fn from_lua_multi(values: MultiValue, lua: &Lua) -> Result<T, Error>
fn from_lua_multi(values: MultiValue, lua: &Lua) -> Result<T, Error>
fn from_lua_args( args: MultiValue, i: usize, to: Option<&str>, lua: &Lua, ) -> Result<T, Error>
unsafe fn from_stack_multi(nvals: i32, lua: &RawLua) -> Result<T, Error>
unsafe fn from_stack_args( nargs: i32, i: usize, to: Option<&str>, lua: &RawLua, ) -> Result<T, Error>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoLuaMulti for Twhere
T: IntoLua,
impl<T> IntoLuaMulti for Twhere
T: IntoLua,
§fn into_lua_multi(self, lua: &Lua) -> Result<MultiValue, Error>
fn into_lua_multi(self, lua: &Lua) -> Result<MultiValue, Error>
unsafe fn push_into_stack_multi(self, lua: &RawLua) -> Result<i32, Error>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
§impl<Source, Target> OctetsInto<Target> for Sourcewhere
Target: OctetsFrom<Source>,
impl<Source, Target> OctetsInto<Target> for Sourcewhere
Target: OctetsFrom<Source>,
type Error = <Target as OctetsFrom<Source>>::Error
§fn try_octets_into(
self,
) -> Result<Target, <Source as OctetsInto<Target>>::Error>
fn try_octets_into( self, ) -> Result<Target, <Source as OctetsInto<Target>>::Error>
§fn octets_into(self) -> Targetwhere
Self::Error: Into<Infallible>,
fn octets_into(self) -> Targetwhere
Self::Error: Into<Infallible>,
§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg
] or
a color-specific method, such as [OwoColorize::green
], Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg
] or
a color-specific method, such as [OwoColorize::on_yellow
], Read more