Struct abi_stable::std_types::string::RString[][src]

#[repr(C)]
pub struct RString { /* fields omitted */ }
Expand description

Ffi-safe equivalent of std::string::String.

Example

This defines a function returning the last word of an RString.

use abi_stable::{sabi_extern_fn, std_types::RString};

#[sabi_extern_fn]
fn first_word(phrase: RString) -> RString {
    match phrase.split_whitespace().next_back() {
        Some(x) => x.into(),
        None => RString::new(),
    }
}

Implementations

Creates a new, empty RString.

Example
use abi_stable::std_types::RString;

let str = RString::new();

assert_eq!(&str[..], "");

Creates a new, empty RString with the capacity for cap bytes without reallocating.

Example
use abi_stable::std_types::RString;

let str = RString::with_capacity(10);

assert_eq!(&str[..], "");
assert_eq!(str.capacity(), 10);

For slicing into RStrs.

This is an inherent method instead of an implementation of the std::ops::Index trait because it does not return a reference.

Example
use abi_stable::std_types::{RStr, RString};

let str = RString::from("What is that.");

assert_eq!(str.slice(..), RStr::from("What is that."));
assert_eq!(str.slice(..4), RStr::from("What"));
assert_eq!(str.slice(4..), RStr::from(" is that."));
assert_eq!(str.slice(4..7), RStr::from(" is"));

Creates a &str with access to all the characters of the RString.

Example
use abi_stable::std_types::RString;

let str = "What is that.";
assert_eq!(RString::from(str).as_str(), str);

Creates an RStr<'_> with access to all the characters of the RString.

Example
use abi_stable::std_types::{RStr, RString};

let str = "What is that.";
assert_eq!(RString::from(str).as_rstr(), RStr::from(str),);

Returns the current length (in bytes) of the RString.

Example
use abi_stable::std_types::RString;

assert_eq!(RString::from("").len(), 0);
assert_eq!(RString::from("a").len(), 1);
assert_eq!(RString::from("Regular").len(), 7);

Returns whether the RString is empty.

Example
use abi_stable::std_types::RString;

assert_eq!(RString::from("").is_empty(), true);
assert_eq!(RString::from("a").is_empty(), false);
assert_eq!(RString::from("Regular").is_empty(), false);

Gets a raw pointer to the start of this RString’s buffer.

Returns the current capacity (in bytes) of the RString.

Example
use abi_stable::std_types::RString;

let mut str = RString::with_capacity(13);

assert_eq!(str.capacity(), 13);

str.push_str("What is that.");
assert_eq!(str.capacity(), 13);

str.push(' ');
assert_ne!(str.capacity(), 13);

An unchecked conversion from a RVec<u8> to an RString.

Safety

This has the same safety requirements as String::from_utf8_unchecked .

Examples
use abi_stable::std_types::{RString, RVec};

let bytes = RVec::from("hello".as_bytes());

unsafe {
    assert_eq!(RString::from_utf8_unchecked(bytes).as_str(), "hello");
}

Converts the vec vector of bytes to an RString.

Errors

This returns a Err(FromUtf8Error{..}) if vec is not valid utf-8.

Examples
use abi_stable::std_types::{RString, RVec};

let bytes_ok = RVec::from("hello".as_bytes());
let bytes_err = RVec::from(vec![255]);

assert_eq!(
    RString::from_utf8(bytes_ok).unwrap(),
    RString::from("hello")
);
assert!(RString::from_utf8(bytes_err).is_err());

Decodes a utf-16 encoded &[u16] to an RString.

Errors

This returns a Err(::std::string::FromUtf16Error{..}) if vec is not valid utf-8.

Example
use abi_stable::std_types::RString;

let str = "What the 😈.";
let str_utf16 = str.encode_utf16().collect::<Vec<u16>>();

assert_eq!(RString::from_utf16(&str_utf16).unwrap(), RString::from(str),);

Cheap conversion of this RString to a RVec<u8>

Example
use abi_stable::std_types::{RString, RVec};

let bytes = RVec::from("hello".as_bytes());
let str = RString::from("hello");

assert_eq!(str.into_bytes(), bytes);

Converts this RString to a String.

Allocation

If this is invoked outside of the dynamic library/binary that created it, it will allocate a new String and move the data into it.

Example
use abi_stable::std_types::RString;

let std_str = String::from("hello");
let str = RString::from("hello");

assert_eq!(str.into_string(), std_str);

Copies the RString into a String.

Example
use abi_stable::std_types::RString;

assert_eq!(RString::from("world").to_string(), String::from("world"));

