From d7717f172119780f7551726b866add71b80e973b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Haudebourg?= Date: Wed, 28 May 2025 13:56:48 +0200 Subject: [PATCH] Add `BitString` to `Vec` conversion. --- .../src/impl/bitstring_status_list/mod.rs | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/crates/status/src/impl/bitstring_status_list/mod.rs b/crates/status/src/impl/bitstring_status_list/mod.rs index 58a5b9c82..4ee6f4d8e 100644 --- a/crates/status/src/impl/bitstring_status_list/mod.rs +++ b/crates/status/src/impl/bitstring_status_list/mod.rs @@ -260,7 +260,6 @@ impl FromStr for StatusPurpose { /// Bit-string with status size. /// -/// /// This type is similar to [`BitString`] but also stores the bit size of /// each item (status size) and the number of items in the list. /// This provides a safer access to the underlying bit-string, ensuring that @@ -415,6 +414,17 @@ impl SizedBitString { pub fn into_unsized(self) -> BitString { self.inner } + + /// Consumes the bit-string and returns its raw bytes. + pub fn into_bytes(self) -> Vec { + self.inner.into_bytes() + } +} + +impl From for Vec { + fn from(value: SizedBitString) -> Self { + value.into_bytes() + } } /// Bit-string as defined by the W3C Bitstring Status List specification. @@ -569,6 +579,17 @@ impl BitString { pub fn encode(&self) -> EncodedList { EncodedList::encode(&self.0) } + + /// Consumes the bit-string and returns its raw bytes. + pub fn into_bytes(self) -> Vec { + self.0 + } +} + +impl From for Vec { + fn from(value: BitString) -> Self { + value.into_bytes() + } } trait OverflowingSignedShift: Sized { @@ -614,9 +635,9 @@ impl StatusList { } } - pub fn from_bytes(bytes: Vec, ttl: TimeToLive) -> Self { + pub fn from_bytes(bytes: impl Into>, ttl: TimeToLive) -> Self { Self { - bit_string: BitString::from_bytes(bytes), + bit_string: BitString::from_bytes(bytes.into()), ttl, } }