Struct rust_icu_ustring::UChar

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

The implementation of the ICU UChar*.

While the original type is defined in umachine.h, most useful functions for manipulating UChar* are in fact here.

The first thing you probably want to do is to start from a UTF-8 rust string, produce a UChar. This is necessarily done with a conversion. See the TryFrom implementations in this crate for that.

Implements UChar* from ICU.

Implementations§

source§

impl UChar

source

pub fn new_with_capacity(capacity: usize) -> UChar

Allocates a new UChar with given capacity.

Capacity and size must always be the same with UChar when used for interacting with low-level code.

source

pub unsafe fn clone_from_raw_parts(rep: *mut UChar, len: i32) -> UChar

Creates a new crate::UChar from its low-level representation, a buffer pointer and a buffer size.

Does not take ownership of the buffer that was passed in.

DO NOT USE UNLESS YOU HAVE NO OTHER CHOICE.

§Safety

rep must point to an initialized sequence of at least len UChars.

source

pub fn make_z(&mut self)

Converts into a zeroed-out string.

This is a very weird ICU API thing, where there apparently exists a zero-terminated UChar*.

source

pub fn as_c_ptr(&self) -> *const UChar

Returns the constant pointer to the underlying C representation. Intended for use in low-level code.

source

pub fn len(&self) -> usize

Returns the length of the string, in code points.

source

pub fn is_empty(&self) -> bool

Returns whether the string is empty.

source

pub fn as_mut_c_ptr(&mut self) -> *mut UChar

Returns the underlying representation as a mutable C representation. Caller MUST ensure that the representation won’t be reallocated as result of adding anything to it, and that it is correctly sized, or bad things will happen.

source

pub fn resize(&mut self, new_size: usize)

Resizes this string to match new_size.

If the string is made longer, the new space is filled with zeroes.

source

pub fn as_string_debug(&self) -> String

Returns the equivalent UTF-8 string, useful for debugging.

Trait Implementations§

source§

impl Clone for UChar

source§

fn clone(&self) -> UChar

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for UChar

source§

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

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

impl From<Vec<u16>> for UChar

source§

fn from(rep: Vec<UChar>) -> UChar

Adopts a vector of sys::UChar into a string.

source§

impl TryFrom<&UChar> for String

source§

fn try_from(u: &UChar) -> Result<String, Self::Error>

Tries to produce a UTF-8 encoded rust string from a UChar.

This conversion ignores warnings and only reports actual ICU errors when they happen.

Implements u_strToUTF8.

§

type Error = Error

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

impl TryFrom<&str> for UChar

source§

fn try_from(rust_string: &str) -> Result<Self, Self::Error>

Tries to produce a string from the UTF-8 encoded thing.

This conversion ignores warnings (e.g. warnings about unterminated buffers), since for rust they are not relevant.

Implements u_strFromUTF8.

§

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations§

§

impl RefUnwindSafe for UChar

§

impl Send for UChar

§

impl Sync for UChar

§

impl Unpin for UChar

§

impl UnwindSafe for UChar

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.