11// Copyright (c) 2022-present INESC-ID.
22// Distributed under the MIT license that can be found in the LICENSE file.
33
4- use crate :: { ByteRepr , In6Addr , InAddr , Ptr , Record , Value } ;
4+ use crate :: { ByteRepr , DeepClone , In6Addr , InAddr , Ptr , Record , Value } ;
55use std:: cell:: RefCell ;
66use std:: rc:: Rc ;
77
88// The fields are at the offsets of the byte representation below.
9- #[ derive( Record , ByteRepr ) ]
9+ #[ derive( DeepClone , Record , ByteRepr ) ]
1010#[ byte_size( 16 ) ]
1111pub struct Sockaddr {
1212 #[ offset( 0 ) ]
@@ -16,7 +16,7 @@ pub struct Sockaddr {
1616 pub sa_data : Value < Box < [ u8 ] > > ,
1717}
1818
19- #[ derive( Record , ByteRepr ) ]
19+ #[ derive( DeepClone , Record , ByteRepr ) ]
2020#[ byte_size( 16 ) ]
2121pub struct SockaddrIn {
2222 #[ offset( 0 ) ]
@@ -30,7 +30,7 @@ pub struct SockaddrIn {
3030 pub sin_zero : Value < Box < [ u8 ] > > ,
3131}
3232
33- #[ derive( Default , Record , ByteRepr ) ]
33+ #[ derive( Clone , Default , Record , ByteRepr ) ]
3434#[ byte_size( 28 ) ]
3535pub struct SockaddrIn6 {
3636 #[ offset( 0 ) ]
@@ -45,7 +45,7 @@ pub struct SockaddrIn6 {
4545 pub sin6_scope_id : u32 ,
4646}
4747
48- #[ derive( Record , ByteRepr ) ]
48+ #[ derive( DeepClone , Record , ByteRepr ) ]
4949#[ byte_size( 110 ) ]
5050pub struct SockaddrUn {
5151 #[ offset( 0 ) ]
@@ -55,7 +55,7 @@ pub struct SockaddrUn {
5555 pub sun_path : Value < Box < [ u8 ] > > ,
5656}
5757
58- #[ derive( Record , ByteRepr ) ]
58+ #[ derive( DeepClone , Record , ByteRepr ) ]
5959#[ byte_size( 128 ) ]
6060pub struct SockaddrStorage {
6161 #[ offset( 0 ) ]
@@ -222,56 +222,6 @@ impl Default for SockaddrStorage {
222222 }
223223}
224224
225- impl Clone for Sockaddr {
226- fn clone ( & self ) -> Self {
227- Self {
228- sa_family : self . sa_family ,
229- sa_data : Rc :: new ( RefCell :: new ( self . sa_data . borrow ( ) . clone ( ) ) ) ,
230- }
231- }
232- }
233-
234- impl Clone for SockaddrIn {
235- fn clone ( & self ) -> Self {
236- Self {
237- sin_family : self . sin_family ,
238- sin_port : self . sin_port ,
239- sin_addr : self . sin_addr . clone ( ) ,
240- sin_zero : Rc :: new ( RefCell :: new ( self . sin_zero . borrow ( ) . clone ( ) ) ) ,
241- }
242- }
243- }
244-
245- impl Clone for SockaddrIn6 {
246- fn clone ( & self ) -> Self {
247- Self {
248- sin6_family : self . sin6_family ,
249- sin6_port : self . sin6_port ,
250- sin6_flowinfo : self . sin6_flowinfo ,
251- sin6_addr : self . sin6_addr . clone ( ) ,
252- sin6_scope_id : self . sin6_scope_id ,
253- }
254- }
255- }
256-
257- impl Clone for SockaddrUn {
258- fn clone ( & self ) -> Self {
259- Self {
260- sun_family : self . sun_family ,
261- sun_path : Rc :: new ( RefCell :: new ( self . sun_path . borrow ( ) . clone ( ) ) ) ,
262- }
263- }
264- }
265-
266- impl Clone for SockaddrStorage {
267- fn clone ( & self ) -> Self {
268- Self {
269- ss_family : self . ss_family ,
270- __pad : Rc :: new ( RefCell :: new ( self . __pad . borrow ( ) . clone ( ) ) ) ,
271- }
272- }
273- }
274-
275225impl ByteRepr for :: libc:: sockaddr { }
276226impl ByteRepr for :: libc:: sockaddr_in { }
277227impl ByteRepr for :: libc:: sockaddr_in6 { }
0 commit comments