pub struct Tuple { /* private fields */ }
Expand description
Tuple
Implementations§
source§impl Tuple
impl Tuple
sourcepub fn new<T>(value: &T) -> Result<Self>where
T: ToTupleBuffer + ?Sized,
pub fn new<T>(value: &T) -> Result<Self>where
T: ToTupleBuffer + ?Sized,
Create a new tuple from value
implementing ToTupleBuffer
.
sourcepub unsafe fn from_raw_data(data: *mut c_char, len: u32) -> Self
pub unsafe fn from_raw_data(data: *mut c_char, len: u32) -> Self
§Safety
data
must point to a buffer containing len
bytes representing a
valid messagepack array
sourcepub unsafe fn from_slice(data: &[u8]) -> Self
pub unsafe fn from_slice(data: &[u8]) -> Self
§Safety
data
must represent a valid messagepack array
pub fn try_from_slice(data: &[u8]) -> Result<Self>
pub fn from_ptr(ptr: NonNull<BoxTuple>) -> Self
pub fn try_from_ptr(ptr: *mut BoxTuple) -> Option<Self>
pub fn is_empty(&self) -> bool
sourcepub fn bsize(&self) -> usize
pub fn bsize(&self) -> usize
Will return the number of bytes in the tuple.
With both the memtx storage engine and the vinyl storage engine the default maximum is one megabyte
(memtx_max_tuple_size
or vinyl_max_tuple_size
). Every field has one or more “length” bytes preceding the
actual contents, so bsize()
returns a value which is slightly greater than the sum of the lengths of the
contents.
The value does not include the size of “struct tuple” (for the current size of this structure look in the tuple.h file in Tarantool’s source code).
sourcepub fn format(&self) -> TupleFormat
pub fn format(&self) -> TupleFormat
Return the associated format.
sourcepub fn iter(&self) -> Result<TupleIterator>
pub fn iter(&self) -> Result<TupleIterator>
Allocate and initialize a new Tuple
iterator. The Tuple
iterator
allow to iterate over fields at root level of MsgPack array.
Example:
let mut it = tuple.iter().unwrap();
while let Some(field) = it.next::<T>().unwrap() {
// process data
}
// rewind iterator to first position
it.rewind();
assert!(it.position() == 0);
// rewind iterator to first position
let field = it.seek::<T>(3).unwrap();
assert!(it.position() == 4);
}
sourcepub fn field<'a, T>(&'a self, fieldno: u32) -> Result<Option<T>>where
T: Decode<'a>,
pub fn field<'a, T>(&'a self, fieldno: u32) -> Result<Option<T>>where
T: Decode<'a>,
Deserialize a tuple field specified by zero-based array index.
fieldno
- zero-based index in MsgPack array.
Returns:
Ok(None)
iffieldno >= self.len()
Err(e)
if deserialization failedOk(Some(field value))
otherwise
See also Tuple::try_get
, Tuple::get
.
sourcepub fn try_get<'a, I, T>(&'a self, key: I) -> Result<Option<T>>where
I: TupleIndex,
T: Decode<'a>,
pub fn try_get<'a, I, T>(&'a self, key: I) -> Result<Option<T>>where
I: TupleIndex,
T: Decode<'a>,
Deserialize a tuple field specified by an index implementing
TupleIndex
trait.
Currently 2 types of indexes are supported:
u32
- zero-based index in MsgPack array (See alsoTuple::field
)&str
- JSON path for tuples with non default formats
NOTE: getting tuple fields by JSON paths is not supported in all
tarantool versions. Use tarantool::ffi::has_tuple_field_by_path
to
check whether it’s supported in your case.
If has_tuple_field_by_path
returns false
this function will always
return Err
.
Returns:
Ok(None)
if index wasn’t foundErr(e)
if deserialization failed (or api not supported)Ok(Some(field value))
otherwise
See also Tuple::get
.
sourcepub fn get<'a, I, T>(&'a self, key: I) -> Option<T>where
I: TupleIndex,
T: Decode<'a>,
pub fn get<'a, I, T>(&'a self, key: I) -> Option<T>where
I: TupleIndex,
T: Decode<'a>,
Deserialize a tuple field specified by an index implementing
TupleIndex
trait.
Currently 2 types of indexes are supported:
u32
- zero-based index in MsgPack array (See alsoTuple::field
)&str
- JSON path for tuples with non default formats
NOTE: getting tuple fields by JSON paths is not supported in all
tarantool versions. Use tarantool::ffi::has_tuple_field_by_path
to
check whether it’s supported in your case.
If has_tuple_field_by_path
returns false
this function will always
panic.
Returns:
None
if index wasn’t found- panics if deserialization failed (or api not supported)
Some(field value)
otherwise
See also Tuple::get
.
sourcepub fn decode<T>(&self) -> Result<T>where
T: DecodeOwned,
pub fn decode<T>(&self) -> Result<T>where
T: DecodeOwned,
Decode tuple contents as T
.
NOTE: Because Tuple
implements DecodeOwned
, you can do
something like this
use tarantool::tuple::{Decode, Tuple};
let tuple: Tuple;
let deep_copy: Tuple = tuple.decode().unwrap();
let inc_ref_count: Tuple = tuple.clone();
“Decoding” a Tuple
into a Tuple
will basically perform a deep
copy of its contents, while tuple.clone()
will just increase tuple’s
reference count. There’s probably no use case for deep copying the
tuple, because there’s actully no way to move data out of it, so keep
this in mind.