Add Index/IndexMut and iter_curry/iter_curry_mut to FnPtr.
This commit is contained in:
@@ -16,6 +16,7 @@ use std::{
|
||||
fmt,
|
||||
hash::{Hash, Hasher},
|
||||
mem,
|
||||
ops::{Index, IndexMut},
|
||||
};
|
||||
|
||||
/// A general function pointer, which may carry additional (i.e. curried) argument values
|
||||
@@ -127,6 +128,16 @@ impl FnPtr {
|
||||
pub fn curry(&self) -> &[Dynamic] {
|
||||
self.curry.as_ref()
|
||||
}
|
||||
/// Iterate the curried arguments.
|
||||
#[inline(always)]
|
||||
pub fn iter_curry(&self) -> impl Iterator<Item = &Dynamic> {
|
||||
self.curry.iter()
|
||||
}
|
||||
/// Mutably-iterate the curried arguments.
|
||||
#[inline(always)]
|
||||
pub fn iter_curry_mut(&mut self) -> impl Iterator<Item = &mut Dynamic> {
|
||||
self.curry.iter_mut()
|
||||
}
|
||||
/// Add a new curried argument.
|
||||
#[inline(always)]
|
||||
pub fn add_curry(&mut self, value: Dynamic) -> &mut Self {
|
||||
@@ -387,3 +398,19 @@ impl<T: Into<Shared<crate::ast::ScriptFnDef>>> From<T> for FnPtr {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Index<usize> for FnPtr {
|
||||
type Output = Dynamic;
|
||||
|
||||
#[inline(always)]
|
||||
fn index(&self, index: usize) -> &Self::Output {
|
||||
self.curry.index(index)
|
||||
}
|
||||
}
|
||||
|
||||
impl IndexMut<usize> for FnPtr {
|
||||
#[inline(always)]
|
||||
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
|
||||
self.curry.index_mut(index)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user