Reserves àdditional additional capacity for any extra string data. This may reserve more than necessary for the additional capacity.

Example
use abi_stable::std_types::RString;

let mut str = RString::new();

str.reserve(10);
assert!(str.capacity() >= 10);

Shrinks the capacity of the RString to match its length.

Example
use abi_stable::std_types::RString;

let mut str = RString::with_capacity(100);
str.push_str("nope");
str.shrink_to_fit();
assert_eq!(str.capacity(), 4);

Reserves àdditional additional capacity for any extra string data.

Prefer using reserve for most situations.

Example
use abi_stable::std_types::RString;

let mut str = RString::new();

str.reserve_exact(10);
assert_eq!(str.capacity(), 10);

Appends ch at the end of this RString.

Example
use abi_stable::std_types::RString;

let mut str = RString::new();

str.push('O');
str.push('O');
str.push('P');

assert_eq!(str.as_str(), "OOP");

Appends str at the end of this RString.

Example
use abi_stable::std_types::RString;

let mut str = RString::new();

str.push_str("green ");
str.push_str("frog");

assert_eq!(str.as_str(), "green frog");

Removes the last character, returns Some(_) if this RString is not empty, otherwise returns None.

Example
use abi_stable::std_types::{RString, RVec};

let mut str = RString::from("yep");

assert_eq!(str.pop(), Some('p'));
assert_eq!(str.pop(), Some('e'));
assert_eq!(str.pop(), Some('y'));
assert_eq!(str.pop(), None);

Removes and returns the character starting at the idx byte position,

Panics

Panics if the index is out of bounds or if it is not on a char boundary.

Example
use abi_stable::std_types::{RString, RVec};

let mut str = RString::from("Galileo");

assert_eq!(str.remove(3), 'i');
assert_eq!(str.as_str(), "Galleo");

assert_eq!(str.remove(4), 'e');
assert_eq!(str.as_str(), "Gallo");

Insert the ch character at the ìdx byte position.

Panics

Panics if the index is out of bounds or if it is not on a char boundary.

Example
use abi_stable::std_types::{RString, RVec};

let mut str = RString::from("Cap");

str.insert(1, 'r');
assert_eq!(str.as_str(), "Crap");

str.insert(4, 'p');
assert_eq!(str.as_str(), "Crapp");

str.insert(5, 'y');
assert_eq!(str.as_str(), "Crappy");

Insert the string at the ìdx byte position.

Panics

Panics if the index is out of bounds or if it is not on a char boundary.

Example
use abi_stable::std_types::{RString, RVec};

let mut str = RString::from("rust");

str.insert_str(0, "T");
assert_eq!(str.as_str(), "Trust");

str.insert_str(5, " the source");
assert_eq!(str.as_str(), "Trust the source");

str.insert_str(5, " the types in");
assert_eq!(str.as_str(), "Trust the types in the source");

Retains only the characters that satisfy the pred predicate

This means that a character will be removed if pred(that_character) returns false.

Example
use abi_stable::std_types::{RString, RVec};

{
    let mut str = RString::from("There were 10 people.");
    str.retain(|c| !c.is_numeric());
    assert_eq!(str.as_str(), "There were  people.");
}
{
    let mut str = RString::from("There were 10 people.");
    str.retain(|c| !c.is_whitespace());
    assert_eq!(str.as_str(), "Therewere10people.");
}
{
    let mut str = RString::from("There were 10 people.");
    str.retain(|c| c.is_numeric());
    assert_eq!(str.as_str(), "10");
}

Turns this into an empty RString, keeping the same allocated buffer.

Example
use abi_stable::std_types::{RString, RVec};

let mut str = RString::from("Nurse");

assert_eq!(str.as_str(), "Nurse");

str.clear();

assert_eq!(str.as_str(), "");

Creates an iterator that yields the chars in the range, removing the characters in that range in the process.

Panic

Panics if the start or end of the range are not on a on a char boundary, or if either are out of bounds.

Example
use abi_stable::std_types::RString;

let orig = "Not a single way";

{
    let mut str = RString::from(orig);
    assert_eq!(str.drain(..).collect::<String>(), orig,);
    assert_eq!(str.as_str(), "");
}
{
    let mut str = RString::from(orig);
    assert_eq!(str.drain(..4).collect::<String>(), "Not ",);
    assert_eq!(str.as_str(), "a single way");
}
{
    let mut str = RString::from(orig);
    assert_eq!(str.drain(4..).collect::<String>(), "a single way",);
    assert_eq!(str.as_str(), "Not ");
}
{
    let mut str = RString::from(orig);
    assert_eq!(str.drain(4..13).collect::<String>(), "a single ",);
    assert_eq!(str.as_str(), "Not way");
}

