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(pilota_build): idl enum should implement the From<NewType> trait for inner type #235

Merged
merged 2 commits into from
Apr 1, 2024
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
11 changes: 10 additions & 1 deletion pilota-build/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,15 @@ where
fn from(value: {repr}) -> Self {{
Self(value)
}}
}}"#
}}

impl ::std::convert::From<{name}> for {repr} {{
fn from(value: {name}) -> {repr} {{
value.0
}}
}}

"#
});

self.backend.codegen_enum_impl(def_id, stream, e);
Expand Down Expand Up @@ -406,6 +414,7 @@ where
Self(v)
}}
}}

"#
});
self.backend.codegen_newtype_impl(def_id, stream, t);
Expand Down
7 changes: 7 additions & 0 deletions pilota-build/test_data/plugin/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ pub mod serde {
Self(value)
}
}

impl ::std::convert::From<C> for i32 {
fn from(value: C) -> i32 {
value.0
}
}

impl ::pilota::thrift::Message for C {
fn encode<T: ::pilota::thrift::TOutputProtocol>(
&self,
Expand Down
7 changes: 7 additions & 0 deletions pilota-build/test_data/protobuf/nested_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ pub mod nested_message {
Self(value)
}
}

impl ::std::convert::From<Label> for i32 {
fn from(value: Label) -> i32 {
value.0
}
}

#[derive(Debug, Default, Clone, PartialEq)]
pub struct T2 {
pub t3: t2::Tt3,
Expand Down
7 changes: 7 additions & 0 deletions pilota-build/test_data/thrift/const_val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ pub mod const_val {
Self(value)
}
}

impl ::std::convert::From<Index> for i32 {
fn from(value: Index) -> i32 {
value.0
}
}

impl ::pilota::thrift::Message for Index {
fn encode<T: ::pilota::thrift::TOutputProtocol>(
&self,
Expand Down
7 changes: 7 additions & 0 deletions pilota-build/test_data/thrift/default_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ pub mod default_value {
Self(value)
}
}

impl ::std::convert::From<B> for i32 {
fn from(value: B) -> i32 {
value.0
}
}

impl ::pilota::thrift::Message for B {
fn encode<T: ::pilota::thrift::TOutputProtocol>(
&self,
Expand Down
7 changes: 7 additions & 0 deletions pilota-build/test_data/thrift/enum_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ pub mod enum_test {
Self(value)
}
}

impl ::std::convert::From<Index> for i32 {
fn from(value: Index) -> i32 {
value.0
}
}

impl ::pilota::thrift::Message for Index {
fn encode<T: ::pilota::thrift::TOutputProtocol>(
&self,
Expand Down
7 changes: 7 additions & 0 deletions pilota-build/test_data/thrift/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,13 @@ pub mod multi {
Self(value)
}
}

impl ::std::convert::From<B> for i32 {
fn from(value: B) -> i32 {
value.0
}
}

impl ::pilota::thrift::Message for B {
fn encode<T: ::pilota::thrift::TOutputProtocol>(
&self,
Expand Down
7 changes: 7 additions & 0 deletions pilota-build/test_data/thrift/pilota_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,13 @@ pub mod pilota_name {
Self(value)
}
}

impl ::std::convert::From<Index> for i32 {
fn from(value: Index) -> i32 {
value.0
}
}

impl ::pilota::thrift::Message for Index {
fn encode<T: ::pilota::thrift::TOutputProtocol>(
&self,
Expand Down
7 changes: 7 additions & 0 deletions pilota-build/test_data/thrift/self_kw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ pub mod self_kw {
Self(value)
}
}

impl ::std::convert::From<Index> for i32 {
fn from(value: Index) -> i32 {
value.0
}
}

impl ::pilota::thrift::Message for Index {
fn encode<T: ::pilota::thrift::TOutputProtocol>(
&self,
Expand Down
7 changes: 7 additions & 0 deletions pilota-build/test_data/unknown_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2591,6 +2591,13 @@ pub mod unknown_fields {
Self(value)
}
}

impl ::std::convert::From<Index> for i32 {
fn from(value: Index) -> i32 {
value.0
}
}

impl ::pilota::thrift::Message for Index {
fn encode<T: ::pilota::thrift::TOutputProtocol>(
&self,
Expand Down
Loading