node: Use `str::trim_end_matches` for stripping '\0' in alias
Signed-off-by: xphoniex <dj.2dixx@gmail.com>
This commit is contained in:
parent
fb63b1c15d
commit
ff81b1a6ed
|
|
@ -121,12 +121,7 @@ impl NodeAnnouncement {
|
||||||
|
|
||||||
/// Get the alias as a UTF-8 string.
|
/// Get the alias as a UTF-8 string.
|
||||||
pub fn alias(&self) -> Result<&str, std::str::Utf8Error> {
|
pub fn alias(&self) -> Result<&str, std::str::Utf8Error> {
|
||||||
let length = self
|
Ok(str::from_utf8(&self.alias)?.trim_end_matches(0 as char))
|
||||||
.alias
|
|
||||||
.iter()
|
|
||||||
.position(|&b| b == 0)
|
|
||||||
.unwrap_or(self.alias.len());
|
|
||||||
str::from_utf8(&self.alias[..length])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue