drogue_bazaar/core/
info.rs

1/// Project information. Intended as information over all your project's components.
2pub struct ProjectInformation {
3    /// Project name
4    pub name: &'static str,
5    /// Version
6    pub version: &'static str,
7    /// Banner
8    pub banner: &'static str,
9}
10
11/// Component information. Intended as information over all your project's components.
12pub struct ComponentInformation {
13    /// Project
14    pub project: &'static ProjectInformation,
15    /// Component name
16    pub name: &'static str,
17    /// Version
18    pub version: &'static str,
19    /// Description
20    pub description: &'static str,
21}
22
23/// Create a new project information constant.
24///
25/// This will define a new constant, including the name of the project as well as the version from
26/// the cargo file.
27///
28/// It is intended to be present once in a central module of your project, possibly in combination
29/// with [`runtime!`].
30#[macro_export]
31macro_rules! project {
32    ($name:literal) => {
33        $crate::project!(PROJECT: $name);
34    };
35    ($v:ident: $name:literal) => {
36        $crate::project!($v: $name => r#"______ ______  _____  _____  _   _  _____   _____         _____ 
37|  _  \| ___ \|  _  ||  __ \| | | ||  ___| |_   _|       |_   _|
38| | | || |_/ /| | | || |  \/| | | || |__     | |    ___    | |  
39| | | ||    / | | | || | __ | | | ||  __|    | |   / _ \   | |  
40| |/ / | |\ \ \ \_/ /| |_\ \| |_| || |___   _| |_ | (_) |  | |  
41|___/  \_| \_| \___/  \____/ \___/ \____/   \___/  \___/   \_/  
42"# );
43    };
44    ($v:ident: $name:expr => $banner:expr) => {
45        pub const $v: $crate::core::info::ProjectInformation =
46            $crate::core::info::ProjectInformation {
47                name: $name,
48                version: env!("CARGO_PKG_VERSION"),
49                banner: $banner,
50        };
51    };
52}
53
54/// Create a new component information constant.
55///
56/// This will define a new constant, extracting the name of the component from the cargo file. It is
57/// intended to be directly used by [`runtime!`].
58#[macro_export]
59macro_rules! component {
60    ($project:expr) => {
61        $crate::core::info::ComponentInformation {
62            project: &$project,
63            name: env!("CARGO_PKG_NAME"),
64            version: env!("CARGO_PKG_VERSION"),
65            description: env!("CARGO_PKG_DESCRIPTION"),
66        }
67    };
68    ($v:ident, $project:expr) => {
69        pub const $v: $crate::core::info::ComponentInformation = $crate::component!($project);
70    };
71}