mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-20 20:48:43 +00:00
Simplify AsyncFileWriter::new
: Ret Self
instead of `io::Result<Self>` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
911c52d8e1
commit
894f9b49f9
2 changed files with 6 additions and 5 deletions
|
@ -65,7 +65,7 @@ pub async fn download<P: AsRef<Path>>(url: &str, path: P) -> Result<(), Binstall
|
||||||
debug!("Downloading to file: '{}'", path.display());
|
debug!("Downloading to file: '{}'", path.display());
|
||||||
|
|
||||||
let mut bytes_stream = resp.bytes_stream();
|
let mut bytes_stream = resp.bytes_stream();
|
||||||
let mut writer = AsyncFileWriter::new(path)?;
|
let mut writer = AsyncFileWriter::new(path);
|
||||||
|
|
||||||
while let Some(res) = bytes_stream.next().await {
|
while let Some(res) = bytes_stream.next().await {
|
||||||
writer.write(res?).await?;
|
writer.write(res?).await?;
|
||||||
|
|
|
@ -25,7 +25,7 @@ struct AsyncFileWriterInner {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsyncFileWriterInner {
|
impl AsyncFileWriterInner {
|
||||||
fn new(path: &Path) -> io::Result<Self> {
|
fn new(path: &Path) -> Self {
|
||||||
let path = path.to_owned();
|
let path = path.to_owned();
|
||||||
let (tx, rx) = mpsc::channel::<Content>(100);
|
let (tx, rx) = mpsc::channel::<Content>(100);
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ impl AsyncFileWriterInner {
|
||||||
Ok(())
|
Ok(())
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Ok(Self { handle, tx })
|
Self { handle, tx }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Upon error, this writer shall not be reused.
|
/// Upon error, this writer shall not be reused.
|
||||||
|
@ -110,8 +110,9 @@ impl AsyncFileWriterInner {
|
||||||
pub struct AsyncFileWriter(ScopeGuard<AsyncFileWriterInner, fn(AsyncFileWriterInner), Always>);
|
pub struct AsyncFileWriter(ScopeGuard<AsyncFileWriterInner, fn(AsyncFileWriterInner), Always>);
|
||||||
|
|
||||||
impl AsyncFileWriter {
|
impl AsyncFileWriter {
|
||||||
pub fn new(path: &Path) -> io::Result<Self> {
|
pub fn new(path: &Path) -> Self {
|
||||||
AsyncFileWriterInner::new(path).map(|inner| Self(guard(inner, AsyncFileWriterInner::abort)))
|
let inner = AsyncFileWriterInner::new(path);
|
||||||
|
Self(guard(inner, AsyncFileWriterInner::abort))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Upon error, this writer shall not be reused.
|
/// Upon error, this writer shall not be reused.
|
||||||
|
|
Loading…
Add table
Reference in a new issue