diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2023-04-10 11:47:34 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2023-04-10 11:47:34 +0100 |
commit | acf390c47f2b23a460e6eb507447809b29eeb3a1 (patch) | |
tree | 9ae8e3a6a6f68e6f626f2ee5a9ae80d6171d1fbf | |
parent | 321eaa952ebd9c445745ea811f54598baf29e74e (diff) | |
download | subplot-acf390c47f2b23a460e6eb507447809b29eeb3a1.tar.gz |
(chore): Update for newer base64 API
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
-rw-r--r-- | src/codegen.rs | 4 | ||||
-rw-r--r-- | src/md.rs | 4 | ||||
-rw-r--r-- | subplotlib/src/file.rs | 12 | ||||
-rw-r--r-- | subplotlib/src/utils.rs | 4 |
4 files changed, 17 insertions, 7 deletions
diff --git a/src/codegen.rs b/src/codegen.rs index 8c69ed3..9f346a9 100644 --- a/src/codegen.rs +++ b/src/codegen.rs @@ -4,7 +4,7 @@ use std::fs::File; use std::io::Write; use std::path::{Path, PathBuf}; -use base64::encode; +use base64::prelude::{Engine as _, BASE64_STANDARD}; use serde::Serialize; use tera::{Context, Tera, Value}; @@ -88,7 +88,7 @@ fn write(filename: &Path, content: &str) -> Result<(), SubplotError> { fn base64(v: &Value, _: &HashMap<String, Value>) -> tera::Result<Value> { match v { - Value::String(s) => Ok(Value::String(encode(s))), + Value::String(s) => Ok(Value::String(BASE64_STANDARD.encode(s))), _ => Err(tera::Error::msg( "can only base64 encode strings".to_string(), )), @@ -360,6 +360,8 @@ mod typeset { use crate::{DiagramMarkup, DotMarkup, PikchrMarkup, PlantumlMarkup, Svg}; // use crate::{Warning, Warnings}; + use base64::prelude::{Engine as _, BASE64_STANDARD}; + pub(crate) fn typeset_element(e: &Element) -> Result<Element, SubplotError> { match e.tag() { ElementTag::Pre if e.has_attr("class", "scenario") => typeset_scenario(e), @@ -434,7 +436,7 @@ mod typeset { } fn svg_as_data_url(svg: Svg) -> String { - let svg = base64::encode(svg.data()); + let svg = BASE64_STANDARD.encode(svg.data()); format!("data:image/svg+xml;base64,{svg}") } diff --git a/subplotlib/src/file.rs b/subplotlib/src/file.rs index 84f3495..c1c9afe 100644 --- a/subplotlib/src/file.rs +++ b/subplotlib/src/file.rs @@ -7,7 +7,8 @@ use std::path::{Path, PathBuf}; use std::sync::Arc; -use base64::decode; +use base64::prelude::{Engine as _, BASE64_STANDARD}; + /// An embedded data file. /// /// Embedded data files have names and content. The subplot template will generate @@ -82,11 +83,16 @@ impl SubplotDataFile { /// /// This will panic if the passed in strings are not correctly base64 encoded. pub fn new(name: &str, data: &str) -> Self { - let name = decode(name).expect("Subplot generated bad base64?"); + let name = BASE64_STANDARD + .decode(name) + .expect("Subplot generated bad base64?"); let name = String::from_utf8_lossy(&name); let name: PathBuf = name.as_ref().into(); let name = name.into(); - let data = decode(data).expect("Subplot generated bad base64?").into(); + let data = BASE64_STANDARD + .decode(data) + .expect("Subplot generated bad base64?") + .into(); Self { name, data } } diff --git a/subplotlib/src/utils.rs b/subplotlib/src/utils.rs index 642848a..25a9360 100644 --- a/subplotlib/src/utils.rs +++ b/subplotlib/src/utils.rs @@ -1,5 +1,7 @@ //! Utility functions used by subplotlib or the generated test functions +use base64::prelude::{Engine as _, BASE64_STANDARD}; + /// Decode a base64 string. /// /// If the result is not a valid utf8 string then it is lossily coerced. @@ -14,6 +16,6 @@ /// /// Will panic if it's not valid base64 leading to a string. pub fn base64_decode(input: &str) -> String { - let dec = base64::decode(input).expect("bad base64"); + let dec = BASE64_STANDARD.decode(input).expect("bad base64"); String::from_utf8_lossy(&dec).to_string() } |