use {futures::*, read_url::*, tokio_util::compat::*};
pub fn main() -> Result<(), UrlError> {
let tokio = tokio::runtime::Builder::new_current_thread().enable_all().build()?;
tokio.block_on(main_async())
}
pub async fn main_async() -> Result<(), UrlError> {
let context = UrlContext::new();
let url = context
.url_async("https://raw.githubusercontent.com/tliron/rust-read-url/refs/heads/main/assets/files/two.txt")
.await?;
let reader = url.open_async()?.await?;
read(&mut reader.compat()).await?;
Ok(())
}
pub async fn read<ReadT>(reader: &mut ReadT) -> io::Result<()>
where
ReadT: io::AsyncRead + Unpin,
{
let mut string = String::default();
reader.read_to_string(&mut string).await?;
println!("{:?}", string);
Ok(())
}