refactor: Use and_then instead of map

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb 2024-07-23 11:49:55 +03:00
parent 79ef0d2448
commit 35a7354de1
Signed by: awiteb
GPG key ID: 3F6B55640AA6682F

View file

@ -44,24 +44,20 @@ impl From<PublicKey> for Value {
impl TryGetable for PublicKey {
fn try_get_by<I: sea_orm::ColIdx>(res: &QueryResult, idx: I) -> Result<Self, TryGetError> {
<String as TryGetable>::try_get_by(res, idx)
.map(|v| {
PublicKey::from_str(&v)
.map_err(|err| TryGetError::DbErr(DbErr::Type(err.to_string())))
})
.and_then(|res| res)
<String as TryGetable>::try_get_by(res, idx).and_then(|v| {
PublicKey::from_str(&v).map_err(|err| TryGetError::DbErr(DbErr::Type(err.to_string())))
})
}
}
impl ValueType for PublicKey {
fn try_from(v: Value) -> Result<Self, ValueTypeErr> {
<String as ValueType>::try_from(v)
.map(|v| PublicKey::from_str(&v).map_err(|_| ValueTypeErr))
.and_then(|res| res)
.and_then(|v| PublicKey::from_str(&v).map_err(|_| ValueTypeErr))
}
fn type_name() -> String {
stringify!(PublicKey).to_owned()
String::from("PublicKey")
}
fn array_type() -> ArrayType {