Trait aanyx::system::System

source ·
pub trait System<Registry, Args: FromRegistry<Registry>> {
    type Return;

    // Required method
    fn apply(&self, registry: &Registry) -> Self::Return;
}
Expand description

A system is a trait that allows a function to be called giving only a registry and letting the compiler figure out what needs to be extracted from that registry in order to call the function

use aanyx::system::System;
use std::rc::Rc;
 
struct Data<T>{ data: Rc<T> }
 
// Simulate other data
struct Location {}
struct Person{ name: String, age: u8 }
fn old_enough( person: Data<Person> ) -> bool { person.data.age > 30 }
 
let registry0 = ( Rc::new(Person{ name: String::from("Alice"), age: 24u8 }),  Location { /* Location data */ }) ;
let registry1 = ( Rc::new(Person{ name: String::from("Bob"), age: 31u8 }),    Location { /* Location data */ });
let registry2 = ( Rc::new(Person{ name: String::from("Charlie"), age: 1u8 }), Location { /* Location data */ });
 
assert_eq!( old_enough.apply( &registry0 ), false );
assert_eq!( old_enough.apply( &registry1 ), true );
assert_eq!( old_enough.apply( &registry2 ), false );

Closures

A closure can be made into a System only if the closure accepts no arguments

use aanyx::system::System;
 
fn always_true() -> bool { true }
let always_true_wrapper = ||{ always_true.apply( &()) };
 
// The &() is required because the `System.apply` expects an argument although the closure has 0 arguments
assert!( always_true_wrapper.apply( &() ) );
use aanyx::system::System;
use std::rc::Rc;
let registry = Rc::new(());
let registry_copy = Rc::clone( &registry );
 
fn always_true() -> bool { true }
let always_true_wrapper = move ||{ always_true.apply( &registry_copy ) };
 
assert!( always_true_wrapper.apply( &registry ))

Performance analysis

Benchamrks performed suggests that the overhead of calling a system insted of the original function is negligible.

Async programming

Actually the system supports async functions, but arguments extraction from registry is not async.

Safety

Calling a unsafe function through the System trait will not generate any new unsafeties, but the function will still be unsafe.

Required Associated Types§

Required Methods§

source

fn apply(&self, registry: &Registry) -> Self::Return

Implementors§

source§

impl<Registry, F, A: FromRegistry<Registry>, FnReturnType> System<Registry, (A,)> for Fwhere F: Fn(A) -> FnReturnType,

§

type Return = FnReturnType

source§

impl<Registry, F, FnReturnType> System<Registry, ()> for Fwhere F: Fn() -> FnReturnType,

§

type Return = FnReturnType

source§

impl<Registry, Func, FnReturnType, A: FromRegistry<Registry>, B: FromRegistry<Registry>> System<Registry, (A, B)> for Funcwhere Func: Fn(A, B) -> FnReturnType,

§

type Return = FnReturnType

source§

impl<Registry, Func, FnReturnType, A: FromRegistry<Registry>, B: FromRegistry<Registry>, C: FromRegistry<Registry>> System<Registry, (A, B, C)> for Funcwhere Func: Fn(A, B, C) -> FnReturnType,

§

type Return = FnReturnType

source§

impl<Registry, Func, FnReturnType, A: FromRegistry<Registry>, B: FromRegistry<Registry>, C: FromRegistry<Registry>, D: FromRegistry<Registry>> System<Registry, (A, B, C, D)> for Funcwhere Func: Fn(A, B, C, D) -> FnReturnType,

§

type Return = FnReturnType

source§

impl<Registry, Func, FnReturnType, A: FromRegistry<Registry>, B: FromRegistry<Registry>, C: FromRegistry<Registry>, D: FromRegistry<Registry>, E: FromRegistry<Registry>> System<Registry, (A, B, C, D, E)> for Funcwhere Func: Fn(A, B, C, D, E) -> FnReturnType,

§

type Return = FnReturnType

source§

impl<Registry, Func, FnReturnType, A: FromRegistry<Registry>, B: FromRegistry<Registry>, C: FromRegistry<Registry>, D: FromRegistry<Registry>, E: FromRegistry<Registry>, F: FromRegistry<Registry>> System<Registry, (A, B, C, D, E, F)> for Funcwhere Func: Fn(A, B, C, D, E, F) -> FnReturnType,

§

type Return = FnReturnType

source§

impl<Registry, Func, FnReturnType, A: FromRegistry<Registry>, B: FromRegistry<Registry>, C: FromRegistry<Registry>, D: FromRegistry<Registry>, E: FromRegistry<Registry>, F: FromRegistry<Registry>, G: FromRegistry<Registry>, H: FromRegistry<Registry>> System<Registry, (A, B, C, D, E, F, G, H)> for Funcwhere Func: Fn(A, B, C, D, E, F, G, H) -> FnReturnType,

