@@ -143,10 +143,7 @@ pub trait NativePType:
143143 fn is_eq ( self , other : Self ) -> bool ;
144144
145145 /// Downcast the provided object to a type-specific instance.
146- fn downcast < V : PTypeDowncast + ?Sized > ( visitor : & V ) -> V :: Output < Self > ;
147-
148- /// Downcast the provided object to a type-specific instance.
149- fn downcast_mut < V : PTypeDowncastMut + ?Sized > ( visitor : & mut V ) -> V :: Output < Self > ;
146+ fn downcast < V : PTypeDowncast > ( visitor : V ) -> V :: Output < Self > ;
150147
151148 /// Upcast a type-specific instance to a generic instance.
152149 fn upcast < V : PTypeUpcast > ( input : V :: Input < Self > ) -> V ;
@@ -157,65 +154,37 @@ pub trait NativePType:
157154pub trait PTypeDowncast {
158155 type Output < T : NativePType > ;
159156
160- fn as_u8 ( & self ) -> Self :: Output < u8 > ;
161- fn as_u16 ( & self ) -> Self :: Output < u16 > ;
162- fn as_u32 ( & self ) -> Self :: Output < u32 > ;
163- fn as_u64 ( & self ) -> Self :: Output < u64 > ;
164- fn as_i8 ( & self ) -> Self :: Output < i8 > ;
165- fn as_i16 ( & self ) -> Self :: Output < i16 > ;
166- fn as_i32 ( & self ) -> Self :: Output < i32 > ;
167- fn as_i64 ( & self ) -> Self :: Output < i64 > ;
168- fn as_f16 ( & self ) -> Self :: Output < f16 > ;
169- fn as_f32 ( & self ) -> Self :: Output < f32 > ;
170- fn as_f64 ( & self ) -> Self :: Output < f64 > ;
157+ fn into_u8 ( self ) -> Self :: Output < u8 > ;
158+ fn into_u16 ( self ) -> Self :: Output < u16 > ;
159+ fn into_u32 ( self ) -> Self :: Output < u32 > ;
160+ fn into_u64 ( self ) -> Self :: Output < u64 > ;
161+ fn into_i8 ( self ) -> Self :: Output < i8 > ;
162+ fn into_i16 ( self ) -> Self :: Output < i16 > ;
163+ fn into_i32 ( self ) -> Self :: Output < i32 > ;
164+ fn into_i64 ( self ) -> Self :: Output < i64 > ;
165+ fn into_f16 ( self ) -> Self :: Output < f16 > ;
166+ fn into_f32 ( self ) -> Self :: Output < f32 > ;
167+ fn into_f64 ( self ) -> Self :: Output < f64 > ;
171168}
172169
173170/// Extension trait to provide generic downcasting for [`PTypeDowncast`].
174171pub trait PTypeDowncastExt : PTypeDowncast {
175172 /// Downcast the object to a specific primitive type.
176- fn as_primitive < T : NativePType > ( & self ) -> Self :: Output < T > {
173+ fn into_primitive < T : NativePType > ( self ) -> Self :: Output < T >
174+ where
175+ Self : Sized ,
176+ {
177177 T :: downcast ( self )
178178 }
179179}
180180
181- impl < T : PTypeDowncast + ?Sized > PTypeDowncastExt for T { }
182-
183- /// A visitor trait for converting a `NativePType` to another mutable parameterized type.
184- #[ allow( missing_docs) ] // Kind of obvious..
185- pub trait PTypeDowncastMut {
186- type Output < T : NativePType > ;
187-
188- fn as_u8 ( & mut self ) -> Self :: Output < u8 > ;
189- fn as_u16 ( & mut self ) -> Self :: Output < u16 > ;
190- fn as_u32 ( & mut self ) -> Self :: Output < u32 > ;
191- fn as_u64 ( & mut self ) -> Self :: Output < u64 > ;
192- fn as_i8 ( & mut self ) -> Self :: Output < i8 > ;
193- fn as_i16 ( & mut self ) -> Self :: Output < i16 > ;
194- fn as_i32 ( & mut self ) -> Self :: Output < i32 > ;
195- fn as_i64 ( & mut self ) -> Self :: Output < i64 > ;
196- fn as_f16 ( & mut self ) -> Self :: Output < f16 > ;
197- fn as_f32 ( & mut self ) -> Self :: Output < f32 > ;
198- fn as_f64 ( & mut self ) -> Self :: Output < f64 > ;
199- }
200-
201- /// Extension trait to provide generic downcasting for [`PTypeDowncastMut`].
202- pub trait PTypeDowncastMutExt : PTypeDowncastMut {
203- /// Downcast the object to a specific primitive type.
204- fn as_primitive_mut < T : NativePType > ( & mut self ) -> Self :: Output < T > {
205- T :: downcast_mut ( self )
206- }
207- }
181+ impl < T : PTypeDowncast > PTypeDowncastExt for T { }
208182
209183macro_rules! impl_ptype_downcast {
210184 ( $T: ty) => {
211185 #[ inline]
212- fn downcast<V : PTypeDowncast + ?Sized >( visitor: & V ) -> V :: Output <Self > {
213- paste:: paste! { visitor. [ <as_ $T>] ( ) }
214- }
215-
216- #[ inline]
217- fn downcast_mut<V : PTypeDowncastMut + ?Sized >( visitor: & mut V ) -> V :: Output <Self > {
218- paste:: paste! { visitor. [ <as_ $T>] ( ) }
186+ fn downcast<V : PTypeDowncast >( visitor: V ) -> V :: Output <Self > {
187+ paste:: paste! { visitor. [ <into_ $T>] ( ) }
219188 }
220189
221190 #[ inline]
@@ -279,8 +248,6 @@ macro_rules! native_ptype {
279248 } ;
280249}
281250
282- impl < T : PTypeDowncastMut + ?Sized > PTypeDowncastMutExt for T { }
283-
284251macro_rules! native_float_ptype {
285252 ( $T: ty, $ptype: tt) => {
286253 impl crate :: NativeDType for $T {
0 commit comments