Crate lunaria_api[][src]

Expand description

A Rust API client for the video game Lunaria.

Lunaria is a video game for programmers, and is played by writing code that interacts with the game through a gRPC API. The public interface of the API is specified using Protocol Buffer definitions, and clients for various languages are automatically generated from these specs.

lunaria-api contains an API client for Rust that is automatically generated from the API specifications using tonic.


  • server: The crate contains not only the API client, but also the server stubs for Lunaria’s API. It exists only so that Lunaria can implement the API, and should not be included by clients.

Required dependencies

lunaria-api wraps a client generated by tonic, which must be added as a dependency as well. tokio is recommended as the async runtime for the client.

lunaria-api = "0.2.1"
tokio = { version = "0.2.22", features = ["macros", "rt-threaded"] }
tonic = "0.3.1"


use lunaria_api::lunaria::v1::lunaria_service_client::LunariaServiceClient;
use lunaria_api::lunaria::v1::{GetVersionRequest, GetVersionResponse, Version};
use tonic::Request;

async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Specify the address and port of Lunaria's API
    let address = "";

    // Initialize the client
    let mut lunaria = LunariaServiceClient::connect(address).await?;

    // Create a request to get the game's version and send it to the server
    let request = Request::new(GetVersionRequest {});
    let grpc_response = lunaria.get_version(request).await?;
    let version_response = grpc_response.into_inner();

    if let Some(version) = version_response.version {
        assert_eq!(0, version.major);
        assert_eq!(2, version.minor);
        assert_eq!(1, version.patch);