Skip to content

Convert callbacks to trait referencesΒ #5

@dhuseby

Description

@dhuseby

The open operation in the bs crate has a function called open_plog that takes two callback functions. I think the more idiomatic way to implement this is to pass in a reference to a trait impl. The current code looks like this:

pub fn open_plog<F1, F2>(config: Config, get_key: F1, sign_entry: F2) -> Result<Log, Error>
where
    F1: Fn(&Key, Codec, usize, usize) -> Result<Multikey, Error>,
    F2: Fn(&Multikey, &[u8]) -> Result<Multisig, Error>,
{
    // ...
}

I think the more idiomatic way is to define a traits and then pass in references to implementations of those traits:

pub fn open_plog(config: Config, get_key: &impl KeyLoader, signer: &impl Signer) -> Result<Log, Error> {
    // ...
}

The update operation in the bs crate has the same callbacks and should be updated as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions