diff --git a/shed/fbthrift_ext/adapters/lib.rs b/shed/fbthrift_ext/adapters/lib.rs index 49ee3bc3c..b7a57e971 100644 --- a/shed/fbthrift_ext/adapters/lib.rs +++ b/shed/fbthrift_ext/adapters/lib.rs @@ -121,5 +121,8 @@ pub use crate::redacted::RedactedAdapter; pub use crate::socket_addr::SocketAddrAdapter; #[doc(inline)] pub use crate::unsigned_int::UnsignedIntAdapter; +#[cfg(target_pointer_width = "64")] +#[doc(inline)] +pub use crate::unsigned_int::UsizeAdapter; #[doc(inline)] pub use crate::uuid::UuidAdapter; diff --git a/shed/fbthrift_ext/adapters/unsigned_int.rs b/shed/fbthrift_ext/adapters/unsigned_int.rs index daffda12f..1fa1d6dbf 100644 --- a/shed/fbthrift_ext/adapters/unsigned_int.rs +++ b/shed/fbthrift_ext/adapters/unsigned_int.rs @@ -30,8 +30,8 @@ use fbthrift::adapter::ThriftAdapter; pub struct UnsignedIntAdapter(PhantomData); macro_rules! unsigned_int_adapter { - ($thrift:ty, $rust:ty) => { - impl ThriftAdapter for UnsignedIntAdapter<$thrift> { + ($thrift:ty, $rust:ty, $adapter:ty) => { + impl ThriftAdapter for $adapter { type StandardType = $thrift; type AdaptedType = $rust; type Error = std::convert::Infallible; @@ -47,7 +47,27 @@ macro_rules! unsigned_int_adapter { }; } -unsigned_int_adapter!(i8, u8); -unsigned_int_adapter!(i16, u16); -unsigned_int_adapter!(i32, u32); -unsigned_int_adapter!(i64, u64); +unsigned_int_adapter!(i8, u8, UnsignedIntAdapter); +unsigned_int_adapter!(i16, u16, UnsignedIntAdapter); +unsigned_int_adapter!(i32, u32, UnsignedIntAdapter); +unsigned_int_adapter!(i64, u64, UnsignedIntAdapter); + +#[cfg(target_pointer_width = "64")] +/// Adapts the platform-appropriate signed Thrift integer type to `usize` +/// +/// # Examples +/// +/// ```thrift +/// include "thrift/annotation/rust.thrift"; +/// +/// @rust.Adapter{name = "::fbthrift_adapters::UsizeAdapter"} +/// typedef i64 Usize; +/// +/// struct Parameters { +/// 1: Usize my_param; +/// } +/// ``` +pub struct UsizeAdapter(PhantomData); + +#[cfg(target_pointer_width = "64")] +unsigned_int_adapter!(i64, usize, UsizeAdapter);