summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2021-11-25 00:11:08 +0100
committerPhilipp Gesang <phg@phi-gamma.net>2021-11-25 00:11:14 +0100
commitd6e8a37767644b50001e14ebbab594e799a94db7 (patch)
treed5b91ee3b1dd0adc25e8dd245e4dde5b63522726 /src/lib.rs
parenta96f86710eaabe5ae8c235ca537ad5b156884fc9 (diff)
downloadvtcol-d6e8a37767644b50001e14ebbab594e799a94db7.tar.gz
move base64 handling out of Palette
Try and not encumber the lower level types with more dependencies than needed.
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/lib.rs b/src/lib.rs
index d0014a5..c652565 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -351,6 +351,25 @@ impl Scheme
{
Self::Custom(Some(path.as_ref().into()))
}
+
+ pub fn base64(&self) -> io::Result<String>
+ {
+ let pal = Palette::try_from(self)?;
+ Ok(base64::encode(&pal.0))
+ }
+
+ pub fn from_base64(b64: &str) -> io::Result<Self>
+ {
+ base64::decode(b64.as_bytes())
+ .map_err(|e| {
+ io::Error::new(
+ io::ErrorKind::Other,
+ format!("failed to decode input as base64: {}", e),
+ )
+ })
+ .and_then(|b| Palette::from_bytes(&b))
+ .map(Self::from)
+ }
} /* [impl Scheme] */
/** Try to select one of the predefined schemes; if that fails,
@@ -591,20 +610,6 @@ impl Palette
}
/* [Palette::from_stdin] */
-
- pub fn base64(&self) -> String { base64::encode(&self.0) }
-
- pub fn from_base64(b64: &str) -> io::Result<Self>
- {
- base64::decode(b64.as_bytes())
- .map_err(|e| {
- io::Error::new(
- io::ErrorKind::Other,
- format!("failed to decode input as base64: {}", e),
- )
- })
- .and_then(|b| Self::from_bytes(&b))
- }
} /* [impl Palette] */
impl fmt::Display for Palette