1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
use crate::abi::{TypeAbi, TypeDescriptionContainer}; use crate::{api::EndpointFinishApi, EndpointResult}; use alloc::string::String; pub enum OptionalResult<T> { Some(T), None, } impl<T> From<Option<T>> for OptionalResult<T> { fn from(v: Option<T>) -> Self { match v { Some(result) => OptionalResult::Some(result), None => OptionalResult::None, } } } impl<FA, T> EndpointResult<FA> for OptionalResult<T> where FA: EndpointFinishApi + Clone + 'static, T: EndpointResult<FA>, { #[inline] fn finish(&self, api: FA) { if let OptionalResult::Some(t) = self { t.finish(api); } } } impl<T: TypeAbi> TypeAbi for OptionalResult<T> { fn type_name() -> String { let mut repr = String::from("OptionalResult<"); repr.push_str(T::type_name().as_str()); repr.push('>'); repr } fn provide_type_descriptions<TDC: TypeDescriptionContainer>(accumulator: &mut TDC) { T::provide_type_descriptions(accumulator); } fn is_multi_arg_or_result() -> bool { true } }