2022-01-07 11:43:47 +08:00
|
|
|
//! Type to hold a mutable reference to the target of an evaluation.
|
|
|
|
|
2022-06-07 20:38:05 +08:00
|
|
|
use crate::{Dynamic, Position, RhaiResultOf};
|
2022-01-07 11:43:47 +08:00
|
|
|
#[cfg(feature = "no_std")]
|
|
|
|
use std::prelude::v1::*;
|
2022-10-20 15:31:57 +08:00
|
|
|
use std::{
|
|
|
|
borrow::Borrow,
|
|
|
|
ops::{Deref, DerefMut},
|
|
|
|
};
|
2022-01-07 11:43:47 +08:00
|
|
|
|
2022-11-08 23:17:31 +08:00
|
|
|
/// Calculate an offset+len pair given an actual length of the underlying array.
|
|
|
|
///
|
|
|
|
/// Negative starting positions count from the end.
|
|
|
|
///
|
|
|
|
/// Values going over bounds are limited to the actual length.
|
2022-11-22 23:30:43 +08:00
|
|
|
#[cfg(not(feature = "no_index"))]
|
2022-01-16 22:54:28 +08:00
|
|
|
#[inline]
|
2022-11-23 13:24:14 +08:00
|
|
|
#[allow(
|
|
|
|
clippy::cast_sign_loss,
|
|
|
|
clippy::absurd_extreme_comparisons,
|
|
|
|
clippy::cast_possible_truncation
|
|
|
|
)]
|
2022-01-16 22:54:28 +08:00
|
|
|
pub fn calc_offset_len(length: usize, start: crate::INT, len: crate::INT) -> (usize, usize) {
|
2022-01-13 18:13:27 +08:00
|
|
|
let start = if start < 0 {
|
2022-08-29 14:27:05 +08:00
|
|
|
let abs_start = start.unsigned_abs();
|
|
|
|
if abs_start as u64 > crate::MAX_USIZE_INT as u64 {
|
|
|
|
0
|
|
|
|
} else {
|
|
|
|
length - usize::min(abs_start as usize, length)
|
|
|
|
}
|
2022-08-27 16:26:41 +08:00
|
|
|
} else if start > crate::MAX_USIZE_INT || start as usize >= length {
|
2022-01-13 18:13:27 +08:00
|
|
|
return (length, 0);
|
|
|
|
} else {
|
|
|
|
start as usize
|
|
|
|
};
|
|
|
|
|
|
|
|
let len = if len <= 0 {
|
|
|
|
0
|
2022-08-27 16:26:41 +08:00
|
|
|
} else if len > crate::MAX_USIZE_INT || len as usize > length - start {
|
2022-01-13 18:13:27 +08:00
|
|
|
length - start
|
|
|
|
} else {
|
|
|
|
len as usize
|
|
|
|
};
|
|
|
|
|
|
|
|
(start, len)
|
|
|
|
}
|
|
|
|
|
2022-11-08 23:17:31 +08:00
|
|
|
/// Calculate an offset+len pair given an actual length of the underlying array.
|
|
|
|
///
|
|
|
|
/// Negative starting positions count from the end.
|
|
|
|
///
|
|
|
|
/// Values going over bounds call the provided closure to return a default value or an error.
|
2022-01-16 22:54:28 +08:00
|
|
|
#[inline]
|
|
|
|
#[allow(dead_code)]
|
2022-11-23 13:24:14 +08:00
|
|
|
#[allow(
|
|
|
|
clippy::cast_sign_loss,
|
|
|
|
clippy::cast_possible_truncation,
|
|
|
|
clippy::absurd_extreme_comparisons
|
|
|
|
)]
|
2022-01-15 10:24:08 +08:00
|
|
|
pub fn calc_index<E>(
|
2022-01-13 18:13:27 +08:00
|
|
|
length: usize,
|
2022-01-16 22:54:28 +08:00
|
|
|
start: crate::INT,
|
2022-01-13 18:13:27 +08:00
|
|
|
negative_count_from_end: bool,
|
2022-11-20 19:12:29 +08:00
|
|
|
err_func: impl FnOnce() -> Result<usize, E>,
|
2022-01-15 10:24:08 +08:00
|
|
|
) -> Result<usize, E> {
|
2022-11-23 11:36:30 +08:00
|
|
|
if start < 0 && negative_count_from_end {
|
2022-11-23 13:24:14 +08:00
|
|
|
let abs_start = start.unsigned_abs();
|
|
|
|
return Ok(if abs_start as u64 > crate::MAX_USIZE_INT as u64 {
|
|
|
|
0
|
|
|
|
} else {
|
|
|
|
length - usize::min(abs_start as usize, length)
|
|
|
|
});
|
2022-01-13 18:13:27 +08:00
|
|
|
}
|
2022-11-23 13:24:14 +08:00
|
|
|
|
2022-11-20 19:12:29 +08:00
|
|
|
if start <= crate::MAX_USIZE_INT && (start as usize) < length {
|
|
|
|
return Ok(start as usize);
|
|
|
|
}
|
|
|
|
|
|
|
|
err_func()
|
2022-01-13 18:13:27 +08:00
|
|
|
}
|
|
|
|
|
2022-01-07 11:43:47 +08:00
|
|
|
/// A type that encapsulates a mutation target for an expression with side effects.
|
|
|
|
#[derive(Debug)]
|
2022-11-28 16:36:40 +08:00
|
|
|
#[must_use]
|
2022-01-07 11:43:47 +08:00
|
|
|
pub enum Target<'a> {
|
|
|
|
/// The target is a mutable reference to a [`Dynamic`].
|
|
|
|
RefMut(&'a mut Dynamic),
|
|
|
|
/// The target is a mutable reference to a _shared_ [`Dynamic`].
|
|
|
|
#[cfg(not(feature = "no_closure"))]
|
|
|
|
SharedValue {
|
|
|
|
/// Lock guard to the shared [`Dynamic`].
|
2022-11-28 23:24:22 +08:00
|
|
|
guard: crate::types::dynamic::DynamicWriteLock<'a, Dynamic>,
|
|
|
|
/// Copy of the shared value.
|
|
|
|
shared_value: Dynamic,
|
2022-01-07 11:43:47 +08:00
|
|
|
},
|
|
|
|
/// The target is a temporary [`Dynamic`] value (i.e. its mutation can cause no side effects).
|
|
|
|
TempValue(Dynamic),
|
|
|
|
/// The target is a bit inside an [`INT`][crate::INT].
|
|
|
|
/// This is necessary because directly pointing to a bit inside an [`INT`][crate::INT] is impossible.
|
|
|
|
#[cfg(not(feature = "no_index"))]
|
|
|
|
Bit {
|
|
|
|
/// Mutable reference to the source [`Dynamic`].
|
|
|
|
source: &'a mut Dynamic,
|
|
|
|
/// Copy of the boolean bit, as a [`Dynamic`].
|
|
|
|
value: Dynamic,
|
|
|
|
/// Bit offset.
|
|
|
|
bit: u8,
|
|
|
|
},
|
|
|
|
/// The target is a range of bits inside an [`INT`][crate::INT].
|
|
|
|
/// This is necessary because directly pointing to a range of bits inside an [`INT`][crate::INT] is impossible.
|
|
|
|
#[cfg(not(feature = "no_index"))]
|
|
|
|
BitField {
|
|
|
|
/// Mutable reference to the source [`Dynamic`].
|
|
|
|
source: &'a mut Dynamic,
|
|
|
|
/// Copy of the integer value of the bits, as a [`Dynamic`].
|
|
|
|
value: Dynamic,
|
|
|
|
/// Bitmask to apply to the source value (i.e. shifted)
|
2022-01-07 12:19:01 +08:00
|
|
|
mask: crate::INT,
|
2022-01-07 11:43:47 +08:00
|
|
|
/// Number of bits to right-shift the source value.
|
|
|
|
shift: u8,
|
|
|
|
},
|
|
|
|
/// The target is a byte inside a [`Blob`][crate::Blob].
|
|
|
|
/// This is necessary because directly pointing to a byte (in [`Dynamic`] form) inside a blob is impossible.
|
|
|
|
#[cfg(not(feature = "no_index"))]
|
|
|
|
BlobByte {
|
|
|
|
/// Mutable reference to the source [`Dynamic`].
|
|
|
|
source: &'a mut Dynamic,
|
|
|
|
/// Copy of the byte at the index, as a [`Dynamic`].
|
|
|
|
value: Dynamic,
|
|
|
|
/// Offset index.
|
|
|
|
index: usize,
|
|
|
|
},
|
|
|
|
/// The target is a character inside a string.
|
|
|
|
/// This is necessary because directly pointing to a char inside a String is impossible.
|
|
|
|
#[cfg(not(feature = "no_index"))]
|
|
|
|
StringChar {
|
|
|
|
/// Mutable reference to the source [`Dynamic`].
|
|
|
|
source: &'a mut Dynamic,
|
|
|
|
/// Copy of the character at the offset, as a [`Dynamic`].
|
|
|
|
value: Dynamic,
|
|
|
|
/// Offset index.
|
|
|
|
index: usize,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Target<'a> {
|
|
|
|
/// Is the [`Target`] a reference pointing to other data?
|
|
|
|
#[allow(dead_code)]
|
|
|
|
#[inline]
|
|
|
|
#[must_use]
|
|
|
|
pub const fn is_ref(&self) -> bool {
|
|
|
|
match self {
|
2022-02-08 09:46:14 +08:00
|
|
|
Self::RefMut(..) => true,
|
2022-01-07 11:43:47 +08:00
|
|
|
#[cfg(not(feature = "no_closure"))]
|
|
|
|
Self::SharedValue { .. } => true,
|
2022-02-08 09:46:14 +08:00
|
|
|
Self::TempValue(..) => false,
|
2022-01-07 11:43:47 +08:00
|
|
|
#[cfg(not(feature = "no_index"))]
|
|
|
|
Self::Bit { .. }
|
|
|
|
| Self::BitField { .. }
|
|
|
|
| Self::BlobByte { .. }
|
|
|
|
| Self::StringChar { .. } => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// Is the [`Target`] a temp value?
|
|
|
|
#[inline]
|
|
|
|
#[must_use]
|
|
|
|
pub const fn is_temp_value(&self) -> bool {
|
|
|
|
match self {
|
2022-02-08 09:46:14 +08:00
|
|
|
Self::RefMut(..) => false,
|
2022-01-07 11:43:47 +08:00
|
|
|
#[cfg(not(feature = "no_closure"))]
|
|
|
|
Self::SharedValue { .. } => false,
|
2022-02-08 09:46:14 +08:00
|
|
|
Self::TempValue(..) => true,
|
2022-01-07 11:43:47 +08:00
|
|
|
#[cfg(not(feature = "no_index"))]
|
|
|
|
Self::Bit { .. }
|
|
|
|
| Self::BitField { .. }
|
|
|
|
| Self::BlobByte { .. }
|
|
|
|
| Self::StringChar { .. } => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// Is the [`Target`] a shared value?
|
|
|
|
#[inline]
|
|
|
|
#[must_use]
|
|
|
|
pub fn is_shared(&self) -> bool {
|
2022-11-28 23:24:22 +08:00
|
|
|
#[cfg(not(feature = "no_closure"))]
|
|
|
|
return match self {
|
2022-01-07 11:43:47 +08:00
|
|
|
Self::RefMut(r) => r.is_shared(),
|
|
|
|
Self::SharedValue { .. } => true,
|
2022-11-19 18:41:51 +08:00
|
|
|
Self::TempValue(value) => value.is_shared(),
|
2022-11-29 15:50:58 +08:00
|
|
|
#[cfg(not(feature = "no_index"))]
|
2022-01-07 11:43:47 +08:00
|
|
|
Self::Bit { .. }
|
|
|
|
| Self::BitField { .. }
|
|
|
|
| Self::BlobByte { .. }
|
|
|
|
| Self::StringChar { .. } => false,
|
2022-11-28 23:24:22 +08:00
|
|
|
};
|
|
|
|
#[cfg(feature = "no_closure")]
|
|
|
|
return false;
|
2022-01-07 11:43:47 +08:00
|
|
|
}
|
|
|
|
/// Get the value of the [`Target`] as a [`Dynamic`], cloning a referenced value if necessary.
|
|
|
|
#[inline]
|
|
|
|
pub fn take_or_clone(self) -> Dynamic {
|
|
|
|
match self {
|
|
|
|
Self::RefMut(r) => r.clone(), // Referenced value is cloned
|
|
|
|
#[cfg(not(feature = "no_closure"))]
|
2022-11-28 23:24:22 +08:00
|
|
|
Self::SharedValue { shared_value, .. } => shared_value, // Original shared value is simply taken
|
2022-11-19 18:41:51 +08:00
|
|
|
Self::TempValue(value) => value, // Owned value is simply taken
|
2022-01-07 11:43:47 +08:00
|
|
|
#[cfg(not(feature = "no_index"))]
|
|
|
|
Self::Bit { value, .. } => value, // boolean is taken
|
|
|
|
#[cfg(not(feature = "no_index"))]
|
|
|
|
Self::BitField { value, .. } => value, // INT is taken
|
|
|
|
#[cfg(not(feature = "no_index"))]
|
|
|
|
Self::BlobByte { value, .. } => value, // byte is taken
|
|
|
|
#[cfg(not(feature = "no_index"))]
|
|
|
|
Self::StringChar { value, .. } => value, // char is taken
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// Take a `&mut Dynamic` reference from the `Target`.
|
|
|
|
#[inline(always)]
|
|
|
|
#[must_use]
|
|
|
|
pub fn take_ref(self) -> Option<&'a mut Dynamic> {
|
|
|
|
match self {
|
|
|
|
Self::RefMut(r) => Some(r),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
2022-10-27 22:08:47 +08:00
|
|
|
/// Convert a shared or reference [`Target`] into a target with an owned value.
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn into_owned(self) -> Self {
|
|
|
|
match self {
|
|
|
|
Self::RefMut(r) => Self::TempValue(r.clone()),
|
|
|
|
#[cfg(not(feature = "no_closure"))]
|
2022-11-28 23:24:22 +08:00
|
|
|
Self::SharedValue { shared_value, .. } => Self::TempValue(shared_value),
|
2022-10-27 22:08:47 +08:00
|
|
|
_ => self,
|
|
|
|
}
|
|
|
|
}
|
2022-01-07 11:43:47 +08:00
|
|
|
/// Get the source [`Dynamic`] of the [`Target`].
|
|
|
|
#[allow(dead_code)]
|
|
|
|
#[inline]
|
|
|
|
pub fn source(&self) -> &Dynamic {
|
|
|
|
match self {
|
2022-09-06 15:32:37 +09:00
|
|
|
Self::RefMut(r) => r,
|
2022-01-07 11:43:47 +08:00
|
|
|
#[cfg(not(feature = "no_closure"))]
|
2022-11-28 23:24:22 +08:00
|
|
|
Self::SharedValue { guard, .. } => guard,
|
2022-11-19 18:41:51 +08:00
|
|
|
Self::TempValue(value) => value,
|
2022-01-07 11:43:47 +08:00
|
|
|
#[cfg(not(feature = "no_index"))]
|
|
|
|
Self::Bit { source, .. } => source,
|
|
|
|
#[cfg(not(feature = "no_index"))]
|
|
|
|
Self::BitField { source, .. } => source,
|
|
|
|
#[cfg(not(feature = "no_index"))]
|
|
|
|
Self::BlobByte { source, .. } => source,
|
|
|
|
#[cfg(not(feature = "no_index"))]
|
|
|
|
Self::StringChar { source, .. } => source,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// Propagate a changed value back to the original source.
|
|
|
|
/// This has no effect for direct references.
|
|
|
|
#[inline]
|
2022-06-08 17:06:49 +08:00
|
|
|
pub fn propagate_changed_value(&mut self, _pos: Position) -> RhaiResultOf<()> {
|
2022-01-07 11:43:47 +08:00
|
|
|
match self {
|
2022-02-08 09:46:14 +08:00
|
|
|
Self::RefMut(..) | Self::TempValue(..) => (),
|
2022-01-07 11:43:47 +08:00
|
|
|
#[cfg(not(feature = "no_closure"))]
|
|
|
|
Self::SharedValue { .. } => (),
|
|
|
|
#[cfg(not(feature = "no_index"))]
|
|
|
|
Self::Bit { source, value, bit } => {
|
|
|
|
// Replace the bit at the specified index position
|
|
|
|
let new_bit = value.as_bool().map_err(|err| {
|
2022-01-07 12:19:01 +08:00
|
|
|
Box::new(crate::ERR::ErrorMismatchDataType(
|
2022-01-07 11:43:47 +08:00
|
|
|
"bool".to_string(),
|
|
|
|
err.to_string(),
|
2022-06-08 17:06:49 +08:00
|
|
|
_pos,
|
2022-01-07 11:43:47 +08:00
|
|
|
))
|
|
|
|
})?;
|
|
|
|
|
|
|
|
let value = &mut *source.write_lock::<crate::INT>().expect("`INT`");
|
|
|
|
|
|
|
|
let index = *bit;
|
|
|
|
|
|
|
|
let mask = 1 << index;
|
|
|
|
if new_bit {
|
|
|
|
*value |= mask;
|
|
|
|
} else {
|
|
|
|
*value &= !mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#[cfg(not(feature = "no_index"))]
|
|
|
|
Self::BitField {
|
|
|
|
source,
|
|
|
|
value,
|
|
|
|
mask,
|
|
|
|
shift,
|
|
|
|
} => {
|
|
|
|
let shift = *shift;
|
|
|
|
let mask = *mask;
|
|
|
|
|
|
|
|
// Replace the bit at the specified index position
|
|
|
|
let new_value = value.as_int().map_err(|err| {
|
2022-01-07 12:19:01 +08:00
|
|
|
Box::new(crate::ERR::ErrorMismatchDataType(
|
2022-01-07 11:43:47 +08:00
|
|
|
"integer".to_string(),
|
|
|
|
err.to_string(),
|
2022-06-08 17:06:49 +08:00
|
|
|
_pos,
|
2022-01-07 11:43:47 +08:00
|
|
|
))
|
|
|
|
})?;
|
|
|
|
|
|
|
|
let new_value = (new_value << shift) & mask;
|
|
|
|
let value = &mut *source.write_lock::<crate::INT>().expect("`INT`");
|
|
|
|
|
|
|
|
*value &= !mask;
|
|
|
|
*value |= new_value;
|
|
|
|
}
|
|
|
|
#[cfg(not(feature = "no_index"))]
|
|
|
|
Self::BlobByte {
|
|
|
|
source,
|
|
|
|
value,
|
|
|
|
index,
|
|
|
|
} => {
|
|
|
|
// Replace the byte at the specified index position
|
|
|
|
let new_byte = value.as_int().map_err(|err| {
|
2022-01-07 12:19:01 +08:00
|
|
|
Box::new(crate::ERR::ErrorMismatchDataType(
|
2022-01-07 11:43:47 +08:00
|
|
|
"INT".to_string(),
|
|
|
|
err.to_string(),
|
2022-06-08 17:06:49 +08:00
|
|
|
_pos,
|
2022-01-07 11:43:47 +08:00
|
|
|
))
|
|
|
|
})?;
|
|
|
|
|
|
|
|
let value = &mut *source.write_lock::<crate::Blob>().expect("`Blob`");
|
|
|
|
|
2022-11-23 13:24:14 +08:00
|
|
|
#[allow(clippy::cast_sign_loss)]
|
|
|
|
{
|
|
|
|
value[*index] = (new_byte & 0x00ff) as u8;
|
|
|
|
}
|
2022-01-07 11:43:47 +08:00
|
|
|
}
|
|
|
|
#[cfg(not(feature = "no_index"))]
|
|
|
|
Self::StringChar {
|
|
|
|
source,
|
|
|
|
value,
|
|
|
|
index,
|
|
|
|
} => {
|
|
|
|
// Replace the character at the specified index position
|
|
|
|
let new_ch = value.as_char().map_err(|err| {
|
2022-01-07 12:19:01 +08:00
|
|
|
Box::new(crate::ERR::ErrorMismatchDataType(
|
2022-01-07 11:43:47 +08:00
|
|
|
"char".to_string(),
|
|
|
|
err.to_string(),
|
2022-06-08 17:06:49 +08:00
|
|
|
_pos,
|
2022-01-07 11:43:47 +08:00
|
|
|
))
|
|
|
|
})?;
|
|
|
|
|
|
|
|
let s = &mut *source
|
2022-01-07 12:19:01 +08:00
|
|
|
.write_lock::<crate::ImmutableString>()
|
2022-01-07 11:43:47 +08:00
|
|
|
.expect("`ImmutableString`");
|
|
|
|
|
|
|
|
*s = s
|
|
|
|
.chars()
|
|
|
|
.enumerate()
|
2022-11-20 19:12:29 +08:00
|
|
|
.map(|(i, ch)| if i == *index { new_ch } else { ch })
|
2022-01-07 11:43:47 +08:00
|
|
|
.collect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> From<&'a mut Dynamic> for Target<'a> {
|
|
|
|
#[inline]
|
|
|
|
fn from(value: &'a mut Dynamic) -> Self {
|
|
|
|
#[cfg(not(feature = "no_closure"))]
|
|
|
|
if value.is_shared() {
|
|
|
|
// Cloning is cheap for a shared value
|
2022-11-28 23:24:22 +08:00
|
|
|
let shared_value = value.clone();
|
|
|
|
let guard = value.write_lock::<Dynamic>().expect("`Dynamic`");
|
|
|
|
return Self::SharedValue {
|
|
|
|
guard,
|
|
|
|
shared_value,
|
|
|
|
};
|
2022-01-07 11:43:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Self::RefMut(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Deref for Target<'_> {
|
|
|
|
type Target = Dynamic;
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn deref(&self) -> &Dynamic {
|
|
|
|
match self {
|
2022-09-06 15:32:37 +09:00
|
|
|
Self::RefMut(r) => r,
|
2022-01-07 11:43:47 +08:00
|
|
|
#[cfg(not(feature = "no_closure"))]
|
2022-11-28 23:24:22 +08:00
|
|
|
Self::SharedValue { guard, .. } => guard,
|
2022-11-19 18:41:51 +08:00
|
|
|
Self::TempValue(ref value) => value,
|
2022-01-07 11:43:47 +08:00
|
|
|
#[cfg(not(feature = "no_index"))]
|
|
|
|
Self::Bit { ref value, .. }
|
|
|
|
| Self::BitField { ref value, .. }
|
|
|
|
| Self::BlobByte { ref value, .. }
|
|
|
|
| Self::StringChar { ref value, .. } => value,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AsRef<Dynamic> for Target<'_> {
|
|
|
|
#[inline(always)]
|
|
|
|
fn as_ref(&self) -> &Dynamic {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-20 15:31:57 +08:00
|
|
|
impl Borrow<Dynamic> for Target<'_> {
|
|
|
|
#[inline(always)]
|
|
|
|
fn borrow(&self) -> &Dynamic {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-07 11:43:47 +08:00
|
|
|
impl DerefMut for Target<'_> {
|
|
|
|
#[inline]
|
|
|
|
fn deref_mut(&mut self) -> &mut Dynamic {
|
|
|
|
match self {
|
2022-09-06 15:32:37 +09:00
|
|
|
Self::RefMut(r) => r,
|
2022-01-07 11:43:47 +08:00
|
|
|
#[cfg(not(feature = "no_closure"))]
|
2022-11-28 23:24:22 +08:00
|
|
|
Self::SharedValue { guard, .. } => &mut *guard,
|
2022-11-19 18:41:51 +08:00
|
|
|
Self::TempValue(ref mut value) => value,
|
2022-01-07 11:43:47 +08:00
|
|
|
#[cfg(not(feature = "no_index"))]
|
|
|
|
Self::Bit { ref mut value, .. }
|
|
|
|
| Self::BitField { ref mut value, .. }
|
|
|
|
| Self::BlobByte { ref mut value, .. }
|
|
|
|
| Self::StringChar { ref mut value, .. } => value,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AsMut<Dynamic> for Target<'_> {
|
|
|
|
#[inline(always)]
|
|
|
|
fn as_mut(&mut self) -> &mut Dynamic {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: Into<Dynamic>> From<T> for Target<'_> {
|
|
|
|
#[inline(always)]
|
|
|
|
fn from(value: T) -> Self {
|
|
|
|
Self::TempValue(value.into())
|
|
|
|
}
|
|
|
|
}
|