Add Dynamic::UNIT.
This commit is contained in:
@@ -532,11 +532,13 @@ impl Clone for Dynamic {
|
||||
impl Default for Dynamic {
|
||||
#[inline(always)]
|
||||
fn default() -> Self {
|
||||
Self(Union::Unit(()))
|
||||
Self::UNIT
|
||||
}
|
||||
}
|
||||
|
||||
impl Dynamic {
|
||||
pub const UNIT: Dynamic = Self(Union::Unit(()));
|
||||
|
||||
/// Create a `Dynamic` from any type. A `Dynamic` value is simply returned as is.
|
||||
///
|
||||
/// # Safety
|
||||
|
@@ -651,7 +651,7 @@ impl Engine {
|
||||
|
||||
let script = script.trim();
|
||||
if script.is_empty() {
|
||||
return Ok(().into());
|
||||
return Ok(Dynamic::UNIT);
|
||||
}
|
||||
|
||||
// Check for stack overflow
|
||||
|
@@ -54,7 +54,7 @@ macro_rules! gen_array_functions {
|
||||
list.resize(len as usize, Dynamic::from(item));
|
||||
}
|
||||
|
||||
Ok(().into())
|
||||
Ok(Dynamic::UNIT)
|
||||
}
|
||||
}
|
||||
})* }
|
||||
@@ -367,7 +367,7 @@ mod array_functions {
|
||||
list: &mut Array,
|
||||
reducer: FnPtr,
|
||||
) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
let mut result: Dynamic = ().into();
|
||||
let mut result: Dynamic = Dynamic::UNIT;
|
||||
|
||||
for (i, item) in list.iter().enumerate() {
|
||||
result = reducer
|
||||
@@ -434,7 +434,7 @@ mod array_functions {
|
||||
list: &mut Array,
|
||||
reducer: FnPtr,
|
||||
) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
let mut result: Dynamic = ().into();
|
||||
let mut result: Dynamic = Dynamic::UNIT;
|
||||
|
||||
for (i, item) in list.iter().enumerate().rev() {
|
||||
result = reducer
|
||||
@@ -529,7 +529,7 @@ mod array_functions {
|
||||
})
|
||||
});
|
||||
|
||||
Ok(().into())
|
||||
Ok(Dynamic::UNIT)
|
||||
}
|
||||
#[rhai_fn(return_raw)]
|
||||
pub fn drain(
|
||||
|
@@ -284,7 +284,7 @@ mod string_functions {
|
||||
}
|
||||
}
|
||||
|
||||
Ok(().into())
|
||||
Ok(Dynamic::UNIT)
|
||||
}
|
||||
#[rhai_fn(name = "pad", return_raw)]
|
||||
pub fn pad_with_string(
|
||||
@@ -328,7 +328,7 @@ mod string_functions {
|
||||
}
|
||||
}
|
||||
|
||||
Ok(().into())
|
||||
Ok(Dynamic::UNIT)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
|
@@ -150,7 +150,7 @@ mod time_functions {
|
||||
#[rhai_fn(return_raw, name = "+=")]
|
||||
pub fn add_assign(x: &mut Instant, seconds: FLOAT) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
*x = add_impl(*x, seconds)?;
|
||||
Ok(().into())
|
||||
Ok(Dynamic::UNIT)
|
||||
}
|
||||
#[rhai_fn(return_raw, name = "-")]
|
||||
pub fn subtract(x: Instant, seconds: FLOAT) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
@@ -162,7 +162,7 @@ mod time_functions {
|
||||
seconds: FLOAT,
|
||||
) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
*x = subtract_impl(*x, seconds)?;
|
||||
Ok(().into())
|
||||
Ok(Dynamic::UNIT)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ mod time_functions {
|
||||
#[rhai_fn(return_raw, name = "+=")]
|
||||
pub fn add_assign(x: &mut Instant, seconds: INT) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
*x = add_impl(*x, seconds)?;
|
||||
Ok(().into())
|
||||
Ok(Dynamic::UNIT)
|
||||
}
|
||||
#[rhai_fn(return_raw, name = "-")]
|
||||
pub fn subtract(x: Instant, seconds: INT) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
@@ -213,7 +213,7 @@ mod time_functions {
|
||||
#[rhai_fn(return_raw, name = "-=")]
|
||||
pub fn subtract_assign(x: &mut Instant, seconds: INT) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
*x = subtract_impl(*x, seconds)?;
|
||||
Ok(().into())
|
||||
Ok(Dynamic::UNIT)
|
||||
}
|
||||
|
||||
#[rhai_fn(name = "==")]
|
||||
|
@@ -957,7 +957,7 @@ fn parse_primary(
|
||||
let var_name_def = IdentX::new(state.get_interned_string(s), settings.pos);
|
||||
Expr::Variable(Box::new((None, None, 0, var_name_def)))
|
||||
}
|
||||
// Module qualification
|
||||
// Namespace qualification
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
Token::Identifier(s) if *next_token == Token::DoubleColon => {
|
||||
// Once the identifier consumed we must enable next variables capturing
|
||||
|
@@ -247,7 +247,7 @@ impl Serializer for &mut DynamicSerializer {
|
||||
}
|
||||
|
||||
fn serialize_none(self) -> Result<Self::Ok, Box<EvalAltResult>> {
|
||||
Ok(().into())
|
||||
Ok(Dynamic::UNIT)
|
||||
}
|
||||
|
||||
fn serialize_some<T: ?Sized + Serialize>(
|
||||
@@ -258,7 +258,7 @@ impl Serializer for &mut DynamicSerializer {
|
||||
}
|
||||
|
||||
fn serialize_unit(self) -> Result<Self::Ok, Box<EvalAltResult>> {
|
||||
Ok(().into())
|
||||
Ok(Dynamic::UNIT)
|
||||
}
|
||||
|
||||
fn serialize_unit_struct(self, _name: &'static str) -> Result<Self::Ok, Box<EvalAltResult>> {
|
||||
|
Reference in New Issue
Block a user