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 #169 #172

Merged
merged 4 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- \[Rust\]: Add license files to crates
- \[Rust\]: Implement a builder pattern for serializing tables and unions
- \[Rust\]: rustfmt runs twice on generated code to ensure it is formatted correctly
- \[Rust\]: Fix an issue with using structs across different flatbuffer namespaces.
- Add support for docstrings, and add them to the Rust output.
- Update the `README` with information about our Discord server.
- Split up `planus-cli` into multiple crates
Expand Down
2 changes: 1 addition & 1 deletion crates/planus-codegen/src/rust/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ impl Backend for RustBackend {
format_relative_namespace(&relative_namespace, &info.owned_name).to_string();
let ref_name = format_relative_namespace(&relative_namespace, &info.ref_name);
getter_return_type = format!("{ref_name}<'a>");
getter_code = format!("{ref_name}(buffer)");
getter_code = format!("::core::convert::From::from(buffer)");
}
ResolvedType::Enum(decl, info, relative_namespace, _) => {
owned_type = format_relative_namespace(&relative_namespace, &info.name).to_string();
Expand Down
6 changes: 6 additions & 0 deletions crates/planus-codegen/src/templates/rust/struct.template
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ impl<'a> ::core::fmt::Debug for {{ info.ref_name }}<'a> {
}
}

impl<'a> ::core::convert::From<::planus::ArrayWithStartOffset<'a, {{ size }}>> for {{ info.ref_name }}<'a> {
fn from(array: ::planus::ArrayWithStartOffset<'a, {{ size }}>) -> Self {
Self(array)
}
}

