pub struct ByteString { /* private fields */ }Expand description
Content of a byte string, CBOR major type 2.
A byte string is either definite, in which case it is encoded as a single
run of bytes, or indefinite, in which case it is encoded as a sequence of
definite chunks terminated by a break. The chunk boundaries are preserved
so that a decoded item re-encodes to the exact same bytes, and they are
reached through chunks and its mutable and owning
counterparts.
§Example
use cbor_next::ByteString;
let definite = ByteString::new([0x01, 0x02]);
assert!(!definite.is_indefinite());
assert_eq!(definite.to_bytes(), [0x01, 0x02]);
let indefinite = ByteString::from_chunks([vec![0x01], vec![0x02]]);
assert!(indefinite.is_indefinite());
assert_eq!(indefinite.chunks().len(), 2);
assert_eq!(indefinite.to_bytes(), [0x01, 0x02]);Implementations§
Source§impl ByteString
impl ByteString
Sourcepub fn new(bytes: impl Into<Vec<u8>>) -> Self
pub fn new(bytes: impl Into<Vec<u8>>) -> Self
Create a definite length byte string from a single run of bytes.
Sourcepub fn from_chunks<I, B>(chunks: I) -> Self
pub fn from_chunks<I, B>(chunks: I) -> Self
Create an indefinite length byte string from its chunks.
Sourcepub fn with_indefinite(self, indefinite: bool) -> Self
pub fn with_indefinite(self, indefinite: bool) -> Self
Return the same content with the definite or indefinite encoding selected.
§Example
use cbor_next::ByteString;
let content = ByteString::new([0x01]).with_indefinite(true);
assert!(content.is_indefinite());Sourcepub fn set_indefinite(&mut self, indefinite: bool)
pub fn set_indefinite(&mut self, indefinite: bool)
Select the definite or indefinite encoding in place.
Sourcepub fn is_indefinite(&self) -> bool
pub fn is_indefinite(&self) -> bool
Whether the byte string uses the indefinite length encoding.
Sourcepub fn chunks(&self) -> &[Vec<u8>]
pub fn chunks(&self) -> &[Vec<u8>]
The chunks the byte string is made of.
A definite length byte string is normally a single chunk.
Sourcepub fn chunks_mut(&mut self) -> &mut Vec<Vec<u8>>
pub fn chunks_mut(&mut self) -> &mut Vec<Vec<u8>>
The chunks the byte string is made of, mutably.
Sourcepub fn into_chunks(self) -> Vec<Vec<u8>>
pub fn into_chunks(self) -> Vec<Vec<u8>>
Take ownership of the chunks the byte string is made of.
Trait Implementations§
Source§impl Clone for ByteString
impl Clone for ByteString
Source§impl Debug for ByteString
impl Debug for ByteString
Source§impl Default for ByteString
impl Default for ByteString
impl Eq for ByteString
Source§impl From<&[u8]> for ByteString
impl From<&[u8]> for ByteString
Source§impl From<ByteString> for DataItem
impl From<ByteString> for DataItem
Source§fn from(value: ByteString) -> Self
fn from(value: ByteString) -> Self
Source§impl From<TextString> for ByteString
impl From<TextString> for ByteString
Source§fn from(value: TextString) -> Self
fn from(value: TextString) -> Self
Source§impl Hash for ByteString
impl Hash for ByteString
Source§impl Ord for ByteString
impl Ord for ByteString
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for ByteString
impl PartialEq for ByteString
Source§impl PartialOrd for ByteString
impl PartialOrd for ByteString
impl StructuralPartialEq for ByteString
Source§impl TryFrom<ByteString> for TextString
impl TryFrom<ByteString> for TextString
Source§type Error = FromUtf8Error
type Error = FromUtf8Error
Auto Trait Implementations§
impl Freeze for ByteString
impl RefUnwindSafe for ByteString
impl Send for ByteString
impl Sync for ByteString
impl Unpin for ByteString
impl UnsafeUnpin for ByteString
impl UnwindSafe for ByteString
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.