1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#![warn(missing_docs)]
#![feature(core_intrinsics, proc_macro, conservative_impl_trait, generators)]

//! Organelle - reactive architecture for emergent AI systems

#[macro_use]
extern crate error_chain;
#[macro_use]
extern crate serde_derive;

extern crate bytes;
extern crate futures_await as futures;
extern crate serde;
extern crate serde_json;
extern crate tokio;
extern crate tokio_core;
extern crate uuid;

#[cfg(feature = "visualizer")]
extern crate hyper;
#[cfg(feature = "visualizer")]
extern crate open;

mod axon;
mod organelle;
mod soma;

/// visualization soma used to visualize the results of a probe
#[cfg(feature = "visualizer")]
pub mod visualizer;

/// probe soma used to inspect the internal structure of an organelle
pub mod probe;

pub use axon::{Axon, Constraint};
pub use organelle::Organelle;
pub use probe::{ConstraintData, SomaData};
pub use soma::{Impulse, Soma, Synapse};

/// organelle error
error_chain! {
    foreign_links {
        Io(std::io::Error) #[doc = "glue for io::Error"];
        FromUtf8(std::string::FromUtf8Error)
            #[doc = "glue for std::string::FromUtf8Error"];

        Canceled(futures::Canceled) #[doc = "glue for futures::Canceled"];
        SerdeJson(serde_json::Error) #[doc = "glue for serde_json::Error"];


        Hyper(hyper::Error)
            #[cfg(feature = "visualizer")]
            #[doc = "glue for hyper::Error"];

        AddrParse(std::net::AddrParseError)
            #[cfg(feature = "visualizer")]
            #[doc = "glue for net::AddrParseError"];
    }
    errors {
        /// a soma returned an error when called into
        SomaError {
            description("an error occurred while calling into a soma"),
            display("an error occurred while calling into a soma")
        }

        /// axon failed to validate a synapse
        InvalidSynapse(msg: String) {
            description("invalid synapse given to somas"),
            display("invalid synapse given to somas - {}", msg)
        }

        /// axon is missing a synapse
        MissingSynapse(msg: String) {
            description("missing synapse"),
            display("invalid synapse - {}", msg)
        }
    }
}

#[cfg(feature = "visualizer")]
impl From<Error> for hyper::Error {
    fn from(e: Error) -> Self {
        hyper::Error::Io(std::io::Error::new(
            std::io::ErrorKind::Other,
            format!("{:?}", e),
        ))
    }
}