Getting the using crate's name from within a library

I'm writing a graphics library, and I would like to make the title of the window reflect the name of the crate that is using the library. For example, my library is called "foo-lib" and the project using the library is called "bar-bin", then I want the window's title to be "bar-bin".

I am aware of the cargo environment variables, but as far as I can tell, they are set when my library is compiled, i.e. CARGO_PKG_NAME or CARGO_CRATE_NAME are the name of my library.

I.e. Is there some way to get information like CARGO_PKG_NAME at runtime? Without requiring the user to explicitly include it in their code.

I just realized that that is possible with macros:

#[macro_export]
macro_rules! pronto_window {
    ($width:expr, $height:expr) => {
        Window::new($width, $height, env!("CARGO_CRATE_NAME"));
    };
}

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.