Struct Tuple

Source
pub struct Tuple { /* private fields */ }
Expand description

A builder for serialized tuples

Implementations§

Source§

impl Tuple

Source

pub fn new() -> Tuple

Create a new tuple

Source

pub fn with_capacity(capacity: usize) -> Tuple

Create a new tuple with a fixed backing capacity

Source

pub fn from_bytes(bytes: &[u8]) -> Tuple

Create a new tuple from an existing byte array

This can be used with as_segments to parse an existing tuple into a list of segments

Examples

use binary_tuples::{Tuple, segment::Segment};

let binary = vec![2, 117, 115, 101, 114, 115, 0, 21, 1];

let tuple = Tuple::from_bytes(&binary)
    .as_segments()
    .unwrap();

assert_eq!(tuple, vec![Segment::String(String::from("users")), Segment::Integer(1)]);
Source

pub fn add_segment(&mut self, input: &Segment)

Add an individual segment to this tuple.

§Notes

It is recommended to import AddToTuple as it greatly simplifies this API

Source

pub fn add_builder(&mut self, input: &Tuple)

Directly embed the contents of another tuple builder in this builder

§Notes

This is more efficient than adding a segment slice as the backing buffer can be memcopied.

Source

pub fn into_bytes(self) -> Vec<u8>

Return a serialized tuple

Source

pub fn as_bytes(&self) -> &[u8]

Return a serialized tuple

Source

pub fn as_segments(&self) -> Result<Vec<Segment>, TupleError>

Deserialize the segments which make up this tuple

Trait Implementations§

Source§

impl<'a> AddToTuple<&'a [u8]> for Tuple

Source§

fn add(&mut self, v: &'a [u8])

Add a new segment to a tuple
Source§

fn with(self, input: T) -> Self

A fluent interface for adding a new segment to a tuple Read more
Source§

impl<'a> AddToTuple<&'a Tuple> for Tuple

Source§

fn add(&mut self, v: &'a Tuple)

Add a new segment to a tuple
Source§

fn with(self, input: T) -> Self

A fluent interface for adding a new segment to a tuple Read more
Source§

impl<'a> AddToTuple<&'a Vec<u8>> for Tuple

Source§

fn add(&mut self, v: &'a Vec<u8>)

Add a new segment to a tuple
Source§

fn with(self, input: T) -> Self

A fluent interface for adding a new segment to a tuple Read more
Source§

impl AddToTuple<&'static str> for Tuple

Source§

fn add(&mut self, v: &'static str)

Add a new segment to a tuple
Source§

fn with(self, input: T) -> Self

A fluent interface for adding a new segment to a tuple Read more
Source§

impl AddToTuple<String> for Tuple

Source§

fn add(&mut self, v: String)

Add a new segment to a tuple
Source§

fn with(self, input: T) -> Self

A fluent interface for adding a new segment to a tuple Read more
Source§

impl AddToTuple<Tuple> for Tuple

Source§

fn add(&mut self, v: Tuple)

Add a new segment to a tuple
Source§

fn with(self, input: T) -> Self

A fluent interface for adding a new segment to a tuple Read more
Source§

impl AddToTuple<Uuid> for Tuple

Source§

fn add(&mut self, v: Uuid)

Add a new segment to a tuple
Source§

fn with(self, input: T) -> Self

A fluent interface for adding a new segment to a tuple Read more
Source§

impl AddToTuple<Vec<Segment>> for Tuple

Source§

fn add(&mut self, v: Vec<Segment>)

Add a new segment to a tuple
Source§

fn with(self, input: T) -> Self

A fluent interface for adding a new segment to a tuple Read more
Source§

impl AddToTuple<Vec<u8>> for Tuple

Source§

fn add(&mut self, v: Vec<u8>)

Add a new segment to a tuple
Source§

fn with(self, input: T) -> Self

A fluent interface for adding a new segment to a tuple Read more
Source§

impl AddToTuple<f32> for Tuple

Source§

fn add(&mut self, v: f32)

Add a new segment to a tuple
Source§

fn with(self, input: T) -> Self

A fluent interface for adding a new segment to a tuple Read more
Source§

impl AddToTuple<f64> for Tuple

Source§

fn add(&mut self, v: f64)

Add a new segment to a tuple
Source§

fn with(self, input: T) -> Self

A fluent interface for adding a new segment to a tuple Read more
Source§

impl AddToTuple<i64> for Tuple

Source§

fn add(&mut self, v: i64)

Add a new segment to a tuple
Source§

fn with(self, input: T) -> Self

A fluent interface for adding a new segment to a tuple Read more
Source§

impl Clone for Tuple

Source§

fn clone(&self) -> Tuple

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

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Tuple

§

impl RefUnwindSafe for Tuple

§

impl Send for Tuple

§

impl Sync for Tuple

§

impl Unpin for Tuple

§

impl UnwindSafe for Tuple

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