Skip to content

Why is DefaultBufFactory private? (prevents generic use of quiche::Connection<F>) #2323

@birneee

Description

@birneee

I have a question about the visibility of DefaultBufFactory and whether this is an intentional design choice.

I would like to create a generic data structure around quiche::Connection so that it can work with either a custom BufFactory or the default one. For example:

struct ConnectionMap<F: BufFactory>(HashMap<usize, Connection<F>>);

This works fine with a custom implementation:

ConnectionMap::<MyCustomBufFactory>::new();

However, because DefaultBufFactory is private, I can’t instantiate the same structure using the default buffer factory:

ConnectionMap::<DefaultBufFactory>::new(); // not possible

As a workaround, I can define two separate types:

struct ConnectionMapWithBufFactory<F: BufFactory>(HashMap<usize, Connection<F>>);
struct ConnectionMapWithoutBufFactory(HashMap<usize, Connection>);

But this quickly propagates to other structs and forces duplication or additional abstraction such as:

trait ConnectionMapWithOrWithoutBufFactory {}
impl ConnectionMapWithOrWithoutBufFactory for ConnectionMapWithBufFactory {}
impl ConnectionMapWithOrWithoutBufFactory for ConnectionMapWithoutBufFactory {}

struct Endpoint<M: ConnectionMapWithOrWithoutBufFactory> { ... }

Should DefaultBufFactory be public?

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