Code style + formatting + logging macros

This commit is contained in:
FliegendeWurst 2021-04-16 13:24:10 +02:00
parent 31d4efff5b
commit 381df53264
3 changed files with 433 additions and 315 deletions

12
Cargo.lock generated
View File

@ -7,6 +7,7 @@ name = "KIT-ILIAS-downloader"
version = "0.2.15"
dependencies = [
"anyhow",
"colored",
"futures",
"futures-channel",
"futures-util",
@ -157,6 +158,17 @@ dependencies = [
"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]]
name = "const_fn"
version = "0.4.6"

File diff suppressed because it is too large Load Diff

View File

@ -23,3 +23,37 @@ pub async fn create_dir(path: &Path) -> Result<()> {
}
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),
}
}
}