In #1998 the lifetime was removed from OctetStringRef by making it a slice newtype, which to simplify looks something like pub struct OctetStringRef([u8]), and in practice used as &OctetStringRef.
What's really nice about this it means we can impl Borrow<OctetStringRef> for OctetString and ToOwned for OctetStringRef, and with that we can use Cow<OctetStringRef>.
We discussed several times whether it would be possible to do this for BitStringRef too and at the time I couldn't figure out a way. I looked into trying to put the unused bits in a tagged pointer but that won't work since we need to construct them from &[u8]. However the other place we can stick the information is in the length part of the fat pointer by using it to store the length in bits instead of bytes.
Concretely that might look like pub struct BitStringRef([UnsafeCell<()>]) where the length of that inner slice represents a number of bits.
Here's a POC of the idea:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=e162511e707fe74c8f9f7731972acd32
cc @baloo @dishmaker
(Thanks to #dark-arts for some help here)
In #1998 the lifetime was removed from
OctetStringRefby making it a slice newtype, which to simplify looks something likepub struct OctetStringRef([u8]), and in practice used as&OctetStringRef.What's really nice about this it means we can
impl Borrow<OctetStringRef> for OctetStringandToOwned for OctetStringRef, and with that we can useCow<OctetStringRef>.We discussed several times whether it would be possible to do this for
BitStringReftoo and at the time I couldn't figure out a way. I looked into trying to put the unused bits in a tagged pointer but that won't work since we need to construct them from&[u8]. However the other place we can stick the information is in the length part of the fat pointer by using it to store the length in bits instead of bytes.Concretely that might look like
pub struct BitStringRef([UnsafeCell<()>])where the length of that inner slice represents a number of bits.Here's a POC of the idea:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=e162511e707fe74c8f9f7731972acd32
cc @baloo @dishmaker
(Thanks to #dark-arts for some help here)