Made the library async using tokio and the iterator return a Result
Check, format and test / build (push) Successful in 33s

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 13:28:32 +02:00
co-authored by Claude Sonnet 5
parent 93f9e9d3af
commit 1745ecc05e
5 changed files with 225 additions and 102 deletions
+32 -23
View File
@@ -28,35 +28,44 @@ If you want to read about this reverse engineering attempt, check out
2. Use the library in you project:
This library is async and built on [tokio](https://tokio.rs); add it to your
own `[dependencies]` (e.g. `tokio = { version = "1", features =
["rt-multi-thread", "macros"] }`) to run the example below.
```rust
use r701::R701;
use tokio_stream::StreamExt;
fn main() {
let mut r701 = R701::connect("127.0.0.1:5005").unwrap();
#[tokio::main]
async fn main() {
let mut r701 = R701::connect("127.0.0.1:5005").await.unwrap();
println!("No\tMchn\tEnNo\t\tName\t\tMode\tIOMd\tDateTime\t");
r701.into_record_iter()
let records = r701
.into_record_iter()
.await
.unwrap()
.collect::<Vec<_>>()
.iter()
.rev()
.enumerate()
.for_each(|(id, record)| {
let name = r701
.get_name(record.employee_id)
.unwrap()
.unwrap_or(format!("user #{}", record.employee_id));
.await;
println!(
"{:0>6}\t{}\t{:0>9}\t{: <10}\t{}\t{}\t{}",
id + 1,
1,
record.employee_id,
name,
35,
record.clock as u8,
record.datetime.format("%Y/%m/%d %H:%M:%S"),
);
});
println!("No\tMchn\tEnNo\t\tName\t\tMode\tIOMd\tDateTime\t");
for (id, record) in records.iter().rev().enumerate() {
let record = record.as_ref().unwrap();
let name = r701
.get_name(record.employee_id)
.await
.unwrap()
.unwrap_or(format!("user #{}", record.employee_id));
println!(
"{:0>6}\t{}\t{:0>9}\t{: <10}\t{}\t{}\t{}",
id + 1,
1,
record.employee_id,
name,
35,
record.clock as u8,
record.datetime.format("%Y/%m/%d %H:%M:%S"),
);
}
}
```