pub struct StringView<'a> { /* private fields */ }Expand description
A borrowed ProtoCache byte string.
ProtoCache does not require string payloads to be UTF-8; use Self::as_str
when text validation is required.
Implementations§
Source§impl<'a> StringView<'a>
impl<'a> StringView<'a>
Sourcepub fn new(words: &'a [u32]) -> Option<Self>
pub fn new(words: &'a [u32]) -> Option<Self>
Parses a string/bytes object from the beginning of words.
Sourcepub fn detect_len(words: &'a [u32]) -> Option<usize>
pub fn detect_len(words: &'a [u32]) -> Option<usize>
Returns the encoded object length in words without constructing a view.
Sourcepub fn detect(words: &'a [u32]) -> Option<&'a [u32]>
pub fn detect(words: &'a [u32]) -> Option<&'a [u32]>
Returns the exact encoded subslice occupied by the string/bytes object.
Sourcepub fn as_str(self) -> Option<&'a str>
pub fn as_str(self) -> Option<&'a str>
Returns the payload as text, or None if it is not valid UTF-8.
Examples found in repository?
examples/basic.rs (line 13)
3fn main() {
4 let mut buffer = Buffer::new();
5 let name = serialize_str("Ada", &mut buffer).expect("name is encodable");
6 let mut fields = [serialize_scalar(42_i32), name];
7 serialize_message(&mut fields, &mut buffer).expect("message is encodable");
8
9 let view = MessageView::new(buffer.view()).expect("valid ProtoCache message");
10 let id = view.scalar::<i32>(0).expect("id field");
11 let name = view
12 .string(1)
13 .and_then(|value| value.as_str())
14 .expect("UTF-8 name field");
15
16 println!("id={id}, name={name}");
17}Sourcepub fn as_bool_array(self) -> BoolArray<'a>
pub fn as_bool_array(self) -> BoolArray<'a>
Interprets every payload byte as one boolean value.
Trait Implementations§
Source§impl AsRef<[u8]> for StringView<'_>
impl AsRef<[u8]> for StringView<'_>
Source§impl<'a> Clone for StringView<'a>
impl<'a> Clone for StringView<'a>
Source§fn clone(&self) -> StringView<'a>
fn clone(&self) -> StringView<'a>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl<'a> Copy for StringView<'a>
Source§impl<'a> Debug for StringView<'a>
impl<'a> Debug for StringView<'a>
Source§impl<'a> Display for StringView<'a>
impl<'a> Display for StringView<'a>
Source§impl<'a> FieldDecode<'a> for StringView<'a>
impl<'a> FieldDecode<'a> for StringView<'a>
Auto Trait Implementations§
impl<'a> Freeze for StringView<'a>
impl<'a> RefUnwindSafe for StringView<'a>
impl<'a> Send for StringView<'a>
impl<'a> Sync for StringView<'a>
impl<'a> Unpin for StringView<'a>
impl<'a> UnsafeUnpin for StringView<'a>
impl<'a> UnwindSafe for StringView<'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