{% if info.should_do_infallible_conversion -%}
impl<'a> ::core::convert::From<{{ info.ref_name }}<'a>> for {{ info.owned_name}} {
#[allow(unreachable_code)]
Expand Down
48 changes: 39 additions & 9 deletions test/files/valid/include_helpers/A.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,43 @@ include "../include_test2.fbs";

namespace A;

table Obj {
here: Obj;
a: A.Obj;
a_a: A.A.Obj;
a_b: A.B.Obj;
b: B.Obj;
b_a: B.A.Obj;
b_b: B.B.Obj;
c: C.Obj;
table Table {
here: Table;
a: A.Table;
a_a: A.A.Table;
a_b: A.B.Table;
b: B.Table;
b_a: B.A.Table;
b_b: B.B.Table;
c: C.Table;
struct_here: Struct;
struct_a: A.Struct;
struct_a_a: A.A.Struct;
struct_a_b: A.B.Struct;
struct_b: B.Struct;
struct_b_a: B.A.Struct;
struct_b_b: B.B.Struct;
struct_c: C.Struct;
}

table Struct {
here: Struct;
a: A.Struct;
a_a: A.A.Struct;
a_b: A.B.Struct;
b: B.Struct;
b_a: B.A.Struct;
b_b: B.B.Struct;
c: C.Struct;
}

union Union {
Table,
A.Table,
A.A.Table,
A.B.Table,
B.Table,
B.A.Table,
B.B.Table,
C.Table
}
48 changes: 39 additions & 9 deletions test/files/valid/include_helpers/A_A.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,43 @@ include "../include_test2.fbs";

namespace A.A;

table Obj {
here: Obj;
a: A.Obj;
a_a: A.A.Obj;
a_b: A.B.Obj;
b: B.Obj;
b_a: B.A.Obj;
b_b: B.B.Obj;
c: C.Obj;
table Table {
here: Table;
a: A.Table;
a_a: A.A.Table;
a_b: A.B.Table;
b: B.Table;
b_a: B.A.Table;
b_b: B.B.Table;
c: C.Table;
struct_here: Struct;
struct_a: A.Struct;
struct_a_a: A.A.Struct;
struct_a_b: A.B.Struct;
struct_b: B.Struct;
struct_b_a: B.A.Struct;
struct_b_b: B.B.Struct;
struct_c: C.Struct;
}

table Struct {
here: Struct;
a: A.Struct;
a_a: A.A.Struct;
a_b: A.B.Struct;
b: B.Struct;
b_a: B.A.Struct;
b_b: B.B.Struct;
c: C.Struct;
}

union Union {
Table,
A.Table,
A.A.Table,
A.B.Table,
B.Table,
B.A.Table,
B.B.Table,
C.Table
}
48 changes: 39 additions & 9 deletions test/files/valid/include_helpers/A_B.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,43 @@ include "../include_test2.fbs";

namespace A.B;

table Obj {
here: Obj;
a: A.Obj;
a_a: A.A.Obj;
a_b: A.B.Obj;
b: B.Obj;
b_a: B.A.Obj;
b_b: B.B.Obj;
c: C.Obj;
table Table {
here: Table;
a: A.Table;
a_a: A.A.Table;
a_b: A.B.Table;
b: B.Table;
b_a: B.A.Table;
b_b: B.B.Table;
c: C.Table;
struct_here: Struct;
struct_a: A.Struct;
struct_a_a: A.A.Struct;
struct_a_b: A.B.Struct;
struct_b: B.Struct;
struct_b_a: B.A.Struct;
struct_b_b: B.B.Struct;
struct_c: C.Struct;
}

table Struct {
here: Struct;
a: A.Struct;
a_a: A.A.Struct;
a_b: A.B.Struct;
b: B.Struct;
b_a: B.A.Struct;
b_b: B.B.Struct;
c: C.Struct;
}

union Union {
Table,
A.Table,
A.A.Table,
A.B.Table,
B.Table,
B.A.Table,
B.B.Table,
C.Table
}
48 changes: 39 additions & 9 deletions test/files/valid/include_helpers/B.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,43 @@ include "../include_test2.fbs";

namespace B;

table Obj {
here: Obj;
a: A.Obj;
a_a: A.A.Obj;
a_b: A.B.Obj;
b: B.Obj;
b_a: B.A.Obj;
b_b: B.B.Obj;
c: C.Obj;
table Table {
here: Table;
a: A.Table;
a_a: A.A.Table;
a_b: A.B.Table;
b: B.Table;
b_a: B.A.Table;
b_b: B.B.Table;
c: C.Table;
struct_here: Struct;
struct_a: A.Struct;
struct_a_a: A.A.Struct;
struct_a_b: A.B.Struct;
struct_b: B.Struct;
struct_b_a: B.A.Struct;
struct_b_b: B.B.Struct;
struct_c: C.Struct;
}

table Struct {
here: Struct;
a: A.Struct;
a_a: A.A.Struct;
a_b: A.B.Struct;
b: B.Struct;
b_a: B.A.Struct;
b_b: B.B.Struct;
c: C.Struct;
}

union Union {
Table,
A.Table,
A.A.Table,
A.B.Table,
B.Table,
B.A.Table,
B.B.Table,
C.Table
}
48 changes: 39 additions & 9 deletions test/files/valid/include_helpers/B_A.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,43 @@ include "../include_test2.fbs";

namespace B.A;

table Obj {
here: Obj;
a: A.Obj;
a_a: A.A.Obj;
a_b: A.B.Obj;
b: B.Obj;
b_a: B.A.Obj;
b_b: B.B.Obj;
c: C.Obj;
table Table {
here: Table;
a: A.Table;
a_a: A.A.Table;
a_b: A.B.Table;
b: B.Table;
b_a: B.A.Table;
b_b: B.B.Table;
c: C.Table;
struct_here: Struct;
struct_a: A.Struct;
struct_a_a: A.A.Struct;
struct_a_b: A.B.Struct;
struct_b: B.Struct;
struct_b_a: B.A.Struct;
struct_b_b: B.B.Struct;
struct_c: C.Struct;
}

table Struct {
here: Struct;
a: A.Struct;
a_a: A.A.Struct;
a_b: A.B.Struct;
b: B.Struct;
b_a: B.A.Struct;
b_b: B.B.Struct;
c: C.Struct;
}

union Union {
Table,
A.Table,
A.A.Table,
A.B.Table,
B.Table,
B.A.Table,
B.B.Table,
C.Table
}
48 changes: 39 additions & 9 deletions test/files/valid/include_helpers/B_B.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,43 @@ include "../include_test2.fbs";

namespace B.B;

table Obj {
here: Obj;
a: A.Obj;
a_a: A.A.Obj;
a_b: A.B.Obj;
b: B.Obj;
b_a: B.A.Obj;
b_b: B.B.Obj;
c: C.Obj;
table Table {
here: Table;
a: A.Table;
a_a: A.A.Table;
a_b: A.B.Table;
b: B.Table;
b_a: B.A.Table;
b_b: B.B.Table;
c: C.Table;
struct_here: Struct;
struct_a: A.Struct;
struct_a_a: A.A.Struct;
struct_a_b: A.B.Struct;
struct_b: B.Struct;
struct_b_a: B.A.Struct;
struct_b_b: B.B.Struct;
struct_c: C.Struct;
}

table Struct {
here: Struct;
a: A.Struct;
a_a: A.A.Struct;
a_b: A.B.Struct;
b: B.Struct;
b_a: B.A.Struct;
b_b: B.B.Struct;
c: C.Struct;
}

union Union {
Table,
A.Table,
A.A.Table,
A.B.Table,
B.Table,
B.A.Table,
B.B.Table,
C.Table
}
Loading