nix
nix copied to clipboard
sys/termios: add cross-platform API for arbitrary baud rates
trafficstars
This commit adds
pub struct ArbitraryBaudRate(pub u32);
impl TryFrom<ArbitraryBaudRate> for BaudRate { ... }
such that arbitrary baud rates can be specified on systems that otherwise do not support it (e.g. Linux) via abstraction.
The one problem I see with this implementation is the duplication of the BaudRate enum. Removing the duplication would require a new macro, which may be too complex for this feature to warrant implementation.
Alan Somers @.***> writes:
Why add the
ArbitraryBaudRatestructure? I think implementingTryFrom<u32>directly onBaudRateshould be fine. TryFromis already implemented but the u32is the C representation of the underlyingB*enum. E.g.assert_eq!(BaudRate::try_from(14), Ok(Baudrate::B115200)), IIRC.