node: Use `str::trim_end_matches` for stripping '\0' in alias

Signed-off-by: xphoniex <dj.2dixx@gmail.com>
This commit is contained in:
xphoniex 2023-06-26 17:04:33 +00:00 committed by Alexis Sellier
parent fb63b1c15d
commit ff81b1a6ed
No known key found for this signature in database
1 changed files with 1 additions and 6 deletions

View File

@ -121,12 +121,7 @@ impl NodeAnnouncement {
/// Get the alias as a UTF-8 string.
pub fn alias(&self) -> Result<&str, std::str::Utf8Error> {
let length = self
.alias
.iter()
.position(|&b| b == 0)
.unwrap_or(self.alias.len());
str::from_utf8(&self.alias[..length])
Ok(str::from_utf8(&self.alias)?.trim_end_matches(0 as char))
}
}