Struct abi_stable::std_types::RSlice[][src]

#[repr(C)]
pub struct RSlice<'a, T> { /* fields omitted */ }
Expand description

Ffi-safe equivalent of &'a [T]

As of the writing this documentation the abi stability of &[T] is not yet guaranteed.

Lifetime problems

Because RSlice dereferences into a slice,you can call slice methods on it.

If you call a slice method that returns a borrow into the slice, it will have the lifetime of the let slice: RSlice<'a,[T]> variable instead of the 'a lifetime that it’s parameterized over.

To get a slice with the same lifetime as an RSlice, one must use the RSlice::as_slice method.

Example of what would not work:

use abi_stable::std_types::RSlice;

fn into_slice<'a,T>(slic:RSlice<'a,T>)->&'a [T] {
    &*slic
}

Example of what would work:

use abi_stable::std_types::RSlice;

fn into_slice<'a,T>(slic:RSlice<'a,T>)->&'a [T] {
    slic.as_slice()
}

Example

Defining an extern fn that returns a reference to the first element that compares equal to a parameter.

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

#[sabi_extern_fn]
pub fn find_first_mut<'a,T>(slice_:RSlice<'a,T>,element:&T)->Option<&'a T>
where
    T:std::cmp::PartialEq
{
    slice_.iter()
        .position(|x| x==element )
        .map(|i| &slice_.as_slice()[i] )
}

Implementations

An empty slice.

Constructs an RSlice<'a,T> from a pointer to the first element, and a length.

Safety

Callers must ensure that:

  • ptr_ points to valid memory,

  • ptr_ .. ptr+len range is accessible memory.

  • ptr_ is aligned to T.

  • The data ptr_ points to must be valid for the 'a lifetime.

Examples

This function unsafely converts a &[T] to an RSlice<T>, equivalent to doing RSlice::from_slice.

use abi_stable::std_types::RSlice;

fn convert<T>(slice_:&[T])->RSlice<'_,T>{
    unsafe{
        RSlice::from_raw_parts( slice_.as_ptr(), slice_.len() )
    }
}

Creates an &'a [T] with access to all the elements of this slice.

Example

use abi_stable::std_types::RSlice;

assert_eq!(RSlice::from_slice(&[0,1,2,3]).as_slice(), &[0,1,2,3]);

Gets a raw pointer to the start of the slice.

The length (in elements) of this slice.

Example

use abi_stable::std_types::RSlice;

assert_eq!(RSlice::<u8>::from_slice(&[]).len(), 0);
assert_eq!(RSlice::from_slice(&[0]).len(), 1);
assert_eq!(RSlice::from_slice(&[0,1]).len(), 2);

Whether this slice is empty.

Example

use abi_stable::std_types::RSlice;

assert_eq!(RSlice::<u8>::from_slice(&[]).is_empty(), true);
assert_eq!(RSlice::from_slice(&[0]).is_empty(), false);
assert_eq!(RSlice::from_slice(&[0,1]).is_empty(), false);

Creates an empty slice

Converts a reference to T to a single element RSlice<'a,T>.

Note:this function does not copy anything.

Example

use abi_stable::std_types::RSlice;

assert_eq!(RSlice::from_ref(&0), RSlice::from_slice(&[0]) );
assert_eq!(RSlice::from_ref(&1), RSlice::from_slice(&[1]) );
assert_eq!(RSlice::from_ref(&2), RSlice::from_slice(&[2]) );
 

Converts a &[T] to an RSlice<'_,T>.

Example

use abi_stable::std_types::RSlice;
 
let empty:&[u8]=&[];
 
assert_eq!(RSlice::<u8>::from_slice(&[]).as_slice(), empty);
assert_eq!(RSlice::from_slice(&[0]).as_slice()     , &[0][..]);
assert_eq!(RSlice::from_slice(&[0,1]).as_slice()   , &[0,1][..]);
 

Creates an RSlice<'a,T> with access to the range range of elements.

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::RSlice;

let slic=RSlice::from_slice(&[0,1,2,3]);

assert_eq!(slic.slice(..),RSlice::from_slice(&[0,1,2,3]));
assert_eq!(slic.slice(..2),RSlice::from_slice(&[0,1]));
assert_eq!(slic.slice(2..),RSlice::from_slice(&[2,3]));
assert_eq!(slic.slice(1..3),RSlice::from_slice(&[1,2]));

Creates a new RVec<T> and clones all the elements of this slice into it.

Example

use abi_stable::std_types::{RSlice,RVec};

let slic=RSlice::from_slice(&[0,1,2,3]);

assert_eq!( slic.slice(..).to_rvec(), RVec::from_slice(&[0,1,2,3]) );
assert_eq!( slic.slice(..2).to_rvec(), RVec::from_slice(&[0,1]) );
assert_eq!( slic.slice(2..).to_rvec(), RVec::from_slice(&[2,3]) );
assert_eq!( slic.slice(1..3).to_rvec(), RVec::from_slice(&[1,2]) );

Transmutes n RSlice<'a,T> to a RSlice<'a,U>

Safety

This has the same safety requirements as calling std::mem::transmute to transmute a &'a [T] to a &'a [U].

Trait Implementations

Performs the conversion.

Immutably borrows from an owned value. Read more

Returns the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more

Tells this buffer that amt bytes have been consumed from the buffer, so they should no longer be returned in calls to read. Read more

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

recently added

Check if the underlying Read has any data left to be read. Read more

Read all bytes into buf until the delimiter byte or EOF is reached. Read more

Read all bytes until a newline (the 0xA byte) is reached, and append them to the provided buffer. Read more

Returns an iterator over the contents of this reader split on the byte byte. Read more

Returns an iterator over the lines of this reader. 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

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.

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

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

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more

Read the exact number of bytes required to fill buf. Read more

Read all bytes until EOF in this source, placing them into buf. Read more

Like read, except that it reads into a slice of buffers. Read more

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

Determines if this Reader has an efficient read_vectored implementation. Read more

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

Determines if this Reader can work with buffers of uninitialized memory. Read more

Read all bytes until EOF in this source, appending them to buf. Read more

Creates a “by reference” adapter for this instance of Read. Read more

Transforms this Read instance to an Iterator over its bytes. Read more

Creates an adapter which will chain this stream with another. Read more

Creates an adapter which will read at most limit bytes from it. 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

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

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.