Giter VIP home page Giter VIP logo

mikrotik-rs's Introduction

mikrotik-rs ๐Ÿ“Ÿ

docs.rs Crates.io Crates.io License Libraries.io dependency status for latest release Crates.io Total Downloads GitHub Repo stars

This Rust library provides an asynchronous interface to interact with the Mikrotik API.

Features ๐ŸŒŸ

  • No Unsafe Code ๐Ÿ’ฅ: Built entirely in safe Rust ๐Ÿฆ€
  • Zero-copy Parsing: Avoid unnecessary memory allocations by parsing the API responses in-place.
  • Concurrent Commands ๐Ÿšฆ: Supports running multiple Mikrotik commands concurrently, with each command and its response managed via dedicated channels.
  • Error Handling โš ๏ธ: Designed with error handling in mind, ensuring that network or parsing errors are gracefully handled and reported back to the caller.

Getting Started ๐Ÿš€

To use this library in your project, run the following command in your project's directory:

cargo add mikrotik-rs

Alternatively, you can add the library to your Cargo.toml file manually:

[dependencies]
mikrotik-rs = "0.3.1"
tokio = { version = "1", features = ["full"] }

Ensure you have Tokio set up in your project as the library relies on the Tokio runtime.

Basic Usage ๐Ÿ“–

use mikrotik_rs::{command::CommandBuilder, MikrotikDevice};
use tokio;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize the MikrotikClient ๐Ÿค– with the router's address and access credentials
    let device = MikrotikDevice::connect("192.168.122.144:8728", "admin", Some("admin")).await?;

    // Execute a command ๐Ÿ“
    let system_resource_cmd = CommandBuilder::new()
        .command("/system/resource/print")
        // Send the update response every 1 second
        .attribute("interval", Some("1"))
        .build();

    // Send the command to the device ๐Ÿ“ก
    // Returns a channel to listen for the command's response(s)
    let response_channel = device.send_command(system_resource_cmd).await;

    // Listen for the command's response ๐Ÿ”Š
    while let Some(res) = response_channel.recv().await {
        println!(">> Get System Res Response {:?}", res);
    }

    Ok(())
}

Documentation ๐Ÿ“š

For more detailed information on the library's API, please refer to the documentation.

Contributing ๐Ÿค

Contributions are welcome! Whether it's submitting a bug report ๐Ÿ›, a feature request ๐Ÿ’ก, or a pull request ๐Ÿ”„, all contributions help improve this library. Before contributing, please read through the CONTRIBUTING.md file for guidelines.

License ๐Ÿ“

This project is licensed under the MIT License - see the LICENSE file for details.

Disclaimer ๐Ÿšซ

This library is not officially associated with Mikrotik. It is developed as an open-source project to facilitate Rust-based applications interacting with Mikrotik devices.

mikrotik-rs's People

Contributors

ferrohd avatar

Stargazers

Matt avatar Mastro avatar

Watchers

 avatar

Forkers

molenick

mikrotik-rs's Issues

feat: Make the library runtime-agnostic

Issue

The library's current dependency on tokio seems excessive for its requirements, manifesting in the following areas:

  1. Utilizing mpsc channels for actor message passing.
  2. Establishing connections to Mikrotik devices with TcpStream.
  3. Handling asynchronous I/O operations through AsyncRead/AsyncWrite traits.

The proposed shift away from tokio is motivated by the mismatch between the library's task complexity and the heavyweight nature of tokio.

Proposed solutions

Considering the library's scoped functionalities, migrating from tokio to more lightweight alternatives could be beneficial. The following approaches are recommended, drawing from crates in the smol runtime ecosystem:

  1. Explore the use of async-channel as a substitute for tokio::mpsc channels.
  2. Leverage async-net for networking primitives, facilitating connections to Mikrotik devices without the bulk of tokio.
  3. Implement async-io for concurrent IO operations.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

cargo
Cargo.toml
  • getrandom 0.2.12
  • tokio 1.36.0
github-actions
.github/workflows/pr-checks.yml
  • actions/checkout v4
  • actions/checkout v4
  • actions/checkout v4
  • actions/checkout v4
.github/workflows/release.yml
  • actions/checkout v4
  • actions/checkout v4
  • softprops/action-gh-release v2

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.