Skip to content

Combine multiple CtOptional results #93

Description

@krnak

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions