ArcSlice

Struct ArcSlice 

Source
#[repr(C)]
pub struct ArcSlice<S: Slice + ?Sized, L: Layout = DefaultLayout> { /* private fields */ }
Expand description

A thread-safe, cheaply cloneable and sliceable container.

ArcSlice<S> is roughly equivalent to a (*const S, Arc<S>) pair: a pointer into a shared buffer and its associated reference-counted owner. This allows it to behave like a slice while ensuring memory safety and shared ownership.
With the appropriate layout, ArcSlice can wrap arbitrary buffers such as Vec, memory-mapped files, etc. Arbitrary metadata can also be attached to the buffer for contextual or domain-specific needs.

It is mainly intended to manipulate [u8]/str byte slices, to facilitate zero-copy operations in network programming, hence the aliases ArcBytes/ArcStr. But it can actually handle any type of slices, from strings with specific invariants to primitive slices with droppable items.

§Examples

use arc_slice::ArcSlice;

let mut mem = ArcSlice::<[u8]>::from(b"hello world");
let a = mem.subslice(0..5);

assert_eq!(a, b"hello");

let b = mem.split_to(6);

assert_eq!(mem, b"world");
assert_eq!(b, b"hello ");

With shared memory:

use std::{
    fs::File,
    path::{Path, PathBuf},
};

use arc_slice::{buffer::AsRefBuffer, layout::ArcLayout, ArcSlice};
use memmap2::Mmap;

let path = Path::new("README.md").to_owned();
let file = File::open(&path)?;
let mmap = unsafe { Mmap::map(&file)? };

let buffer = AsRefBuffer(mmap);
let bytes: ArcSlice<[u8], ArcLayout<true>> = ArcSlice::from_buffer_with_metadata(buffer, path);
assert!(bytes.starts_with(b"# arc-slice"));
assert_eq!(bytes.metadata::<PathBuf>().unwrap(), Path::new("README.md"));

Implementations§

Source§

impl<S: Slice + ?Sized, L: Layout> ArcSlice<S, L>

Source

pub const fn new() -> Self
where S: Emptyable, L: StaticLayout,

Creates a new empty ArcSlice.

This operation doesn’t allocate; it is roughly equivalent to ArcSlice::from_static(&[]).

§Examples
use arc_slice::{layout::ArcLayout, ArcSlice};

let s = ArcSlice::<[u8], ArcLayout<true, true>>::new();
assert_eq!(s, []);
Source

pub fn from_slice(slice: &S) -> Self
where S::Item: Copy,

Available on crate feature oom-handling only.

Creates a new ArcSlice by copying the given slice.

§Panics

Panics if the new capacity exceeds isize::MAX - size_of::<usize>() bytes.

§Examples
use arc_slice::ArcSlice;

let s = ArcSlice::<[u8]>::from_slice(b"hello world");
assert_eq!(s, b"hello world");
Source

pub fn try_from_slice(slice: &S) -> Result<Self, AllocError>
where S::Item: Copy,

Tries creating a new ArcSlice by copying the given slice, returning an error if the allocation fails.

§Examples
use arc_slice::ArcSlice;

let s = ArcSlice::<[u8]>::try_from_slice(b"hello world")?;
assert_eq!(s, b"hello world");
Source

pub const fn len(&self) -> usize

Returns the number of items in the slice.

§Examples
use arc_slice::ArcSlice;

let s = ArcSlice::<[u8]>::from(&[0, 1, 2]);
assert_eq!(s.len(), 3);
Source

pub const fn is_empty(&self) -> bool

Returns true if the slice contains no items.

§Examples
use arc_slice::ArcSlice;

let s = ArcSlice::<[u8]>::from(&[0, 1, 2]);
assert!(!s.is_empty());

let s = ArcSlice::<[u8]>::from(&[]);
assert!(s.is_empty());
Source

pub const fn as_ptr(&self) -> *const S::Item

Returns a raw pointer to the slice’s first item.

See slice::as_ptr.

Source

pub fn as_slice(&self) -> &S

Returns a reference to the underlying slice.

Equivalent to &self[..].

§Examples
use arc_slice::ArcSlice;

let s = ArcSlice::<[u8]>::from(b"hello world");
assert_eq!(s.as_slice(), b"hello world");
Source

pub fn borrow(&self, range: impl RangeBounds<usize>) -> ArcSliceBorrow<'_, S, L>
where S: Subsliceable,

Returns a borrowed view of an ArcSlice subslice with a given range.

See ArcSliceBorrow documentation.

§Examples
use arc_slice::ArcSlice;

let s = ArcSlice::<[u8]>::from(b"hello world");
let borrow = s.borrow(..5);
assert_eq!(&borrow[..], b"hello");
let s2: ArcSlice<[u8]> = borrow.clone_arc();
Source

pub fn borrow_from_ref(&self, subset: &S) -> ArcSliceBorrow<'_, S, L>
where S: Subsliceable,

Returns a borrowed view of an ArcSlice subslice from a slice reference.

See ArcSliceBorrow documentation.

§Examples
use arc_slice::ArcSlice;

let s = ArcSlice::<[u8]>::from(b"hello world");
let hello = &s[..5];
let borrow = s.borrow_from_ref(hello);
assert_eq!(&borrow[..], b"hello");
let s2: ArcSlice<[u8]> = borrow.clone_arc();
Source

pub fn try_clone(&self) -> Result<Self, AllocError>

Tries cloning the ArcSlice, returning an error if an allocation fails.

The operation may allocate. See CloneNoAllocLayout documentation for cases where it does not.

§Examples
use arc_slice::ArcSlice;

let s = ArcSlice::<[u8]>::try_from_slice(b"hello world")?;
let s2 = s.try_clone()?;
assert_eq!(s2, b"hello world");
Source

pub fn try_subslice( &self, range: impl RangeBounds<usize>, ) -> Result<Self, AllocError>
where S: Subsliceable,

Tries extracting a subslice of an ArcSlice with a given range, returning an error if an allocation fails.

The operation may allocate. See CloneNoAllocLayout documentation for cases where it does not.

§Examples
use arc_slice::ArcSlice;

let s = ArcSlice::<[u8]>::try_from_slice(b"hello world")?;
let s2 = s.try_subslice(..5)?;
assert_eq!(s2, b"hello");
Source

