diff --git a/CHANGELOG.md b/CHANGELOG.md index e9479029..bdc8e453 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ project adheres to [Semantic Versioning](https://semver.org/). ## [Unreleased] ### Added * Added conversions between `DataBits`, `StopBits` types and their numeric representations +* Added `FromStr` implementation for `FlowControl` ### Changed ### Fixed * Fixes a bug where `available_ports()` returned disabled devices on Windows. diff --git a/src/lib.rs b/src/lib.rs index 47ecffbd..f369c41c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,6 +36,7 @@ use std::convert::From; use std::error::Error as StdError; use std::fmt; use std::io; +use std::str::FromStr; use std::time::Duration; #[cfg(unix)] @@ -284,6 +285,19 @@ impl fmt::Display for FlowControl { } } +impl FromStr for FlowControl { + type Err = (); + + fn from_str(s: &str) -> core::result::Result { + match s { + "None" | "none" | "n" => Ok(FlowControl::None), + "Software" | "software" | "SW" | "sw" | "s" => Ok(FlowControl::Software), + "Hardware" | "hardware" | "HW" | "hw" | "h" => Ok(FlowControl::Hardware), + _ => Err(()), + } + } +} + /// Specifies which buffer or buffers to purge when calling [`clear`] /// /// [`clear`]: trait.SerialPort.html#tymethod.clear