dcl_rpc/lib.rs
1//! Rust Implementation of Decentraland RPC.
2//!
3//! Communicates between different services written in different languages, just sharing a `.proto` file.
4//! Decentraland RPC implementation uses protobuffer as the messaging format and you can create custom transports (muest meet [Transport trait][`crate::transports::Transport`] requirements) or use the existing ones for communication.
5//!
6//! The communication is carried out by a client (or many ones) and a server. A [`RpcClient`](crate::client::RpcClient) connects to a [`RpcServer`](crate::server::RpcServer) . A `RpcServer` accepts multiple clients.
7//! For example, the `RpcServer` could have a WebSocket server listening for new connections for then [attaching][`crate::server::RpcServer::attach_transport`] each new connection socket to the `RpcServer`.
8//! And on the client side, a connection to the WebSocket server could be established for then creating a new `RpcClient` passing the connection socket generated.
9//!
10//! After that, the `RpcClient` should create a [`RpcClientPort`](crate::client::RpcClientPort) by calling [`RpcClient::create_port`][`crate::client::RpcClient::create_port`], this sends a request to the `RpcServer` to create a [`crate::server::RpcServerPort`] in the server too.
11//! A created port is "detached" from the client and the server. A port can be closed or destroyed but the client (`RpcClient`) will keep existing, also the server (`RpcServer`), just the port will be removed from the client's memory and the server's memory.
12//!
13//! On the server side, each port created owns different types of modules (A `service` in `.proto` file). Each port has its registered modules and loaded modules.
14//! Every time that a port is created, on the server side, a handler is executed to register a module or multiple ones. Also, the handler could have conditions to register a module depending on specific conditions like a port name or something else.
15//!
16//! On the client side, each port created can request remote modules (A 'service' in `.proto` file) to the `RpcServer` as long as the port has the given module registered or loaded. A client could create and have multiple ports, each procedure request has the id of the port that is making the request.
17//!
18//! The `RpcServer` shares a context through all its registered modules. This context should have the app context, like a database connection/component. Every procedure can access and use the server context, and the same instance of the context is shared between them (`Arc<Context>`).
19//!
20//! You could find basic and complex examples in the [examples folder](https://github.com/decentraland/rpc-rust/tree/main/examples) on the [github repository](https://github.com/decentraland/rpc-rust).
21//!
22
23#[cfg(feature = "client")]
24pub mod client;
25#[cfg(feature = "codegen")]
26pub mod codegen;
27pub mod messages_handlers;
28pub mod rpc_protocol;
29#[cfg(feature = "server")]
30pub mod server;
31#[cfg(feature = "server")]
32pub mod service_module_definition;
33pub mod stream_protocol;
34pub mod transports;
35
36#[derive(Debug)]
37pub enum CommonError {
38 ProtocolError,
39 TransportError,
40 TransportNotAttached,
41 UnexpectedError(String),
42 TransportWasClosed,
43}