pub fn try_subslice_from_ref(&self, subset: &S) -> Result<Self, AllocError>
where S: Subsliceable,

Tries extracting a subslice of an ArcSlice from a slice reference, returning an error if an allocation fails.

The operation may allocate. See CloneNoAllocLayout documentation for case where it does not.

§Examples
use arc_slice::ArcSlice;

let s = ArcSlice::<[u8]>::try_from_slice(b"hello world")?;
let hello = &s[..5];
let s2 = s.try_subslice_from_ref(hello)?;
assert_eq!(s2, b"hello");
Source

pub fn advance(&mut self, offset: usize)
where S: Subsliceable,

Advances the start of the slice by offset items.

This operation does not touch the underlying buffer.

§Panics

Panics if offset > self.len().

§Examples
use arc_slice::ArcSlice;

let mut s = ArcSlice::<[u8]>::from(b"hello world");
s.advance(6);
assert_eq!(s, b"world");
Source

pub fn try_truncate(&mut self, len: usize) -> Result<(), AllocError>
where S: Subsliceable,

Tries truncating the slice to the first len items, returning an error if an allocation fails.

If len is greater than the slice length, this has no effect.

The operation may not allocate, see TruncateNoAllocLayout documentation.

use arc_slice::ArcSlice;

let mut s = ArcSlice::<[u8]>::from(b"hello world");
s.try_truncate(5)?;
assert_eq!(s, b"hello");
}
Source

pub fn try_split_off(&mut self, at: usize) -> Result<Self, AllocError>
where S: Subsliceable,

Tries splitting the slice into two at the given index, returning an error if an allocation fails.

Afterwards self contains elements [0, at), and the returned ArcSlice contains elements [at, len). This operation does not touch the underlying buffer.

The operation may not allocate, see CloneNoAllocLayout documentation.

§Panics

Panics if at > self.len().

§Examples
use arc_slice::ArcSlice;

let mut a = ArcSlice::<[u8]>::from(b"hello world");
let b = a.try_split_off(5)?;

assert_eq!(a, b"hello");
assert_eq!(b, b" world");
Source

pub fn try_split_to(&mut self, at: usize) -> Result<Self, AllocError>
where S: Subsliceable,

Tries splitting the slice into two at the given index, returning an error if an allocation fails.

Afterwards self contains elements [at, len), and the returned ArcSlice contains elements [0, at). This operation does not touch the underlying buffer.

The operation may not allocate, see CloneNoAllocLayout documentation.

§Panics

Panics if at > self.len().

§Examples
use arc_slice::ArcSlice;

let mut a = ArcSlice::<[u8]>::from(b"hello world");
let b = a.try_split_to(5)?;

assert_eq!(a, b" world");
assert_eq!(b, b"hello");
Source

pub fn try_into_mut<L2: LayoutMut>(self) -> Result<ArcSliceMut<S, L2>, Self>

Tries to acquire the slice as mutable, returning an ArcSliceMut on success.

There must be no other reference to the underlying buffer, and this one must be mutable for the conversion to succeed. Otherwise, the original slice is returned. An ArcSlice created from an array/slice or a vector is guaranteed to have a mutable buffer, as well as one returned ArcSliceMut::freeze.

The conversion may allocate depending on the given layouts, but allocation errors are caught and the original slice is also returned in this case.

§Examples
use arc_slice::{layout::DefaultLayoutMut, ArcSlice, ArcSliceMut};

let mut a = ArcSlice::<[u8]>::from(b"hello world");
let b = a.clone();

assert!(b.try_into_mut::<DefaultLayoutMut>().is_err());
// b has been dropped
let a_mut: ArcSliceMut<[u8]> = a.try_into_mut().unwrap();
Source

pub fn is_unique(&self) -> bool

Returns true if this is the only reference to the underlying buffer, and if this one is unique (see Buffer::is_unique).

§Examples
use arc_slice::ArcSlice;

let s = ArcSlice::<[u8]>::from(b"hello world");
assert!(s.is_unique());
let s2 = s.clone();
assert!(!s.is_unique());
drop(s2);
assert!(s.is_unique());
Source

pub fn metadata<M: Any>(&self) -> Option<&M>

Accesses the metadata of the underlying buffer if it can be successfully downcast.

§Examples
use arc_slice::{layout::ArcLayout, ArcSlice};

let metadata = "metadata".to_string();
let s = ArcSlice::<[u8], ArcLayout<true>>::from_buffer_with_metadata(vec![0, 1, 2], metadata);
assert_eq!(s.metadata::<String>().unwrap(), "metadata");
Source

pub fn try_into_buffer<B: Buffer<S>>(self) -> Result<B, Self>

Tries downcasting the ArcSlice to its underlying buffer.

§Examples
use arc_slice::{layout::ArcLayout, ArcSlice};

let s = ArcSlice::<[u8], ArcLayout<true>>::from(vec![0, 1, 2]);
assert_eq!(s.try_into_buffer::<Vec<u8>>().unwrap(), [0, 1, 2]);
Source

pub fn try_with_layout<L2: Layout>(self) -> Result<ArcSlice<S, L2>, Self>

Tries to replace the layout of the ArcSlice, returning the original slice if it fails.

The layouts must be compatible for the conversion to succeed, see FromLayout.

The conversion may allocate depending on the given layouts, but allocation errors are caught and the original slice is also returned in this case.

§Examples
use arc_slice::{
    layout::{ArcLayout, BoxedSliceLayout, VecLayout},
    ArcSlice,
};

let a = ArcSlice::<[u8], BoxedSliceLayout>::from(vec![0, 1, 2]);

let b = a.try_with_layout::<VecLayout>().unwrap();
assert!(b.try_with_layout::<ArcLayout<false>>().is_err());
Source

pub fn into_arc_slice(self) -> ArcSlice<[S::Item], L>

Converts an ArcSlice into a primitive ArcSlice.

§Examples
use arc_slice::ArcSlice;

let s = ArcSlice::<str>::from("hello world");
let bytes: ArcSlice<[u8]> = s.into_arc_slice();
assert_eq!(bytes, b"hello world");
Source

pub fn try_from_arc_slice( slice: ArcSlice<[S::Item], L>, ) -> Result<Self, (S::TryFromSliceError, ArcSlice<[S::Item], L>)>

Tries converting an item slice into the given ArcSlice.

The conversion uses Slice::try_from_slice.

§Examples
use arc_slice::ArcSlice;

let utf8 = ArcSlice::<[u8]>::from(b"hello world");
let not_utf8 = ArcSlice::<[u8]>::from(b"\x80\x81");

assert!(ArcSlice::<str>::try_from_arc_slice(utf8).is_ok());
assert!(ArcSlice::<str>::try_from_arc_slice(not_utf8).is_err());
Source

pub unsafe fn from_arc_slice_unchecked(slice: ArcSlice<[S::Item], L>) -> Self

Converts an item slice into the given ArcSlice, without checking the slice validity.

§Safety

The operation has the same contract as Slice::from_slice_unchecked.

§Examples
use arc_slice::ArcSlice;

let utf8 = ArcSlice::<[u8]>::from(b"hello world");

// SAFETY: `utf8` is a valid utf8 string
let s = unsafe { ArcSlice::<str>::from_arc_slice_unchecked(utf8) };
assert_eq!(s, "hello world");
Source

pub fn drop_with_unique_hint(self)

Drops an ArcSlice, hinting that it should be unique.

In case of actual unicity, this method should be a little bit more efficient than a conventional drop. Indeed, in the case where an Arc has been allocated, it will first check the refcount, and shortcut the atomic fetch-and-sub if the count is one.

Source§

impl<T: Send + Sync + 'static, L: Layout> ArcSlice<[T], L>

Source

pub fn from_array<const N: usize>(array: [T; N]) -> Self

Available on crate feature oom-handling only.

Creates a new ArcSlice by moving the given array.

§Panics

Panics if the new capacity exceeds isize::MAX - size_of::<usize>() bytes.

§Examples
use arc_slice::ArcSlice;

let s = ArcSlice::<[u8]>::from_array([0, 1, 2]);
assert_eq!(s, [0, 1, 2]);
Source

pub fn try_from_array<const N: usize>(array: [T; N]) -> Result<Self, [T; N]>

Tries creating a new ArcSlice by moving the given array, returning it if an allocation fails.

§Examples
use arc_slice::ArcSlice;

let s = ArcSlice::<[u8]>::try_from_array([0, 1, 2]).unwrap();
assert_eq!(s, [0, 1, 2]);
Source§

impl<S: Slice + ?Sized, L: Layout> ArcSlice<S, L>

Source

pub fn truncate(&mut self, len: usize)
where S: Subsliceable,

Truncate the slice to the first len items.

If len is greater than the slice length, this has no effect.

use arc_slice::ArcSlice;

let mut s = ArcSlice::<[u8]>::from(b"hello world");
s.truncate(5);
assert_eq!(s, b"hello");
Source§

impl<S: Slice + ?Sized, L: Layout> ArcSlice<S, L>

Source

pub fn subslice(&self, range: impl RangeBounds<usize>) -> Self
where S: Subsliceable,

Extracts a subslice of an ArcSlice with a given range.

§Examples
use arc_slice::ArcSlice;

let s = ArcSlice::<[u8]>::from(b"hello world");
let s2 = s.subslice(..5);
assert_eq!(s2, b"hello");
Source

pub fn subslice_from_ref(&self, subset: &S) -> Self
where S: Subsliceable,

Extracts a subslice of an ArcSlice from a slice reference.

§Examples
use arc_slice::ArcSlice;

let s = ArcSlice::<[u8]>::from(b"hello world");
let hello = &s[..5];
let s2 = s.subslice_from_ref(hello);
assert_eq!(s2, b"hello");
Source

pub fn split_off(&mut self, at: usize) -> Self
where S: Subsliceable,

Splits the slice into two at the given index.

Afterwards self contains elements [0, at), and the returned ArcSlice contains elements [at, len). This operation does not touch the underlying buffer.

§Panics

Panics if at > self.len().

§Examples
use arc_slice::ArcSlice;

let mut a = ArcSlice::<[u8]>::from(b"hello world");
let b = a.split_off(5);

assert_eq!(a, b"hello");
assert_eq!(b, b" world");
Source

pub fn split_to(&mut self, at: usize) -> Self
where S: Subsliceable,

Splits the slice into two at the given index.

Afterwards self contains elements [at, len), and the returned ArcSlice contains elements [0, at). This operation does not touch the underlying buffer.

§Panics

Panics if at > self.len().

§Examples
use arc_slice::ArcSlice;

let mut a = ArcSlice::<[u8]>::from(b"hello world");
let b = a.split_to(5);

assert_eq!(a, b" world");
assert_eq!(b, b"hello");
Source§

impl<S: Slice + ?Sized, L: Layout> ArcSlice<S, L>

Source

pub fn with_layout<L2: FromLayout<L>>(self) -> ArcSlice<S, L2>

Available on crate feature oom-handling only.

Replace the layout of the ArcSlice.

The layouts must be compatible, see FromLayout.

§Examples
use arc_slice::{
    layout::{ArcLayout, BoxedSliceLayout, VecLayout},
    ArcSlice,
};

let a = ArcSlice::<[u8]>::from(b"hello world");

let b = a.with_layout::<VecLayout>();
Source§

impl<S: Slice + ?Sized, L: AnyBufferLayout> ArcSlice<S, L>

Source

pub fn from_buffer<B: Buffer<S>>(buffer: B) -> Self

Available on crate feature oom-handling only.

Creates a new ArcSlice with the given underlying buffer.

The buffer can be extracted back using try_into_buffer.

§Examples
use arc_slice::{layout::ArcLayout, ArcSlice};

let s = ArcSlice::<[u8], ArcLayout<true>>::from_buffer(vec![0, 1, 2]);
assert_eq!(s, [0, 1, 2]);
assert_eq!(s.try_into_buffer::<Vec<u8>>().unwrap(), vec![0, 1, 2]);
Source

pub fn try_from_buffer<B: Buffer<S>>(buffer: B) -> Result<Self, B>

Tries creating a new ArcSlice with the given underlying buffer, returning it if an allocation fails.

The buffer can be extracted back using try_into_buffer.

Having an Arc allocation depends on the layout and the buffer type, e.g. there will be no allocation for a Vec with VecLayout.

§Examples
use arc_slice::{layout::ArcLayout, ArcSlice};

