Struct leveldb::string::String

source ·
pub struct String { /* private fields */ }
Expand description

A LevelDB CString.

Like regular CStrings, it is a byte-array with no specified encoding. The length is also stored alongside the pointer, so this supports interior NULs.

Implementations§

source§

impl String

source

pub unsafe fn from_ptr(ptr: *mut c_char) -> Self

Make a String from a ptr.

This will use strlen to determine the string length.

Safety

The pointer must be a malloc-ed C string from the leveldb C api.

Panics

Panics if the ptr is null.

source

pub unsafe fn try_from_ptr(ptr: *mut c_char) -> Option<Self>

Make a String from a ptr.

Fallibly make a string from a ptr.

Safety

The pointer must be a malloc-ed C string from the leveldb C api.

source

pub unsafe fn try_from_ptr_len(ptr: *mut c_char, len: usize) -> Option<Self>

Make a String from a ptr and a len, fallibly.

Safety
  • The pointer must be a malloc-ed C string from the leveldb C api.
  • The length must be the length of the string, excluding the nul byte.
source

pub fn len(&self) -> usize

Get the len.

source

pub fn is_empty(&self) -> bool

Check if this is empty.

source

pub fn as_bytes(&self) -> &[u8]

Get the contents as a byte slice.

source

pub fn to_str(&self) -> Result<&str, Utf8Error>

Try to convert this into a str.

source

pub fn to_string_lossy(&self) -> Cow<'_, str>

Lossily convert this into a str.

Trait Implementations§

source§

impl Debug for String

source§

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

Formats the value using the given formatter. Read more
source§

impl Drop for String

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for String

§

impl !Send for String

§

impl !Sync for String

§

impl Unpin for String

§

impl UnwindSafe for String

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

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

Performs the conversion.