§

type Return = FnReturnType

source§

impl<Registry, Func, FnReturnType, A: FromRegistry<Registry>, B: FromRegistry<Registry>, C: FromRegistry<Registry>, D: FromRegistry<Registry>, E: FromRegistry<Registry>, F: FromRegistry<Registry>, G: FromRegistry<Registry>, H: FromRegistry<Registry>, I: FromRegistry<Registry>> System<Registry, (A, B, C, D, E, F, G, H, I)> for Funcwhere Func: Fn(A, B, C, D, E, F, G, H, I) -> FnReturnType,

§

type Return = FnReturnType

source§

impl<Registry, Func, FnReturnType, A: FromRegistry<Registry>, B: FromRegistry<Registry>, C: FromRegistry<Registry>, D: FromRegistry<Registry>, E: FromRegistry<Registry>, F: FromRegistry<Registry>, G: FromRegistry<Registry>, H: FromRegistry<Registry>, I: FromRegistry<Registry>, J: FromRegistry<Registry>> System<Registry, (A, B, C, D, E, F, G, H, I, J)> for Funcwhere Func: Fn(A, B, C, D, E, F, G, H, I, J) -> FnReturnType,

§

type Return = FnReturnType

source§

impl<Registry, Func, FnReturnType, A: FromRegistry<Registry>, B: FromRegistry<Registry>, C: FromRegistry<Registry>, D: FromRegistry<Registry>, E: FromRegistry<Registry>, F: FromRegistry<Registry>, G: FromRegistry<Registry>, H: FromRegistry<Registry>, I: FromRegistry<Registry>, J: FromRegistry<Registry>, K: FromRegistry<Registry>> System<Registry, (A, B, C, D, E, F, G, H, I, J, K)> for Funcwhere Func: Fn(A, B, C, D, E, F, G, H, I, J, K) -> FnReturnType,

§

type Return = FnReturnType

source§

impl<Registry, Func, FnReturnType, A: FromRegistry<Registry>, B: FromRegistry<Registry>, C: FromRegistry<Registry>, D: FromRegistry<Registry>, E: FromRegistry<Registry>, F: FromRegistry<Registry>, G: FromRegistry<Registry>, H: FromRegistry<Registry>, I: FromRegistry<Registry>, J: FromRegistry<Registry>, K: FromRegistry<Registry>, L: FromRegistry<Registry>> System<Registry, (A, B, C, D, E, F, G, H, I, J, K, L)> for Funcwhere Func: Fn(A, B, C, D, E, F, G, H, I, J, K, L) -> FnReturnType,

§

type Return = FnReturnType

source§

impl<Registry, Func, FnReturnType, A: FromRegistry<Registry>, B: FromRegistry<Registry>, C: FromRegistry<Registry>, D: FromRegistry<Registry>, E: FromRegistry<Registry>, F: FromRegistry<Registry>, G: FromRegistry<Registry>, H: FromRegistry<Registry>, I: FromRegistry<Registry>, J: FromRegistry<Registry>, K: FromRegistry<Registry>, L: FromRegistry<Registry>, M: FromRegistry<Registry>> System<Registry, (A, B, C, D, E, F, G, H, I, J, K, L, M)> for Funcwhere Func: Fn(A, B, C, D, E, F, G, H, I, J, K, L, M) -> FnReturnType,

§

type Return = FnReturnType

source§

impl<Registry, Func, FnReturnType, A: FromRegistry<Registry>, B: FromRegistry<Registry>, C: FromRegistry<Registry>, D: FromRegistry<Registry>, E: FromRegistry<Registry>, F: FromRegistry<Registry>, G: FromRegistry<Registry>, H: FromRegistry<Registry>, I: FromRegistry<Registry>, J: FromRegistry<Registry>, K: FromRegistry<Registry>, L: FromRegistry<Registry>, M: FromRegistry<Registry>, N: FromRegistry<Registry>> System<Registry, (A, B, C, D, E, F, G, H, I, J, K, L, M, N)> for Funcwhere Func: Fn(A, B, C, D, E, F, G, H, I, J, K, L, M, N) -> FnReturnType,

§

type Return = FnReturnType

source§

impl<Registry, Func, FnReturnType, A: FromRegistry<Registry>, B: FromRegistry<Registry>, C: FromRegistry<Registry>, D: FromRegistry<Registry>, E: FromRegistry<Registry>, F: FromRegistry<Registry>, G: FromRegistry<Registry>, H: FromRegistry<Registry>, I: FromRegistry<Registry>, J: FromRegistry<Registry>, K: FromRegistry<Registry>, L: FromRegistry<Registry>, M: FromRegistry<Registry>, N: FromRegistry<Registry>, O: FromRegistry<Registry>> System<Registry, (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)> for Funcwhere Func: Fn(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O) -> FnReturnType,

§

type Return = FnReturnType