mirror of
https://github.com/FliegendeWurst/KIT-ILIAS-downloader.git
synced 2024-08-28 04:04:18 +00:00
Code style + formatting + logging macros
This commit is contained in:
parent
31d4efff5b
commit
381df53264
12
Cargo.lock
generated
12
Cargo.lock
generated
@ -7,6 +7,7 @@ name = "KIT-ILIAS-downloader"
|
|||||||
version = "0.2.15"
|
version = "0.2.15"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"colored",
|
||||||
"futures",
|
"futures",
|
||||||
"futures-channel",
|
"futures-channel",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
@ -157,6 +158,17 @@ dependencies = [
|
|||||||
"vec_map",
|
"vec_map",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "colored"
|
||||||
|
version = "2.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd"
|
||||||
|
dependencies = [
|
||||||
|
"atty",
|
||||||
|
"lazy_static",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "const_fn"
|
name = "const_fn"
|
||||||
version = "0.4.6"
|
version = "0.4.6"
|
||||||
|
628
src/main.rs
628
src/main.rs
File diff suppressed because it is too large
Load Diff
34
src/util.rs
34
src/util.rs
@ -23,3 +23,37 @@ pub async fn create_dir(path: &Path) -> Result<()> {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove once result_flattening is stable (https://github.com/rust-lang/rust/issues/70142)
|
||||||
|
pub trait Result2 {
|
||||||
|
type V;
|
||||||
|
type E;
|
||||||
|
type F;
|
||||||
|
|
||||||
|
fn flatten2(self) -> Result<Self::V, Self::E>
|
||||||
|
where
|
||||||
|
Self::F: Into<Self::E>;
|
||||||
|
|
||||||
|
fn flatten_with<O: FnOnce(Self::F) -> Self::E>(self, op: O) -> Result<Self::V, Self::E>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<V, E, F> Result2 for Result<Result<V, F>, E> {
|
||||||
|
type V = V;
|
||||||
|
type E = E;
|
||||||
|
type F = F;
|
||||||
|
|
||||||
|
fn flatten2(self) -> Result<Self::V, Self::E>
|
||||||
|
where
|
||||||
|
Self::F: Into<Self::E>,
|
||||||
|
{
|
||||||
|
self.flatten_with(|e| e.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn flatten_with<O: FnOnce(Self::F) -> Self::E>(self, op: O) -> Result<Self::V, Self::E> {
|
||||||
|
match self {
|
||||||
|
Ok(Ok(v)) => Ok(v),
|
||||||
|
Ok(Err(f)) => Err(op(f)),
|
||||||
|
Err(e) => Err(e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user