prost_simple_rpc/descriptor.rs
1//! Traits for defining generic service descriptor definitions.
2//!
3//! These traits are built on the assumption that some form of code generation is being used (e.g.
4//! using only `&'static str`s) but it's of course possible to implement these traits manually.
5use std::any;
6use std::fmt;
7
8/// A descriptor for an available RPC service.
9pub trait ServiceDescriptor: Clone + fmt::Debug + Send + Sync {
10 /// The associated type of method descriptors.
11 type Method: MethodDescriptor + fmt::Debug;
12
13 /// The name of the service, used in Rust code and perhaps for human readability.
14 fn name() -> &'static str;
15
16 /// The raw protobuf name of the service.
17 fn proto_name() -> &'static str;
18
19 /// The package name of the service.
20 fn package() -> &'static str {
21 ""
22 }
23
24 /// All of the available methods on the service.
25 fn methods() -> &'static [Self::Method];
26}
27
28/// A descriptor for a method available on an RPC service.
29pub trait MethodDescriptor: Clone + Copy + fmt::Debug + Send + Sync {
30 /// The name of the service, used in Rust code and perhaps for human readability.
31 fn name(&self) -> &'static str;
32
33 /// The raw protobuf name of the service.
34 fn proto_name(&self) -> &'static str;
35
36 /// The Rust `TypeId` for the input that this method accepts.
37 fn input_type(&self) -> any::TypeId;
38
39 /// The raw protobuf name for the input type that this method accepts.
40 fn input_proto_type(&self) -> &'static str;
41
42 /// The Rust `TypeId` for the output that this method produces.
43 fn output_type(&self) -> any::TypeId;
44
45 /// The raw protobuf name for the output type that this method produces.
46 fn output_proto_type(&self) -> &'static str;
47}