lifecycle: u16::try_from instead of as-cast
This commit is contained in:
parent
d0f954bbc1
commit
6dbf4eedd7
2 changed files with 271 additions and 1 deletions
|
|
@ -34,7 +34,8 @@ pub fn agent_web_port(name: &str) -> u16 {
|
|||
hash ^= u32::from(b);
|
||||
hash = hash.wrapping_mul(16_777_619);
|
||||
}
|
||||
WEB_PORT_BASE + (hash % u32::from(WEB_PORT_RANGE)) as u16
|
||||
// Modulo of a u32 by a u16's value is guaranteed < u16::MAX, so try_from never fails.
|
||||
WEB_PORT_BASE + u16::try_from(hash % u32::from(WEB_PORT_RANGE)).unwrap_or(0)
|
||||
}
|
||||
|
||||
pub fn container_name(name: &str) -> String {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue