/// Update the value, return true if updated. pubfn update(&mutself, now: Instant, rate: Option<Bitrate>) -> bool { // This uses the simplest form of update, to keep it simple. // A fancier method would remember some number of higher-rate updates // and switch to those when the lower rate expires. if rate.is_some_and(|r| r <= self.rate) || self.expired(now) { self.updated = now; let rate = rate.unwrap_or_default(); let changed = rate != self.rate; self.rate = rate;
changed
} else { false
}
}
}
impl PartialOrd for Bitrate { // This compares `UNKNOWN` as higher than all other values. fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { self.0.partial_cmp(&other.0)
}
}
impl From<(u8, u32)> for Bitrate { fn from((first, version): (u8, u32)) -> Self { // 7-bit signal: bits [6:1] from first byte, bit [0] from version MSB. Self(u8::try_from(version >> 31).expect("always u8") | ((first & 0x3f) << 1))
}
}
impl From<Bitrate> for Option<NonZeroU64> { #[expect(clippy::cast_possible_truncation, reason = "We want truncation here")] #[expect(clippy::cast_sign_loss, reason = "negative values are impossible")] fn from(value: Bitrate) -> Self {
value
.is_set()
.then(|| { // Bitrate formula is 100_000 * 10^(n/20), // log10(100_000) is 5, and 10^(1/20) is 1.122...
NonZeroU64::new(1.122_018_454_301_963_3_f64.powi(100 + i32::from(value.0)) as u64)
})
.flatten()
}
}
#[cfg(test)] mod test { use std::{num::NonZeroU64, time::Duration};
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.22Bemerkung:
(vorverarbeitet am 2026-08-25)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.