Skip to content

Commit c26e650

Browse files
committed
- fix: more naming issues when outputting rust
1 parent 65ee270 commit c26e650

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

generator/src/codegen/rust/codegen_source.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ impl<'a, W: Write> CodeSourceGenerator<'a, W> {
3434
cg!(self, "/* Generated with IDL v{} */\n", version);
3535
cg!(self, r#"use bincode::{{Encode, Decode}};"#);
3636
cg!(self, r#"use crate::packet::PacketPayload;"#);
37+
38+
for content in packet.contents() {
39+
use self::PacketContent::*;
40+
match content {
41+
Include(ref inc, system) => {
42+
cg!(self, r#"use {};"#, inc);
43+
},
44+
_ => {}
45+
};
46+
}
3747
cg!(self);
3848

3949
let iserialize = packet.contents().iter().filter_map(|elem| {
@@ -82,7 +92,10 @@ impl<'a, W: Write> CodeSourceGenerator<'a, W> {
8292
}
8393
Some(rust_type)
8494
}
85-
// TODO Map complex type
95+
PacketContent::Complex(ref e) => {
96+
let rust_type = (e.name().clone(), e.name().clone());
97+
Some(rust_type)
98+
}
8699
_ => None,
87100
}
88101
}).collect::<HashMap<String, String>>(); // Collect into a HashMap
@@ -106,7 +119,7 @@ impl<'a, W: Write> CodeSourceGenerator<'a, W> {
106119
cg!(self);
107120

108121
cg!(self, r#"#[derive(Debug, Encode, Decode)]"#);
109-
cg!(self, "pub struct {} {{", packet.class_name());
122+
cg!(self, "pub struct {} {{", packet.class_name().to_upper_camel_case());
110123
self.indent();
111124
for content in packet.contents() {
112125
use self::PacketContent::*;
@@ -119,7 +132,7 @@ impl<'a, W: Write> CodeSourceGenerator<'a, W> {
119132
cg!(self, "}}");
120133

121134
cg!(self);
122-
cg!(self, "impl PacketPayload for {} {{}}", packet.class_name());
135+
cg!(self, "impl PacketPayload for {} {{}}", packet.class_name().to_upper_camel_case());
123136

124137

125138
Ok(())
@@ -270,9 +283,9 @@ fn rename_if_reserved(name: &str) -> String {
270283
];
271284

272285
if reserved_keywords.contains(&name) {
273-
format!("{}_", name) // Append a suffix to avoid conflicts
286+
format!("{}_", name.to_snake_case()) // Append a suffix to avoid conflicts
274287
} else {
275-
name.to_string()
288+
name.to_string().to_snake_case()
276289
}
277290
}
278291

generator/src/flat_ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl Packet {
155155
(name.clone(),
156156
name.clone().to_snake_case())
157157
} else {
158-
let name = "srv".to_string() + &name[5..];
158+
let name = "Srv".to_string() + &name[5..];
159159
(name.clone(),
160160
name.clone().to_snake_case())
161161
}

0 commit comments

Comments
 (0)