Skip to main content

ItemRef

Struct ItemRef 

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

A reference to a Lua value.

When running .execute or .store on a ItemRef.
The global lua variable: self will be the referenced value this links to.

Can also be used as an argument to a Script with arg_ref or named_arg_ref.

Implementations§

Source§

impl ItemRef

Source

pub unsafe fn new(resolve: Resolve, id: u64) -> Self

Creates a new ItemRef with it’s lua module id and the Resolve instance it was retrieved from.

§Safety

This is unsafe since if you were to mismatch the id and which Resolve instance it was gathered from then it would be undefined behavior. Only ever use this if you know for a fact that the id you pass it derives from the same Resolve instance and hasn’t already been dropped in the module.

Source

pub fn id(&self) -> u64

Returns the unique id for this reference

Source

pub async fn execute<'c, T>( &'c self, script: impl Into<Script<'c>>, ) -> Result<T, Error>

Execute some lua code, setting self to the stored reference value and returning what the code returned.

Look at Resolve::execute for more info on how it works.

§Errors

If the module executing the code fails or if the script can’t be sent

Source

pub async fn store<'c>( &'c self, script: impl Into<Script<'c>>, ) -> Result<ItemRef, Error>

Store a reference to Lua value in Rust, global variable self is set to the value stored in the ItemRef.

Look at Resolve::store for more info on how it works.

§Errors

If the module executing the code fails, if the script can’t be sent or if the returned value is nil

Source

pub async fn store_option<'c>( &'c self, script: impl Into<Script<'c>>, ) -> Result<Option<ItemRef>, Error>

Maybe stores a reference to Lua value in Rust, global variable self is set to the value stored in the ItemRef.

If the returned value is nil, this will return None.

Look at store for more info.

§Errors

If the module executing the code fails or if the script can’t be sent

Source

pub async fn store_list<'c>( &'c self, script: impl Into<Script<'c>>, ) -> Result<ItemRefList, Error>

Store multiple references to Lua values in Rust,

Look at Resolve::store_list for more info on how it works.

§Errors

If the module executing the code fails or if the script can’t be sent.
Or if the returned value from lua was not a table

Source

pub async fn value<T>(&self) -> Result<T, Error>

Returns the referenced value directly.

Reference is still valid, this just clones the value.

§Errors

If the module executing the code fails or if the script can’t be sent

Source

pub async unsafe fn manual_drop(resolve: Resolve, id: u64)

Sends a packet to the lua module to drop the reference in the lua context.
This can be used to ensure a reference is dropped before doing anything else.
Aka, this is blocking if you .await it since the normal Drop can finish anytime it wants in the background.

§Safety

You must ensure that the id came from correct Resolve instance and that the value hasn’t already been dropped

§Error

This will silently fail and print its err to stderr if it fails.

Trait Implementations§

Source§

impl Clone for ItemRef

Source§

fn clone(&self) -> ItemRef

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ItemRef

Source§

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

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

impl Display for ItemRef

Source§

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

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

impl Eq for ItemRef

Source§

impl Hash for ItemRef

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ItemRef

Source§

fn eq(&self, other: &ItemRef) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl ResolveExecute for ItemRef

Source§

fn execute<'c, T: DeserializeOwned + Send>( &'c self, script: impl Into<Script<'c>> + Send, ) -> impl Future<Output = Result<T, Error>> + Send

Source§

impl ResolveStore for ItemRef

Source§

fn store<'c>( &'c self, script: impl Into<Script<'c>> + Send, ) -> impl Future<Output = Result<ItemRef, Error>> + Send

Source§

fn store_option<'c>( &'c self, script: impl Into<Script<'c>> + Send, ) -> impl Future<Output = Result<Option<ItemRef>, Error>> + Send

Source§

fn store_list<'c>( &'c self, script: impl Into<Script<'c>> + Send, ) -> impl Future<Output = Result<ItemRefList, Error>> + Send

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

fn try_clone(&self) -> Result<T, Error>

Clones self, possibly returning an error.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V