CommandBuilder

Struct CommandBuilder 

Source
pub struct CommandBuilder<Cmd> { /* private fields */ }
Expand description

Builds MikroTik router commands using a fluid API.

Ensures that only commands with at least one operation can be built and sent.

§Examples

let cmd = CommandBuilder::new()
    .command("/system/resource/print")
    .attribute("detail", None)
    .build();

Implementations§

Source§

impl CommandBuilder<NoCmd>

Source

pub fn new() -> Self

Begin building a new Command with a randomly generated tag.

Source

pub fn with_tag(tag: u16) -> Self

Begin building a new Command with a specified tag.

§Arguments
  • tag - A u16 tag value that identifies the command for RouterOS correlation. Must be unique.
§Examples
let builder = CommandBuilder::with_tag(1234);
Source

pub fn login(username: &str, password: Option<&str>) -> Command

Builds a login command with the provided username and optional password.

§Arguments
  • username - The username for the login command.
  • password - An optional password for the login command.
§Returns

A Command which represents the login operation.

§Examples
let login_cmd = CommandBuilder::login("admin", Some("password"));
Source

pub fn cancel(tag: u16) -> Command

Builds a command to cancel a specific running command identified by tag.

§Arguments
  • tag - The tag of the command to be canceled.
§Returns

A Command which represents the cancel operation.

§Examples
let cancel_cmd = CommandBuilder::cancel(1234);
Source

pub fn command(self, command: &str) -> CommandBuilder<Cmd>

Specify the command to be executed.

§Arguments
  • command - The MikroTik command to execute.
§Returns

The builder transitioned to the Cmd state for attributes configuration.

Source§

impl CommandBuilder<Cmd>

Source

pub fn attribute(self, key: &str, value: Option<&str>) -> Self

Adds an attribute to the command being built.

§Arguments
  • key - The attribute’s key.
  • value - The attribute’s value, which is optional. If None, the attribute is treated as a flag (e.g., =key=).
§Returns

The builder with the attribute added, allowing for method chaining.

Source

pub fn attribute_raw(self, key: &str, value: Option<&[u8]>) -> Self

Adds an attribute with a raw byte value to the command being built.

Use this method when your attribute values might contain non-UTF-8 or binary data. For regular string values, CommandBuilder<Cmd>::attribute provides a more convenient interface.

§Arguments
  • key - The attribute’s key (must be valid UTF-8).
  • value - The attribute’s value as raw bytes, which is optional. If None, the attribute is treated as a flag.
§Returns

The builder with the attribute added, allowing for method chaining.

Source

pub fn query_is_present(self, name: &str) -> Self

Adds a query to the command being built. pushes ‘true’ if an item has a value of property name, ‘false’ if it does not.

#Arguments

  • name: name of the property to check
§Returns

The builder with the attribute added, allowing for method chaining.

Source

pub fn query_not_present(self, name: &str) -> Self

Adds a query to the command being built. pushes ‘true’ if an item has a value of property name, ‘false’ if it does not.

#Arguments

  • name: name of the property to check
§Returns

The builder with the attribute added, allowing for method chaining.

Source

pub fn query_equal(self, name: &str, value: &str) -> Self

Adds a query to the command being built. pushes ‘true’ if the property name has a value equal to x, ‘false’ otherwise.

#Arguments

  • name: name of the property to compare
  • value: value to be compared with
§Returns

The builder with the attribute added, allowing for method chaining.

Source

pub fn query_gt(self, key: &str, value: &str) -> Self

Adds a query to the command being built. pushes ‘true’ if the property name has a value greater than x, ‘false’ otherwise.

#Arguments

  • name: name of the property to compare
  • value: value to be compared with
§Returns

The builder with the attribute added, allowing for method chaining.

Source

pub fn query_lt(self, key: &str, value: &str) -> Self

Adds a query to the command being built. pushes ‘true’ if the property name has a value less than x, ‘false’ otherwise.

#Arguments

  • name: name of the property to compare
  • value: value to be compared with
§Returns

The builder with the attribute added, allowing for method chaining.

Source

pub fn query_operations( self, operations: impl Iterator<Item = QueryOperator>, ) -> Self

defines combination of defined operations https://help.mikrotik.com/docs/spaces/ROS/pages/47579160/API#API-Queries #Arguments

  • operations: operation sequence to be applied to the results on the stack
§Returns

The builder with the attribute added, allowing for method chaining.

Source

pub fn build(self) -> Command

Finalizes the command construction process, producing a Command.

§Returns

A Command instance ready for execution.

Trait Implementations§

Source§

impl<Cmd: Clone> Clone for CommandBuilder<Cmd>

Source§

fn clone(&self) -> CommandBuilder<Cmd>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for CommandBuilder<NoCmd>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<Cmd> Freeze for CommandBuilder<Cmd>

§

impl<Cmd> RefUnwindSafe for CommandBuilder<Cmd>
where Cmd: RefUnwindSafe,

§

impl<Cmd> Send for CommandBuilder<Cmd>
where Cmd: Send,

§

impl<Cmd> Sync for CommandBuilder<Cmd>
where Cmd: Sync,

§

impl<Cmd> Unpin for CommandBuilder<Cmd>
where Cmd: Unpin,

§

impl<Cmd> UnwindSafe for CommandBuilder<Cmd>
where Cmd: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.