awesome_operates/
lib.rs

1pub mod build;
2pub mod consts;
3pub mod embed;
4pub mod error;
5pub mod graceful;
6pub mod helper;
7pub mod manage;
8pub mod proxy;
9pub mod router;
10pub mod schedule;
11pub mod swagger;
12
13/// usage
14/// ```
15/// use rust_embed::RustEmbed;
16///
17/// #[derive(RustEmbed)]
18/// #[folder = "embed_files"]
19/// struct Asset;
20///
21/// async fn extract() -> anyhow::Result<()>{
22/// #   awesome_operates::extract_all_files!(Asset);
23///     Ok(())
24/// }
25///
26/// ```
27#[macro_export]
28macro_rules! extract_all_files {
29    ($asset:ty) => {
30        for file in <$asset>::iter() {
31            tracing::debug!("extract {}", file.as_ref());
32            let filepath = file.as_ref();
33            if let Some(parent) = std::path::Path::new(filepath).parent() {
34                if !parent.exists() {
35                    tokio::fs::create_dir_all(parent).await?;
36                }
37            }
38            let file = <$asset>::get(filepath).unwrap().data;
39            tokio::fs::write(filepath, file).await?;
40            #[cfg(unix)]
41            $crate::helper::add_execute_permission(filepath).await?;
42        }
43    };
44}