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-07-10 16:36:15 +02:00
committed by Alexis Sellier
parent fb63b1c15d
commit ff81b1a6ed
+1 -6
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))
}
}