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
//! Traits for defining generic service descriptor definitions.
//!
//! These traits are built on the assumption that some form of code generation is being used (e.g.
//! using only `&'static str`s) but it's of course possible to implement these traits manually.
use std::any;
use std::fmt;

/// A descriptor for an available RPC service.
pub trait ServiceDescriptor: Clone + fmt::Debug + Send + Sync {
    /// The associated type of method descriptors.
    type Method: MethodDescriptor + fmt::Debug;

    /// The name of the service, used in Rust code and perhaps for human readability.
    fn name() -> &'static str;

    /// The raw protobuf name of the service.
    fn proto_name() -> &'static str;

    /// The package name of the service.
    fn package() -> &'static str {
        ""
    }

    /// All of the available methods on the service.
    fn methods() -> &'static [Self::Method];
}

/// A descriptor for a method available on an RPC service.
pub trait MethodDescriptor: Clone + Copy + fmt::Debug + Send + Sync {
    /// The name of the service, used in Rust code and perhaps for human readability.
    fn name(&self) -> &'static str;

    /// The raw protobuf name of the service.
    fn proto_name(&self) -> &'static str;

    /// The Rust `TypeId` for the input that this method accepts.
    fn input_type(&self) -> any::TypeId;

    /// The raw protobuf name for the input type that this method accepts.
    fn input_proto_type(&self) -> &'static str;

    /// The Rust `TypeId` for the output that this method produces.
    fn output_type(&self) -> any::TypeId;

    /// The raw protobuf name for the output type that this method produces.
    fn output_proto_type(&self) -> &'static str;
}