31 lines
729 B
Rust
31 lines
729 B
Rust
use async_speed_limit::Limiter;
|
|
use futures_util::{
|
|
future::try_join,
|
|
io::{self, AsyncRead, AsyncWrite},
|
|
};
|
|
use std::marker::Unpin;
|
|
|
|
fn main() {
|
|
println!("Hello, world!");
|
|
}
|
|
|
|
#[warn(dead_code)]
|
|
async fn copy_both_slowly(
|
|
r1: impl AsyncRead,
|
|
w1: &mut (impl AsyncWrite + Unpin),
|
|
r2: impl AsyncRead,
|
|
w2: &mut (impl AsyncWrite + Unpin),
|
|
) -> io::Result<()> {
|
|
// create a speed limiter of 1.0 KiB/s.
|
|
let limiter = <Limiter>::new(1024.0);
|
|
|
|
// limit both readers by the same queue
|
|
// (so 1.0 KiB/s is the combined maximum speed)
|
|
let r1 = limiter.clone().limit(r1);
|
|
let r2 = limiter.limit(r2);
|
|
|
|
// do the copy.
|
|
try_join(io::copy(r1, w1), io::copy(r2, w2)).await?;
|
|
Ok(())
|
|
}
|