mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 06:44:17 +00:00
feat: add Resource::and_then
This commit is contained in:
parent
3b88c8ccd2
commit
7094308287
1 changed files with 18 additions and 0 deletions
|
@ -695,6 +695,24 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T, E, Ser> Resource<Result<T, E>, Ser>
|
||||
where
|
||||
Ser: Encoder<Result<T, E>> + Decoder<Result<T, E>>,
|
||||
<Ser as Encoder<Result<T, E>>>::Error: Debug,
|
||||
<Ser as Decoder<Result<T, E>>>::Error: Debug,
|
||||
<<Ser as Decoder<Result<T, E>>>::Encoded as FromEncodedStr>::DecodingError:
|
||||
Debug,
|
||||
<Ser as Encoder<Result<T, E>>>::Encoded: IntoEncodedString,
|
||||
<Ser as Decoder<Result<T, E>>>::Encoded: FromEncodedStr,
|
||||
T: Send + Sync + Clone,
|
||||
E: Send + Sync + Clone,
|
||||
{
|
||||
#[track_caller]
|
||||
pub fn and_then<U>(&self, f: impl FnOnce(&T) -> U) -> Option<Result<U, E>> {
|
||||
self.map(|data| data.as_ref().map(f).map_err(|e| e.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, Ser> IntoFuture for Resource<T, Ser>
|
||||
where
|
||||
T: Clone + Send + Sync + 'static,
|
||||
|
|
Loading…
Reference in a new issue