1extern crate alloc;
2use crate::Real;
3
4#[cfg(not(test))]
5use alloc::rc::Rc;
6use alloc::string::{String, ToString};
7#[cfg(test)]
8use std::rc::Rc;
9
10pub struct OwnedNativeFunction {
11 pub arity: usize,
12 pub implementation: Rc<dyn Fn(&[Real]) -> Real>,
13 pub name: String, pub description: Option<String>,
15}
16
17impl From<&crate::types::NativeFunction> for OwnedNativeFunction {
19 fn from(nf: &crate::types::NativeFunction) -> Self {
20 OwnedNativeFunction {
21 arity: nf.arity,
22 implementation: nf.implementation.clone(),
23 name: nf.name.to_string(), description: nf.description.clone(),
25 }
26 }
27}
28
29pub enum FunctionCacheEntry {
30 Native(OwnedNativeFunction),
31 Expression(crate::types::ExpressionFunction),
32}
33
34impl Clone for FunctionCacheEntry {
35 fn clone(&self) -> Self {
36 match self {
37 FunctionCacheEntry::Native(nf) => FunctionCacheEntry::Native(OwnedNativeFunction {
38 arity: nf.arity,
39 implementation: nf.implementation.clone(),
40 name: nf.name.clone(),
41 description: nf.description.clone(),
42 }),
43 FunctionCacheEntry::Expression(ef) => FunctionCacheEntry::Expression(ef.clone()),
44 }
45 }
46}