subplotlib/utils.rs
1//! Utility functions used by subplotlib or the generated test functions
2
3use base64::prelude::{Engine as _, BASE64_STANDARD};
4
5/// Decode a base64 string.
6///
7/// If the result is not a valid utf8 string then it is lossily coerced.
8///
9/// ```
10/// # use subplotlib::prelude::*;
11///
12/// assert_eq!(base64_decode("aGVsbG8="), "hello");
13/// ```
14///
15/// # Panics
16///
17/// Will panic if it's not valid base64 leading to a string.
18pub fn base64_decode(input: &str) -> String {
19 let dec = BASE64_STANDARD.decode(input).expect("bad base64");
20 String::from_utf8_lossy(&dec).to_string()
21}