let s = ArcSlice::<[u8], ArcLayout<true>>::try_from_buffer(vec![0, 1, 2]).unwrap();
assert_eq!(s, [0, 1, 2]);
assert_eq!(s.try_into_buffer::<Vec<u8>>().unwrap(), vec![0, 1, 2]);
Source

pub fn from_buffer_with_metadata<B: Buffer<S>, M: Send + Sync + 'static>( buffer: B, metadata: M, ) -> Self

Available on crate feature oom-handling only.

Creates a new ArcSlice with the given underlying buffer and its associated metadata.

The buffer can be extracted back using try_into_buffer; metadata can be retrieved with metadata.

§Examples
use arc_slice::{layout::ArcLayout, ArcSlice};

let metadata = "metadata".to_string();
let s = ArcSlice::<[u8], ArcLayout<true>>::from_buffer_with_metadata(vec![0, 1, 2], metadata);
assert_eq!(s, [0, 1, 2]);
assert_eq!(s.metadata::<String>().unwrap(), "metadata");
assert_eq!(s.try_into_buffer::<Vec<u8>>().unwrap(), vec![0, 1, 2]);
Source

pub fn try_from_buffer_with_metadata<B: Buffer<S>, M: Send + Sync + 'static>( buffer: B, metadata: M, ) -> Result<Self, (B, M)>

Tries creates a new ArcSlice with the given underlying buffer and its associated metadata, returning them if an allocation fails.

The buffer can be extracted back using try_into_buffer; metadata can be retrieved with metadata.

Having an Arc allocation depends on the layout and the buffer type, e.g. there will be no allocation for a Vec with VecLayout.

§Examples
use arc_slice::{layout::ArcLayout, ArcSlice};

let metadata = "metadata".to_string();
let s =
    ArcSlice::<[u8], ArcLayout<true>>::try_from_buffer_with_metadata(vec![0, 1, 2], metadata)
        .unwrap();
assert_eq!(s, [0, 1, 2]);
assert_eq!(s.metadata::<String>().unwrap(), "metadata");
assert_eq!(s.try_into_buffer::<Vec<u8>>().unwrap(), vec![0, 1, 2]);
Source

pub fn from_buffer_with_borrowed_metadata<B: Buffer<S> + BorrowMetadata>( buffer: B, ) -> Self

Available on crate feature oom-handling only.

Creates a new ArcSlice with the given underlying buffer with borrowed metadata.

The buffer can be extracted back using try_into_buffer; metadata can be retrieved with metadata.

§Examples
use arc_slice::{
    buffer::{BorrowMetadata, Buffer},
    layout::ArcLayout,
    ArcSlice,
};

#[derive(Debug, PartialEq, Eq)]
struct MyBuffer(Vec<u8>);
impl Buffer<[u8]> for MyBuffer {
    fn as_slice(&self) -> &[u8] {
        &self.0
    }
}
#[derive(Debug, PartialEq, Eq)]
struct MyMetadata;
impl BorrowMetadata for MyBuffer {
    type Metadata = MyMetadata;
    fn borrow_metadata(&self) -> &Self::Metadata {
        &MyMetadata
    }
}
let buffer = MyBuffer(vec![0, 1, 2]);
let s = ArcSlice::<[u8], ArcLayout<true>>::from_buffer_with_borrowed_metadata(buffer);
assert_eq!(s, [0, 1, 2]);
assert_eq!(s.metadata::<MyMetadata>().unwrap(), &MyMetadata);
assert_eq!(
    s.try_into_buffer::<MyBuffer>().unwrap(),
    MyBuffer(vec![0, 1, 2])
);
Source

pub fn try_from_buffer_with_borrowed_metadata<B: Buffer<S> + BorrowMetadata>( buffer: B, ) -> Result<Self, B>

Tries creating a new ArcSlice with the given underlying buffer with borrowed metadata, returning it if an allocation fails.

The buffer can be extracted back using try_into_buffer; metadata can be retrieved with metadata.

Having an Arc allocation depends on the layout and the buffer type, e.g. there will be no allocation for a Vec with VecLayout.

§Examples
use arc_slice::{
    buffer::{BorrowMetadata, Buffer},
    layout::ArcLayout,
    ArcSlice,
};

#[derive(Debug, PartialEq, Eq)]
struct MyBuffer(Vec<u8>);
impl Buffer<[u8]> for MyBuffer {
    fn as_slice(&self) -> &[u8] {
        &self.0
    }
}
#[derive(Debug, PartialEq, Eq)]
struct MyMetadata;
impl BorrowMetadata for MyBuffer {
    type Metadata = MyMetadata;
    fn borrow_metadata(&self) -> &Self::Metadata {
        &MyMetadata
    }
}
let buffer = MyBuffer(vec![0, 1, 2]);
let s =
    ArcSlice::<[u8], ArcLayout<true>>::try_from_buffer_with_borrowed_metadata(buffer).unwrap();
assert_eq!(s, [0, 1, 2]);
assert_eq!(s.metadata::<MyMetadata>().unwrap(), &MyMetadata);
assert_eq!(
    s.try_into_buffer::<MyBuffer>().unwrap(),
    MyBuffer(vec![0, 1, 2])
);
Source

pub fn from_raw_buffer<B: RawBuffer<S>>(buffer: B) -> Self

Available on crate features raw-buffer and oom-handling only.

Creates a new ArcSlice with the given underlying raw buffer.

For layouts others than RawLayout, it is the same as from_buffer.

The buffer can be extracted back using try_into_buffer.

§Examples
use std::sync::Arc;

use arc_slice::{layout::RawLayout, ArcSlice};

let s = ArcSlice::<[u8], RawLayout>::from_raw_buffer(Arc::new(vec![0, 1, 2]));
assert_eq!(s, [0, 1, 2]);
assert_eq!(
    s.try_into_buffer::<Arc<Vec<u8>>>().unwrap(),
    Arc::new(vec![0, 1, 2])
);
Source

pub fn try_from_raw_buffer<B: RawBuffer<S>>(buffer: B) -> Result<Self, B>

Available on crate feature raw-buffer only.

Tries creating a new ArcSlice with the given underlying raw buffer, returning it if an allocation fails.

For layouts others than RawLayout, it is the same as try_from_buffer.

The buffer can be extracted back using try_into_buffer.

§Examples
use std::sync::Arc;

use arc_slice::{layout::RawLayout, ArcSlice};

let s = ArcSlice::<[u8], RawLayout>::try_from_raw_buffer(Arc::new(vec![0, 1, 2])).unwrap();
assert_eq!(s, [0, 1, 2]);
assert_eq!(
    s.try_into_buffer::<Arc<Vec<u8>>>().unwrap(),
    Arc::new(vec![0, 1, 2])
);
Source

pub fn from_raw_buffer_with_borrowed_metadata<B: RawBuffer<S> + BorrowMetadata>( buffer: B, ) -> Self

Available on crate features raw-buffer and oom-handling only.

Creates a new ArcSlice with the given underlying raw buffer with borrowed metadata.

For layouts others than RawLayout, it is the same as from_buffer.

The buffer can be extracted back using try_into_buffer; metadata can be retrieved with metadata.

§Examples
use std::sync::Arc;

///
use arc_slice::buffer::{BorrowMetadata, Buffer};
use arc_slice::{layout::RawLayout, ArcSlice};

#[derive(Debug, PartialEq, Eq)]
struct MyBuffer(Vec<u8>);
impl Buffer<[u8]> for MyBuffer {
    fn as_slice(&self) -> &[u8] {
        &self.0
    }
}
#[derive(Debug, PartialEq, Eq)]
struct MyMetadata;
impl BorrowMetadata for MyBuffer {
    type Metadata = MyMetadata;
    fn borrow_metadata(&self) -> &Self::Metadata {
        &MyMetadata
    }
}

let buffer = Arc::new(MyBuffer(vec![0, 1, 2]));
let s = ArcSlice::<[u8], RawLayout>::from_raw_buffer_with_borrowed_metadata(buffer);
assert_eq!(s, [0, 1, 2]);
assert_eq!(s.metadata::<MyMetadata>().unwrap(), &MyMetadata);
assert_eq!(
    s.try_into_buffer::<Arc<MyBuffer>>().unwrap(),
    Arc::new(MyBuffer(vec![0, 1, 2]))
);
Source

pub fn try_from_raw_buffer_with_borrowed_metadata<B: RawBuffer<S> + BorrowMetadata>( buffer: B, ) -> Result<Self, B>

Available on crate feature raw-buffer only.

Tries creating a new ArcSlice with the given underlying raw buffer with borrowed metadata, returning it if an allocation fails.

For layouts others than RawLayout, it is the same as from_buffer.

The buffer can be extracted back using try_into_buffer; metadata can be retrieved with metadata.

Having an Arc allocation depends on the layout and the buffer type, e.g. there will be no allocation for a Vec with VecLayout.

§Examples
use std::sync::Arc;

///
use arc_slice::buffer::{BorrowMetadata, Buffer};
use arc_slice::{layout::RawLayout, ArcSlice};

#[derive(Debug, PartialEq, Eq)]
struct MyBuffer(Vec<u8>);
impl Buffer<[u8]> for MyBuffer {
    fn as_slice(&self) -> &[u8] {
        &self.0
    }
}
#[derive(Debug, PartialEq, Eq)]
struct MyMetadata;
impl BorrowMetadata for MyBuffer {
    type Metadata = MyMetadata;
    fn borrow_metadata(&self) -> &Self::Metadata {
        &MyMetadata
    }
}

let buffer = Arc::new(MyBuffer(vec![0, 1, 2]));
let s =
    ArcSlice::<[u8], RawLayout>::try_from_raw_buffer_with_borrowed_metadata(buffer).unwrap();
assert_eq!(s, [0, 1, 2]);
assert_eq!(s.metadata::<MyMetadata>().unwrap(), &MyMetadata);
assert_eq!(
    s.try_into_buffer::<Arc<MyBuffer>>().unwrap(),
    Arc::new(MyBuffer(vec![0, 1, 2]))
);
Source§

impl<L: StaticLayout> ArcSlice<[u8], L>

Source

