Skip to main content

String

Struct String 

Source
pub struct String(/* private fields */);
Expand description

An Objective-C string object.

C++ equivalent: NS::String

Implementations§

Source§

impl String

Source

pub fn string() -> Option<Self>

Create an empty string.

C++ equivalent: static String* string()

Source

pub fn string_with_string(string: &String) -> Option<Self>

Create a string from another string.

C++ equivalent: static String* string(const String* pString)

Source

pub fn string_with_cstring( cstring: *const c_char, encoding: StringEncoding, ) -> Option<Self>

Create a string from a C string with the specified encoding.

C++ equivalent: static String* string(const char* pString, StringEncoding encoding)

Source

pub fn alloc() -> Option<Self>

Allocate a new string.

C++ equivalent: static String* alloc()

Source

pub fn init(&self) -> Option<Self>

Initialize an allocated string.

C++ equivalent: String* init()

Source

pub fn init_with_string(&self, string: &String) -> Option<Self>

Initialize with another string.

C++ equivalent: String* init(const String* pString)

Source

pub fn init_with_cstring( &self, cstring: *const c_char, encoding: StringEncoding, ) -> Option<Self>

Initialize with a C string and encoding.

C++ equivalent: String* init(const char* pString, StringEncoding encoding)

Source

pub fn init_with_bytes_no_copy( &self, bytes: *mut c_void, len: UInteger, encoding: StringEncoding, free_when_done: bool, ) -> Option<Self>

Initialize with bytes, length, encoding, and free buffer flag.

C++ equivalent: String* init(void* pBytes, UInteger len, StringEncoding encoding, bool freeBuffer)

Source

pub fn character(&self, index: UInteger) -> Unichar

Get the character at the specified index.

C++ equivalent: unichar character(UInteger index) const

Source

pub fn length(&self) -> UInteger

Get the length of the string in characters.

C++ equivalent: UInteger length() const

Source

pub fn c_string(&self, encoding: StringEncoding) -> *const c_char

Get the string as a C string with the specified encoding.

C++ equivalent: const char* cString(StringEncoding encoding) const

Source

pub fn utf8_string(&self) -> *const c_char

Get the string as a UTF-8 C string.

C++ equivalent: const char* utf8String() const

Source

pub fn maximum_length_of_bytes(&self, encoding: StringEncoding) -> UInteger

Get the maximum length in bytes for the specified encoding.

C++ equivalent: UInteger maximumLengthOfBytes(StringEncoding encoding) const

Source

pub fn length_of_bytes(&self, encoding: StringEncoding) -> UInteger

Get the actual length in bytes for the specified encoding.

C++ equivalent: UInteger lengthOfBytes(StringEncoding encoding) const

Source

pub fn is_equal_to_string(&self, string: &String) -> bool

Check if this string is equal to another string.

C++ equivalent: bool isEqualToString(const String* pString) const

Source

pub fn range_of_string( &self, string: &String, options: StringCompareOptions, ) -> Range

Find the range of a substring with the specified options.

C++ equivalent: Range rangeOfString(const String* pString, StringCompareOptions options) const

Source

pub fn file_system_representation(&self) -> *const c_char

Get the file system representation of the string.

C++ equivalent: const char* fileSystemRepresentation() const

Source

pub fn string_by_appending_string(&self, string: &String) -> Option<Self>

Create a new string by appending another string.

C++ equivalent: String* stringByAppendingString(const String* pString) const

Source

pub fn case_insensitive_compare(&self, string: &String) -> ComparisonResult

Perform a case-insensitive comparison with another string.

C++ equivalent: ComparisonResult caseInsensitiveCompare(const String* pString) const

Source

pub unsafe fn from_ptr(ptr: *mut c_void) -> Option<Self>

Create a String from a raw pointer.

§Safety

The pointer must be a valid Objective-C NSString object.

Source

pub fn from_str(s: &str) -> Option<Self>

Create a string from a Rust &str.

This is a convenience method for Rust users.

Source

pub fn to_string(&self) -> Option<String>

Convert to a Rust String.

This is a convenience method for Rust users.

Trait Implementations§

Source§

impl Clone for String

Source§

fn clone(&self) -> String

Returns a duplicate 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 Copying for String

Source§

fn copy(&self) -> Option<Self>

Create a copy of this object. Read more
Source§

impl Debug for String

Source§

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

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

impl Display for String

Source§

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

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

impl Referencing for String

Source§

fn as_ptr(&self) -> *const c_void

Get the raw pointer to the Objective-C object.
Source§

fn as_mut_ptr(&self) -> *mut c_void

Get the raw mutable pointer to the Objective-C object.
Source§

fn retain(&self) -> Self
where Self: Clone,

Retain the object, incrementing its reference count. Read more
Source§

fn release(&self)

Release the object, decrementing its reference count. Read more
Source§

fn autorelease(&self) -> Self
where Self: Clone,

Autorelease the object. Read more
Source§

fn retain_count(&self) -> UInteger

Get the retain count of the object. Read more
Source§

impl Send for String

Source§

impl Sync for String

Auto Trait Implementations§

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

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

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>,

Source§

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.