Struct nekolib::utils::op_closure::OpClosure
source · pub struct OpClosure<T, Op: Fn(T, T) -> T, Id: Fn() -> T>(/* private fields */);
Expand description
任意の結合的な演算を持つ。
結合性については使用者側に保証してもらう。
Examples
use std::cell::RefCell;
use nekolib::traits::{Magma, Identity};
use nekolib::utils::OpClosure;
let runtime_mod = 10;
let op_memo = RefCell::new(vec![]);
let id_times = RefCell::new(0);
let op_cl = OpClosure::new(|x: i32, y| {
op_memo.borrow_mut().push((x, y));
(x + y).rem_euclid(runtime_mod)
}, || {
*id_times.borrow_mut() += 1;
0
});
assert_eq!(op_cl.op(1, 9), 0);
assert_eq!(op_cl.op(3, 8), 1);
assert_eq!(op_cl.op(-5, -3), 2);
assert_eq!(op_cl.id(), 0);
assert_eq!(*op_memo.borrow(), [(1, 9), (3, 8), (-5, -3)]);
assert_eq!(*id_times.borrow(), 1);
Implementations§
Trait Implementations§
source§impl<T: Clone, Op: Clone + Fn(T, T) -> T, Id: Clone + Fn() -> T> Clone for OpClosure<T, Op, Id>
impl<T: Clone, Op: Clone + Fn(T, T) -> T, Id: Clone + Fn() -> T> Clone for OpClosure<T, Op, Id>
source§impl<T: Debug, Op: Debug + Fn(T, T) -> T, Id: Debug + Fn() -> T> Debug for OpClosure<T, Op, Id>
impl<T: Debug, Op: Debug + Fn(T, T) -> T, Id: Debug + Fn() -> T> Debug for OpClosure<T, Op, Id>
source§impl<T: Default, Op: Default + Fn(T, T) -> T, Id: Default + Fn() -> T> Default for OpClosure<T, Op, Id>
impl<T: Default, Op: Default + Fn(T, T) -> T, Id: Default + Fn() -> T> Default for OpClosure<T, Op, Id>
impl<T: Eq, Op: Fn(T, T) -> T, Id: Fn() -> T> Associative for OpClosure<T, Op, Id>
impl<T: Copy, Op: Copy + Fn(T, T) -> T, Id: Copy + Fn() -> T> Copy for OpClosure<T, Op, Id>
Auto Trait Implementations§
impl<T, Op, Id> RefUnwindSafe for OpClosure<T, Op, Id>where Id: RefUnwindSafe, Op: RefUnwindSafe,
impl<T, Op, Id> Send for OpClosure<T, Op, Id>where Id: Send, Op: Send,
impl<T, Op, Id> Sync for OpClosure<T, Op, Id>where Id: Sync, Op: Sync,
impl<T, Op, Id> Unpin for OpClosure<T, Op, Id>where Id: Unpin, Op: Unpin,
impl<T, Op, Id> UnwindSafe for OpClosure<T, Op, Id>where Id: UnwindSafe, Op: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more