Skip to content

Commit feca88a

Browse files
committed
refactor: unify TryFrom traits
use &str instead () in TryFrom<&str>
1 parent 8f1a1d0 commit feca88a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@ impl AsRef<String> for NonEmptyString {
128128
}
129129

130130
impl<'s> TryFrom<&'s str> for NonEmptyString {
131-
type Error = ();
131+
type Error = &'s str;
132132

133133
fn try_from(value: &'s str) -> Result<Self, Self::Error> {
134134
if value.is_empty() {
135-
Err(())
136-
} else {
137-
Ok(NonEmptyString::new(value.to_owned()).expect("Value is not empty"))
135+
return Err(value);
138136
}
137+
138+
Ok(NonEmptyString(value.to_owned()))
139139
}
140140
}
141141

0 commit comments

Comments
 (0)