Closed
Description
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
Labels
No labels