aldrin_codegen/rust/
names.rs

1use crate::util;
2
3/// Returns the name for a functions's enum variant.
4pub fn function_variant(func: &str) -> String {
5    util::to_camel_case(func)
6}
7
8/// Returns the name for an inline struct or enum used as a functions's `args`.
9pub fn function_args(service: &str, func: &str) -> String {
10    let func = util::to_camel_case(func);
11    format!("{service}{func}Args")
12}
13
14/// Returns the name for an inline struct or enum used as a functions's `ok`.
15pub fn function_ok(service: &str, func: &str) -> String {
16    let func = util::to_camel_case(func);
17    format!("{service}{func}Ok")
18}
19
20/// Returns the name for an inline struct or enum used as a functions's `err`.
21pub fn function_err(service: &str, func: &str) -> String {
22    let func = util::to_camel_case(func);
23    format!("{service}{func}Error")
24}
25
26/// Returns the name of the function call that takes an argument by value.
27pub fn call_val(func: &str) -> String {
28    format!("{func}_val")
29}
30
31/// Returns the name of the function call that takes an argument by reference.
32pub fn call_ref(func: &str) -> String {
33    format!("{func}_ref")
34}
35
36/// Returns the name for an event's enum variant.
37pub fn event_variant(event: &str) -> String {
38    util::to_camel_case(event)
39}
40
41/// Returns the name for an inline struct or enum used as an event's argument.
42pub fn event_args(service: &str, event: &str) -> String {
43    let event = util::to_camel_case(event);
44    format!("{service}{event}Args")
45}
46
47/// Returns the name of the event emitter that takes an argument by value.
48pub fn emit_val(event: &str) -> String {
49    format!("{event}_val")
50}
51
52/// Returns the name of the event emitter that takes an argument by reference.
53pub fn emit_ref(event: &str) -> String {
54    format!("{event}_ref")
55}
56
57/// Returns the name of event's subscribe function.
58pub fn subscribe(event: &str) -> String {
59    format!("subscribe_{event}")
60}
61
62/// Returns the name of event's unsubscribe function.
63pub fn unsubscribe(event: &str) -> String {
64    format!("unsubscribe_{event}")
65}
66
67/// Returns the name of a service's proxy type.
68pub fn service_proxy(service: &str) -> String {
69    format!("{service}Proxy")
70}
71
72/// Returns the name of a service's event type.
73pub fn service_event(service: &str) -> String {
74    format!("{service}Event")
75}
76
77/// Returns the name of a service's event handler trait.
78pub fn service_event_handler(service: &str) -> String {
79    format!("{service}EventHandler")
80}
81
82/// Returns the name of a service's call type.
83pub fn service_call(service: &str) -> String {
84    format!("{service}Call")
85}
86
87/// Returns the name of a service's call handler trait.
88pub fn service_call_handler(service: &str) -> String {
89    format!("{service}CallHandler")
90}
91
92/// Returns the name of a service's introspection type.
93pub fn service_introspection(service: &str) -> String {
94    format!("{service}Introspection")
95}
96
97/// Returns the default name for a ref type.
98pub fn default_ref_type(ty: &str) -> String {
99    format!("{ty}Ref")
100}
101
102/// Returns the name of the constructor function in a ref type for an enum's variant.
103pub fn enum_ref_type_ctor(variant: &str) -> String {
104    util::to_snake_case(variant)
105}
106
107pub fn register_introspection(schema: &str) -> String {
108    format!("register_introspection_{schema}")
109}