Builder

Struct Builder 

pub struct Builder<PID, EXP, TIME, THREAD> {
    process_id: Option<ProcessId>,
    exporter: Option<&'static (dyn Export + Sync)>,
    timestamp_fn: Option<fn() -> u64>,
    thread_id_fn: Option<fn() -> NonZero<u64>>,
    _pid: PhantomData<PID>,
    _exp: PhantomData<EXP>,
    _time: PhantomData<TIME>,
    _thread: PhantomData<THREAD>,
}
Expand description

Builder for initializing the telemetry collector.

Uses type-state pattern to ensure all required components are configured at compile time. Created via build() and finalized with set_global().

Fields§

§process_id: Option<ProcessId>§exporter: Option<&'static (dyn Export + Sync)>§timestamp_fn: Option<fn() -> u64>§thread_id_fn: Option<fn() -> NonZero<u64>>§_pid: PhantomData<PID>§_exp: PhantomData<EXP>§_time: PhantomData<TIME>§_thread: PhantomData<THREAD>

Implementations§

§

impl<PID, EXP, TIME, THREAD> Builder<PID, EXP, TIME, THREAD>

pub fn process_id( self, process_id: ProcessId, ) -> Builder<WithProcessId, EXP, TIME, THREAD>

Sets the process id for this collector instance.

pub fn exporter( self, exporter: &'static (dyn Export + Sync), ) -> Builder<PID, WithExporter, TIME, THREAD>

Sets the exporter for telemetry data.

pub fn time<T>(self) -> Builder<PID, EXP, WithTime, THREAD>
where T: TimeAbstraction,

Configures the time abstraction to use (monotonic time only).

pub fn system_time<T>(self) -> Builder<PID, EXP, WithTime, THREAD>

Configures the time abstraction with system time to use (Unix epoch synchronization).

pub fn thread<Th>(self) -> Builder<PID, EXP, TIME, WithThread>

Configures the thread abstraction to use.

§

impl<EXP, TIME, THREAD> Builder<NoProcessId, EXP, TIME, THREAD>

pub fn random_process_id(self) -> Builder<WithProcessId, EXP, TIME, THREAD>

Available on crate feature std only.

Sets a randomly generated process id.

Equivalent to .process_id(ProcessId::random(&mut rand::rng())).

§Examples
use veecle_osal_std::{time::Time, thread::Thread};
use veecle_telemetry::collector;

collector::build()
    .random_process_id()
    .exporter(exporter)
    .time::<Time>()
    .thread::<Thread>()
    .set_global().unwrap();
§

impl<PID, TIME, THREAD> Builder<PID, NoExporter, TIME, THREAD>

pub fn leaked_exporter( self, exporter: impl Export + Sync + 'static, ) -> Builder<PID, WithExporter, TIME, THREAD>

Available on crate feature alloc only.

Sets the given exporter by leaking it to obtain a static reference.

This is a convenience method for dynamic exporters that need to be boxed and leaked. Equivalent to .exporter(Box::leak(Box::new(exporter))).

§Examples
use veecle_osal_std::{time::Time, thread::Thread};
use veecle_telemetry::collector::TestExporter;

let (exporter, _collected) = TestExporter::new();
veecle_telemetry::collector::build()
    .random_process_id()
    .leaked_exporter(exporter)
    .time::<Time>()
    .thread::<Thread>()
    .set_global().unwrap();

pub fn console_json_exporter(self) -> Builder<PID, WithExporter, TIME, THREAD>

Available on crate feature std only.

Sets the exporter to be the ConsoleJsonExporter.

Equivalent to .exporter(&ConsoleJsonExporter::DEFAULT).

§Examples
use veecle_osal_std::{time::Time, thread::Thread};
use veecle_telemetry::collector;

collector::build()
    .random_process_id()
    .console_json_exporter()
    .time::<Time>()
    .thread::<Thread>()
    .set_global().unwrap();
§

impl Builder<WithProcessId, WithExporter, WithTime, WithThread>

pub fn build(self) -> Collector

Builds this configuration into a Collector instance.

pub fn set_global(self) -> Result<(), SetGlobalError>

Sets this collector as the global collector instance.

This can only be called once per process.

Trait Implementations§

§

impl<PID, EXP, TIME, THREAD> Debug for Builder<PID, EXP, TIME, THREAD>
where PID: Debug, EXP: Debug, TIME: Debug, THREAD: Debug,

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<PID, EXP, TIME, THREAD> Freeze for Builder<PID, EXP, TIME, THREAD>

§

impl<PID, EXP, TIME, THREAD> !RefUnwindSafe for Builder<PID, EXP, TIME, THREAD>

§

impl<PID, EXP, TIME, THREAD> Send for Builder<PID, EXP, TIME, THREAD>
where PID: Send, EXP: Send, TIME: Send, THREAD: Send,

§

impl<PID, EXP, TIME, THREAD> Sync for Builder<PID, EXP, TIME, THREAD>
where PID: Sync, EXP: Sync, TIME: Sync, THREAD: Sync,

§

impl<PID, EXP, TIME, THREAD> Unpin for Builder<PID, EXP, TIME, THREAD>
where PID: Unpin, EXP: Unpin, TIME: Unpin, THREAD: Unpin,

§

impl<PID, EXP, TIME, THREAD> !UnwindSafe for Builder<PID, EXP, TIME, THREAD>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V