diff --git a/src/func/args.rs b/src/func/args.rs index e2e21f6a..71941ee5 100644 --- a/src/func/args.rs +++ b/src/func/args.rs @@ -9,7 +9,7 @@ use std::prelude::v1::*; /// Trait that parses arguments to a function call. /// -/// Any data type can implement this trait in order to pass arguments to a function call. +/// Any data type can implement this trait in order to pass arguments to [`Engine::call_fn`][crate::Engine::call_fn]. pub trait FuncArgs { /// Parse function call arguments into a container. /// @@ -26,10 +26,10 @@ pub trait FuncArgs { /// } /// /// impl FuncArgs for Options { - /// fn parse>(self, container: &mut CONTAINER) { - /// container.extend(std::iter::once(self.foo.into())); - /// container.extend(std::iter::once(self.bar.into())); - /// container.extend(std::iter::once(self.baz.into())); + /// fn parse>(self, args: &mut ARGS) { + /// args.extend(std::iter::once(self.foo.into())); + /// args.extend(std::iter::once(self.bar.into())); + /// args.extend(std::iter::once(self.baz.into())); /// } /// } /// @@ -55,13 +55,13 @@ pub trait FuncArgs { /// # Ok(()) /// # } /// ``` - fn parse>(self, container: &mut CONTAINER); + fn parse>(self, args: &mut ARGS); } impl FuncArgs for Vec { #[inline] - fn parse>(self, container: &mut CONTAINER) { - container.extend(self.into_iter().map(Variant::into_dynamic)); + fn parse>(self, args: &mut ARGS) { + args.extend(self.into_iter().map(Variant::into_dynamic)); } } @@ -73,9 +73,9 @@ macro_rules! impl_args { { #[inline] #[allow(unused_variables)] - fn parse>(self, container: &mut CONTAINER) { + fn parse>(self, args: &mut ARGS) { let ($($p,)*) = self; - $(container.extend(Some($p.into_dynamic()));)* + $(args.extend(Some($p.into_dynamic()));)* } } diff --git a/src/packages/iter_basic.rs b/src/packages/iter_basic.rs index cd5579ef..bf675eac 100644 --- a/src/packages/iter_basic.rs +++ b/src/packages/iter_basic.rs @@ -1,10 +1,12 @@ use crate::plugin::*; use crate::types::dynamic::Variant; use crate::{def_package, ExclusiveRange, InclusiveRange, RhaiResultOf, INT}; -use std::iter::{ExactSizeIterator, FusedIterator}; -use std::ops::{Range, RangeInclusive}; #[cfg(feature = "no_std")] use std::prelude::v1::*; +use std::{ + iter::{ExactSizeIterator, FusedIterator}, + ops::{Range, RangeInclusive}, +}; #[cfg(not(feature = "unchecked"))] use num_traits::{CheckedAdd as Add, CheckedSub as Sub}; @@ -159,12 +161,10 @@ impl Iterator for BitRange { type Item = bool; fn next(&mut self) -> Option { - let Self(value, mask, len) = *self; - - if len == 0 { + if self.2 == 0 { None } else { - let r = (value & mask) != 0; + let r = (self.0 & self.1) != 0; self.1 <<= 1; self.2 -= 1; Some(r) @@ -263,7 +263,6 @@ macro_rules! reg_range { ($lib:ident | $x:expr => $( $y:ty ),*) => { $( $lib.set_iterator::>(); - $lib.set_iterator::>(); let _hash = $lib.set_native_fn($x, |from: $y, to: $y| Ok(from..to)); #[cfg(feature = "metadata")] @@ -272,6 +271,8 @@ macro_rules! reg_range { concat!("to: ", stringify!($y)), concat!("Iterator") ]); + + $lib.set_iterator::>(); )* }; ($lib:ident | step $x:expr => $( $y:ty ),*) => { @@ -450,7 +451,7 @@ def_package! { Ok(CharsStream::new(string, from, to - from)) }); #[cfg(feature = "metadata")] - lib.update_fn_metadata(_hash, &["string: &str", "range: Range", "Iterator"]); + lib.update_fn_metadata(_hash, &["string: &str", "range: Range", "Iterator"]); let _hash = lib.set_native_fn("chars", |string, range: InclusiveRange| { let from = INT::max(*range.start(), 0); @@ -458,7 +459,7 @@ def_package! { Ok(CharsStream::new(string, from, to-from + 1)) }); #[cfg(feature = "metadata")] - lib.update_fn_metadata(_hash, &["string: &str", "range: RangeInclusive", "Iterator"]); + lib.update_fn_metadata(_hash, &["string: &str", "range: RangeInclusive", "Iterator"]); let _hash = lib.set_native_fn("chars", |string, from, len| Ok(CharsStream::new(string, from, len))); #[cfg(feature = "metadata")] @@ -488,7 +489,7 @@ def_package! { BitRange::new(value, from, to - from) }); #[cfg(feature = "metadata")] - lib.update_fn_metadata(_hash, &["value: INT", "range: Range", "Iterator"]); + lib.update_fn_metadata(_hash, &["value: INT", "range: Range", "Iterator"]); let _hash = lib.set_native_fn("bits", |value, range: InclusiveRange| { let from = INT::max(*range.start(), 0); @@ -496,7 +497,7 @@ def_package! { BitRange::new(value, from, to - from + 1) }); #[cfg(feature = "metadata")] - lib.update_fn_metadata(_hash, &["value: INT", "range: RangeInclusive", "Iterator"]); + lib.update_fn_metadata(_hash, &["value: INT", "range: RangeInclusive", "Iterator"]); let _hash = lib.set_native_fn("bits", BitRange::new); #[cfg(feature = "metadata")] @@ -514,7 +515,7 @@ def_package! { { let _hash = lib.set_getter_fn("bits", |value: &mut INT| BitRange::new(*value, 0, INT::MAX) ); #[cfg(feature = "metadata")] - lib.update_fn_metadata(_hash, &["value: &mut INT", "range: Range", "Iterator"]); + lib.update_fn_metadata(_hash, &["value: &mut INT", "range: Range", "Iterator"]); } combine_with_exported_module!(lib, "range", range_functions);