2022-08-10 01:56:22 +01:00
|
|
|
use std::convert::Into;
|
|
|
|
use usdpl_back::core::serdes::Primitive;
|
|
|
|
|
|
|
|
use crate::settings::SettingError;
|
|
|
|
|
2022-09-01 01:18:15 +01:00
|
|
|
#[inline]
|
2022-08-10 01:56:22 +01:00
|
|
|
pub fn map_result<T: Into<Primitive>>(result: Result<T, SettingError>) -> super::ApiParameterType {
|
|
|
|
match result {
|
|
|
|
Ok(val) => vec![val.into()],
|
2022-09-01 01:18:15 +01:00
|
|
|
Err(e) => {
|
|
|
|
log::debug!("Mapping error to primitive: {}", e);
|
|
|
|
vec![e.msg.into()]
|
2023-03-28 02:11:22 +01:00
|
|
|
}
|
2022-08-10 01:56:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-19 20:21:09 +00:00
|
|
|
#[inline]
|
2023-03-28 02:11:22 +01:00
|
|
|
pub fn map_optional_result<T: Into<Primitive>>(
|
|
|
|
result: Result<Option<T>, SettingError>,
|
|
|
|
) -> super::ApiParameterType {
|
2022-11-19 20:21:09 +00:00
|
|
|
match result {
|
|
|
|
Ok(val) => match val {
|
|
|
|
Some(val) => vec![val.into()],
|
|
|
|
None => vec![Primitive::Empty],
|
|
|
|
},
|
|
|
|
Err(e) => {
|
|
|
|
log::debug!("Mapping error to primitive: {}", e);
|
|
|
|
vec![e.msg.into()]
|
2023-03-28 02:11:22 +01:00
|
|
|
}
|
2022-11-19 20:21:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-10 03:09:05 +00:00
|
|
|
/*#[inline]
|
2022-08-10 01:56:22 +01:00
|
|
|
pub fn map_empty_result<T: Into<Primitive>>(
|
|
|
|
result: Result<(), SettingError>,
|
|
|
|
success: T,
|
|
|
|
) -> super::ApiParameterType {
|
|
|
|
match result {
|
|
|
|
Ok(_) => vec![success.into()],
|
2022-09-01 01:18:15 +01:00
|
|
|
Err(e) => {
|
|
|
|
log::debug!("Mapping error to primitive: {}", e);
|
|
|
|
vec![e.msg.into()]
|
|
|
|
},
|
2022-08-10 01:56:22 +01:00
|
|
|
}
|
2022-11-10 03:09:05 +00:00
|
|
|
}*/
|