subtle
subtle copied to clipboard
Combine multiple `CtOption`al results
My problem
struct C(A, B);
fn create_c(a: &[u8], b: &[u8]) -> CtOption<C> {
let a: CtOption<A> = A::from_bytes(a);
let b: CtOption<B> = B::from_bytes(b);
// ???
}
Proposed solution
impl<T,U> CtOption<T> {
pub fn merge<U>(self, other: CtOption<U>) -> CtOption<(T,U)> {
CtOption {
value: (self.value, other.value),
is_some: self.is_some & other.is_some,
}
}
}
let c = a.merge(b).map(|(a, b)| C(a,b));
May I prepare a PR? Or do you have any better idea?
That API seems fine to me