@@ -153,14 +153,14 @@ impl IpAddress {
153
153
154
154
/// Returns a raw pointer to the IP address.
155
155
#[ must_use]
156
- pub const fn as_ptr ( & self ) -> * const u8 {
157
- core:: ptr:: addr_of!( * self ) . cast ( )
156
+ pub const fn as_ptr ( & self ) -> * const Self {
157
+ core:: ptr:: addr_of!( * self )
158
158
}
159
159
160
160
/// Returns a raw mutable pointer to the IP address.
161
161
#[ must_use]
162
- pub fn as_ptr_mut ( & mut self ) -> * mut u8 {
163
- core:: ptr:: addr_of_mut!( * self ) . cast ( )
162
+ pub fn as_ptr_mut ( & mut self ) -> * mut Self {
163
+ core:: ptr:: addr_of_mut!( * self )
164
164
}
165
165
}
166
166
@@ -262,11 +262,12 @@ mod tests {
262
262
#[ test]
263
263
fn ip_ptr ( ) {
264
264
let mut ip = IpAddress :: new_v4 ( [ 0 ; 4 ] ) ;
265
+ let ptr = ip. as_ptr_mut ( ) . cast :: < u8 > ( ) ;
265
266
unsafe {
266
- core:: ptr:: write ( ip . as_ptr_mut ( ) , 192 ) ;
267
- core:: ptr:: write ( ip . as_ptr_mut ( ) . add ( 1 ) , 168 ) ;
268
- core:: ptr:: write ( ip . as_ptr_mut ( ) . add ( 2 ) , 42 ) ;
269
- core:: ptr:: write ( ip . as_ptr_mut ( ) . add ( 3 ) , 73 ) ;
267
+ core:: ptr:: write ( ptr , 192 ) ;
268
+ core:: ptr:: write ( ptr . add ( 1 ) , 168 ) ;
269
+ core:: ptr:: write ( ptr . add ( 2 ) , 42 ) ;
270
+ core:: ptr:: write ( ptr . add ( 3 ) , 73 ) ;
270
271
}
271
272
unsafe { assert_eq ! ( ip. v4. octets( ) , [ 192 , 168 , 42 , 73 ] ) }
272
273
}
0 commit comments