Struct binread::NullString[][src]

pub struct NullString(pub Vec<u8>);
Expand description

A null terminated UTF-8 string designed to make reading any null-terminated data easier.

Note: Result does not include the null, but the null is consumed from the Reader.

use binread::{BinRead, BinReaderExt, NullString, io::Cursor};

let mut null_separated_strings = Cursor::new(b"null terminated strings? in my system's language?\0no thanks\0");

assert_eq!(
    null_separated_strings.read_be::<NullString>().unwrap().into_string(),
    "null terminated strings? in my system's language?"
);

assert_eq!(
    null_separated_strings.read_be::<NullString>().unwrap().into_string(),
    "no thanks"
);

Tuple Fields

0: Vec<u8>

Implementations

Methods from Deref<Target = Vec<u8>>

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)

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);

Returns true if the vector contains no elements.

Examples

let mut v = Vec::new();
assert!(v.is_empty());

v.push(1);
assert!(!v.is_empty());

Trait Implementations

The type of arguments needed to be supplied in order to read this type, usually a tuple. Read more

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

The default arguments to be used when using the read shortcut method. Override this for any type that optionally requries arguments Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

The resulting type after dereferencing.

Dereferences the value.

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 !=.

Converts the given value to a String. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.