Skip to content

Commit 74360d7

Browse files
Merge pull request #119 from tarcieri/ctoption-into-option
Add `CtOption::into_option`
2 parents dc3bce7 + 4ffd51d commit 74360d7

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,22 @@ impl<T> CtOption<T> {
794794

795795
Self::conditional_select(&self, &f, is_none)
796796
}
797+
798+
/// Convert the `CtOption<T>` wrapper into an `Option<T>`, depending on whether
799+
/// the underlying `is_some` `Choice` was a `0` or a `1` once unwrapped.
800+
///
801+
/// # Note
802+
///
803+
/// This function exists to avoid ending up with ugly, verbose and/or bad handled
804+
/// conversions from the `CtOption<T>` wraps to an `Option<T>` or `Result<T, E>`.
805+
/// This implementation doesn't intend to be constant-time nor try to protect the
806+
/// leakage of the `T` since the `Option<T>` will do it anyways.
807+
///
808+
/// It's equivalent to the corresponding `From` impl, however this version is
809+
/// friendlier for type inference.
810+
pub fn into_option(self) -> Option<T> {
811+
self.into()
812+
}
797813
}
798814

799815
impl<T: ConditionallySelectable> ConditionallySelectable for CtOption<T> {

0 commit comments

Comments
 (0)