Skip to main content

clamp_volume

Function clamp_volume 

Source
pub fn clamp_volume(current: u8, requested: u8) -> u8
Expand description

Returns the volume level to apply for requested while current is in force.

This is clamp_volume_with with VolumePolicy::default: a request to 40 or below is applied as asked, and above 40 one request may raise the level by at most 20. Both values are first limited to the protocol’s 0-100 range, so the result is always a level the server accepts.

assert_eq!(clamp_volume(40, 100), 60);
assert_eq!(clamp_volume(40, 10), 10);
assert_eq!(clamp_volume(100, 90), 90);
assert_eq!(clamp_volume(100, 150), 100);