Skip to content

Commit

Permalink
feat: Add TryInto trait for simplicity of conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
andoriyu committed Mar 22, 2020
1 parent 5bff686 commit 5f1cff2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,16 @@ pub trait FromObject<T>: Sized {
/// Performs the conversion.
fn try_from(value: T) -> Result<Self, ObjectError>;
}

pub trait TryInto<T> :Sized {
fn try_into(self) -> Result<T, ObjectError>;
}

impl<T, U> TryInto<U> for T
where
U: FromObject<T>,
{
fn try_into(self) -> Result<U, ObjectError> {
U::try_from(self)
}
}

0 comments on commit 5f1cff2

Please sign in to comment.