Skip to content

Commit 6a5cce8

Browse files
authored
nit: golf NameRef::try_from_ascii_str() (#3786)
this golfs down the return expression in `NameRef::try_from_ascii_str()`. rather than binding our `s` to a temporary variable, in order to return a `Self(s)` result, we can take the same result and use `Result::map` to convert a `Result<&'a str, InvalidName>` to a `Result<NameRef<'a>, InvalidName>`. Signed-off-by: katelyn martin <kate@buoyant.io>
1 parent acbea26 commit 6a5cce8

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

linkerd/dns/name/src/name.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ impl<'a> NameRef<'a> {
118118
return Err(InvalidName);
119119
}
120120

121-
let s = std::str::from_utf8(dns_name).map_err(|_| InvalidName)?;
122-
Ok(Self(s))
121+
std::str::from_utf8(dns_name)
122+
.map(Self)
123+
.map_err(|_| InvalidName)
123124
}
124125

125126
pub fn try_from_ascii_str(n: &'a str) -> Result<Self, InvalidName> {

0 commit comments

Comments
 (0)