summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
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