Skip to content

Commit

Permalink
πŸ› zv: Maybe::get now construct value from reference
Browse files Browse the repository at this point in the history
This makes all `get` methods in zvariant consistent with each other.
  • Loading branch information
zeenix committed Nov 28, 2023
1 parent fa51eea commit 6643ffc
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions zvariant/src/maybe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,15 @@ impl<'a> Maybe<'a> {
}

/// Get the inner value as a concrete type
pub fn get<T>(self) -> core::result::Result<Option<T>, Error>
pub fn get<T>(&'a self) -> core::result::Result<Option<T>, Error>
where
T: TryFrom<Value<'a>>,
T: ?Sized + TryFrom<&'a Value<'a>>,
<T as TryFrom<&'a Value<'a>>>::Error: Into<crate::Error>,
{
self.value
.map(|v| v.downcast().ok_or(Error::IncorrectType))
.as_ref()
.as_ref()
.map(|v| v.downcast_ref())
.transpose()
}

Expand Down

0 comments on commit 6643ffc

Please sign in to comment.