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::{
    std_types::RStr,
    sabi_extern_fn,
};


#[sabi_extern_fn]
fn first_word(phrase:RStr<'_>)->RStr<'_>{
    match phrase.as_str().split_whitespace().next() {
        Some(x)=>x.into(),
        None=>"".into()
    }
}

Implementations

An empty RStr.

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 this RStr<'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 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;

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 a raw pointer to the start of the string slice.

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);

Queries whether this RStr is empty.

Example

use abi_stable::std_types::RStr;

assert_eq!(RStr::from("").is_empty(),true);
assert_eq!(RStr::from("a").is_empty(),false);
assert_eq!(RStr::from("What").is_empty(),false);

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

Feeds this value into the given Hasher. Read more

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

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

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.

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

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

The indentation of the first line. Read more

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

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.

Converts a box back to the original type.

Converts an Arc back to the original type. Read more

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.

Converts a box back to the original type.

Converts an Arc back to the original type.

Converts an Rc back to the original type.