mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2024-11-25 08:14:20 +00:00
Fix ApplicationInfo::from_cargo_toml
(#776)
* Replace `from_cargo_toml` with a macro * Update docs * Use `None` as ApplicationInfo default * Re-add and deprecate the old function * Fix doctest * Rename macro to `app_info_from_cargo_toml` * Update deprecated note * Fix build
This commit is contained in:
parent
0b126e58a9
commit
08a4dbe6e1
@ -515,6 +515,7 @@ impl<'a> ApplicationInfo<'a> {
|
||||
/// - Panics if the required environment variables are missing, which happens if the project
|
||||
/// wasn't built by Cargo.
|
||||
///
|
||||
#[deprecated(note="Please use the `app_info_from_cargo_toml!` macro instead")]
|
||||
pub fn from_cargo_toml() -> ApplicationInfo<'a> {
|
||||
let version = Version {
|
||||
major: env!("CARGO_PKG_VERSION_MAJOR").parse().unwrap(),
|
||||
@ -533,9 +534,41 @@ impl<'a> ApplicationInfo<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds an `ApplicationInfo` from the information gathered by Cargo.
|
||||
///
|
||||
/// # Panic
|
||||
///
|
||||
/// - Panics if the required environment variables are missing, which happens if the project
|
||||
/// wasn't built by Cargo.
|
||||
///
|
||||
#[macro_export]
|
||||
macro_rules! app_info_from_cargo_toml {
|
||||
() => {{
|
||||
let version = $crate::instance::Version {
|
||||
major: env!("CARGO_PKG_VERSION_MAJOR").parse().unwrap(),
|
||||
minor: env!("CARGO_PKG_VERSION_MINOR").parse().unwrap(),
|
||||
patch: env!("CARGO_PKG_VERSION_PATCH").parse().unwrap(),
|
||||
};
|
||||
|
||||
let name = env!("CARGO_PKG_NAME");
|
||||
|
||||
$crate::instance::ApplicationInfo {
|
||||
application_name: Some(name.into()),
|
||||
application_version: Some(version),
|
||||
engine_name: None,
|
||||
engine_version: None,
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
impl<'a> Default for ApplicationInfo<'a> {
|
||||
fn default() -> ApplicationInfo<'a> {
|
||||
ApplicationInfo::from_cargo_toml()
|
||||
ApplicationInfo {
|
||||
application_name: None,
|
||||
application_version: None,
|
||||
engine_name: None,
|
||||
engine_version: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,15 +81,16 @@
|
||||
//! behavior for your application alone through a control panel.
|
||||
//!
|
||||
//! ```no_run
|
||||
//! use vulkano::instance::ApplicationInfo;
|
||||
//! use vulkano::instance::Instance;
|
||||
//! use vulkano::instance::InstanceExtensions;
|
||||
//! # #[macro_use] extern crate vulkano;
|
||||
//! # fn main() {
|
||||
//! use vulkano::instance::{Instance, InstanceExtensions};
|
||||
//!
|
||||
//! // Builds an `ApplicationInfo` by looking at the content of the `Cargo.toml` file at
|
||||
//! // compile-time.
|
||||
//! let app_infos = ApplicationInfo::from_cargo_toml();
|
||||
//! let app_infos = app_info_from_cargo_toml!();
|
||||
//!
|
||||
//! let _instance = Instance::new(Some(&app_infos), &InstanceExtensions::none(), None).unwrap();
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
//! # Enumerating physical devices and creating a device
|
||||
|
Loading…
Reference in New Issue
Block a user