Struct actix_web::payload::PayloadItem [] [src]

pub struct PayloadItem(pub Bytes);

Just Bytes object

Methods from Deref<Target = Bytes>

[src]

Returns the number of bytes contained in this Bytes.

Examples

use bytes::Bytes;

let b = Bytes::from(&b"hello"[..]);
assert_eq!(b.len(), 5);

[src]

Returns true if the Bytes has a length of 0.

Examples

use bytes::Bytes;

let b = Bytes::new();
assert!(b.is_empty());

[src]

Returns a slice of self for the index range [begin..end).

This will increment the reference count for the underlying memory and return a new Bytes handle set to the slice.

This operation is O(1).

Examples

use bytes::Bytes;

let a = Bytes::from(&b"hello world"[..]);
let b = a.slice(2, 5);

assert_eq!(&b[..], b"llo");

Panics

Requires that begin <= end and end <= self.len(), otherwise slicing will panic.

[src]

Returns a slice of self for the index range [begin..self.len()).

This will increment the reference count for the underlying memory and return a new Bytes handle set to the slice.

This operation is O(1) and is equivalent to self.slice(begin, self.len()).

Examples

use bytes::Bytes;

let a = Bytes::from(&b"hello world"[..]);
let b = a.slice_from(6);

assert_eq!(&b[..], b"world");

Panics

Requires that begin <= self.len(), otherwise slicing will panic.

[src]

Returns a slice of self for the index range [0..end).

This will increment the reference count for the underlying memory and return a new Bytes handle set to the slice.

This operation is O(1) and is equivalent to self.slice(0, end).

Examples

use bytes::Bytes;

let a = Bytes::from(&b"hello world"[..]);
let b = a.slice_to(5);

assert_eq!(&b[..], b"hello");

Panics

Requires that end <= self.len(), otherwise slicing will panic.

[src]

Splits the bytes into two at the given index.

Afterwards self contains elements [0, at), and the returned Bytes contains elements [at, len).

This is an O(1) operation that just increases the reference count and sets a few indices.

Examples

use bytes::Bytes;

let mut a = Bytes::from(&b"hello world"[..]);
let b = a.split_off(5);

assert_eq!(&a[..], b"hello");
assert_eq!(&b[..], b" world");

Panics

Panics if at > len.

[src]

Splits the bytes into two at the given index.

Afterwards self contains elements [at, len), and the returned Bytes contains elements [0, at).

This is an O(1) operation that just increases the reference count and sets a few indices.

Examples

use bytes::Bytes;

let mut a = Bytes::from(&b"hello world"[..]);
let b = a.split_to(5);

assert_eq!(&a[..], b" world");
assert_eq!(&b[..], b"hello");

Panics

Panics if at > len.

[src]

Shortens the buffer, keeping the first len bytes and dropping the rest.

If len is greater than the buffer's current length, this has no effect.

The split_off method can emulate truncate, but this causes the excess bytes to be returned instead of dropped.

Examples

use bytes::Bytes;

let mut buf = Bytes::from(&b"hello world"[..]);
buf.truncate(5);
assert_eq!(buf, b"hello"[..]);

[src]

Shortens the buffer, dropping the first cnt bytes and keeping the rest.

This is the same function as Buf::advance, and in the next breaking release of bytes, this implementation will be removed in favor of having Bytes implement Buf.

Panics

This function panics if cnt is greater than self.len()

[src]

Clears the buffer, removing all data.

Examples

use bytes::Bytes;

let mut buf = Bytes::from(&b"hello world"[..]);
buf.clear();
assert!(buf.is_empty());

[src]

Attempts to convert into a BytesMut handle.

This will only succeed if there are no other outstanding references to the underlying chunk of memory. Bytes handles that contain inlined bytes will always be convertable to BytesMut.

Examples

use bytes::Bytes;

let a = Bytes::from(&b"Mary had a little lamb, little lamb, little lamb..."[..]);

// Create a shallow clone
let b = a.clone();

// This will fail because `b` shares a reference with `a`
let a = a.try_mut().unwrap_err();

drop(b);

// This will succeed
let mut a = a.try_mut().unwrap();

a[0] = b'b';

assert_eq!(&a[..4], b"bary");

[src]

Appends given bytes to this object.

If this Bytes object has not enough capacity, it is resized first. If it is shared (refcount > 1), it is copied first.

This operation can be less effective than the similar operation on BytesMut, especially on small additions.

Examples

use bytes::Bytes;

let mut buf = Bytes::from("aabb");
buf.extend_from_slice(b"ccdd");
buf.extend_from_slice(b"eeff");

assert_eq!(b"aabbccddeeff", &buf[..]);

Trait Implementations

impl ResponseType for PayloadItem
[src]

The type of value that this message will resolved with if it is successful.

The type of error that this message will resolve with if it fails in a normal fashion.

impl PartialEq for PayloadItem
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl Deref for PayloadItem
[src]

The resulting type after dereferencing.

[src]

Dereferences the value.

impl DerefMut for PayloadItem
[src]

[src]

Mutably dereferences the value.

impl Debug for PayloadItem
[src]

[src]

Formats the value using the given formatter.