Skip to content

Prevent implementing both ArcCastPtr and BoxCastPtr on the same type #349

Closed
@jsha

Description

@jsha

In #341 (comment) we ran into a problem: both ArcCastPtr and BoxCastPtr were implemented for rustls_client_cert_verifier. This turned out fine because only the Box-related casts were used, but it could have turned out badly if, for instance, a pointer was created as a Box and later (incorrectly) cast to an Arc.

We should see if we can use the Rust type system to make it impossible to implement both of these for the same type.

Also, right now we have helper traits CastPtr / ConstConstPtr that are trait bounds for ArcCastPtr and BoxCastPtr. So for each C-facing type, we need to do two trait impls. We could probably simplify things by removing the trait bound, and instead adding a blanket impl of CastConstPtr for all ArcCastPtr and all BoxCastPtr; and a blanket impl of CastPtr for all BoxCastPtr. That way we would only need to impl one of ArcCastPtr / BoxCastPtr for any given Rust type:

today:

impl CastPtr for rustls_root_cert_store_builder {
    type RustType = Option<RootCertStoreBuilder>;
}

impl BoxCastPtr for rustls_root_cert_store_builder {}

future?

impl BoxCastPtr for rustls_root_cert_store_builder {
    type RustType = Option<RootCertStoreBuilder>;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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