use ::once_cell::sync::Lazy;
use ::syn::*;
pub trait Behavior: Sync + Send {
fn is(&self, sty: &Type) -> bool;
fn imports(&self, sty: &Type, pkg: &str, crate_name: &str) -> Vec<String>;
fn name(&self, sty: &Type) -> String;
fn shim(&self, sty: &Type) -> String { self.ffi(sty) }
fn ffi(&self, sty: &Type) -> String;
fn native(&self, sty: &Type) -> String;
fn native_to_ffi(&self, sty: &Type, expr: String) -> String;
fn ffi_to_native(&self, sty: &Type, expr: String) -> String;
}
pub fn switch<'a, 'b>(sty: &'a Type) -> &'b Box<dyn Behavior> {
BEHAVIORS.iter().find(|tyb| tyb.is(sty)).expect("cannot find behavior for given type")
}
static BEHAVIORS: Lazy<Vec<Box<dyn Behavior>>> = Lazy::new(|| {
vec![
Box::new(BehaviorScalars),
Box::new(BehaviorBool),
Box::new(BehaviorDuration),
Box::new(BehaviorString),
Box::new(BehaviorOption),
Box::new(BehaviorResult),
Box::new(BehaviorVec),
Box::new(BehaviorReference),
Box::new(BehaviorForeign),
]
});
mod scalars; pub use scalars::Behavior as BehaviorScalars;
mod bool; pub use self::bool::Behavior as BehaviorBool;
mod duration; pub use duration::Behavior as BehaviorDuration;
mod string; pub use string::Behavior as BehaviorString;
mod option; pub use option::Behavior as BehaviorOption;
mod result; pub use result::Behavior as BehaviorResult;
mod vec; pub use vec::Behavior as BehaviorVec;
mod reference; pub use reference::Behavior as BehaviorReference;
mod foreign; pub use foreign::Behavior as BehaviorForeign;