#[repr(C)]pub struct String { /* private fields */ }
Expand description
Binding to the string type used by Neovim.
Unlike Rust’s String
, this type is not guaranteed to contain valid UTF-8
byte sequences, it can contain null bytes, and it is null-terminated.
Implementations§
Source§impl String
impl String
pub fn as_bytes(&self) -> &[u8] ⓘ
Sourcepub fn as_nvim_str(&self) -> NvimStr<'_>
pub fn as_nvim_str(&self) -> NvimStr<'_>
Returns an NvimStr
view of this String
.
Sourcepub fn from_bytes(bytes: &[u8]) -> Self
pub fn from_bytes(bytes: &[u8]) -> Self
Creates a String
from a byte slice by allocating bytes.len() + 1
bytes of memory and copying the contents of bytes
into it, followed
by a null byte.
Sourcepub unsafe fn from_raw_parts(data: *const c_char, len: usize) -> Self
pub unsafe fn from_raw_parts(data: *const c_char, len: usize) -> Self
Creates a String
from a pointer to the underlying data and a length.
§Safety
The caller must ensure that the pointer is valid for len + 1
elements and that the last element is a null byte.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of the String
, not including the final null
byte.
Sourcepub fn to_str(&self) -> Result<&str, Utf8Error>
pub fn to_str(&self) -> Result<&str, Utf8Error>
Yields a string slice if the String
’s contents are valid UTF-8.
Sourcepub fn to_string_lossy(&self) -> Cow<'_, str>
pub fn to_string_lossy(&self) -> Cow<'_, str>
Converts the String
into Rust’s std::string::String
. If it already
holds a valid UTF-8 byte sequence no allocation is made. If it doesn’t
the String
is copied and all invalid sequences are replaced with �
.
Trait Implementations§
Source§impl<'a> From<&'a String> for NvimStr<'a>
impl<'a> From<&'a String> for NvimStr<'a>
Source§fn from(string: &'a NvimString) -> Self
fn from(string: &'a NvimString) -> Self
Source§impl From<String> for Object
impl From<String> for Object
Source§fn from(string: NvimString) -> Self
fn from(string: NvimString) -> Self
Source§impl Ord for String
impl Ord for String
Source§impl PartialOrd for String
impl PartialOrd for String
impl Eq for String
impl StructuralPartialEq for String
Auto Trait Implementations§
impl Freeze for String
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FromObject for T
impl<T> FromObject for T
Source§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
Source§type Error = Infallible
type Error = Infallible
Result
.Source§fn into_result(self) -> Result<T, <T as IntoResult<T>>::Error>
fn into_result(self) -> Result<T, <T as IntoResult<T>>::Error>
Result
.