Skip to content

Commit 5937e0f

Browse files
committed
Fix the implementation of Display and TryFrom<&str> for Teletype
Fixes #7732 and fixes #7733
1 parent e1645bb commit 5937e0f

File tree

1 file changed

+7
-7
lines changed
  • src/uucore/src/lib/features

1 file changed

+7
-7
lines changed

src/uucore/src/lib/features/tty.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ pub enum Teletype {
2020
impl Display for Teletype {
2121
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
2222
match self {
23-
Self::Tty(id) => write!(f, "/dev/pts/{id}"),
24-
Self::TtyS(id) => write!(f, "/dev/tty{id}"),
25-
Self::Pts(id) => write!(f, "/dev/ttyS{id}"),
23+
Self::Tty(id) => write!(f, "/dev/tty{id}"),
24+
Self::TtyS(id) => write!(f, "/dev/ttyS{id}"),
25+
Self::Pts(id) => write!(f, "/dev/pts/{id}"),
2626
Self::Unknown => write!(f, "?"),
2727
}
2828
}
@@ -32,10 +32,6 @@ impl TryFrom<String> for Teletype {
3232
type Error = ();
3333

3434
fn try_from(value: String) -> Result<Self, Self::Error> {
35-
if value == "?" {
36-
return Ok(Self::Unknown);
37-
}
38-
3935
Self::try_from(value.as_str())
4036
}
4137
}
@@ -44,6 +40,10 @@ impl TryFrom<&str> for Teletype {
4440
type Error = ();
4541

4642
fn try_from(value: &str) -> Result<Self, Self::Error> {
43+
if value == "?" {
44+
return Ok(Self::Unknown);
45+
}
46+
4747
Self::try_from(PathBuf::from(value))
4848
}
4949
}

0 commit comments

Comments
 (0)