Expand description
§MikroTik-rs
mikrotik-rs is a Rust library for interfacing with MikroTik routers via
the RouterOS API protocol. It allows sending commands and receiving responses
in parallel through channels.
This crate re-exports types from:
mikrotik-proto— sans-IO protocol implementation (always available)mikrotik-tokio— Tokio-based async client (requires thetokiofeature)mikrotik-embassy— Embassy embedded async client (requires theembassyfeature)
§Feature flags
| Feature | Default | Description |
|---|---|---|
std | yes | Uses std::collections::HashMap in public response types. Disable for no_std (falls back to hashbrown::HashMap). |
tokio | yes | Enables the Tokio async adapter and MikrotikDevice client |
embassy | no | Enables the Embassy embedded async adapter and run function |
tokio-tls | no | Enables TLS support via tokio-rustls (bring your own crypto provider) |
To use only the protocol types without pulling in any runtime:
[dependencies]
mikrotik-rs = { version = "0.7", default-features = false }To use the Embassy adapter instead of Tokio:
[dependencies]
mikrotik-rs = { version = "0.7", default-features = false, features = ["embassy"] }To enable TLS (e.g., for API-SSL on port 8729):
[dependencies]
mikrotik-rs = { version = "0.7", features = ["tokio-tls"] }
rustls = { version = "0.23", features = ["ring"] } # or "aws-lc-rs"§Architecture
The library is split into multiple crates:
-
mikrotik-proto—#![no_std]-compatible, runtime-agnostic protocol core. Handles wire-format encoding/decoding, command building, response parsing, and the connection state machine. Performs no I/O. -
mikrotik-tokio— Thin async adapter that drivesmikrotik-protousing Tokio’s async runtime. Provides the high-levelMikrotikDeviceclient. -
mikrotik-embassy— Embedded async adapter that drivesmikrotik-protousing Embassy’s networking stack. Provides arunfunction that the user spawns as an Embassy task. -
mikrotik-rs(this crate) — Convenience re-exports from all crates.
§Examples
use mikrotik_rs::{MikrotikDevice, CommandBuilder};
let device = MikrotikDevice::connect("192.168.88.1:8728", "admin", Some("password")).await?;
let cmd = CommandBuilder::new().command("/interface/print").build();
let mut rx = device.send_command(cmd).await?;
while let Some(event) = rx.recv().await {
println!("{event:?}");
}Re-exports§
pub use mikrotik_proto as proto;pub use mikrotik_tokio as tokio_client;
Modules§
- command
- Re-export the
command!macro frommikrotik_proto. Command builder with typestate pattern and compile-time validation. Command builder with typestate pattern and compile-time validation.
Macros§
- command
- Re-export the
command!macro frommikrotik_proto. Macro that enforcesMikroTikcommand syntax at compile time.
Structs§
- Authenticated
- A fully authenticated connection, ready for commands.
- Command
- A finalized command ready to be sent to the router.
- Command
Builder - Builds
MikroTikrouter commands using a fluent typestate API. - Connection
- The sans-IO connection state machine for the
MikroTikAPI protocol. - Device
Builder - A typestate builder for establishing connections to
MikroTikdevices. - Done
Response - Represents a successful command completion response.
- Empty
Response - Represents an empty response (
RouterOS7.18+). - Handshaking
- A connection that has not yet authenticated.
- HashMap
- A hash map implemented with quadratic probing and SIMD lookup.
- Mikrotik
Device - A client for interacting with
MikroTikdevices. - Plaintext
- Plaintext TCP transport — carries no additional configuration.
- Reply
Response - Represents a reply to a command, including a tag and multiple attributes.
- Tag
- A unique tag identifying a command for response correlation.
- Transmit
- Outbound data that must be sent to the remote device.
- Trap
Response - Represents an error or warning while executing a command.
Enums§
- Actor
Error - Errors related to the device connection actor being unavailable.
- Command
Response - Various types of responses a command can produce.
- Connection
Error - Errors from the
Connectionstate machine. - Device
Error - Custom error type for
MikroTikdevice operations. - Event
- Application-facing events produced by the connection state machine.
- Login
Error - Errors from the login handshake process.
- Login
Progress - Result of checking login progress.
- Protocol
Error - Errors that can occur while parsing a
CommandResponsefrom a decoded sentence. - Query
Operator - Represents a query operator for
MikroTikAPI query expressions. - State
- Connection state.
- Trap
Category - Categories for
TrapResponse, defining the nature of the error.
Type Aliases§
- Device
Result - Result type alias for
MikroTikdevice operations. - Fatal
Response - Type alias for a fatal response message.