Skip to main content

Crate mabi_core

Crate mabi_core 

Source
Expand description

§trap-sim-core

Core abstractions and utilities for the TRAP protocol simulator.

This crate provides:

  • Device trait and abstractions
  • Data point types and value representations
  • Simulator engine for managing virtual devices
  • Metrics collection and export
  • Configuration management with hot reload support
  • Structured logging and tracing
  • Common utilities and helper functions

§Quick Start

Use the prelude module for convenient imports:

use mabi_core::prelude::*;

#[tokio::main]
async fn main() -> Result<()> {
    // Initialize logging
    init_logging(&LogConfig::development())?;

    // Create and start the engine
    let config = EngineConfig::default();
    let engine = SimulatorEngine::new(config);
    engine.start().await?;

    Ok(())
}

§Module Overview

  • config: Configuration types and hot reload support
  • [device]: Device trait and device management
  • engine: Simulator engine for orchestrating devices
  • error: Error types and result aliases
  • factory: Device factory pattern for extensibility
  • logging: Structured logging and tracing setup
  • metrics: Prometheus metrics collection
  • protocol: Protocol definitions (Modbus, OPC UA, BACnet, KNX)
  • types: Data point types and addresses
  • utils: Utility functions and helper macros
  • value: Dynamic value types
  • prelude: Convenient re-exports for glob imports

§Example

use mabi_core::{SimulatorEngine, EngineConfig, Protocol};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = EngineConfig::default();
    let engine = SimulatorEngine::new(config);

    engine.start().await?;
    Ok(())
}

Re-exports§

pub use error::Error;
pub use error::ErrorSeverity;
pub use error::Result;
pub use error::ResultExt;
pub use error::ValidationErrors;
pub use error::ValidationErrorsBuilder;
pub use protocol::Protocol;
pub use value::Value;
pub use config::DeviceConfig;
pub use config::EngineConfig;
pub use config::ConfigFormat;
pub use config::ConfigLoader;
pub use config::ConfigDiscovery;
pub use config::EnvOverrides;
pub use config::EnvConfigurable;
pub use config::EnvApplyResult;
pub use config::Validatable;
pub use config::Validator;
pub use config::ValidationContext;
pub use config::ConfigEvent;
pub use config::ConfigSource;
pub use config::ConfigWatcher;
pub use config::SharedConfigWatcher;
pub use config::WatcherState;
pub use config::FileWatcherService;
pub use config::FileWatcherConfig;
pub use config::HotReloadManager;
pub use config::ReloadStrategy;
pub use config::ReloadEvent;
pub use device::Device;
pub use device::DeviceInfo;
pub use device::DeviceState;
pub use tags::Tags;
pub use tags::TagsBuilder;
pub use tags::Taggable;
pub use tags::parse_tag_string;
pub use tags::parse_tags;
pub use engine::EnginePreset;
pub use engine::SimulatorEngine;
pub use engine::SimulatorEngineBuilder;
pub use factory::DeviceFactory;
pub use factory::FactoryRegistry;
pub use factory::Plugin;
pub use factory::PluginManager;
pub use metrics::MetricsCollector;
pub use types::DataPoint;
pub use types::DataPointId;
pub use types::Quality;
pub use logging::init_logging;
pub use logging::init_test_logging;
pub use logging::is_logging_initialized;
pub use logging::LogConfig;
pub use logging::LogConfigBuilder;
pub use logging::LogLevel;
pub use logging::LogFormat;
pub use logging::LogTarget;
pub use logging::RotationConfig;
pub use logging::RotationStrategy;
pub use logging::RetentionPolicy;
pub use logging::LogFileStats;
pub use logging::LogLevelController;
pub use logging::DebugModeGuard;
pub use logging::ModuleTraceGuard;
pub use logging::TraceContext;
pub use logging::RequestContext;
pub use logging::DeviceContext;
pub use logging::SharedTraceContext;
pub use logging::shared_context;
pub use capabilities::Capability;
pub use capabilities::CapabilitySet;
pub use capabilities::CapabilitySetBuilder;
pub use capabilities::ProtocolCapabilities;
pub use lifecycle::DeviceLifecycle;
pub use lifecycle::LifecycleEvent;
pub use lifecycle::LifecycleStateMachine;
pub use lifecycle::StopReason;
pub use device_builder::device;
pub use device_builder::point;
pub use device_builder::DataPointBuilder;
pub use device_builder::DeviceConfigBuilder;
pub use typed_point::BoolPoint;
pub use typed_point::DataPointType;
pub use typed_point::Float32Point;
pub use typed_point::Float64Point;
pub use typed_point::FromDefinition;
pub use typed_point::Int32Point;
pub use typed_point::Int64Point;
pub use typed_point::StringPoint;
pub use typed_point::TypedDataPoint;
pub use typed_point::TypedPointValue;
pub use typed_point::UInt32Point;
pub use typed_point::UInt64Point;
pub use profiling::Profiler;
pub use profiling::ProfilerConfig;
pub use profiling::ProfileReport;
pub use profiling::MemoryProfiler;
pub use profiling::MemoryProfilerConfig;
pub use profiling::MemorySnapshot;
pub use profiling::MemoryReport;
pub use profiling::RegionSnapshot;
pub use profiling::LeakDetector;
pub use profiling::LeakDetectorConfig;
pub use profiling::LeakWarning;
pub use profiling::LeakSeverity;
pub use profiling::RegionAnalysis;
pub use profiling::ReportExporter;
pub use profiling::ReportFormat;
pub use profiling::ReportComparison;
pub use profiling::MemoryReportBuilder;
pub use simulation::Simulator;
pub use simulation::SimulationConfig;
pub use simulation::SimulationPhase;
pub use simulation::SimulationEvent;
pub use simulation::SimulationMetrics;
pub use simulation::SimulationResult;
pub use simulation::ScaleConfig;
pub use simulation::MemoryPattern;
pub use simulation::CustomMemoryPattern;
pub use simulation::SawtoothPattern;
pub use simulation::SteppedPattern;
pub use simulation::BurstPattern;
pub use simulation::LeakPattern;
pub use simulation::FailureConfig;
pub use simulation::FailureType;
pub use simulation::FailureSchedule;
pub use simulation::ScheduledFailure;
pub use simulation::FailureInjector;
pub use simulation::LoadPattern;
pub use simulation::LoadPatternBuilder;
pub use simulation::Scenario;
pub use simulation::ScenarioBuilder;
pub use simulation::ScenarioSuite;

