vector_common/
lib.rs

1//! The Vector Core common library
2//!
3//! This library includes common functionality relied upon by vector-core
4//! and core-related crates (e.g. buffers).
5
6#![deny(warnings)]
7#![deny(clippy::all)]
8#![deny(clippy::pedantic)]
9#![deny(unreachable_pub)]
10#![deny(unused_allocation)]
11#![deny(unused_extern_crates)]
12#![deny(unused_assignments)]
13#![deny(unused_comparisons)]
14
15pub use vector_common_macros::NamedInternalEvent;
16
17#[cfg(feature = "btreemap")]
18pub use vrl::btreemap;
19
20#[cfg(feature = "byte_size_of")]
21pub mod byte_size_of;
22
23pub mod json_size;
24
25pub mod config;
26
27pub mod constants;
28
29#[cfg(feature = "conversion")]
30pub use vrl::compiler::TimeZone;
31
32#[cfg(feature = "encoding")]
33pub mod encode_logfmt {
34    pub use vrl::core::encode_logfmt::*;
35}
36
37pub mod conversion {
38    pub use vrl::compiler::conversion::*;
39}
40
41pub mod event_data_eq;
42pub use event_data_eq::EventDataEq;
43
44#[cfg(any(test, feature = "test"))]
45pub mod event_test_util;
46
47pub mod finalization;
48pub mod finalizer;
49pub use finalizer::EmptyStream;
50
51pub mod id;
52
53pub mod internal_event;
54
55pub mod request_metadata;
56
57pub mod shutdown;
58
59#[cfg(feature = "sensitive_string")]
60pub mod sensitive_string;
61
62pub mod atomic;
63pub mod stats;
64pub mod trigger;
65
66#[macro_use]
67extern crate tracing;
68
69/// Typed wrapper around `metrics::counter!` that only accepts [`internal_event::CounterName`].
70#[macro_export]
71macro_rules! counter {
72    ($name:expr) => {{
73        let _name: $crate::internal_event::CounterName = $name;
74        #[allow(clippy::disallowed_macros)]
75        {
76            metrics::counter!(_name.as_str())
77        }
78    }};
79    ($name:expr, $($rest:tt)*) => {{
80        let _name: $crate::internal_event::CounterName = $name;
81        #[allow(clippy::disallowed_macros)]
82        {
83            metrics::counter!(_name.as_str(), $($rest)*)
84        }
85    }};
86}
87
88/// Typed wrapper around `metrics::histogram!` that only accepts [`internal_event::HistogramName`].
89#[macro_export]
90macro_rules! histogram {
91    ($name:expr) => {{
92        let _name: $crate::internal_event::HistogramName = $name;
93        #[allow(clippy::disallowed_macros)]
94        {
95            metrics::histogram!(_name.as_str())
96        }
97    }};
98    ($name:expr, $($rest:tt)*) => {{
99        let _name: $crate::internal_event::HistogramName = $name;
100        #[allow(clippy::disallowed_macros)]
101        {
102            metrics::histogram!(_name.as_str(), $($rest)*)
103        }
104    }};
105}
106
107/// Typed wrapper around `metrics::gauge!` that only accepts [`internal_event::GaugeName`].
108#[macro_export]
109macro_rules! gauge {
110    ($name:expr) => {{
111        let _name: $crate::internal_event::GaugeName = $name;
112        #[allow(clippy::disallowed_macros)]
113        {
114            metrics::gauge!(_name.as_str())
115        }
116    }};
117    ($name:expr, $($rest:tt)*) => {{
118        let _name: $crate::internal_event::GaugeName = $name;
119        #[allow(clippy::disallowed_macros)]
120        {
121            metrics::gauge!(_name.as_str(), $($rest)*)
122        }
123    }};
124}
125
126/// Vector's basic error type, dynamically dispatched and safe to send across
127/// threads.
128pub type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
129
130/// Vector's basic result type, defined in terms of [`Error`] and generic over
131/// `T`.
132pub type Result<T> = std::result::Result<T, Error>;