@@ -153,14 +153,14 @@ impl IpAddress {
153153
154154 /// Returns a raw pointer to the IP address.
155155 #[ 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 )
158158 }
159159
160160 /// Returns a raw mutable pointer to the IP address.
161161 #[ 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 )
164164 }
165165}
166166
@@ -262,11 +262,12 @@ mod tests {
262262 #[ test]
263263 fn ip_ptr ( ) {
264264 let mut ip = IpAddress :: new_v4 ( [ 0 ; 4 ] ) ;
265+ let ptr = ip. as_ptr_mut ( ) . cast :: < u8 > ( ) ;
265266 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 ) ;
270271 }
271272 unsafe { assert_eq ! ( ip. v4. octets( ) , [ 192 , 168 , 42 , 73 ] ) }
272273 }
0 commit comments