Skip to content

Commit fedb625

Browse files
object: address misleading casting docs
The NOTE in the downcast* docs was lifted from upcast and incorrect, and the dynamic_cast doc gave the impression that downcast* would perform fewer runtime checks.
1 parent 1fddbfd commit fedb625

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

glib/src/object.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,9 @@ pub trait Cast: ObjectType {
122122
/// Returns `Ok(T)` if the object is an instance of `T` and `Err(self)`
123123
/// otherwise.
124124
///
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.
129128
///
130129
/// # Example
131130
///
@@ -152,10 +151,9 @@ pub trait Cast: ObjectType {
152151
/// Returns `Some(T)` if the object is an instance of `T` and `None`
153152
/// otherwise.
154153
///
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.
159157
///
160158
/// # Example
161159
///
@@ -179,7 +177,9 @@ pub trait Cast: ObjectType {
179177
// rustdoc-stripper-ignore-next
180178
/// Tries to cast to an object of type `T`. This handles upcasting, downcasting
181179
/// 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.
183183
///
184184
/// It is not always known at compile-time, whether a specific object implements an interface or
185185
/// not, and checking has to be performed at runtime.

0 commit comments

Comments
 (0)