Eliminate assets crate

This commit is contained in:
Max Brunsfeld 2023-06-06 11:46:46 -07:00
parent 53906fd3da
commit dbbd0558c3
24 changed files with 142 additions and 160 deletions

View file

@ -21,6 +21,7 @@ isahc.workspace = true
smol.workspace = true
url = "2.2"
rand.workspace = true
rust-embed.workspace = true
tempdir = { workspace = true, optional = true }
serde.workspace = true
serde_json.workspace = true

View file

@ -7,6 +7,7 @@ pub mod paths;
pub mod test;
use std::{
borrow::Cow,
cmp::{self, Ordering},
ops::{AddAssign, Range, RangeInclusive},
panic::Location,
@ -284,6 +285,14 @@ impl<T: Rng> Iterator for RandomCharIter<T> {
}
}
/// Get an embedded file as a string.
pub fn asset_str<A: rust_embed::RustEmbed>(path: &str) -> Cow<'static, str> {
match A::get(path).unwrap().data {
Cow::Borrowed(bytes) => Cow::Borrowed(std::str::from_utf8(bytes).unwrap()),
Cow::Owned(bytes) => Cow::Owned(String::from_utf8(bytes).unwrap()),
}
}
// copy unstable standard feature option unzip
// https://github.com/rust-lang/rust/issues/87800
// Remove when this ship in Rust 1.66 or 1.67