Remove unsafe from impl Compact for ClientVersion (#11318)

Co-authored-by: Emilia Hane <elsaemiliaevahane@gmail.com>
Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>
This commit is contained in:
0xriazaka.eth
2024-10-17 21:28:13 +01:00
committed by GitHub
parent a6c8bda029
commit 8eb5d4f047
2 changed files with 22 additions and 11 deletions

View File

@ -78,6 +78,21 @@ pub trait Compact: Sized {
}
}
impl Compact for alloc::string::String {
fn to_compact<B>(&self, buf: &mut B) -> usize
where
B: bytes::BufMut + AsMut<[u8]>,
{
self.as_bytes().to_compact(buf)
}
fn from_compact(buf: &[u8], len: usize) -> (Self, &[u8]) {
let (vec, buf) = Vec::<u8>::from_compact(buf, len);
let string = Self::from_utf8(vec).unwrap(); // Safe conversion
(string, buf)
}
}
impl<T: Compact> Compact for &T {
fn to_compact<B>(&self, buf: &mut B) -> usize
where