Struct NulError

pub struct NulError(pub(in ::ffi::c_str) usize, pub(in ::ffi::c_str) Vec<u8>);

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

Fields

0: usize
1: Vec<u8>

Implementations

impl NulError

fn nul_position(&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) -> 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");

Trait Implementations

impl Clone for NulError

fn clone(&self) -> NulError

impl Debug for NulError

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

impl Display for NulError

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

impl Eq for NulError

fn assert_fields_are_eq(&self)

impl Error for NulError

impl PartialEq for NulError

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

impl StructuralPartialEq for NulError

Auto Trait Implementations

impl Freeze for NulError

impl RefUnwindSafe for NulError

impl Send for NulError

impl Sync for NulError

impl Unpin for NulError

impl UnsafeUnpin for NulError

impl UnwindSafe for NulError

Blanket Implementations

impl<T> Any for NulError where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for NulError where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for NulError where T: ?Sized,

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

impl<T> CloneToUninit for NulError where T: Clone,

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

impl<T> From<T> for NulError

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> SizeHint for NulError where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for NulError

impl<T> ToOwned for NulError where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T> ToString for NulError where T: Display + ?Sized,

fn to_string(&self) -> String

impl<T, U> Into<U> for NulError where U: From<T>,

fn into(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<U> for NulError where U: Into<T>,

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

impl<T, U> TryInto<U> for NulError where U: TryFrom<T>,

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