1pub use container::{app, Container};
2
3mod container;
4
5pub fn type_name<T>() -> String
6where
7 T: std::any::Any + ?Sized,
8{
9 std::any::type_name::<T>()
10 .split("::")
11 .last()
12 .expect("Cannot get type name")
13 .to_string()
14}
15
16pub fn copy(from: &std::path::Path, to: &std::path::Path) -> crate::Result<()> {
17 match std::fs::metadata(from)?.is_dir() {
18 false => {
19 std::fs::copy(from, to)?;
20 }
21 true => {
22 std::fs::create_dir_all(to)?;
23
24 for entry in std::fs::read_dir(from)? {
25 let entry = entry?;
26 let from = entry.path();
27 let to = to.join(entry.file_name());
28
29 if from.is_dir() {
30 copy(&from, &to)?;
31 } else {
32 std::fs::copy(&from, to)?;
33 }
34 }
35 }
36 };
37
38 Ok(())
39}
40
41pub fn dir(
42 directory: &std::path::Path,
43 files: &mut Vec<(std::ffi::OsString, std::path::PathBuf)>,
44) -> crate::Result<()> {
45 for entry in std::fs::read_dir(directory)? {
46 let entry = entry?;
47 let path = entry.path();
48
49 if path.is_dir() {
50 dir(&path, files)?;
51 } else {
52 files.push((entry.file_name(), path));
53 }
54 }
55
56 Ok(())
57}
58
59pub fn base_path(str: &str) -> std::path::PathBuf {
60 let base_path = std::env::var("CARGO_MANIFEST_DIR")
61 .map(std::path::PathBuf::from)
62 .unwrap_or_else(|_| {
63 std::env::current_dir().expect("project directory does not exist or permissions are insufficient")
64 });
65
66 base_path.join(str)
67}