# Sharing immutable reference to mutable struct in a single thread

**URL:** <https://users.rust-lang.org/t/sharing-immutable-reference-to-mutable-struct-in-a-single-thread/51467>\
**Category:** help\
**Created:** [November 14, 2020, 8:20pm UTC](https://users.rust-lang.org/t/sharing-immutable-reference-to-mutable-struct-in-a-single-thread/51467 "2020-11-14T20:20:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alvinary](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/alvinary/32/17939_2.png) [@alvinary](https://users.rust-lang.org/u/alvinary)\
**Post date:** [November 14, 2020, 8:20pm UTC](https://users.rust-lang.org/t/sharing-immutable-reference-to-mutable-struct-in-a-single-thread/51467/1 "2020-11-14T20:20:53Z")

</div>

Hi! I'm completely new to rust, and I'm having trouble with wrapper types and ownership (Boxes, Cells, Refcells, and the like). How would you implement something like the 'foo' below, if you needed 'data' to be mutable, did not need to run anything in more than one thread, and wanted to stay within safe rust?

```
fn foo(value: T, data: SomeWrapper<SomeStruct>) {
    unwrap(data).vector_field.push(value.clone());
}

```

I apologize if this is vague or dumb, I don't have much experience with systems programming.

---

<div class="post-metadata">

**Author:** ![cuviper](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/cuviper/32/3156_2.png) [@cuviper](https://users.rust-lang.org/u/cuviper)\
**Post date:** [November 14, 2020, 9:05pm UTC](https://users.rust-lang.org/t/sharing-immutable-reference-to-mutable-struct-in-a-single-thread/51467/2 "2020-11-14T21:05:24Z")

</div>

With `data: &RefCell<SomeStruct>`, you can use `data.borrow_mut().vector_field.push(...)`.

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/system/32/51372_2.png) [@system](https://users.rust-lang.org/u/system)\
**Post date:** [February 12, 2021, 9:05pm UTC](https://users.rust-lang.org/t/sharing-immutable-reference-to-mutable-struct-in-a-single-thread/51467/3 "2021-02-12T21:05:29Z")

</div>

Closed on February 12, 2021, 9:05pm UTC

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.
