@@ -122,10 +122,9 @@ pub trait Cast: ObjectType {
122
122
/// Returns `Ok(T)` if the object is an instance of `T` and `Err(self)`
123
123
/// otherwise.
124
124
///
125
- /// *NOTE*: This statically checks at compile-time if casting is possible. It is not always
126
- /// known at compile-time, whether a specific object implements an interface or not, in which case
127
- /// `upcast` would fail to compile. `dynamic_cast` can be used in these circumstances, which
128
- /// is checking the types at runtime.
125
+ /// *NOTE*: This will check at compile-time if `T` is lower down the
126
+ /// inheritance tree of `Self`, but also check at runtime if downcasting
127
+ /// is indeed possible.
129
128
///
130
129
/// # Example
131
130
///
@@ -137,7 +136,7 @@ pub trait Cast: ObjectType {
137
136
#[ inline]
138
137
fn downcast < T : ObjectType > ( self ) -> Result < T , Self >
139
138
where
140
- Self : CanDowncast < T > ,
139
+ Self : MayDowncastTo < T > ,
141
140
{
142
141
if self . is :: < T > ( ) {
143
142
Ok ( unsafe { self . unsafe_cast ( ) } )
@@ -152,10 +151,9 @@ pub trait Cast: ObjectType {
152
151
/// Returns `Some(T)` if the object is an instance of `T` and `None`
153
152
/// otherwise.
154
153
///
155
- /// *NOTE*: This statically checks at compile-time if casting is possible. It is not always
156
- /// known at compile-time, whether a specific object implements an interface or not, in which case
157
- /// `upcast` would fail to compile. `dynamic_cast` can be used in these circumstances, which
158
- /// is checking the types at runtime.
154
+ /// *NOTE*: This will check at compile-time if `T` is lower down the
155
+ /// inheritance tree of `Self`, but also check at runtime if downcasting
156
+ /// is indeed possible.
159
157
///
160
158
/// # Example
161
159
///
@@ -167,7 +165,7 @@ pub trait Cast: ObjectType {
167
165
#[ inline]
168
166
fn downcast_ref < T : ObjectType > ( & self ) -> Option < & T >
169
167
where
170
- Self : CanDowncast < T > ,
168
+ Self : MayDowncastTo < T > ,
171
169
{
172
170
if self . is :: < T > ( ) {
173
171
Some ( unsafe { self . unsafe_cast_ref ( ) } )
@@ -179,7 +177,9 @@ pub trait Cast: ObjectType {
179
177
// rustdoc-stripper-ignore-next
180
178
/// Tries to cast to an object of type `T`. This handles upcasting, downcasting
181
179
/// and casting between interface and interface implementors. All checks are performed at
182
- /// runtime, while `downcast` and `upcast` will do many checks at compile-time already.
180
+ /// runtime, while `upcast` will do many checks at compile-time already. `downcast` will
181
+ /// perform the same checks at runtime as `dynamic_cast`, but will also ensure some amount of
182
+ /// compile-time safety.
183
183
///
184
184
/// It is not always known at compile-time, whether a specific object implements an interface or
185
185
/// not, and checking has to be performed at runtime.
@@ -303,10 +303,10 @@ pub trait CastNone: Sized {
303
303
type Inner ;
304
304
fn and_downcast < T : ObjectType > ( self ) -> Option < T >
305
305
where
306
- Self :: Inner : CanDowncast < T > ;
306
+ Self :: Inner : MayDowncastTo < T > ;
307
307
fn and_downcast_ref < T : ObjectType > ( & self ) -> Option < & T >
308
308
where
309
- Self :: Inner : CanDowncast < T > ;
309
+ Self :: Inner : MayDowncastTo < T > ;
310
310
fn and_upcast < T : ObjectType > ( self ) -> Option < T >
311
311
where
312
312
Self :: Inner : IsA < T > ;
@@ -322,15 +322,15 @@ impl<I: ObjectType + Sized> CastNone for Option<I> {
322
322
#[ inline]
323
323
fn and_downcast < T : ObjectType > ( self ) -> Option < T >
324
324
where
325
- Self :: Inner : CanDowncast < T > ,
325
+ Self :: Inner : MayDowncastTo < T > ,
326
326
{
327
327
self . and_then ( |i| i. downcast ( ) . ok ( ) )
328
328
}
329
329
330
330
#[ inline]
331
331
fn and_downcast_ref < T : ObjectType > ( & self ) -> Option < & T >
332
332
where
333
- Self :: Inner : CanDowncast < T > ,
333
+ Self :: Inner : MayDowncastTo < T > ,
334
334
{
335
335
self . as_ref ( ) . and_then ( |i| i. downcast_ref ( ) )
336
336
}
@@ -365,9 +365,9 @@ impl<I: ObjectType + Sized> CastNone for Option<I> {
365
365
366
366
// rustdoc-stripper-ignore-next
367
367
/// Marker trait for the statically known possibility of downcasting from `Self` to `T`.
368
- pub trait CanDowncast < T > { }
368
+ pub trait MayDowncastTo < T > { }
369
369
370
- impl < Super : IsA < Super > , Sub : IsA < Super > > CanDowncast < Sub > for Super { }
370
+ impl < Super : IsA < Super > , Sub : IsA < Super > > MayDowncastTo < Sub > for Super { }
371
371
372
372
// Manual implementation of glib_shared_wrapper! because of special cases
373
373
#[ repr( transparent) ]
0 commit comments