/// Helper for ensuring that `ClassType::ThreadKind`, if specified, is set /// correctly. pubtrait ValidThreadKind<Requested: ?Sized + ThreadKind> where Self: ClassType<ThreadKind = Requested>, // Ensure the user did not attempt to declare or define a root class. Self::Super: ClassType,
{ // Required to reference the trait. fn check() {}
}
/// But restrict `AnyThread` to only if the superclass also sets it. impl<'a, 'b, Cls> ValidThreadKind<dyn AnyThread + 'a> for Cls where Self: ClassType<ThreadKind = dyn AnyThread + 'a>, Self::Super: ClassType<ThreadKind = dyn AnyThread + 'b>,
{
}
/// Check that `MainThreadOnly` types do not implement `Send` and `Sync`. /// /// Check implemented using type inference: /// let _ = <MyType as MainThreadOnlyDoesNotImplSendSync<_>>::check pubtrait MainThreadOnlyDoesNotImplSendSync<Inferred> { // Required to reference the trait. fn check() {}
}
// Type inference will find this blanket impl... impl<Cls: ?Sized> MainThreadOnlyDoesNotImplSendSync<()> for Cls {}
// ... unless one of these impls also apply, then type inference fails. struct ImplsSend; impl<Cls: ?Sized + MainThreadOnly + Send> MainThreadOnlyDoesNotImplSendSync<ImplsSend> for Cls {}
/// Check that class does not implement `Drop`. /// /// This is not needed for soundness, it's just a nice footgun to avoid (since /// it wouldn't ever get called). /// /// Check implemented using type inference: /// let _ = <MyType as DoesNotImplDrop<_>>::check pubtrait DoesNotImplDrop<Inferred> { // Required to reference the trait. fn check() {}
}
// Type inference will find this blanket impl... impl<Cls: ?Sized> DoesNotImplDrop<()> for Cls {}
// ... unless this impl also applies, then type inference fails. struct ImplsDrop; #[allow(drop_bounds)] // We're intentionally using `Drop` as a bound. impl<Cls: ?Sized + Drop> DoesNotImplDrop<ImplsDrop> for Cls {}
#[cfg(test)] mod tests { usesuper::*; usecrate::extern_class; usecrate::runtime::NSObject;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.