pub fn from_string(string: &str) -> Result<Self, Error> {
        let list_of: HashMap<String, Value> =
            serde_json::from_str(string).map_err(|_| Error::ClaimInvalidJson)?;

        // Validate any possible registered claims for their type
        for registered_claim in Self::REGISTERED_CLAIMS {
            if let Some(claim) = list_of.get(registered_claim) {
                if let Some(claim_value) = claim.as_str() {
                    if registered_claim == "exp"
                        || registered_claim == "nbf"
                        || registered_claim == "iat"
                    {
                        OffsetDateTime::parse(claim_value, &Rfc3339)
                            .map_err(|_| Error::InvalidClaim)?;
                    }
                } else {
                    return Err(Error::InvalidClaim);
                }
            }
        }

        Ok(Self { list_of })
    }
/// Attempt to create `Claims` from a string.
///
/// Errors:
/// - `string` does not decode as valid JSON
/// - `string` top-most JSON object does not decode to a map
/// - if any registered claims exist and they are not a `String`
/// - if `exp`, `nbf` or `iat` exist and they cannot be parsed as `DateTime`
Attempt to create `Claims` from a string.
Attempt to create ` Claims ` from a string .
pub fn from_string(string: &str) -> Result<Self, Error> {
        let list_of: HashMap<String, Value> =
            serde_json::from_str(string).map_err(|_| Error::ClaimInvalidJson)?;
        // Validate any possible registered claims for their type
        for registered_claim in Self::REGISTERED_CLAIMS {
            if let Some(claim) = list_of.get(registered_claim) {
                if let Some(claim_value) = claim.as_str() {
                    if registered_claim == "exp"
                        || registered_claim == "nbf"
                        || registered_claim == "iat"
                    {
                        OffsetDateTime::parse(claim_value, &Rfc3339)
                            .map_err(|_| Error::InvalidClaim)?;
                    }
                } else {
                    return Err(Error::InvalidClaim);
                }
            }
        }
        Ok(Self { list_of })
    }
pub fn from_string ( string : & str ) -> Result < Self , Error > { let list_of : HashMap < String , Value > = serde_json :: from_str ( string ) . map_err ( | _ | Error :: ClaimInvalidJson ) ? ; // Validate any possible registered claims for their type for registered_claim in Self :: REGISTERED_CLAIMS { if let Some ( claim ) = list_of . get ( registered_claim ) { if let Some ( claim_value ) = claim . as_str ( ) { if registered_claim == " " || registered_claim == " " || registered_claim == " " { OffsetDateTime :: parse ( claim_value , & Rfc3339 ) . map_err ( | _ | Error :: InvalidClaim ) ? ; } } else { return Err ( Error :: InvalidClaim ) ; } } } Ok ( Self { list_of } ) }
Attempt to create `Claims` from a string.
Attempt to create ` Claims ` from a string .
string
&str