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 RStr
s.
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");
}
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
Returns an empty RString
Deserialize this value from the given Serde deserializer. Read more
Creates a value from an iterator. Read more
Creates a value from an iterator. Read more
type StaticEquivalent = _static_RString
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 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 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 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 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 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 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 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 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 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 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 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 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
type IsNonZeroType = False
type IsNonZeroType = False
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
Auto Trait Implementations
impl RefUnwindSafe for RString
impl UnwindSafe for RString
Blanket Implementations
Mutably borrows from an owned value. Read more
type ROwned = T
type ROwned = T
The owned type, stored in RCow::Owned
type ForSelf = WithMetadata_<T, T>
type ForSelf = WithMetadata_<T, T>
This is always WithMetadata_<Self, Self>
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
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
fn split_while<P, T>(&'a self, mapper: P) -> SplitWhile<'a, P, T> where
T: Eq + Clone,
P: FnMut(char) -> T,
fn split_while<P, T>(&'a self, mapper: P) -> SplitWhile<'a, P, T> where
T: Eq + Clone,
P: FnMut(char) -> T,
Returns an iterator over substrings whose characters were mapped to
the same key by mapper
. Read more
fn rsplit_while<P, T>(&'a self, mapper: P) -> RSplitWhile<'a, P, T> where
T: Eq + Clone,
P: FnMut(char) -> T,
fn rsplit_while<P, T>(&'a self, mapper: P) -> RSplitWhile<'a, P, T> where
T: Eq + Clone,
P: FnMut(char) -> T,
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 a string containing the first n
chars. Read more
Returns a string containing the last n
chars Read more
Returns the string from the n
th 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
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
core_str_methods
or crate feature alloc
only.The indentation of the first line. Read more
core_str_methods
or crate feature alloc
only.The minimum indentation of the string, ignoring lines that only contain whitespace. Read more
core_str_methods
or crate feature alloc
only.The maximum indentation of the string, ignoring lines that only contain whitespace. Read more
unsafe fn transmute_element<T>(
self
) -> <Self as CanTransmuteElement<T>>::TransmutedPtr where
Self: CanTransmuteElement<T>,
unsafe fn transmute_element<T>(
self
) -> <Self as CanTransmuteElement<T>>::TransmutedPtr where
Self: CanTransmuteElement<T>,
Transmutes the element type of this pointer.. Read more
type Type = T
type Type = T
This is always Self
.
Converts a value back to the original type.
Converts a mutable reference back to the original type.
alloc
only.Converts a box back to the original type.
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.
alloc
only.Converts a box back to the original type.
alloc
only.Converts an Arc back to the original type.
alloc
only.Converts an Rc back to the original type.