Skip to main content

endpoint_libs/model/
service.rs

1use alloc::string::String;
2use alloc::vec::Vec;
3
4use crate::model::EndpointSchema;
5use serde::*;
6
7/// `Service` is a struct that represents a single service in the API.
8#[derive(Debug, Serialize, Deserialize)]
9pub struct Service {
10    /// The name of the service (e.g. `user`)
11    pub name: String,
12
13    /// The ID of the service (e.g. `1`)
14    pub id: u16,
15
16    /// A list of endpoints (schemas) that the service contains (e.g. `user_endpoints::get_user_endpoints()`)
17    pub endpoints: Vec<EndpointSchema>,
18}
19
20impl Service {
21    /// Creates a new `Service` with the given name, ID and endpoints.
22    pub fn new(name: impl Into<String>, id: u16, endpoints: Vec<EndpointSchema>) -> Self {
23        Self {
24            name: name.into(),
25            id,
26            endpoints,
27        }
28    }
29}