Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,20 @@ impl fmt::Display for DataBits {
}
}

impl FromStr for DataBits {
type Err = ();

fn from_str(s: &str) -> core::result::Result<Self, Self::Err> {
match s {
"Five" | "five" | "5" => Ok(Self::Five),
"Six" | "six" | "6" => Ok(Self::Six),
"Seven" | "seven" | "7" => Ok(Self::Seven),
"Eight" | "eight" | "8" => Ok(Self::Eight),
_ => Err(()),
}
}
}

impl From<DataBits> for u8 {
fn from(value: DataBits) -> Self {
match value {
Expand Down Expand Up @@ -221,6 +235,19 @@ impl fmt::Display for Parity {
}
}

impl FromStr for Parity {
type Err = ();

fn from_str(s: &str) -> std::result::Result::<Self, Self::Err> {
match s {
"None" | "none" => Ok(Self::None),
"Odd" | "odd" => Ok(Self::Odd),
"Even" | "even" => Ok(Self::Even),
_ => Err(()),
}
}
}

/// Number of stop bits
///
/// Stop bits are transmitted after every character.
Expand All @@ -243,6 +270,18 @@ impl fmt::Display for StopBits {
}
}

impl FromStr for StopBits {
type Err = ();

fn from_str(s: &str) -> core::result::Result<Self, Self::Err> {
match s {
"One" | "one" | "1" => Ok(Self::One),
"Two" | "two" | "2" => Ok(Self::Two),
_ => Err(()),
}
}
}

impl From<StopBits> for u8 {
fn from(value: StopBits) -> Self {
match value {
Expand Down
Loading