lua_protobuf_rs/descriptor_proto/
method_descriptor_proto.rs1use crate::descriptor_proto::method_options::LuaMethodOptions;
2use crate::{add_message_dyn_trait_method, add_message_full_trait_method, add_message_trait_method};
3use derive_more::{Deref, DerefMut, From, Into};
4use mlua::prelude::LuaUserData;
5use mlua::{MetaMethod, UserDataFields, UserDataMethods};
6use protobuf::descriptor::MethodDescriptorProto;
7
8#[derive(PartialEq, Clone, Default, Debug, Deref, DerefMut, From, Into)]
9pub struct LuaMethodDescriptorProto(pub MethodDescriptorProto);
10
11impl LuaUserData for LuaMethodDescriptorProto {
12 fn add_fields<F: UserDataFields<Self>>(fields: &mut F) {
13 fields.add_field_method_get("name", |_, this| {
14 Ok(this.name.clone())
15 });
16
17 fields.add_field_method_get("input_type", |_, this| {
18 Ok(this.input_type.clone())
19 });
20
21 fields.add_field_method_get("output_type", |_, this| {
22 Ok(this.output_type.clone())
23 });
24
25 fields.add_field_method_get("options", |_, this| {
26 let options: Option<LuaMethodOptions> = this.options.clone().into_option().map(Into::into);
27 Ok(options)
28 });
29
30 fields.add_field_method_get("client_streaming", |_, this| {
31 Ok(this.client_streaming.clone())
32 });
33
34 fields.add_field_method_get("server_streaming", |_, this| {
35 Ok(this.server_streaming.clone())
36 });
37 }
38
39 fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
40 methods.add_meta_method(MetaMethod::ToString, |_, this, ()| {
41 Ok(this.to_string())
42 });
43
44 methods.add_method("name", |_, this, ()| {
45 Ok(this.name().to_string())
46 });
47
48 methods.add_method_mut("clear_name", |_, this, ()| {
49 this.clear_name();
50 Ok(())
51 });
52
53 methods.add_method("has_name", |_, this, ()| {
54 Ok(this.has_name())
55 });
56
57 methods.add_method_mut("set_name", |_, this, value: String| {
58 this.set_name(value);
59 Ok(())
60 });
61
62 methods.add_method_mut("mut_name", |_, this, ()| {
63 Ok(this.mut_name().clone())
64 });
65
66 methods.add_method_mut("take_name", |_, this, ()| {
67 Ok(this.take_name())
68 });
69
70 methods.add_method("input_type", |_, this, ()| {
71 Ok(this.input_type().to_string())
72 });
73
74 methods.add_method_mut("clear_input_type", |_, this, ()| {
75 this.clear_input_type();
76 Ok(())
77 });
78
79 methods.add_method("has_input_type", |_, this, ()| {
80 Ok(this.has_input_type())
81 });
82
83 methods.add_method_mut("set_input_type", |_, this, value: String| {
84 this.set_input_type(value);
85 Ok(())
86 });
87
88 methods.add_method_mut("mut_input_type", |_, this, ()| {
89 Ok(this.mut_input_type().clone())
90 });
91
92 methods.add_method_mut("take_input_type", |_, this, ()| {
93 Ok(this.take_input_type())
94 });
95
96 methods.add_method("output_type", |_, this, ()| {
97 Ok(this.output_type().to_string())
98 });
99
100 methods.add_method_mut("clear_output_type", |_, this, ()| {
101 this.clear_output_type();
102 Ok(())
103 });
104
105 methods.add_method("has_output_type", |_, this, ()| {
106 Ok(this.has_output_type())
107 });
108
109 methods.add_method_mut("set_output_type", |_, this, value: String| {
110 this.set_output_type(value);
111 Ok(())
112 });
113
114 methods.add_method_mut("mut_output_type", |_, this, ()| {
115 Ok(this.mut_output_type().clone())
116 });
117
118 methods.add_method_mut("take_output_type", |_, this, ()| {
119 Ok(this.take_output_type())
120 });
121
122 methods.add_method("client_streaming", |_, this, ()| {
123 Ok(this.client_streaming())
124 });
125
126 methods.add_method_mut("clear_client_streaming", |_, this, ()| {
127 this.clear_client_streaming();
128 Ok(())
129 });
130
131 methods.add_method("has_client_streaming", |_, this, ()| {
132 Ok(this.has_client_streaming())
133 });
134
135 methods.add_method_mut("set_client_streaming", |_, this, value: bool| {
136 this.set_client_streaming(value);
137 Ok(())
138 });
139
140 methods.add_method("server_streaming", |_, this, ()| {
141 Ok(this.server_streaming())
142 });
143
144 methods.add_method_mut("clear_server_streaming", |_, this, ()| {
145 this.clear_server_streaming();
146 Ok(())
147 });
148
149 methods.add_method("has_server_streaming", |_, this, ()| {
150 Ok(this.has_server_streaming())
151 });
152
153 methods.add_method_mut("set_server_streaming", |_, this, value: bool| {
154 this.set_server_streaming(value);
155 Ok(())
156 });
157
158 add_message_trait_method!(methods, MethodDescriptorProto, LuaMethodDescriptorProto);
159
160 add_message_dyn_trait_method!(methods, MethodDescriptorProto, LuaMethodDescriptorProto);
161
162 add_message_full_trait_method!(methods, MethodDescriptorProto, LuaMethodDescriptorProto);
163 }
164}