Add Index/IndexMut and iter_curry/iter_curry_mut to FnPtr.
This commit is contained in:
parent
db7410776a
commit
3cc016b03c
@ -61,6 +61,8 @@ Enhancements
|
|||||||
* Block-style doc-comments are now "un-indented" for better formatting.
|
* Block-style doc-comments are now "un-indented" for better formatting.
|
||||||
* Doc-comments on plugin modules are now captured in the module's `doc` field.
|
* Doc-comments on plugin modules are now captured in the module's `doc` field.
|
||||||
* Expression nesting levels is refined such that it grows less excessively for common patterns.
|
* Expression nesting levels is refined such that it grows less excessively for common patterns.
|
||||||
|
* The traits `Index` and `IndexMut` are added to `FnPtr`.
|
||||||
|
* `FnPtr::iter_curry` and `FnPtr::iter_curry_mut` are added.
|
||||||
|
|
||||||
|
|
||||||
Version 1.11.0
|
Version 1.11.0
|
||||||
|
@ -16,6 +16,7 @@ use std::{
|
|||||||
fmt,
|
fmt,
|
||||||
hash::{Hash, Hasher},
|
hash::{Hash, Hasher},
|
||||||
mem,
|
mem,
|
||||||
|
ops::{Index, IndexMut},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A general function pointer, which may carry additional (i.e. curried) argument values
|
/// A general function pointer, which may carry additional (i.e. curried) argument values
|
||||||
@ -127,6 +128,16 @@ impl FnPtr {
|
|||||||
pub fn curry(&self) -> &[Dynamic] {
|
pub fn curry(&self) -> &[Dynamic] {
|
||||||
self.curry.as_ref()
|
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.
|
/// Add a new curried argument.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn add_curry(&mut self, value: Dynamic) -> &mut Self {
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user