Modules§

capabilities
Protocol capabilities and feature detection.
config
Configuration types and hot reload support.
device
Device trait and related types.
device_builder
Device builder pattern for fluent device construction.
engine
Simulator engine - orchestrates all devices and protocols.
error
Error types for the simulator.
factory
Device factory and plugin system for extensibility.
lifecycle
Device lifecycle management traits and types.
logging
Logging and tracing infrastructure.
metrics
Metrics collection and export.
prelude
Prelude module for convenient imports.
profiling
Memory and performance profiling module.
protocol
Protocol definitions.
simulation
Simulation framework for comprehensive testing scenarios.
tags
Device tagging system.
typed_point
Type-safe data point handling.
types
Core types for data points and addresses.
utils
Common utilities and helper functions.
value
Value types for data points.

Macros§

builder_setter
Implement a builder pattern setter method.
builder_setter_into
Implement a builder pattern setter method that takes impl Into.
builder_setter_option
Implement a builder pattern setter method for Option.
builder_with
Implement a builder pattern with_* prefix setter method.
measure_request
Measure request duration and record to metrics.
record_error
Record an error with context.
trace_connection
Log a connection event.
trace_device
Create a span for tracing device operations.
trace_enter
Log entering a critical section or important function.
trace_error
Log a failed operation with error details.
trace_exit
Log exiting a critical section or important function.
trace_message
Create a span for protocol message handling.
trace_metric
Log a metric observation.
trace_request
Create a span for tracing protocol requests.
trace_state_change
Log a state change with before/after values.
trace_success
Log a successful operation with timing.
trace_tick
Create a span for engine tick processing.
validate
Macro to simplify validation checks.