forked from proxmox-mirrors/proxmox
api: add a meta module to help with macro impls
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
cb2c260f87
commit
7cbc6d0962
@ -186,6 +186,7 @@ pub trait ApiType {
|
|||||||
Self::type_info()
|
Self::type_info()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn should_skip_serialization(&self) -> bool {
|
fn should_skip_serialization(&self) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
@ -239,6 +240,7 @@ impl<T: ApiType> ApiType for Option<T> {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn should_skip_serialization(&self) -> bool {
|
fn should_skip_serialization(&self) -> bool {
|
||||||
self.is_none()
|
self.is_none()
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,8 @@ pub use router::*;
|
|||||||
|
|
||||||
pub mod cli;
|
pub mod cli;
|
||||||
|
|
||||||
|
pub mod meta;
|
||||||
|
|
||||||
/// Return type of an API method.
|
/// Return type of an API method.
|
||||||
pub type ApiOutput<Body> = Result<Response<Body>, Error>;
|
pub type ApiOutput<Body> = Result<Response<Body>, Error>;
|
||||||
|
|
||||||
|
28
proxmox-api/src/meta.rs
Normal file
28
proxmox-api/src/meta.rs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
//! Type related meta information, mostly used by the macro code.
|
||||||
|
|
||||||
|
use crate::ApiType;
|
||||||
|
|
||||||
|
/// Helper trait for entries with a `default` value in their api type definition.
|
||||||
|
pub trait OrDefault {
|
||||||
|
type Output;
|
||||||
|
|
||||||
|
fn or_default(&self, def: &'static Self::Output) -> &Self::Output;
|
||||||
|
fn set(&mut self, value: Self::Output);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> OrDefault for Option<T>
|
||||||
|
where
|
||||||
|
T: ApiType,
|
||||||
|
{
|
||||||
|
type Output = T;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn or_default(&self, def: &'static Self::Output) -> &Self::Output {
|
||||||
|
self.as_ref().unwrap_or(def)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn set(&mut self, value: Self::Output) {
|
||||||
|
*self = Some(value);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user