summaryrefslogtreecommitdiff
path: root/src/compression.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/compression.rs')
-rw-r--r--src/compression.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/compression.rs b/src/compression.rs
index b3010cb..7e20a94 100644
--- a/src/compression.rs
+++ b/src/compression.rs
@@ -1,7 +1,7 @@
use anyhow::{Context, Error};
use flate2::{read::GzDecoder, write::GzEncoder};
use rayon::prelude::*;
-use std::{convert::TryFrom, io::Read, io::Write, path::Path};
+use std::{convert::TryFrom, fmt, io::Read, io::Write, path::Path, str::FromStr};
use xz2::{read::XzDecoder, write::XzEncoder};
#[derive(Debug, Copy, Clone)]
@@ -80,6 +80,29 @@ impl TryFrom<&'_ str> for CompressionFormats {
}
}
+impl FromStr for CompressionFormats {
+ type Err = Error;
+
+ fn from_str(value: &str) -> Result<Self, Self::Err> {
+ Self::try_from(value)
+ }
+}
+
+impl fmt::Display for CompressionFormats {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ for (i, format) in self.iter().enumerate() {
+ if i != 0 {
+ write!(f, ",")?;
+ }
+ fmt::Display::fmt(match format {
+ CompressionFormat::Xz => "xz",
+ CompressionFormat::Gz => "gz",
+ }, f)?;
+ }
+ Ok(())
+ }
+}
+
impl Default for CompressionFormats {
fn default() -> Self {
Self(vec![CompressionFormat::Gz, CompressionFormat::Xz])