libpt_core/lib.rs
1//! # common functionalities
2//!
3//! This crate is part of [`pt`](../libpt/index.html), but can also be used as a standalone
4//! module.
5//!
6//! This crate implements core functionality useful for many use cases, such as macros,
7//! formatting functions and more.
8
9/// macros to make things faster in your code
10pub mod macros;
11
12/// ## Get the name of the crate that uses your library
13///
14/// Let's say you're writing the library `foo` and need the name of the crate that uses `foo`. With
15/// this function, you can get the name of the crate that uses `foo`.
16///
17/// Will return [None] if [`std::env::current_exe()`] errors or if conversion to [String] from [std::ffi::OsStr] fails.
18pub fn get_crate_name() -> Option<String> {
19 if let Ok(exe) = std::env::current_exe() {
20 return Some(exe.file_stem()?.to_str()?.to_string());
21 }
22 None
23}