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
impl Value
sourcepub unsafe fn new(tag: ValueTag, data: ValueData) -> Value
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.
sourcepub unsafe fn turf_by_id_unchecked(id: u32) -> Value
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.
sourcepub fn turf_by_id(id: u32) -> DMResult
pub fn turf_by_id(id: u32) -> DMResult
Gets a turf by ID, with bounds checking.
sourcepub fn get_number<S: Into<StringRef>>(&self, name: S) -> DMResult<f32>
pub fn get_number<S: Into<StringRef>>(&self, name: S) -> DMResult<f32>
Gets a variable by name and safely casts it to a float.
sourcepub fn get_string<S: Into<StringRef>>(&self, name: S) -> DMResult<String>
pub fn get_string<S: Into<StringRef>>(&self, name: S) -> DMResult<String>
Gets a variable by name and safely casts it to a string.
sourcepub fn get_list<S: Into<StringRef>>(&self, name: S) -> DMResult<List>
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.
sourcepub fn set<S: Into<StringRef>, V: Into<Value>>(
&self,
name: S,
value: V
) -> DMResult<()>
pub fn set<S: Into<StringRef>, V: Into<Value>>( &self, name: S, value: V ) -> DMResult<()>
Sets a variable by name to a given value.
sourcepub fn as_string(&self) -> DMResult<String>
pub fn as_string(&self) -> DMResult<String>
Check if the current value is a string and casts it.
pub fn to_dmstring(&self) -> DMResult<StringRef>
pub fn to_string(&self) -> DMResult<String>
sourcepub fn is_exact_type<S: AsRef<str>>(&self, typepath: S) -> bool
pub fn is_exact_type<S: AsRef<str>>(&self, typepath: S) -> bool
Checks whether this Value’s type is equal to typepath
.
pub fn is_truthy(&self) -> bool
sourcepub fn from_string<S: AsRef<str>>(data: S) -> DMResult
pub fn from_string<S: AsRef<str>>(data: S) -> DMResult
pub fn from_string_raw(data: &[u8]) -> DMResult
sourcepub unsafe fn from_raw(v: Value) -> Self
pub unsafe fn from_raw(v: Value) -> Self
blah blah lifetime is not verified with this so use at your peril
sourcepub unsafe fn from_raw_owned(v: Value) -> Value
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)