Skip to content

Support private casts #9

Closed
Closed
@197g

Description

@197g

This is related but not the same as #3. For many applications the reference cast is wanted in a safe interface but want to assert some invariants on an inner type in the process. It would be very useful to expose a converter that can only be used by the type itself, instead of always generating a trait which by definition can be used by all users.

struct ethernet_frame([u8]);

impl ethernet_frame {
    pub fn new(bytes: &[u8]) -> Option<&Self> {
        if Self::valid(bytes) { // E.g. validate length, encoding, ...
            Some(ethernet_frame::__private_derive_conversion(bytes))
        } else {
            None
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions