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 deviceserror: Error types and result aliasesfactory: Device factory pattern for extensibilitylogging: Structured logging and tracing setupmetrics: Prometheus metrics collectionprotocol: Protocol definitions (Modbus, OPC UA, BACnet, KNX)types: Data point types and addressesutils: Utility functions and helper macrosvalue: Dynamic value typesprelude: 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::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 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 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.