@@ -7,7 +7,7 @@ use crate::encode::{Encoding, RefEncode};
7
7
use crate :: rc:: { autoreleasepool_leaking, Id } ;
8
8
use crate :: runtime:: __nsstring:: nsstring_to_str;
9
9
use crate :: runtime:: { AnyObject , NSObjectProtocol } ;
10
- use crate :: { Message , ProtocolType } ;
10
+ use crate :: Message ;
11
11
12
12
/// An internal helper trait for [`ProtocolObject`].
13
13
///
@@ -57,25 +57,25 @@ pub unsafe trait ImplementedBy<T: ?Sized + Message> {
57
57
/// ```
58
58
#[ doc( alias = "id" ) ]
59
59
#[ repr( C ) ]
60
- pub struct ProtocolObject < P : ?Sized + ProtocolType > {
60
+ pub struct ProtocolObject < P : ?Sized > {
61
61
inner : AnyObject ,
62
62
p : PhantomData < P > ,
63
63
}
64
64
65
65
// SAFETY: The type is `#[repr(C)]` and `AnyObject` internally
66
- unsafe impl < P : ?Sized + ProtocolType > RefEncode for ProtocolObject < P > {
66
+ unsafe impl < P : ?Sized > RefEncode for ProtocolObject < P > {
67
67
const ENCODING_REF : Encoding = Encoding :: Object ;
68
68
}
69
69
70
70
// SAFETY: The type is `AnyObject` internally, and is mean to be messaged
71
71
// as-if it's an object.
72
- unsafe impl < P : ?Sized + ProtocolType > Message for ProtocolObject < P > { }
72
+ unsafe impl < P : ?Sized > Message for ProtocolObject < P > { }
73
73
74
- impl < P : ?Sized + ProtocolType > ProtocolObject < P > {
74
+ impl < P : ?Sized > ProtocolObject < P > {
75
75
/// Get an immutable type-erased reference from a type implementing a
76
76
/// protocol.
77
77
#[ inline]
78
- pub fn from_ref < T : Message > ( obj : & T ) -> & Self
78
+ pub fn from_ref < T : ? Sized + Message > ( obj : & T ) -> & Self
79
79
where
80
80
P : ImplementedBy < T > ,
81
81
{
@@ -89,7 +89,7 @@ impl<P: ?Sized + ProtocolType> ProtocolObject<P> {
89
89
/// Get a mutable type-erased reference from a type implementing a
90
90
/// protocol.
91
91
#[ inline]
92
- pub fn from_mut < T : Message > ( obj : & mut T ) -> & mut Self
92
+ pub fn from_mut < T : ? Sized + Message > ( obj : & mut T ) -> & mut Self
93
93
where
94
94
P : ImplementedBy < T > ,
95
95
{
@@ -118,24 +118,24 @@ impl<P: ?Sized + ProtocolType> ProtocolObject<P> {
118
118
}
119
119
}
120
120
121
- impl < P : ?Sized + ProtocolType + NSObjectProtocol > PartialEq for ProtocolObject < P > {
121
+ impl < P : ?Sized + NSObjectProtocol > PartialEq for ProtocolObject < P > {
122
122
#[ inline]
123
123
#[ doc( alias = "isEqual:" ) ]
124
124
fn eq ( & self , other : & Self ) -> bool {
125
125
self . __isEqual ( other)
126
126
}
127
127
}
128
128
129
- impl < P : ?Sized + ProtocolType + NSObjectProtocol > Eq for ProtocolObject < P > { }
129
+ impl < P : ?Sized + NSObjectProtocol > Eq for ProtocolObject < P > { }
130
130
131
- impl < P : ?Sized + ProtocolType + NSObjectProtocol > hash:: Hash for ProtocolObject < P > {
131
+ impl < P : ?Sized + NSObjectProtocol > hash:: Hash for ProtocolObject < P > {
132
132
#[ inline]
133
133
fn hash < H : hash:: Hasher > ( & self , state : & mut H ) {
134
134
self . __hash ( ) . hash ( state) ;
135
135
}
136
136
}
137
137
138
- impl < P : ?Sized + ProtocolType + NSObjectProtocol > fmt:: Debug for ProtocolObject < P > {
138
+ impl < P : ?Sized + NSObjectProtocol > fmt:: Debug for ProtocolObject < P > {
139
139
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
140
140
// Attempt to format description string
141
141
if let Some ( description) = self . __description ( ) {
@@ -159,29 +159,27 @@ impl<P: ?Sized + ProtocolType + NSObjectProtocol> fmt::Debug for ProtocolObject<
159
159
}
160
160
}
161
161
162
- impl < P , T > AsRef < ProtocolObject < T > > for ProtocolObject < P >
162
+ impl < P : ? Sized , T > AsRef < ProtocolObject < T > > for ProtocolObject < P >
163
163
where
164
- P : ?Sized + ProtocolType ,
165
- T : ?Sized + ProtocolType + ImplementedBy < ProtocolObject < P > > ,
164
+ T : ?Sized + ImplementedBy < ProtocolObject < P > > ,
166
165
{
167
166
#[ inline]
168
167
fn as_ref ( & self ) -> & ProtocolObject < T > {
169
168
ProtocolObject :: from_ref ( self )
170
169
}
171
170
}
172
171
173
- impl < P , T > AsMut < ProtocolObject < T > > for ProtocolObject < P >
172
+ impl < P : ? Sized , T > AsMut < ProtocolObject < T > > for ProtocolObject < P >
174
173
where
175
- P : ?Sized + ProtocolType ,
176
- T : ?Sized + ProtocolType + ImplementedBy < ProtocolObject < P > > ,
174
+ T : ?Sized + ImplementedBy < ProtocolObject < P > > ,
177
175
{
178
176
#[ inline]
179
177
fn as_mut ( & mut self ) -> & mut ProtocolObject < T > {
180
178
ProtocolObject :: from_mut ( self )
181
179
}
182
180
}
183
181
184
- // TODO: Maybe iplement Borrow + BorrowMut?
182
+ // TODO: Maybe implement Borrow + BorrowMut?
185
183
186
184
#[ cfg( test) ]
187
185
#[ allow( clippy:: missing_safety_doc) ]
@@ -194,7 +192,9 @@ mod tests {
194
192
use super :: * ;
195
193
use crate :: mutability:: Mutable ;
196
194
use crate :: runtime:: { NSObject , NSObjectProtocol } ;
197
- use crate :: { declare_class, extern_methods, extern_protocol, ClassType , DeclaredClass } ;
195
+ use crate :: {
196
+ declare_class, extern_methods, extern_protocol, ClassType , DeclaredClass , ProtocolType ,
197
+ } ;
198
198
199
199
extern_protocol ! (
200
200
unsafe trait Foo {
0 commit comments