Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix semicolon in rust binding #355

Merged
merged 1 commit into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions rust/candid/src/bindings/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,20 @@ fn pp_defs<'a>(env: &'a TypeEnv, def_list: &'a [&'a str], recs: &'a RecPoints) -
let ty = env.find_type(id).unwrap();
let name = ident(id).append(" ");
match ty {
Type::Record(fs) => str(derive)
.append(RcDoc::line())
.append("struct ")
.append(name)
.append(pp_record_fields(fs, recs))
.append(RcDoc::hardline()),
Type::Record(fs) => {
let separator = if is_tuple(fs) {
RcDoc::text(";")
} else {
RcDoc::nil()
};
str(derive)
.append(RcDoc::line())
.append("struct ")
.append(name)
.append(pp_record_fields(fs, recs))
.append(separator)
.append(RcDoc::hardline())
}
Type::Variant(fs) => str(derive)
.append(RcDoc::line())
.append("enum ")
Expand Down
2 changes: 1 addition & 1 deletion rust/candid/tests/assets/ok/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct h_ret0 { _42_: h_ret0_42, id: candid::Nat }

type f = candid::Func;
#[derive(CandidType, Deserialize)]
struct b (candid::Int,candid::Nat,)
struct b (candid::Int,candid::Nat,);

#[derive(CandidType, Deserialize)]
enum a { a, b(b) }
Expand Down
2 changes: 1 addition & 1 deletion rust/candid/tests/assets/ok/fieldnat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct baz_arg0 { _2_: candid::Int, #[serde(rename="2")] _50_: candid::Nat }
struct baz_ret0 {}

#[derive(CandidType, Deserialize)]
struct tuple (String,String,)
struct tuple (String,String,);

#[derive(CandidType, Deserialize)]
struct non_tuple { _1_: String, _2_: String }
Expand Down