lunaria_api/
lib.rs

1//! _A Rust API client for the video game Lunaria._
2//!
3//! [Lunaria] is a video game for programmers, and is played by writing code
4//! that interacts with the game through a [gRPC] API. The public interface of
5//! the API is specified using [Protocol Buffer][protobuf] definitions, and
6//! clients for various languages are automatically generated from these specs.
7//!
8//! `lunaria-api` contains an API client for Rust that is automatically
9//! generated from the API specifications using [tonic].
10//!
11//! # Features
12//!
13//! - `server`: The crate contains not only the API client, but also the server
14//!   stubs for Lunaria's API. It exists only so that Lunaria can implement the
15//!   API, and should not be included by clients.
16//!
17//! # Required dependencies
18//!
19//! `lunaria-api` wraps a client generated by [`tonic`][tonic], which must be
20//! added as a dependency as well. [`tokio`][tokio] is recommended as the async
21//! runtime for the client.
22//!
23//! ```toml
24//! [dependencies]
25//! lunaria-api = "0.2.1"
26//! tokio = { version = "0.2.22", features = ["macros", "rt-threaded"] }
27//! tonic = "0.3.1"
28//! ```
29//!
30//! # Examples
31//!
32//! ```rust
33//! use lunaria_api::lunaria::v1::lunaria_service_client::LunariaServiceClient;
34//! use lunaria_api::lunaria::v1::{GetVersionRequest, GetVersionResponse, Version};
35//! use tonic::Request;
36//!
37//! #[tokio::main]
38//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
39//!     // Specify the address and port of Lunaria's API
40//!     let address = "http://127.0.0.1:1904";
41//!
42//!     // Initialize the client
43//!     let mut lunaria = LunariaServiceClient::connect(address).await?;
44//!
45//!     // Create a request to get the game's version and send it to the server
46//!     let request = Request::new(GetVersionRequest {});
47//!     let grpc_response = lunaria.get_version(request).await?;
48//!     let version_response = grpc_response.into_inner();
49//!
50//!     if let Some(version) = version_response.version {
51//!         assert_eq!(0, version.major);
52//!         assert_eq!(2, version.minor);
53//!         assert_eq!(1, version.patch);
54//!     }
55//!
56//!     Ok(())
57//! }
58//! ```
59//!
60//! [grpc]: https://grpc.io
61//! [lunaria]: https://playlunaria.com
62//! [lunaria-api]: https://github.com/playlunaria/lunaria-api
63//! [protobuf]: https://developers.google.com/protocol-buffers/
64//! [tokio]: https://github.com/tokio-rs/tokio
65//! [tonic]: https://github.com/hyperium/tonic
66
67pub mod lunaria {
68    pub mod v1 {
69        tonic::include_proto!("lunaria.v1");
70    }
71}