#[cfg(feature = "stream")]
use httpclient::{Client, ResponseExt};
#[cfg(feature = "stream")]
use futures::StreamExt;
#[cfg(feature = "stream")]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new();
let response = client.get("https://httpbin.org/stream/3").send().await?;
let mut stream = response.bytes_stream();
while let Some(chunk) = stream.next().await {
match chunk {
Ok(bytes) => {
let text = String::from_utf8_lossy(&bytes);
println!("Received chunk: {}", text);
}
Err(e) => {
eprintln!("Error reading chunk: {:?}", e);
break;
}
}
}
Ok(())
}
#[cfg(not(feature = "stream"))]
fn main() {
println!("This example requires the 'stream' feature to be enabled.");
println!("Run with: cargo run --example stream --features stream");
}