From 5f1cff23fd1ab75a1c92fc2748bcae84a63125ed Mon Sep 17 00:00:00 2001 From: Andrey Cherkashin <148123+andoriyu@users.noreply.github.com> Date: Sat, 21 Mar 2020 17:39:06 -0700 Subject: [PATCH] feat: Add TryInto trait for simplicity of conversion. --- .idea/vcs.xml | 5 +++++ src/traits.rs | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..78cface 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,5 +1,10 @@ + + + + + diff --git a/src/traits.rs b/src/traits.rs index abd689f..f1115c5 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -6,3 +6,16 @@ pub trait FromObject: Sized { /// Performs the conversion. fn try_from(value: T) -> Result; } + +pub trait TryInto :Sized { + fn try_into(self) -> Result; +} + +impl TryInto for T + where + U: FromObject, +{ + fn try_into(self) -> Result { + U::try_from(self) + } +} \ No newline at end of file