-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: idl map type with const enum (#262)
* fix: idl map type with const enum * update test case * rm useless clone for const or temporary var in map * fix: faststr can use from_static_str to get const var * rm useless clone for vec * rm unused clone in map * increase version
- Loading branch information
1 parent
e1b3ec2
commit 21efbba
Showing
5 changed files
with
147 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
pub mod enum_map { | ||
#![allow(warnings, clippy::all)] | ||
|
||
pub mod enum_map { | ||
#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] | ||
pub struct TypeB(pub i32); | ||
|
||
impl ::std::ops::Deref for TypeB { | ||
type Target = i32; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl From<i32> for TypeB { | ||
fn from(v: i32) -> Self { | ||
Self(v) | ||
} | ||
} | ||
|
||
impl ::pilota::thrift::Message for TypeB { | ||
fn encode<T: ::pilota::thrift::TOutputProtocol>( | ||
&self, | ||
__protocol: &mut T, | ||
) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { | ||
#[allow(unused_imports)] | ||
use ::pilota::thrift::TOutputProtocolExt; | ||
__protocol.write_i32(*(&**self))?; | ||
::std::result::Result::Ok(()) | ||
} | ||
|
||
fn decode<T: ::pilota::thrift::TInputProtocol>( | ||
__protocol: &mut T, | ||
) -> ::std::result::Result<Self, ::pilota::thrift::ThriftException> { | ||
#[allow(unused_imports)] | ||
use ::pilota::{thrift::TLengthProtocolExt, Buf}; | ||
::std::result::Result::Ok(TypeB(__protocol.read_i32()?)) | ||
} | ||
|
||
fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( | ||
__protocol: &'a mut T, | ||
) -> ::std::pin::Pin< | ||
::std::boxed::Box< | ||
dyn ::std::future::Future< | ||
Output = ::std::result::Result<Self, ::pilota::thrift::ThriftException>, | ||
> + Send | ||
+ 'a, | ||
>, | ||
> { | ||
::std::boxed::Box::pin(async move { | ||
::std::result::Result::Ok(TypeB(__protocol.read_i32().await?)) | ||
}) | ||
} | ||
|
||
fn size<T: ::pilota::thrift::TLengthProtocol>(&self, __protocol: &mut T) -> usize { | ||
#[allow(unused_imports)] | ||
use ::pilota::thrift::TLengthProtocolExt; | ||
__protocol.i32_len(*&**self) | ||
} | ||
} | ||
pub const TYPE_A2: TypeA = TypeA(::pilota::FastStr::from_static_str("a2")); | ||
pub const TYPE_B2: TypeB = TypeB(2i32); | ||
pub const TYPE_A1: TypeA = TypeA(::pilota::FastStr::from_static_str("a1")); | ||
pub const TYPE_B1: TypeB = TypeB(1i32); | ||
::pilota::lazy_static::lazy_static! { | ||
pub static ref TYPE_A_MAP: ::pilota::AHashMap<TypeB, TypeA> = { | ||
let mut map = ::pilota::AHashMap::with_capacity(2); | ||
map.insert(TYPE_B1, TYPE_A1);map.insert(TYPE_B2, TYPE_A2); | ||
map | ||
}; | ||
} | ||
#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] | ||
pub struct TypeA(pub ::pilota::FastStr); | ||
|
||
impl ::std::ops::Deref for TypeA { | ||
type Target = ::pilota::FastStr; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl From<::pilota::FastStr> for TypeA { | ||
fn from(v: ::pilota::FastStr) -> Self { | ||
Self(v) | ||
} | ||
} | ||
|
||
impl ::pilota::thrift::Message for TypeA { | ||
fn encode<T: ::pilota::thrift::TOutputProtocol>( | ||
&self, | ||
__protocol: &mut T, | ||
) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { | ||
#[allow(unused_imports)] | ||
use ::pilota::thrift::TOutputProtocolExt; | ||
__protocol.write_faststr((&**self).clone())?; | ||
::std::result::Result::Ok(()) | ||
} | ||
|
||
fn decode<T: ::pilota::thrift::TInputProtocol>( | ||
__protocol: &mut T, | ||
) -> ::std::result::Result<Self, ::pilota::thrift::ThriftException> { | ||
#[allow(unused_imports)] | ||
use ::pilota::{thrift::TLengthProtocolExt, Buf}; | ||
::std::result::Result::Ok(TypeA(__protocol.read_faststr()?)) | ||
} | ||
|
||
fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( | ||
__protocol: &'a mut T, | ||
) -> ::std::pin::Pin< | ||
::std::boxed::Box< | ||
dyn ::std::future::Future< | ||
Output = ::std::result::Result<Self, ::pilota::thrift::ThriftException>, | ||
> + Send | ||
+ 'a, | ||
>, | ||
> { | ||
::std::boxed::Box::pin(async move { | ||
::std::result::Result::Ok(TypeA(__protocol.read_faststr().await?)) | ||
}) | ||
} | ||
|
||
fn size<T: ::pilota::thrift::TLengthProtocol>(&self, __protocol: &mut T) -> usize { | ||
#[allow(unused_imports)] | ||
use ::pilota::thrift::TLengthProtocolExt; | ||
__protocol.faststr_len(&**self) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
typedef i32 TypeB | ||
|
||
const TypeB TypeB1 = 1 | ||
const TypeB TypeB2 = 2 | ||
|
||
typedef string TypeA | ||
|
||
const TypeA TypeA1 = "a1" | ||
const TypeA TypeA2 = "a2" | ||
|
||
const map<TypeB, TypeA> TypeAMap = { | ||
TypeB1: TypeA1, | ||
TypeB2: TypeA2, | ||
} |