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 89 90 91 92 93
//! # Interlink
//!
//! Interlink is an async framework
//!
//! # Starting a service
//!
//! In order to get a link to a service and for the service to run you will first need to start the service
//!
//! ```
//! use interlink::prelude::*;
//!
//! /// Define your backing structure for the service you can use
//! /// the service derive macro here or implement the trait to
//! /// get access to the `started` and `stopping` hooks
//! #[derive(Service)]
//! struct Example;
//!
//! // You must be within the tokio runtime to use interlink
//! #[tokio::main]
//! async fn main() {
//! // Create the service
//! let service = Example {};
//! // Start the service to get a link to the service
//! let link = service.start();
//! }
//!```
//!
//! # Sending a message to a service
//!
//! To communicate with services and between services you use messages below is an example of how to create and send messages.
//!
//!```
//! use interlink::prelude::*;
//!
//! // Define your backing structure for the service
//! #[derive(Service)]
//! struct Example;
//!
//! // The message struct with a string response type
//! #[derive(Message)]
//! #[msg(rtype = "String")]
//! struct TextMessage {
//! value: String,
//! }
//!
//! /// Implement a handler for the message type
//! impl Handler<TextMessage> for Example {
//!
//! /// Basic response type which just responds with the value
//! type Response = Mr<TextMessage>;
//!
//! fn handle(
//! &mut self,
//! msg: TextMessage,
//! ctx: &mut ServiceContext<Self>
//! ) -> Self::Response {
//! println!("Got message: {}", &msg.value);
//! Mr(msg.value)
//! }
//! }
//!
//! // You must be within the tokio runtime to use interlink
//! #[tokio::main]
//! async fn main() {
//! // Create the service
//! let service = Example {};
//! // Start the service to get a link to the service
//! let link = service.start();
//!
//! // Send the text message to the service and await the response
//! let res: String = link.send(TextMessage {
//! value: "Example".to_string(),
//! })
//! .await
//! .unwrap();
//!
//! assert_eq!(&res, "Example");
//!
//! // You can also send without waiting for a response
//! link.do_send(TextMessage {
//! value: "Example".to_string(),
//! })
//! .unwrap();
//!
//! }
//! ```
mod envelope;
pub mod ext;
pub mod link;
pub mod msg;
pub mod prelude;
pub mod service;