Struct binread::NullWideString [−][src]
Expand description
A null terminated UTF-16 string designed to make reading any 16 bit wide null-terminated data easier.
Note: Does not include the null.
Note: This is endian dependent on a per-character basis. Will read u16
s until a 0u16
is found.
use binread::{BinRead, BinReaderExt, NullWideString, io::Cursor};
const WIDE_STRINGS: &[u8] = b"w\0i\0d\0e\0 \0s\0t\0r\0i\0n\0g\0s\0\0\0";
const ARE_ENDIAN_DEPENDENT: &[u8] = b"\0a\0r\0e\0 \0e\0n\0d\0i\0a\0n\0 \0d\0e\0p\0e\0n\0d\0e\0n\0t\0\0";
let mut wide_strings = Cursor::new(WIDE_STRINGS);
let mut are_endian_dependent = Cursor::new(ARE_ENDIAN_DEPENDENT);
assert_eq!(
// notice: read_le
wide_strings.read_le::<NullWideString>().unwrap().into_string(),
"wide strings"
);
assert_eq!(
// notice: read_be
are_endian_dependent.read_be::<NullWideString>().unwrap().into_string(),
"are endian dependent"
);
Tuple Fields
0: Vec<u16>
Implementations
Methods from Deref<Target = Vec<u16>>
Returns the number of elements the vector can hold without reallocating.
Examples
let vec: Vec<i32> = Vec::with_capacity(10);
assert_eq!(vec.capacity(), 10);
Extracts a slice containing the entire vector.
Equivalent to &s[..]
.
Examples
use std::io::{self, Write};
let buffer = vec![1, 2, 3, 5, 8];
io::sink().write(buffer.as_slice()).unwrap();
Returns a raw pointer to the vector’s buffer.
The caller must ensure that the vector outlives the pointer this function returns, or else it will end up pointing to garbage. Modifying the vector may cause its buffer to be reallocated, which would also make any pointers to it invalid.
The caller must also ensure that the memory the pointer (non-transitively) points to
is never written to (except inside an UnsafeCell
) using this pointer or any pointer
derived from it. If you need to mutate the contents of the slice, use as_mut_ptr
.
Examples
let x = vec![1, 2, 4];
let x_ptr = x.as_ptr();
unsafe {
for i in 0..x.len() {
assert_eq!(*x_ptr.add(i), 1 << i);
}
}
🔬 This is a nightly-only experimental API. (allocator_api
)
allocator_api
)Returns a reference to the underlying allocator.
Returns the number of elements in the vector, also referred to as its ‘length’.
Examples
let a = vec![1, 2, 3];
assert_eq!(a.len(), 3);
Trait Implementations
The type of arguments needed to be supplied in order to read this type, usually a tuple. Read more
fn read_options<R: Read + Seek>(
reader: &mut R,
options: &ReadOptions,
args: Self::Args
) -> BinResult<Self>
fn read_options<R: Read + Seek>(
reader: &mut R,
options: &ReadOptions,
args: Self::Args
) -> BinResult<Self>
Read the type from the reader
Read the type from the reader while assuming no arguments have been passed Read more
Read the type from the reader using the specified arguments
fn after_parse<R: Read + Seek>(
&mut self,
_: &mut R,
_: &ReadOptions,
_: Self::Args
) -> BinResult<()>
Returns the “default value” for a type. Read more
Performs the conversion.
Performs the conversion.
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
Auto Trait Implementations
impl RefUnwindSafe for NullWideString
impl Send for NullWideString
impl Sync for NullWideString
impl Unpin for NullWideString
impl UnwindSafe for NullWideString
Blanket Implementations
Mutably borrows from an owned value. Read more