emf_core_base_rs_ffi/version.rs
1//! Version api.
2//!
3//! # Example
4//!
5//! ```no_run
6//! # use emf_core_base_rs_ffi::CBaseBinding;
7//! # let base_interface: &mut dyn CBaseBinding = unsafe { std::mem::MaybeUninit::uninit().assume_init() };
8//! use emf_core_base_rs_ffi::sys::api::SysBinding;
9//! use emf_core_base_rs_ffi::version::api::VersionBinding;
10//! use emf_core_base_rs_ffi::collections::{NonNullConst, ConstSpan};
11//!
12//! unsafe {
13//! // `base_interface` has the type `&mut dyn CBaseBinding`.
14//! let v1 = VersionBinding::new_short(base_interface, 1, 2, 3);
15//!
16//! let v2_string = ConstSpan::from("1.2.3-beta.5+54845652");
17//! let v2 = match VersionBinding::from_string(
18//! base_interface,
19//! NonNullConst::from(&v2_string)
20//! ).to_result() {
21//! Ok(v) => v,
22//! Err(_) => {
23//! SysBinding::lock(base_interface);
24//! SysBinding::panic(
25//! base_interface,
26//! Some(NonNullConst::from(b"Could not construct from string.\0"))
27//! );
28//! SysBinding::unlock(base_interface);
29//! }
30//! };
31//!
32//! if VersionBinding::compare_weak(
33//! base_interface,
34//! NonNullConst::from(&v1),
35//! NonNullConst::from(&v2)) != 0 {
36//! SysBinding::lock(base_interface);
37//! SysBinding::panic(
38//! base_interface,
39//! Some(NonNullConst::from(b"Should not happen.\0"))
40//! );
41//! SysBinding::unlock(base_interface);
42//! }
43//! }
44//! ```
45
46pub mod api;
47
48/// Major version of the targeted version.
49pub const VERSION_MAJOR: i32 = 0;
50
51/// Minor version of the targeted version.
52pub const VERSION_MINOR: i32 = 1;
53
54/// Patch version of the targeted version.
55pub const VERSION_PATCH: i32 = 0;
56
57/// Release type of the targeted version.
58pub const VERSION_RELEASE_TYPE: ReleaseType = ReleaseType::Stable;
59
60/// Release number of the targeted version.
61pub const VERSION_RELEASE_NUMBER: i8 = 0;
62
63/// Build number of the targeted version.
64pub const VERSION_BUILD: i64 = 0;
65
66/// Version string of the targeted version.
67pub const VERSION_STRING: &str = "0.1.0";
68
69/// Errors of the version api.
70#[repr(i32)]
71#[non_exhaustive]
72#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
73pub enum Error {
74 InvalidString = 0,
75 BufferOverflow = 1,
76}
77
78/// Errors of the version api.
79#[repr(i8)]
80#[non_exhaustive]
81#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
82pub enum ReleaseType {
83 Stable = 0,
84 Unstable = 1,
85 Beta = 2,
86}
87
88/// A version.
89#[repr(C)]
90#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
91pub struct Version {
92 pub major: i32,
93 pub minor: i32,
94 pub patch: i32,
95 pub build: i64,
96 pub release_number: i8,
97 pub release_type: ReleaseType,
98}