pub struct Tuple { /* private fields */ }
Expand description
A builder for serialized tuples
Implementations§
Source§impl Tuple
impl Tuple
Sourcepub fn with_capacity(capacity: usize) -> Tuple
pub fn with_capacity(capacity: usize) -> Tuple
Create a new tuple with a fixed backing capacity
Sourcepub fn from_bytes(bytes: &[u8]) -> Tuple
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)]);
Sourcepub fn add_segment(&mut self, input: &Segment)
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
Sourcepub fn add_builder(&mut self, input: &Tuple)
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.
Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Return a serialized tuple
Sourcepub fn as_segments(&self) -> Result<Vec<Segment>, TupleError>
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
impl<'a> AddToTuple<&'a [u8]> for Tuple
Source§impl<'a> AddToTuple<&'a Tuple> for Tuple
impl<'a> AddToTuple<&'a Tuple> for Tuple
Source§impl AddToTuple<&'static str> for Tuple
impl AddToTuple<&'static str> for Tuple
Source§impl AddToTuple<String> for Tuple
impl AddToTuple<String> for Tuple
Source§impl AddToTuple<Tuple> for Tuple
impl AddToTuple<Tuple> for Tuple
Source§impl AddToTuple<Uuid> for Tuple
impl AddToTuple<Uuid> for Tuple
Source§impl AddToTuple<f32> for Tuple
impl AddToTuple<f32> for Tuple
Source§impl AddToTuple<f64> for Tuple
impl AddToTuple<f64> for Tuple
Source§impl AddToTuple<i64> for Tuple
impl AddToTuple<i64> for Tuple
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more