Unverified Commit 4eccaada authored by 82marbag's avatar 82marbag Committed by GitHub
Browse files

Implement FromParts for Option, Result (#2068)



* Implement FromParts for Option, Result

Signed-off-by: default avatarDaniele Ahmed <ahmeddan@amazon.de>
parent 18fc6923
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -36,6 +36,14 @@
//!
//! See [Accessing Un-modelled data](https://github.com/awslabs/smithy-rs/blob/main/design/src/server/from_parts.md)
//! a comprehensive overview.
//!
//! The following implementations exist:
//! * Tuples up to size 8, extracting each component.
//! * `Option<T>`: `Some(T)` if extracting `T` is successful, `None` otherwise.
//! * `Result<T, T::Rejection>`: `Ok(T)` if extracting `T` is successful, `Err(T::Rejection)` otherwise.
//!
//! when `T: FromParts`.
//!

use std::{
    convert::Infallible,
@@ -236,3 +244,25 @@ where
        )
    }
}

impl<P, T> FromParts<P> for Option<T>
where
    T: FromParts<P>,
{
    type Rejection = Infallible;

    fn from_parts(parts: &mut Parts) -> Result<Self, Self::Rejection> {
        Ok(T::from_parts(parts).ok())
    }
}

impl<P, T> FromParts<P> for Result<T, T::Rejection>
where
    T: FromParts<P>,
{
    type Rejection = Infallible;

    fn from_parts(parts: &mut Parts) -> Result<Self, Self::Rejection> {
        Ok(T::from_parts(parts))
    }
}