Struct abi_stable::std_types::RStr [−][src]
#[repr(C)]pub struct RStr<'a> { /* fields omitted */ }
Expand description
Ffi-safe equivalent of &'a str
Example
This defines a function that returns the first word in a string.
use abi_stable::{sabi_extern_fn, std_types::RStr};
#[sabi_extern_fn]
fn first_word(phrase: RStr<'_>) -> RStr<'_> {
match phrase.as_str().split_whitespace().next() {
Some(x) => x.into(),
None => "".into(),
}
}
Implementations
Constructs an empty RStr<'a>
.
Example
use abi_stable::std_types::RStr;
const STR: RStr<'static> = RStr::empty();
assert_eq!(STR, RStr::from(""));
Constructs an RStr<'a>
from a pointer to the first byte,
and a length.
Safety
Callers must ensure that:
-
ptr_
points to valid memory, -
ptr_ .. ptr+len
range is accessible memory, and is valid utf-8. -
The data that
ptr_
points to must be valid for the lifetime of thisRStr<'a>
Examples
This function unsafely converts a &str
to an RStr<'_>
,
equivalent to doing RStr::from
.
use abi_stable::std_types::RStr;
fn convert(slice_: &str) -> RStr<'_> {
unsafe { RStr::from_raw_parts(slice_.as_ptr(), slice_.len()) }
}
Converts &'a str
to a RStr<'a>
.
Example
use abi_stable::std_types::RStr;
assert_eq!(RStr::from_str("").as_str(), "");
assert_eq!(RStr::from_str("Hello").as_str(), "Hello");
assert_eq!(RStr::from_str("World").as_str(), "World");
For slicing 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;
let str = RStr::from("What is that.");
assert_eq!(str.slice(..), str);
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"));
Accesses the underlying byte slice.
Example
use abi_stable::std_types::{RSlice, RStr};
let str = RStr::from("What is that.");
let bytes = RSlice::from("What is that.".as_bytes());
assert_eq!(str.as_rslice(), bytes);
Casts this RStr<'a>
to a &'a str
.
Example
use abi_stable::std_types::RStr;
let str = "What is that.";
assert_eq!(RStr::from(str).as_str(), str);
Gets the length(in bytes) of this RStr<'a>
.
Example
use abi_stable::std_types::RStr;
assert_eq!(RStr::from("").len(), 0);
assert_eq!(RStr::from("a").len(), 1);
assert_eq!(RStr::from("What").len(), 4);
Trait Implementations
Deserialize this value from the given Serde deserializer. Read more
type StaticEquivalent = _static_RStr<'static>
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.
Auto Trait Implementations
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.