Enum rhai::Target

source ·
pub enum Target<'a> {
    RefMut(&'a mut Dynamic),
    SharedValue {
        guard: DynamicWriteLock<'a, Dynamic>,
        shared_value: Dynamic,
    },
    TempValue(Dynamic),
    Bit {
        source: &'a mut Dynamic,
        value: Dynamic,
        bit: u8,
    },
    BitField {
        source: &'a mut Dynamic,
        value: Dynamic,
        mask: INT,
        shift: u8,
    },
    BlobByte {
        source: &'a mut Dynamic,
        value: Dynamic,
        index: usize,
    },
    StringChar {
        source: &'a mut Dynamic,
        value: Dynamic,
        index: usize,
    },
    StringSlice {
        source: &'a mut Dynamic,
        value: Dynamic,
        start: usize,
        end: usize,
        exclusive: bool,
    },
}
Expand description

(internals) A type that encapsulates a mutation target for an expression with side effects. Exported under the internals feature only.

This type is typically used to hold a mutable reference to the target of an indexing or property access operation.

§Example

// Normal `Dynamic` value
let mut value = Dynamic::from(42_i64);
let target: Target = value.into();

// Mutable reference to a `Dynamic` value
let mut value = Dynamic::from(42_i64);
let value_ref = &mut value;
let target: Target = value.into();

Variants§

§

RefMut(&'a mut Dynamic)

The target is a mutable reference to a Dynamic.

§

SharedValue

The target is a mutable reference to a shared Dynamic.

Fields

§guard: DynamicWriteLock<'a, Dynamic>

Lock guard to the shared Dynamic.

§shared_value: Dynamic

Copy of the shared value.

§

TempValue(Dynamic)

The target is a temporary Dynamic value (i.e. its mutation can cause no side effects).

§

Bit

The target is a bit inside an INT. This is necessary because directly pointing to a bit inside an INT is impossible.

Fields

§source: &'a mut Dynamic

Mutable reference to the source Dynamic.

§value: Dynamic

Copy of the boolean bit, as a Dynamic.

§bit: u8

Bit offset.

§

BitField

The target is a range of bits inside an INT. This is necessary because directly pointing to a range of bits inside an INT is impossible.

Fields

§source: &'a mut Dynamic

Mutable reference to the source Dynamic.

§value: Dynamic

Copy of the integer value of the bits, as a Dynamic.

§mask: INT

Bitmask to apply to the source value (i.e. shifted)

§shift: u8

Number of bits to right-shift the source value.

§

BlobByte

The target is a byte inside a Blob. This is necessary because directly pointing to a byte inside a BLOB is impossible.

Fields

§source: &'a mut Dynamic

Mutable reference to the source Dynamic.

§value: Dynamic

Copy of the byte at the index, as a Dynamic.

§index: usize

Offset index.

§

StringChar

The target is a character inside a string. This is necessary because directly pointing to a char inside a String is impossible.

Fields

§source: &'a mut Dynamic

Mutable reference to the source Dynamic.

§value: Dynamic

Copy of the character at the offset, as a Dynamic.

§index: usize

Offset index.

§

StringSlice

The target is a slice of a string. This is necessary because directly pointing to a char inside a String is impossible.

Fields

§source: &'a mut Dynamic

Mutable reference to the source Dynamic.

§value: Dynamic

Copy of the character at the offset, as a Dynamic.

§start: usize

Offset index.

§end: usize

End index.

§exclusive: bool

Is exclusive?

Implementations§

source§

impl<'a> Target<'a>

source

pub const fn is_ref(&self) -> bool

Is the Target a reference pointing to other data?

source

pub const fn is_temp_value(&self) -> bool

Is the Target a temp value?

source

pub fn is_shared(&self) -> bool

Is the Target a shared value?

source

pub fn take_or_clone(self) -> Dynamic

Get the value of the Target as a Dynamic, cloning a referenced value if necessary.

source

pub fn take_ref(self) -> Option<&'a mut Dynamic>

Take a &mut Dynamic reference from the Target.

source

pub fn into_owned(self) -> Self

Convert a shared or reference Target into a target with an owned value.

source

pub fn source(&self) -> &Dynamic

Get the source Dynamic of the Target.

source

pub fn propagate_changed_value( &mut self, _pos: Position ) -> Result<(), Box<EvalAltResult>>

Propagate a changed value back to the original source. This has no effect for direct references.

Trait Implementations§

source§

impl AsMut<Dynamic> for Target<'_>

source§

fn as_mut(&mut self) -> &mut Dynamic

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl AsRef<Dynamic> for Target<'_>

source§

fn as_ref(&self) -> &Dynamic

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Borrow<Dynamic> for Target<'_>

source§

fn borrow(&self) -> &Dynamic

Immutably borrows from an owned value. Read more
source§

impl BorrowMut<Dynamic> for Target<'_>

source§

fn borrow_mut(&mut self) -> &mut Dynamic

Mutably borrows from an owned value. Read more
source§

impl<'a> Debug for Target<'a>

source§

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

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

impl<'a> From<&'a mut Dynamic> for Target<'a>

source§

fn from(value: &'a mut Dynamic) -> Self

Converts to this type from the input type.
source§

impl<T: Into<Dynamic>> From<T> for Target<'_>

source§

fn from(value: T) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a> Freeze for Target<'a>

§

impl<'a> !RefUnwindSafe for Target<'a>

§

impl<'a> !Send for Target<'a>

§

impl<'a> !Sync for Target<'a>

§

impl<'a> Unpin for Target<'a>

§

impl<'a> !UnwindSafe for Target<'a>

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