Skip to content

Commit

Permalink
wip: assets
Browse files Browse the repository at this point in the history
  • Loading branch information
ElaBosak233 committed Jul 30, 2024
1 parent 8ec0047 commit 42b01a3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/assets/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
use std::fs;

use rust_embed::Embed;

#[derive(Embed)]
#[folder = "assets/"]
pub struct Assets;

pub fn get(path: &str) -> Option<Vec<u8>> {
let path = format!("assets/{}", path);
if let Ok(file) = fs::read(&path) {
return Some(file);
}
return Assets::get(&path).map(|e| e.data.into_owned());
}
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ use tracing::info;

#[tokio::main]
async fn main() {
let banner = assets::Assets::get("banner.txt").unwrap();
let banner = assets::get("banner.txt").unwrap();
println!(
"{}",
std::str::from_utf8(banner.data.as_ref())
std::str::from_utf8(&banner)
.unwrap()
.replace("{{version}}", env!("CARGO_PKG_VERSION"))
.replace("{{commit}}", env!("GIT_COMMIT_ID"))
Expand Down

0 comments on commit 42b01a3

Please sign in to comment.