From 42b01a3b73d731978c700a93ffdda64b34f5cd7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9F=83=E6=8B=89?= Date: Tue, 30 Jul 2024 17:08:37 +0800 Subject: [PATCH] wip: assets --- src/assets/mod.rs | 10 ++++++++++ src/main.rs | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/assets/mod.rs b/src/assets/mod.rs index 32fcdfcb..e2c16b28 100644 --- a/src/assets/mod.rs +++ b/src/assets/mod.rs @@ -1,5 +1,15 @@ +use std::fs; + use rust_embed::Embed; #[derive(Embed)] #[folder = "assets/"] pub struct Assets; + +pub fn get(path: &str) -> Option> { + 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()); +} diff --git a/src/main.rs b/src/main.rs index b83da4d8..1ab4b052 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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"))