Arc on an array element

There are two functions:

impl PipelineLayout {
    pub fn descriptor_set_layouts(&self) -> &[Arc<DescriptorSetLayout>]
}

and

impl PersistentDescriptorSet {
    pub fn start(layout: Arc<DescriptorSetLayout>) -> PersistentDescriptorSetBuilder
}

I want to pass the first element of the array returned by the first function as the parameter to the second function, however I can't create an Arc on it because of the reference:

let layout: Arc<DescriptorSetLayout> = foo().descriptor_set_layouts().get(0)
        .expect("Couldn't find layout descriptor 0.");

// error[E0308]: mismatched types
//   --> src/main.rs:72:44
//    |
// 72 |       let layout: Arc<DescriptorSetLayout> = foo().descriptor_set_layouts().get(0)
//    |  _________________------------------------___^
//    | |                 |
//    | |                 expected due to this
// 73 | |         .expect("Couldn't find layout descriptor 0.");
//    | |_____________________________________________________^ expected struct `Arc`, found reference
//    |
//    = note: expected struct `Arc<DescriptorSetLayout>`
//            found reference `&Arc<DescriptorSetLayout>`

How can I get an Arc on an element of that array (or any other way to pass an element of that array to the second function)?

You will have to clone it. For an Arc this will only increase the reference count and not clone the inner data.

3 Likes

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.