asic_rs/
lib.rs

1//! asic-rs is a miner management and control library, designed to abstract away the complexity of working with different types of ASIC miners.
2//! # Getting Started
3//! The first step to controlling a miner with asic-rs is to get the struct that represents it, with methods used for data gathering and control.
4//!
5//! ### Getting a miner
6//! If you know the IP address of your miner, it is fairly easy to discover it.  Use the [`MinerFactory`] to select the correct type.
7//! ```no_run
8//! use asic_rs::MinerFactory;
9//! use std::str::FromStr;
10//! use std::net::IpAddr;
11//! use tokio;
12//!
13//! #[tokio::main]
14//! async fn main() {
15//!     let factory = MinerFactory::new();
16//!     let ip = IpAddr::from_str("192.168.1.10").unwrap();
17//!     let miner = factory.get_miner(ip).await.unwrap();
18//!     // now we can do data gathering or control
19//! }
20//! ```
21//!
22//! ### Miner discovery
23//! If you don't know the specific IP of your miner, asic-rs can discover it on your network.
24//! ```no_run
25//! use asic_rs::MinerFactory;
26//! use std::str::FromStr;
27//! use tokio;
28//!
29//! #[tokio::main]
30//! async fn main() {
31//!     let subnet = "192.168.1.0/24";
32//!     let factory = MinerFactory::from_subnet(subnet).unwrap();
33//!     let miners = factory.scan().await.unwrap();
34//! }
35//! ```
36//!
37//! There are other ways to define a discovery range to be scanned, such as:
38//!
39//! - Octets
40//! ```no_run
41//! # use asic_rs::MinerFactory;
42//! # use std::str::FromStr;
43//! # use tokio;
44//! # #[tokio::main]
45//! # async fn main() {
46//! #     let subnet = "192.168.1.0/24";
47//!     let factory = MinerFactory::from_octets("192", "168", "1", "1-255").unwrap();
48//! #     let miners = factory.scan().await.unwrap();
49//! # }
50//! ```
51//! - Range string
52//! ```no_run
53//! # use asic_rs::MinerFactory;
54//! # use std::str::FromStr;
55//! # use tokio;
56//! # #[tokio::main]
57//! # async fn main() {
58//! #     let subnet = "192.168.1.0/24";
59//!     let factory = MinerFactory::from_range("192.168.1.1-255").unwrap();
60//! #     let miners = factory.scan().await.unwrap();
61//! # }
62//! ```
63//!
64//! These also have corresponding methods for appending to an existing factory, or overwriting existing ranges.
65//! See [`MinerFactory`] for more details.
66//!
67//! ### Data gathering
68//! Getting data is very simple with asic-rs, everything you need can be gathered with a single call.
69//! Extending the "Getting a miner" example:
70//! ```no_run
71//! use asic_rs::MinerFactory;
72//! use std::str::FromStr;
73//! use std::net::IpAddr;
74//! use tokio;
75//!
76//! #[tokio::main]
77//! async fn main() {
78//!     let factory = MinerFactory::new();
79//!     let ip = IpAddr::from_str("192.168.1.10").unwrap();
80//!     let miner_opt = factory.get_miner(ip).await.unwrap();
81//!     // First unwrap represents an error getting the miner
82//!     // Now make sure there is actually a valid, supported miner
83//!     if let Some(miner) = miner_opt {
84//!         let data = miner.get_data().await;
85//!     }
86//! }
87//! ```
88//!
89//! If you only want specific data, that can be done with individual function calls:
90//! ```no_run
91//! # use asic_rs::MinerFactory;
92//! # use std::str::FromStr;
93//! # use std::net::IpAddr;
94//! # use tokio;
95//! # #[tokio::main]
96//! # async fn main() {
97//! #     let factory = MinerFactory::new();
98//! #     let ip = IpAddr::from_str("192.168.1.10").unwrap();
99//! #     let miner_opt = factory.get_miner(ip).await.unwrap();
100//! #     // First unwrap represents an error getting the miner
101//! #     // Now make sure there is actually a valid, supported miner
102//! #     if let Some(miner) = miner_opt {
103//!         let mac = miner.get_mac().await;
104//! #     }
105//! # }
106//! ```
107//!
108//! Most data points from [`MinerData`][`data::miner::MinerData`] have a corresponding `get_...` function.
109//! See the [`GetMinerData`][`miners::backends::traits::GetMinerData`] trait for more info.
110//!
111//! ### Miner control
112//! Controlling a miner is very similar to getting data in asic-rs.
113//! Each miner has some control functions defined by the [`HasMinerControl`][`miners::backends::traits::HasMinerControl`] trait.
114//! Again extending the "Getting a miner" example:
115//! ```no_run
116//! use asic_rs::MinerFactory;
117//! use std::str::FromStr;
118//! use std::net::IpAddr;
119//! use tokio;
120//!
121//! #[tokio::main]
122//! async fn main() {
123//!     let factory = MinerFactory::new();
124//!     let ip = IpAddr::from_str("192.168.1.10").unwrap();
125//!     let miner_opt = factory.get_miner(ip).await.unwrap();
126//!     // First unwrap represents an error getting the miner
127//!     // Now make sure there is actually a valid, supported miner
128//!     if let Some(miner) = miner_opt {
129//!         let result = miner.restart().await;
130//!         if let Ok(true) = result {
131//!             println!("Miner restart succeeded")
132//!         }
133//!     }
134//! }
135//! ```
136
137pub use crate::miners::factory::MinerFactory;
138pub use crate::miners::listener::MinerListener;
139
140pub mod data;
141pub mod miners;
142pub(crate) mod test;
143
144#[cfg(feature = "python")]
145mod python;