pub const fn from_static(slice: &'static [u8]) -> Self

Creates a new ArcSlice from a static slice.

The operation never allocates.

§Examples
use arc_slice::{layout::ArcLayout, ArcSlice};

static HELLO_WORLD: ArcSlice<[u8], ArcLayout<true, true>> =
    ArcSlice::<[u8], ArcLayout<true, true>>::from_static(b"hello world");
Source§

impl<L: StaticLayout> ArcSlice<str, L>

Source

pub const fn from_static(slice: &'static str) -> Self

Creates a new ArcSlice from a static str.

The operation never allocates.

§Examples
use arc_slice::{layout::ArcLayout, ArcSlice};

static HELLO_WORLD: ArcSlice<str, ArcLayout<true, true>> =
    ArcSlice::<str, ArcLayout<true, true>>::from_static("hello world");

Trait Implementations§

Source§

impl<S: Slice + ?Sized, L: Layout> AsRef<S> for ArcSlice<S, L>

Source§

fn as_ref(&self) -> &S

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<S: Slice + ?Sized, L: Layout> Borrow<S> for ArcSlice<S, L>

Source§

fn borrow(&self) -> &S

Immutably borrows from an owned value. Read more
Source§

impl<S: Slice<Item = u8> + Subsliceable + ?Sized, L: Layout> Buf for ArcSlice<S, L>

Available on crate feature bytes only.
Source§

fn remaining(&self) -> usize

Returns the number of bytes between the current position and the end of the buffer. Read more
Source§

fn chunk(&self) -> &[u8]

Returns a slice starting at the current position and of length between 0 and Buf::remaining(). Note that this can return a shorter slice (this allows non-continuous internal representation). Read more
Source§

fn advance(&mut self, cnt: usize)

Advance the internal cursor of the Buf Read more
Source§

fn has_remaining(&self) -> bool

Returns true if there are any more bytes to consume Read more
Source§

fn copy_to_slice(&mut self, dst: &mut [u8])

Copies bytes from self into dst. Read more
Source§

fn get_u8(&mut self) -> u8

Gets an unsigned 8 bit integer from self. Read more
Source§

fn get_i8(&mut self) -> i8

Gets a signed 8 bit integer from self. Read more
Source§

fn get_u16(&mut self) -> u16

Gets an unsigned 16 bit integer from self in big-endian byte order. Read more
Source§

fn get_u16_le(&mut self) -> u16

Gets an unsigned 16 bit integer from self in little-endian byte order. Read more
Source§

fn get_u16_ne(&mut self) -> u16

Gets an unsigned 16 bit integer from self in native-endian byte order. Read more
Source§

fn get_i16(&mut self) -> i16

Gets a signed 16 bit integer from self in big-endian byte order. Read more
Source§

fn get_i16_le(&mut self) -> i16

Gets a signed 16 bit integer from self in little-endian byte order. Read more
Source§

fn get_i16_ne(&mut self) -> i16

Gets a signed 16 bit integer from self in native-endian byte order. Read more
Source§

fn get_u32(&mut self) -> u32

Gets an unsigned 32 bit integer from self in the big-endian byte order. Read more
Source§

fn get_u32_le(&mut self) -> u32

Gets an unsigned 32 bit integer from self in the little-endian byte order. Read more
Source§

fn get_u32_ne(&mut self) -> u32

Gets an unsigned 32 bit integer from self in native-endian byte order. Read more
Source§

fn get_i32(&mut self) -> i32

Gets a signed 32 bit integer from self in big-endian byte order. Read more
Source§

fn get_i32_le(&mut self) -> i32

Gets a signed 32 bit integer from self in little-endian byte order. Read more
Source§

fn get_i32_ne(&mut self) -> i32

Gets a signed 32 bit integer from self in native-endian byte order. Read more
Source§

fn get_u64(&mut self) -> u64

Gets an unsigned 64 bit integer from self in big-endian byte order. Read more
Source§

fn get_u64_le(&mut self) -> u64

Gets an unsigned 64 bit integer from self in little-endian byte order. Read more
Source§

fn get_u64_ne(&mut self) -> u64

Gets an unsigned 64 bit integer from self in native-endian byte order. Read more
Source§

fn get_i64(&mut self) -> i64

Gets a signed 64 bit integer from self in big-endian byte order. Read more
Source§

fn get_i64_le(&mut self) -> i64

Gets a signed 64 bit integer from self in little-endian byte order. Read more
Source§

fn get_i64_ne(&mut self) -> i64

Gets a signed 64 bit integer from self in native-endian byte order. Read more
Source§

fn get_u128(&mut self) -> u128

Gets an unsigned 128 bit integer from self in big-endian byte order. Read more
Source§

fn get_u128_le(&mut self) -> u128

Gets an unsigned 128 bit integer from self in little-endian byte order. Read more
Source§

fn get_u128_ne(&mut self) -> u128

Gets an unsigned 128 bit integer from self in native-endian byte order. Read more
Source§

fn get_i128(&mut self) -> i128

Gets a signed 128 bit integer from self in big-endian byte order. Read more
Source§

fn get_i128_le(&mut self) -> i128

Gets a signed 128 bit integer from self in little-endian byte order. Read more
Source§

fn get_i128_ne(&mut self) -> i128

Gets a signed 128 bit integer from self in native-endian byte order. Read more
Source§

fn get_uint(&mut self, nbytes: usize) -> u64

Gets an unsigned n-byte integer from self in big-endian byte order. Read more
Source§

fn get_uint_le(&mut self, nbytes: usize) -> u64

Gets an unsigned n-byte integer from self in little-endian byte order. Read more
Source§

fn get_uint_ne(&mut self, nbytes: usize) -> u64

Gets an unsigned n-byte integer from self in native-endian byte order. Read more
Source§

fn get_int(&mut self, nbytes: usize) -> i64

Gets a signed n-byte integer from self in big-endian byte order. Read more
Source§

fn get_int_le(&mut self, nbytes: usize) -> i64

Gets a signed n-byte integer from self in little-endian byte order. Read more
Source§

fn get_int_ne(&mut self, nbytes: usize) -> i64

Gets a signed n-byte integer from self in native-endian byte order. Read more
Source§

fn get_f32(&mut self) -> f32

Gets an IEEE754 single-precision (4 bytes) floating point number from self in big-endian byte order. Read more
Source§

fn get_f32_le(&mut self) -> f32

Gets an IEEE754 single-precision (4 bytes) floating point number from self in little-endian byte order. Read more
Source§

fn get_f32_ne(&mut self) -> f32

Gets an IEEE754 single-precision (4 bytes) floating point number from self in native-endian byte order. Read more
Source§

fn get_f64(&mut self) -> f64

Gets an IEEE754 double-precision (8 bytes) floating point number from self in big-endian byte order. Read more
Source§

fn get_f64_le(&mut self) -> f64

Gets an IEEE754 double-precision (8 bytes) floating point number from self in little-endian byte order. Read more
Source§

fn get_f64_ne(&mut self) -> f64

Gets an IEEE754 double-precision (8 bytes) floating point number from self in native-endian byte order. Read more
Source§

fn try_copy_to_slice(&mut self, dst: &mut [u8]) -> Result<(), TryGetError>

Copies bytes from self into dst. Read more
Source§

fn try_get_u8(&mut self) -> Result<u8, TryGetError>

Gets an unsigned 8 bit integer from self. Read more
Source§

fn try_get_i8(&mut self) -> Result<i8, TryGetError>

Gets a signed 8 bit integer from self. Read more
Source§

fn try_get_u16(&mut self) -> Result<u16, TryGetError>

Gets an unsigned 16 bit integer from self in big-endian byte order. Read more
Source§

fn try_get_u16_le(&mut self) -> Result<u16, TryGetError>

Gets an unsigned 16 bit integer from self in little-endian byte order. Read more
Source§

fn try_get_u16_ne(&mut self) -> Result<u16, TryGetError>

Gets an unsigned 16 bit integer from self in native-endian byte order. Read more
Source§

fn try_get_i16(&mut self) -> Result<i16, TryGetError>

Gets a signed 16 bit integer from self in big-endian byte order. Read more
Source§

fn try_get_i16_le(&mut self) -> Result<i16, TryGetError>

Gets an signed 16 bit integer from self in little-endian byte order. Read more
Source§

fn try_get_i16_ne(&mut self) -> Result<i16, TryGetError>

Gets a signed 16 bit integer from self in native-endian byte order. Read more
Source§

fn try_get_u32(&mut self) -> Result<u32, TryGetError>

Gets an unsigned 32 bit integer from self in big-endian byte order. Read more
Source§

fn try_get_u32_le(&mut self) -> Result<u32, TryGetError>

Gets an unsigned 32 bit integer from self in little-endian byte order. Read more
Source§

fn try_get_u32_ne(&mut self) -> Result<u32, TryGetError>

Gets an unsigned 32 bit integer from self in native-endian byte order. Read more
Source§

fn try_get_i32(&mut self) -> Result<i32, TryGetError>

Gets a signed 32 bit integer from self in big-endian byte order. Read more
Source§

fn try_get_i32_le(&mut self) -> Result<i32, TryGetError>

Gets a signed 32 bit integer from self in little-endian byte order. Read more
Source§

fn try_get_i32_ne(&mut self) -> Result<i32, TryGetError>

Gets a signed 32 bit integer from self in native-endian byte order. Read more
Source§

fn try_get_u64(&mut self) -> Result<u64, TryGetError>

Gets an unsigned 64 bit integer from self in big-endian byte order. Read more
Source§

fn try_get_u64_le(&mut self) -> Result<u64, TryGetError>

Gets an unsigned 64 bit integer from self in little-endian byte order. Read more
Source§

fn try_get_u64_ne(&mut self) -> Result<u64, TryGetError>

Gets an unsigned 64 bit integer from self in native-endian byte order. Read more
Source§

fn try_get_i64(&mut self) -> Result<i64, TryGetError>

Gets a signed 64 bit integer from self in big-endian byte order. Read more
Source§

fn try_get_i64_le(&mut self) -> Result<i64, TryGetError>

Gets a signed 64 bit integer from self in little-endian byte order. Read more
Source§

fn try_get_i64_ne(&mut self) -> Result<i64, TryGetError>

Gets a signed 64 bit integer from self in native-endian byte order. Read more
Source§

fn try_get_u128(&mut self) -> Result<u128, TryGetError>

Gets an unsigned 128 bit integer from self in big-endian byte order. Read more
Source§

fn try_get_u128_le(&mut self) -> Result<u128, TryGetError>

Gets an unsigned 128 bit integer from self in little-endian byte order. Read more
Source§

fn try_get_u128_ne(&mut self) -> Result<u128, TryGetError>

Gets an unsigned 128 bit integer from self in native-endian byte order. Read more
Source§

fn try_get_i128(&mut self) -> Result<i128, TryGetError>

Gets a signed 128 bit integer from self in big-endian byte order. Read more
Source§

fn try_get_i128_le(&mut self) -> Result<i128, TryGetError>

Gets a signed 128 bit integer from self in little-endian byte order. Read more
Source§

fn try_get_i128_ne(&mut self) -> Result<i128, TryGetError>

Gets a signed 128 bit integer from self in native-endian byte order. Read more
Source§

fn try_get_uint(&mut self, nbytes: usize) -> Result<u64, TryGetError>

Gets an unsigned n-byte integer from self in big-endian byte order. Read more
Source§

fn try_get_uint_le(&mut self, nbytes: usize) -> Result<u64, TryGetError>

Gets an unsigned n-byte integer from self in little-endian byte order. Read more
Source§

fn try_get_uint_ne(&mut self, nbytes: usize) -> Result<u64, TryGetError>

Gets an unsigned n-byte integer from self in native-endian byte order. Read more
Source§

fn try_get_int(&mut self, nbytes: usize) -> Result<i64, TryGetError>

Gets a signed n-byte integer from self in big-endian byte order. Read more
Source§

fn try_get_int_le(&mut self, nbytes: usize) -> Result<i64, TryGetError>

Gets a signed n-byte integer from self in little-endian byte order. Read more
Source§

fn try_get_int_ne(&mut self, nbytes: usize) -> Result<i64, TryGetError>

Gets a signed n-byte integer from self in native-endian byte order. Read more
Source§

fn try_get_f32(&mut self) -> Result<f32, TryGetError>

Gets an IEEE754 single-precision (4 bytes) floating point number from self in big-endian byte order. Read more
Source§

fn try_get_f32_le(&mut self) -> Result<f32, TryGetError>

Gets an IEEE754 single-precision (4 bytes) floating point number from self in little-endian byte order. Read more
Source§

fn try_get_f32_ne(&mut self) -> Result<f32, TryGetError>

Gets an IEEE754 single-precision (4 bytes) floating point number from self in native-endian byte order. Read more
Source§

fn try_get_f64(&mut self) -> Result<f64, TryGetError>

Gets an IEEE754 double-precision (8 bytes) floating point number from self in big-endian byte order. Read more
Source§

fn try_get_f64_le(&mut self) -> Result<f64, TryGetError>

Gets an IEEE754 double-precision (8 bytes) floating point number from self in little-endian byte order. Read more
Source§

fn try_get_f64_ne(&mut self) -> Result<f64, TryGetError>

Gets an IEEE754 double-precision (8 bytes) floating point number from self in native-endian byte order. Read more
Source§

fn copy_to_bytes(&mut self, len: usize) -> Bytes

Consumes len bytes inside self and returns new instance of Bytes with this data. Read more
Source§

fn take(self, limit: usize) -> Take<Self>
where Self: Sized,

Creates an adaptor which will read at most limit bytes from self. Read more
Source§

fn chain<U>(self, next: U) -> Chain<Self, U>
where U: Buf, Self: Sized,

Creates an adaptor which will chain this buffer with another. Read more
Source§

impl<S: Slice + ?Sized, L: Layout> Clone for ArcSlice<S, L>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S: Debug + Slice + ?Sized, L: Layout> Debug for ArcSlice<S, L>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S: Emptyable + ?Sized, L: StaticLayout> Default for ArcSlice<S, L>

Source§

fn default() -> Self

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

impl<S: Slice + ?Sized, L: Layout> Deref for ArcSlice<S, L>

Source§

type Target = S

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'de, S: Slice + Deserializable + ?Sized, L: Layout> Deserialize<'de> for ArcSlice<S, L>
where S::Item: for<'a> Deserialize<'a>, S::TryFromSliceError: Display,

Available on crate feature serde only.
Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<S: Display + Slice + ?Sized, L: Layout> Display for ArcSlice<S, L>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S: Slice + ?Sized, L: Layout> Drop for ArcSlice<S, L>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: Copy + Send + Sync + 'static, L: Layout, const N: usize> From<&[T; N]> for ArcSlice<[T], L>

Available on crate feature oom-handling only.
Source§

fn from(value: &[T; N]) -> Self

Converts to this type from the input type.
Source§

impl<S: Slice + ?Sized, L: Layout> From<&S> for ArcSlice<S, L>
where S::Item: Copy,

Available on crate feature oom-handling only.
Source§

fn from(value: &S) -> Self

Converts to this type from the input type.
Source§

impl<T: Send + Sync + 'static, L: Layout, const N: usize> From<[T; N]> for ArcSlice<[T], L>

Available on crate feature oom-handling only.
Source§

fn from(value: [T; N]) -> Self

Converts to this type from the input type.
Source§

impl<S: Slice<Item = u8> + ?Sized, L: Layout> From<ArcSlice<S, L>> for SmallArcSlice<S, L>

Available on crate feature inlined only.
Source§

fn from(value: ArcSlice<S, L>) -> Self

Converts to this type from the input type.
Source§

impl<S: Slice + ?Sized, L: AnyBufferLayout> From<Box<S>> for ArcSlice<S, L>

Available on crate feature oom-handling only.
Source§

fn from(value: Box<S>) -> Self

Converts to this type from the input type.
Source§

impl<L: AnyBufferLayout> From<String> for ArcSlice<str, L>

Available on crate feature oom-handling only.
Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl<T: Send + Sync + 'static, L: AnyBufferLayout> From<Vec<T>> for ArcSlice<[T], L>

Available on crate feature oom-handling only.
Source§

fn from(value: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<L: Layout> FromStr for ArcSlice<str, L>

Available on crate feature oom-handling only.
Source§

type Err = Infallible

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

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

impl<S: Hash + Slice + ?Sized, L: Layout> Hash for ArcSlice<S, L>

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl<S: Slice<Item = u8> + ?Sized, L: Layout> LowerHex for ArcSlice<S, L>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S: Ord + Slice + ?Sized, L: Layout> Ord for ArcSlice<S, L>

Source§

fn cmp(&self, other: &ArcSlice<S, L>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<'a, T: PartialEq + Send + Sync + 'static, L: Layout, const N: usize> PartialEq<&'a [T; N]> for ArcSlice<[T], L>

Source§

fn eq(&self, other: &&'a [T; N]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, S: PartialEq + Slice + ?Sized, L: Layout> PartialEq<&'a S> for ArcSlice<S, L>

Source§

fn eq(&self, other: &&'a S) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialEq + Send + Sync + 'static, L: Layout, const N: usize> PartialEq<[T; N]> for ArcSlice<[T], L>

Source§

fn eq(&self, other: &[T; N]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialEq + Send + Sync + 'static, L: Layout> PartialEq<ArcSlice<[T], L>> for [T]

Source§

fn eq(&self, other: &ArcSlice<[T], L>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialEq + Send + Sync + 'static, L: Layout, const N: usize> PartialEq<ArcSlice<[T], L>> for [T; N]

Source§

fn eq(&self, other: &ArcSlice<[T], L>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialEq + Send + Sync + 'static, L: Layout> PartialEq<ArcSlice<[T], L>> for Vec<T>

Source§

fn eq(&self, other: &ArcSlice<[T], L>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<L: Layout> PartialEq<ArcSlice<str, L>> for String

Source§

fn eq(&self, other: &ArcSlice<str, L>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<L: Layout> PartialEq<ArcSlice<str, L>> for str

Source§

fn eq(&self, other: &ArcSlice<str, L>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<S: PartialEq + Slice + ?Sized, L: Layout> PartialEq<S> for ArcSlice<S, L>

Source§

fn eq(&self, other: &S) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<L: Layout> PartialEq<String> for ArcSlice<str, L>

Source§

fn eq(&self, other: &String) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialEq + Send + Sync + 'static, L: Layout> PartialEq<Vec<T>> for ArcSlice<[T], L>

Source§

fn eq(&self, other: &Vec<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<S: PartialEq + Slice + ?Sized, L: Layout> PartialEq for ArcSlice<S, L>

Source§

fn eq(&self, other: &ArcSlice<S, L>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<S: PartialOrd + Slice + ?Sized, L: Layout> PartialOrd for ArcSlice<S, L>

Source§

fn partial_cmp(&self, other: &ArcSlice<S, L>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<L: Layout> Read for ArcSlice<[u8], L>

Available on crate feature std only.
Source§

fn read(&mut self, buf: &mut [u8]) -> Result<usize>

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

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>

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

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
1.0.0 · Source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>

Reads all bytes until EOF in this source, placing them into buf. Read more
1.0.0 · Source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

Reads all bytes until EOF in this source, appending them to buf. Read more
1.6.0 · Source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

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

fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
Source§

fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Reads the exact number of bytes required to fill cursor. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adaptor for this instance of Read. Read more
1.0.0 · Source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · Source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · Source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more
Source§

impl<S: Serialize + Slice + ?Sized, L: Layout> Serialize for ArcSlice<S, L>

Available on crate feature serde only.
Source§

fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where Ser: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: Send + Sync + 'static, L: Layout, const N: usize> TryFrom<ArcSlice<[T], L>> for [T; N]

Source§

type Error = ArcSlice<[T], L>

The type returned in the event of a conversion error.
Source§

fn try_from(value: ArcSlice<[T], L>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<S: Slice<Item = u8> + ?Sized, L: Layout> UpperHex for ArcSlice<S, L>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S: PartialEq + Slice + ?Sized, L: Layout> Eq for ArcSlice<S, L>

Source§

impl<S: Slice + ?Sized, L: Layout> Send for ArcSlice<S, L>

Source§

impl<S: Slice + ?Sized, L: Layout> Sync for ArcSlice<S, L>

Auto Trait Implementations§

§

impl<S, L> Freeze for ArcSlice<S, L>
where <L as ArcSliceLayout>::Data: Freeze, S: ?Sized,

§

impl<S, L> RefUnwindSafe for ArcSlice<S, L>
where <L as ArcSliceLayout>::Data: RefUnwindSafe, <S as Slice>::Item: RefUnwindSafe, S: ?Sized,

§

impl<S, L> Unpin for ArcSlice<S, L>
where <L as ArcSliceLayout>::Data: Unpin, S: ?Sized,

§

impl<S, L> UnwindSafe for ArcSlice<S, L>
where <L as ArcSliceLayout>::Data: UnwindSafe, <S as Slice>::Item: RefUnwindSafe, S: ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,