minor imports refactoring

This commit is contained in:
Jörn-Michael Miehe 2025-06-08 00:40:29 +00:00
parent e208df9711
commit 5b6fa3eaf7
4 changed files with 45 additions and 11 deletions

27
Cargo.lock generated
View file

@ -236,7 +236,7 @@ checksum = "658bce805d770f407bc62102fca7c2c64ceef2fbcb2b8bd19d2765ce093980de"
dependencies = [
"console",
"shell-words",
"thiserror",
"thiserror 1.0.69",
]
[[package]]
@ -702,7 +702,7 @@ checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
dependencies = [
"getrandom",
"libredox",
"thiserror",
"thiserror 1.0.69",
]
[[package]]
@ -856,6 +856,7 @@ dependencies = [
"log",
"serde",
"serde_json",
"thiserror 2.0.12",
"ureq",
]
@ -911,7 +912,16 @@ version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
dependencies = [
"thiserror-impl",
"thiserror-impl 1.0.69",
]
[[package]]
name = "thiserror"
version = "2.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708"
dependencies = [
"thiserror-impl 2.0.12",
]
[[package]]
@ -925,6 +935,17 @@ dependencies = [
"syn",
]
[[package]]
name = "thiserror-impl"
version = "2.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "time"
version = "0.3.41"

View file

@ -15,6 +15,7 @@ indicatif = { version = "0.17.11", default-features = false }
log = "0.4.27"
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"
thiserror = "2.0.12"
ureq = { version = "3.0.11", features = ["json"] }
[profile.release]

View file

@ -1,4 +1,4 @@
use std::fmt::Display;
use std::fmt;
use serde::{Deserialize, Serialize};
@ -17,8 +17,8 @@ impl Uri {
}
}
impl Display for Uri {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
impl fmt::Display for Uri {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}://{}/api/v2", self.protocol, self.base_url)
}
}

View file

@ -1,6 +1,6 @@
use std::{
ffi::OsStr,
fs,
fmt, fs,
io::{self, Read, Seek, SeekFrom},
path::PathBuf,
};
@ -19,12 +19,24 @@ pub struct FileUploading {
offset: u64,
}
#[derive(Debug)]
#[derive(Debug, thiserror::Error)]
pub enum UploadError {
FileIO(io::Error),
#[error("file I/O error: {0}")]
FileIO(#[from] io::Error),
#[error("network request failed")]
Request,
#[error("unexpected response status")]
ResponseStatus,
#[error("could not parse offset header")]
ResponseOffset,
// #[error("chunk length conversion failed: {0}")]
// InvalidChunkLength(String),
// #[error("offset mismatch")]
// ResponseOffsetMismatch,
}
pub enum ChunkState {
@ -33,8 +45,8 @@ pub enum ChunkState {
Finished(PathBuf),
}
impl std::fmt::Display for FileUploading {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
impl fmt::Display for FileUploading {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Uploading {:?} ({}/{})",