Clonable struct and Arc field

Hi,

with

#[derive(Clone)]
struct MyStruct {
    field: Arc<MyType>
} 

what is the difference between:
let varc : Arc<MyStruct> and let v: MyStruct

when we call varc.clone() and v.clone() ?

I'm wondering if I need to Arc MyStruct in order to share it

The very point of Arc is to provide shared ownership and cheap cloneability for types that are expensive or impossible to clone. You don't need to wrap stuff in two layers of Arc.

1 Like

Thanks!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.