refactor: Use and_then
instead of map
Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
parent
79ef0d2448
commit
35a7354de1
1 changed files with 5 additions and 9 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue