Struct NulError

struct NulError(_, _)

An error indicating that an interior nul byte was found.

While Rust strings may contain nul bytes in the middle, C strings can't, as that byte would effectively truncate the string.

This error is created by the [new]CString::new method on CString. See its documentation for more.

Examples

use std::ffi::{CString, NulError};

let _: NulError = CString::new(b"f\0oo".to_vec()).unwrap_err();

Implementations

impl NulError

fn nul_position(self: &Self) -> usize

Returns the position of the nul byte in the slice that caused CString::new to fail.

Examples

use std::ffi::CString;

let nul_error = CString::new("foo\0bar").unwrap_err();
assert_eq!(nul_error.nul_position(), 3);

let nul_error = CString::new("foo bar\0").unwrap_err();
assert_eq!(nul_error.nul_position(), 7);
fn into_vec(self: Self) -> Vec<u8>

Consumes this error, returning the underlying vector of bytes which generated the error in the first place.

Examples

use std::ffi::CString;

let nul_error = CString::new("foo\0bar").unwrap_err();
assert_eq!(nul_error.into_vec(), b"foo\0bar");

impl Clone for NulError

fn clone(self: &Self) -> NulError

impl Debug for NulError

fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result

impl Display for NulError

fn fmt(self: &Self, f: &mut fmt::Formatter<'_>) -> fmt::Result

impl Eq for NulError

impl Error for NulError

impl Freeze for NulError

impl PartialEq for NulError

fn eq(self: &Self, other: &NulError) -> bool

impl RefUnwindSafe for NulError

impl Send for NulError

impl StructuralPartialEq for NulError

impl Sync for NulError

impl Unpin for NulError

impl UnwindSafe for NulError

impl<T> Any for NulError

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for NulError

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for NulError

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for NulError

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for NulError

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for NulError

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T> ToString for NulError

fn to_string(self: &Self) -> String

impl<T, U> Into for NulError

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for NulError

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for NulError

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>