Trait Implementations

Performs the conversion.

Performs the conversion.

Immutably borrows from an owned value. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns an empty RString

Returns the “default value” for a type. Read more

The resulting type after dereferencing.

Dereferences the value.

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Creates a value from an iterator. Read more

Creates a value from an iterator. Read more

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

The #[repr(Rust)] equivalent.

Performs the conversion

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. Read more

Whether this type has a single invalid bit-pattern. Read more

The layout of the type provided by implementors.

const-equivalents of the associated types.

Writes a string slice into this writer, returning whether the write succeeded. Read more

Writes a char into this writer, returning whether the write succeeded. Read more

Glue for usage of the write! macro with implementors of this trait. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

The owned type, stored in RCow::Owned

The borrowed type, stored in RCow::Borrowed

Performs the conversion.

This is always WithMetadata_<Self, Self>

Performs the conversion.

Gets a reference to a field, determined by offset. Read more

Gets a muatble reference to a field, determined by offset. Read more

Gets a const pointer to a field, the field is determined by offset. Read more

Gets a mutable pointer to a field, determined by offset. Read more

Replaces a field (determined by offset) with value, returning the previous value of the field. Read more

Swaps a field (determined by offset) with the same field in right. Read more

Gets a copy of a field (determined by offset). The field is determined by offset. Read more

Replaces a field (determined by offset) with value, returning the previous value of the field. Read more

Swaps a field (determined by offset) with the same field in right. Read more

Gets a copy of a field (determined by offset). The field is determined by offset. Read more

Compares the address of self with the address of other. Read more

Emulates the pipeline operator, allowing method syntax in more places. Read more

The same as piped except that the function takes &Self Useful for functions that take &Self instead of Self. Read more

The same as piped, except that the function takes &mut Self. Useful for functions that take &mut Self instead of Self. Read more

Mutates self using a closure taking self by mutable reference, passing it along the method chain. Read more

Observes the value of self, passing it along unmodified. Useful in long method chains. Read more

Performs a conversion with Into. using the turbofish .into_::<_>() syntax. Read more

Performs a reference to reference conversion with AsRef, using the turbofish .as_ref_::<_>() syntax. Read more

Performs a mutable reference to mutable reference conversion with AsMut, using the turbofish .as_mut_::<_>() syntax. Read more

Drops self using method notation. Alternative to std::mem::drop. Read more

Returns the previous character boundary, stopping at 0. Read more

Returns the next character boundary. Read more

Returns the closest characted boundary left of index(including index). Read more

Returns the closest characted boundary right of index(including index). Read more

Returns an iterator over substrings whose characters were mapped to the same key by mapper. Read more

A variation of split_while that iterates from the right(the order of substrings is reversed). Read more

The byte index of the nth character Read more

The byte index of the nth character Read more

Returns the nth character in the str. Read more

Returns a string containing the first n chars. Read more

Returns a string containing the last n chars Read more

Returns the string from the nth character Read more

Returns the length of the string in utf16 Read more

Returns the character at the at_byte index inside of the string, returning None if the index is outside the string. Read more

Returns an iterator over (index,char) pairs up to (but not including) the char at the to byte. Read more

Returns an iterator over (index, char) pairs, starting from the from byte. Read more

This is supported on crate feature alloc only.

Pads the string on the left with how_much additional spaces. Read more

Returns a value that pads the string on the left with how_much additional spaces in its Display impl. Read more

This is supported on core_str_methods or crate feature alloc only.

The indentation of the first line. Read more

This is supported on core_str_methods or crate feature alloc only.

The minimum indentation of the string, ignoring lines that only contain whitespace. Read more

This is supported on core_str_methods or crate feature alloc only.

The maximum indentation of the string, ignoring lines that only contain whitespace. Read more

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

Transmutes the element type of this pointer.. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

This is always Self.

Converts a value back to the original type.

Converts a reference back to the original type.

Converts a mutable reference back to the original type.

This is supported on crate feature alloc only.

Converts a box back to the original type.

This is supported on crate feature alloc only.

Converts an Arc back to the original type. Read more

This is supported on crate feature alloc only.

Converts an Rc back to the original type. Read more

Converts a value back to the original type.

Converts a reference back to the original type.

Converts a mutable reference back to the original type.

This is supported on crate feature alloc only.

Converts a box back to the original type.

This is supported on crate feature alloc only.

Converts an Arc back to the original type.

This is supported on crate feature alloc only.

Converts an Rc back to the original type.