Skip to main content

MockSourceBuilder

Struct MockSourceBuilder 

Source
pub struct MockSourceBuilder { /* private fields */ }
Expand description

Builder for MockSource instances.

Provides a fluent API for constructing mock sources with sensible defaults. This is the recommended way to create a MockSource.

§Defaults

OptionDefault
data_typeDataType::Generic
interval_ms5000
dispatch_modeChannel
dispatch_buffer_capacity1000
auto_starttrue

§Example

use drasi_source_mock::{MockSource, DataType};

let source = MockSource::builder("my-source")
    .with_data_type(DataType::sensor_reading(10))
    .with_interval_ms(1000)
    .with_auto_start(false)  // Don't start automatically
    .build()?;

Implementations§

Source§

impl MockSourceBuilder

Source

pub fn new(id: impl Into<String>) -> Self

Create a new builder with the given source ID.

§Arguments
  • id - Unique identifier for the source instance
Source

pub fn with_data_type(self, data_type: DataType) -> Self

Set the data type to generate.

§Arguments
  • data_type - One of: DataType::Counter, DataType::SensorReading { sensor_count }, or DataType::Generic (default)

For SensorReading, use DataType::sensor_reading(count) helper method.

Source

pub fn with_interval_ms(self, interval_ms: u64) -> Self

Set the generation interval in milliseconds.

§Arguments
  • interval_ms - Interval between data generation (default: 5000)
Source

pub fn with_dispatch_mode(self, mode: DispatchMode) -> Self

Set the dispatch mode for event routing.

§Arguments
  • mode - Channel (default, with backpressure) or Broadcast
Source

pub fn with_dispatch_buffer_capacity(self, capacity: usize) -> Self

Set the dispatch buffer capacity.

§Arguments
  • capacity - Buffer size for dispatch channels (default: 1000)
Source

pub fn with_bootstrap_provider( self, provider: impl BootstrapProvider + 'static, ) -> Self

Set the bootstrap provider for initial data delivery.

§Arguments
  • provider - Bootstrap provider implementation
Source

pub fn with_auto_start(self, auto_start: bool) -> Self

Set whether this source should auto-start when DrasiLib starts.

Default is true. Set to false if this source should only be started manually via start_source().

Source

pub fn build(self) -> Result<MockSource>

Build the MockSource instance.

§Returns

A fully constructed MockSource, or an error if construction fails.

§Errors

Returns an error if:

  • The base source cannot be initialized
  • The configuration is invalid (e.g., interval_ms is 0, sensor_count is 0)

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more