From a8d89f566285733167bc0ee5ab0d48382639a350 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 23 Dec 2023 11:52:07 +0000 Subject: [PATCH] Replace copy_to with direct use of the Read trait --- src/main.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index cc81e63..f562a74 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,18 +1,22 @@ // use mastodonochrome::types::*; +use std::io::Read; fn main() { let auth = std::fs::read_to_string( "/home/simon/.config/mastodonochrome/auth").unwrap(); - dbg!(&auth); let auth: serde_json::Value = serde_json::from_str(&auth).unwrap(); - dbg!(&auth); let auth = &auth["user_token"].as_str().unwrap(); - dbg!(&auth); let client = reqwest::blocking::Client::new(); let mut req = client.get( "https://hachyderm.io/api/v1/streaming/user") .bearer_auth(auth) .send().unwrap(); - req.copy_to(&mut std::io::stdout()); + + const BUFSIZE: usize = 4096; + let mut buf: [u8; BUFSIZE] = [0; BUFSIZE]; + while let Ok(sz) = req.read(&mut buf) { + let read = &buf[..sz]; + dbg!(read); + } } -- 2.30.2