pub struct KxSnRef<'a> { /* private fields */ }Expand description
Zero-copy view over the k elements of a KxSn array (each element is a
2-byte, byte-order-dependent length prefix followed by the payload).
Elements are decoded with the same rule as SnRef::as_str and can be
iterated directly:
use rust_stdf::{ByteOrder, KxSnRef};
let raw = [2, 0, b'A', b'B', 2, 0, b'C', b'D']; // two elements: "AB", "CD"
let kx = KxSnRef::new(&raw, 0, 2, ByteOrder::LittleEndian);
for s in &kx {
println!("{s}");
}Implementations§
Source§impl<'a> KxSnRef<'a>
impl<'a> KxSnRef<'a>
Sourcepub fn new(raw: &'a [u8], start: usize, k: usize, order: ByteOrder) -> Self
pub fn new(raw: &'a [u8], start: usize, k: usize, order: ByteOrder) -> Self
Construct a view over k elements starting at byte offset start,
using order for the 2-byte length prefixes.
Normally obtained from a generated *View getter; only needed when
parsing a known raw layout directly.
Sourcepub fn get_str(&self, i: usize) -> Option<Cow<'a, str>>
pub fn get_str(&self, i: usize) -> Option<Cow<'a, str>>
Decoded i-th element; None when i is out of range.
Valid UTF-8 payloads are borrowed zero-copy; other payloads are decoded
byte → char (Latin-1) into an owned String.
Sourcepub fn get_bytes(&self, i: usize) -> Option<&'a [u8]>
pub fn get_bytes(&self, i: usize) -> Option<&'a [u8]>
Raw payload bytes of the i-th element (without the length prefix);
None when i is out of range.
Sourcepub fn iter(&self) -> KxSnRefIter<'a> ⓘ
pub fn iter(&self) -> KxSnRefIter<'a> ⓘ
Iterator over the decoded elements, one pass.
Trait Implementations§
impl<'a> Copy for KxSnRef<'a>
Auto Trait Implementations§
impl<'a> Freeze for KxSnRef<'a>
impl<'a> RefUnwindSafe for KxSnRef<'a>
impl<'a> Send for KxSnRef<'a>
impl<'a> Sync for KxSnRef<'a>
impl<'a> Unpin for KxSnRef<'a>
impl<'a> UnsafeUnpin for KxSnRef<'a>
impl<'a> UnwindSafe for KxSnRef<'a>
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
Mutably borrows from an owned value. Read more