Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine multiple CtOptional results #93

Open
krnak opened this issue Mar 16, 2022 · 1 comment · May be fixed by #132
Open

Combine multiple CtOptional results #93

krnak opened this issue Mar 16, 2022 · 1 comment · May be fixed by #132

Comments

@krnak
Copy link

krnak commented Mar 16, 2022

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?

@tarcieri
Copy link
Contributor

That API seems fine to me

@AaronFeickert AaronFeickert linked a pull request Jul 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants