Struct auxtools::Value

source ·
pub struct Value {
    pub raw: Value,
    /* private fields */
}
Expand description

Value represents any value a DM variable can hold, such as numbers, strings, datums, etc.

There’s a lot of lifetime shenanigans going on, the gist of it is to just not keep Values around for longer than your hook’s execution.

Fields§

§raw: Value

Implementations§

source§

impl Value

source

pub unsafe fn new(tag: ValueTag, data: ValueData) -> Value

Creates a new value from raw tag and data. Use if you know what you are doing.

source

pub fn globals() -> Value

Equivalent to DM’s global.vars.

source

pub fn world() -> Value

Equivalent to DM’s world.

source

pub fn null() -> Value

Equivalent to DM’s null.

source

pub unsafe fn turf_by_id_unchecked(id: u32) -> Value

Gets a turf by ID, without bounds checking. Use turf_by_id if you’re not sure about how to check the bounds.

source

pub fn turf_by_id(id: u32) -> DMResult

Gets a turf by ID, with bounds checking.

source

pub fn turf(x: u32, y: u32, z: u32) -> DMResult

Gets a turf by coordinates.

source

pub fn get<S: Into<StringRef>>(&self, name: S) -> DMResult

Gets a variable by name.

source

pub fn get_number<S: Into<StringRef>>(&self, name: S) -> DMResult<f32>

Gets a variable by name and safely casts it to a float.

source

pub fn get_string<S: Into<StringRef>>(&self, name: S) -> DMResult<String>

Gets a variable by name and safely casts it to a string.

source

pub fn get_list<S: Into<StringRef>>(&self, name: S) -> DMResult<List>

Gets a variable by name and safely casts it to a list::List.

source

pub fn set<S: Into<StringRef>, V: Into<Value>>( &self, name: S, value: V ) -> DMResult<()>

Sets a variable by name to a given value.

source

pub fn as_number(&self) -> DMResult<f32>

Check if the current value is a number and casts it.

source

pub fn as_string(&self) -> DMResult<String>

Check if the current value is a string and casts it.

source

pub fn as_list(&self) -> DMResult<List>

Check if the current value is a list and casts it.

source

pub fn call<S: AsRef<str>>(&self, procname: S, args: &[&Value]) -> DMResult

Calls a method of the value with the given arguments.

Examples:

This example is equivalent to src.explode(3) in DM.

src.call("explode", &[&Value::from(3.0)]);
source

pub fn to_dmstring(&self) -> DMResult<StringRef>

source

pub fn to_string(&self) -> DMResult<String>

source

pub fn get_type(&self) -> Result<String, Runtime>

Gets the type of the Value as a string

source

pub fn is_exact_type<S: AsRef<str>>(&self, typepath: S) -> bool

Checks whether this Value’s type is equal to typepath.

source

pub fn is_truthy(&self) -> bool

source

pub fn from_string<S: AsRef<str>>(data: S) -> DMResult

Creates a Value that references a byond string. Will panic if the given string contains null bytes

Examples:
let my_string = Value::from_string("Testing!");
source

pub fn from_string_raw(data: &[u8]) -> DMResult

source

pub unsafe fn from_raw(v: Value) -> Self

blah blah lifetime is not verified with this so use at your peril

source

pub unsafe fn from_raw_owned(v: Value) -> Value

same as from_raw but does not increment the reference count (assumes we already own this reference)

source§

impl Value

source

pub fn as_weak(&self) -> DMResult<WeakValue>

Creates a WeakValue referencing this datum.

Trait Implementations§

source§

impl Clone for Value

source§

fn clone(&self) -> Value

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 Value

source§

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

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

impl Display for Value

source§

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

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

impl Drop for Value

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl From<&List> for Value

source§

fn from(list: &List) -> Self

Converts to this type from the input type.
source§

impl From<&StringRef> for Value

source§

fn from(string: &StringRef) -> Self

Converts to this type from the input type.
source§

impl From<&Value> for Value

source§

fn from(val: &Value) -> Self

Converts to this type from the input type.
source§

impl<T: Into<Value> + Clone> From<&Vec<T, Global>> for Value

source§

fn from(vec: &Vec<T>) -> Self

Converts to this type from the input type.
source§

impl From<List> for Value

source§

fn from(list: List) -> Self

Converts to this type from the input type.
source§

impl From<StringRef> for Value

source§

fn from(string: StringRef) -> Self

Converts to this type from the input type.
source§

impl From<bool> for Value

source§

fn from(b: bool) -> Self

Converts to this type from the input type.
source§

impl From<f32> for Value

source§

fn from(num: f32) -> Self

Converts to this type from the input type.
source§

impl From<i32> for Value

source§

fn from(num: i32) -> Self

Converts to this type from the input type.
source§

impl From<u32> for Value

source§

fn from(num: u32) -> Self

Converts to this type from the input type.
source§

impl FromIterator<Value> for List

source§

fn from_iter<I: IntoIterator<Item = Value>>(it: I) -> Self

Creates a value from an iterator. Read more
source§

impl Hash for Value

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<Value> for Value

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<A: Into<Value> + Clone, B: Into<Value> + Clone> TryFrom<&HashMap<A, B, RandomState>> for Value

§

type Error = Runtime

The type returned in the event of a conversion error.
source§

fn try_from(hashmap: &HashMap<A, B>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<T: Into<Value> + Clone> TryFrom<&HashMap<String, T, RandomState>> for Value

§

type Error = Runtime

The type returned in the event of a conversion error.
source§

fn try_from(hashmap: &HashMap<String, T>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Eq for Value

Auto Trait Implementations§

§

impl RefUnwindSafe for Value

§

impl !Send for Value

§

impl !Sync for Value

§

impl Unpin for Value

§

impl UnwindSafe for Value

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

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

Mutably borrows from an owned value. Read more
§

impl<T> CallHasher for Twhere T: Hash + ?Sized,

§

fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64where H: Hash + ?Sized, B: BuildHasher,

source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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> Same<T> for T

§

type Output = T

Should always be Self
source§

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

source§

default fn to_string(&self) -> String

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

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.