Currently certain fields in some headers can be filled with invalid data that can not be represented on the wire. An example is the flow_label field in the Ipv6Header. In the struct it currently is an u32 but on the wire it is a 20-bit value. That means you can assign values to the struct that are not representable on the wire. Currently this would trigger a ValueError when writing a header, but it would be nicer if no "invalid" data is even settable in the header in the first place and the actual setting on an invalid data triggers an error.
The idea would be to introduce struct types (e.g. Ipv6FlowLabel) that implements the core::convert::TryFrom trait and disallow setting of invalid values in the first place.
Currently certain fields in some headers can be filled with invalid data that can not be represented on the wire. An example is the
flow_label
field in theIpv6Header
. In the struct it currently is anu32
but on the wire it is a 20-bit value. That means you can assign values to the struct that are not representable on the wire. Currently this would trigger aValueError
when writing a header, but it would be nicer if no "invalid" data is even settable in the header in the first place and the actual setting on an invalid data triggers an error.The idea would be to introduce struct types (e.g.
Ipv6FlowLabel
) that implements thecore::convert::TryFrom
trait and disallow setting of invalid values in the first place.