Skip to main content

Crate mikrotik_rs

Crate mikrotik_rs 

Source
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 the tokio feature)
  • mikrotik-embassy — Embassy embedded async client (requires the embassy feature)

§Feature flags

FeatureDefaultDescription
stdyesUses std::collections::HashMap in public response types. Disable for no_std (falls back to hashbrown::HashMap).
tokioyesEnables the Tokio async adapter and MikrotikDevice client
embassynoEnables the Embassy embedded async adapter and run function
tokio-tlsnoEnables 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 drives mikrotik-proto using Tokio’s async runtime. Provides the high-level MikrotikDevice client.

  • mikrotik-embassy — Embedded async adapter that drives mikrotik-proto using Embassy’s networking stack. Provides a run function 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 from mikrotik_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 from mikrotik_proto. Macro that enforces MikroTik command syntax at compile time.

Structs§

Authenticated
A fully authenticated connection, ready for commands.
Command
A finalized command ready to be sent to the router.
CommandBuilder
Builds MikroTik router commands using a fluent typestate API.
Connection
The sans-IO connection state machine for the MikroTik API protocol.
DeviceBuilder
A typestate builder for establishing connections to MikroTik devices.
DoneResponse
Represents a successful command completion response.
EmptyResponse
Represents an empty response (RouterOS 7.18+).
Handshaking
A connection that has not yet authenticated.
HashMap
A hash map implemented with quadratic probing and SIMD lookup.
MikrotikDevice
A client for interacting with MikroTik devices.
Plaintext
Plaintext TCP transport — carries no additional configuration.
ReplyResponse
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.
TrapResponse
Represents an error or warning while executing a command.

Enums§

ActorError
Errors related to the device connection actor being unavailable.
CommandResponse
Various types of responses a command can produce.
ConnectionError
Errors from the Connection state machine.
DeviceError
Custom error type for MikroTik device operations.
Event
Application-facing events produced by the connection state machine.
LoginError
Errors from the login handshake process.
LoginProgress
Result of checking login progress.
ProtocolError
Errors that can occur while parsing a CommandResponse from a decoded sentence.
QueryOperator
Represents a query operator for MikroTik API query expressions.
State
Connection state.
TrapCategory
Categories for TrapResponse, defining the nature of the error.

Type Aliases§

DeviceResult
Result type alias for MikroTik device operations.
FatalResponse
Type alias for a fatal response message.