diff --git a/ctutils/src/choice.rs b/ctutils/src/choice.rs index d6fed7cc..7a1f31ec 100644 --- a/ctutils/src/choice.rs +++ b/ctutils/src/choice.rs @@ -49,6 +49,7 @@ impl Choice { /// /// # Panics /// - in `debug` builds, panics if the value is anything other than `0` or `1`. + // TODO(tarcieri): deprecate this in favor of non-panicking constructors? #[inline] pub const fn new(value: u8) -> Self { // Compare to what should be the non-secret upper bits of the value, which should always be @@ -388,6 +389,17 @@ impl CtSelect for Choice { } } +/// Create a new [`Choice`] from the given `u8` value, which MUST be either `0` or `1`. +/// +/// # Panics +/// - in `debug` builds, panics if the value is anything other than `0` or `1`. +// TODO(tarcieri): deprecate this in favor of non-panicking constructors? +impl From for Choice { + fn from(value: u8) -> Self { + Choice::new(value) + } +} + impl From for u8 { fn from(choice: Choice) -> u8 { choice.to_u8()