pub struct Priority(/* private fields */);Expand description
A candidate priority: a positive integer up to 2^31 − 1 (RFC 8839 §5.1).
The bound is the type’s whole reason for existing. RFC 8445 §6.1.2.3 combines two priorities
into a pair priority as 2^32*MIN(G,D) + 2*MAX(G,D) + (G>D?1:0). With both operands at
2^31 − 1 that comes to 2^63 − 2: the G > D term is zero when the two are equal, so the
2^63 − 1 upper bound is approached and never reached, and every in-range pair therefore has
half a u64 of headroom.
Carry an unchecked u32 from the wire into the same expression and the headroom is spent.
The overflow is not one step past the bound — the arithmetic is still exact at 4294967294 —
but 4294967295 on both sides, the ten-digit value 1*10DIGIT admits, comes to 2^64 + 2^32 − 2 and wraps. In a release build it wraps silently, reordering the checklist that the
arithmetic exists to order. the_priority_bound_is_what_keeps_the_pair_priority_in_a_u64
asserts both halves of this.
Implementations§
Source§impl Priority
impl Priority
Sourcepub fn parse(text: &str) -> Option<Self>
pub fn parse(text: &str) -> Option<Self>
Read a priority production.
1*10DIGIT admits ten digits, so 4294967295 is well-formed text that is not a legal
priority. It is read wide and then range-checked, so that an out-of-range value is
rejected as out of range rather than silently truncated to something plausible.