Struct tarantool::tuple::Tuple

source ·
pub struct Tuple { /* private fields */ }
Expand description

Tuple

Implementations§

source§

impl Tuple

source

pub fn new<T>(value: &T) -> Result<Self>
where T: ToTupleBuffer + ?Sized,

Create a new tuple from value implementing ToTupleBuffer.

source

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

source

pub unsafe fn from_slice(data: &[u8]) -> Self

Safety

data must represent a valid messagepack array

source

pub fn try_from_slice(data: &[u8]) -> Result<Self>

source

pub fn from_ptr(ptr: NonNull<BoxTuple>) -> Self

source

pub fn try_from_ptr(ptr: *mut BoxTuple) -> Option<Self>

source

pub fn len(&self) -> u32

Return the number of fields in tuple (the size of MsgPack Array).

source

pub fn is_empty(&self) -> bool

source

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

source

pub fn format(&self) -> TupleFormat

Return the associated format.

source

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);
}
source

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) if fieldno >= self.len()
  • Err(e) if deserialization failed
  • Ok(Some(field value)) otherwise

See also Tuple::try_get, Tuple::get.

source

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 also Tuple::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 found
  • Err(e) if deserialization failed (or api not supported)
  • Ok(Some(field value)) otherwise

See also Tuple::get.

source

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 also Tuple::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.

source

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.

Trait Implementations§

source§

impl Clone for Tuple

source§

fn clone(&self) -> Self

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
source§

impl Debug for Tuple

source§

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

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

impl Decode<'_> for Tuple

source§

fn decode(data: &[u8]) -> Result<Self>

source§

impl Drop for Tuple

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl From<&FunctionArgs> for Tuple

source§

fn from(args: &FunctionArgs) -> Tuple

Converts to this type from the input type.
source§

impl From<&Tuple> for TupleBuffer

source§

fn from(t: &Tuple) -> Self

Converts to this type from the input type.
source§

impl From<&TupleBuffer> for Tuple

source§

fn from(buf: &TupleBuffer) -> Self

Converts to this type from the input type.
source§

impl From<FunctionArgs> for Tuple

source§

fn from(args: FunctionArgs) -> Tuple

Converts to this type from the input type.
source§

impl From<Tuple> for TupleBuffer

source§

fn from(t: Tuple) -> Self

Converts to this type from the input type.
source§

impl<L> LuaRead<L> for Tuple
where L: AsLua,

source§

fn lua_read_at_position(lua: L, index: NonZeroI32) -> ReadResult<Self, L>

Reads the data from Lua at a given position.
source§

fn n_values_expected() -> i32

source§

fn lua_read(lua: L) -> Result<Self, (L, WrongType)>

Reads the data from Lua.
source§

fn lua_read_at_maybe_zero_position( lua: L, index: i32 ) -> Result<Self, (L, WrongType)>
where L: AsLua,

source§

impl<L> Push<L> for Tuple
where L: AsLua,

§

type Err = Void

Error that can happen when pushing a value.
source§

fn push_to_lua(&self, lua: L) -> PushResult<L, Self>

Pushes the value on the top of the stack. Read more
source§

fn push_no_err(&self, lua: L) -> PushGuard<L>
where Self::Err: Into<Void>,

Same as push_to_lua but can only succeed and is only available if Err implements Into<Void>.
source§

impl<L> PushInto<L> for Tuple
where L: AsLua,

§

type Err = Void

source§

fn push_into_lua(self, lua: L) -> PushResult<L, Self>

Push the value into lua by value
source§

fn push_into_no_err(self, lua: L) -> PushGuard<L>
where Self: Sized, Self::Err: Into<Void>,

Same as push_into_lua but can only succeed and is only available if Err implements Into<Void>.
source§

impl Return for Tuple

source§

fn ret(self, ctx: FunctionCtx) -> c_int

source§

impl ToTupleBuffer for Tuple

source§

fn to_tuple_buffer(&self) -> Result<TupleBuffer>

source§

fn write_tuple_data(&self, w: &mut impl Write) -> Result<()>

source§

fn tuple_data(&self) -> Option<&[u8]>

Returns a slice of bytes represeting the underlying tarantool tuple. Read more
source§

impl<L> PushOne<L> for Tuple
where L: AsLua,

source§

impl<L> PushOneInto<L> for Tuple
where L: AsLua,

Auto Trait Implementations§

§

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> 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> IntoClones<(T,)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T, T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T, T, T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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

§

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

§

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> DecodeOwned for T
where T: for<'de> Decode<'de>,