Skip to content

Commit aac536d

Browse files
object: rename CanDowncast to MayDowncastTo for clarity
CanDowncast sounds too certain to me, and made me wonder why downcast* still need to perform runtime checks if it could downcast to the type.
1 parent fedb625 commit aac536d

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

glib/src/object.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub trait Cast: ObjectType {
136136
#[inline]
137137
fn downcast<T: ObjectType>(self) -> Result<T, Self>
138138
where
139-
Self: CanDowncast<T>,
139+
Self: MayDowncastTo<T>,
140140
{
141141
if self.is::<T>() {
142142
Ok(unsafe { self.unsafe_cast() })
@@ -165,7 +165,7 @@ pub trait Cast: ObjectType {
165165
#[inline]
166166
fn downcast_ref<T: ObjectType>(&self) -> Option<&T>
167167
where
168-
Self: CanDowncast<T>,
168+
Self: MayDowncastTo<T>,
169169
{
170170
if self.is::<T>() {
171171
Some(unsafe { self.unsafe_cast_ref() })
@@ -303,10 +303,10 @@ pub trait CastNone: Sized {
303303
type Inner;
304304
fn and_downcast<T: ObjectType>(self) -> Option<T>
305305
where
306-
Self::Inner: CanDowncast<T>;
306+
Self::Inner: MayDowncastTo<T>;
307307
fn and_downcast_ref<T: ObjectType>(&self) -> Option<&T>
308308
where
309-
Self::Inner: CanDowncast<T>;
309+
Self::Inner: MayDowncastTo<T>;
310310
fn and_upcast<T: ObjectType>(self) -> Option<T>
311311
where
312312
Self::Inner: IsA<T>;
@@ -322,15 +322,15 @@ impl<I: ObjectType + Sized> CastNone for Option<I> {
322322
#[inline]
323323
fn and_downcast<T: ObjectType>(self) -> Option<T>
324324
where
325-
Self::Inner: CanDowncast<T>,
325+
Self::Inner: MayDowncastTo<T>,
326326
{
327327
self.and_then(|i| i.downcast().ok())
328328
}
329329

330330
#[inline]
331331
fn and_downcast_ref<T: ObjectType>(&self) -> Option<&T>
332332
where
333-
Self::Inner: CanDowncast<T>,
333+
Self::Inner: MayDowncastTo<T>,
334334
{
335335
self.as_ref().and_then(|i| i.downcast_ref())
336336
}
@@ -365,9 +365,9 @@ impl<I: ObjectType + Sized> CastNone for Option<I> {
365365

366366
// rustdoc-stripper-ignore-next
367367
/// Marker trait for the statically known possibility of downcasting from `Self` to `T`.
368-
pub trait CanDowncast<T> {}
368+
pub trait MayDowncastTo<T> {}
369369

370-
impl<Super: IsA<Super>, Sub: IsA<Super>> CanDowncast<Sub> for Super {}
370+
impl<Super: IsA<Super>, Sub: IsA<Super>> MayDowncastTo<Sub> for Super {}
371371

372372
// Manual implementation of glib_shared_wrapper! because of special cases
373373
#[repr(transparent)]

0 commit comments

Comments
 (0)