3 ms·
Well, it depends on what you define by passing a pointer. Is the pointer mutable (needs to modify the data it is pointing at?) or immutable? Is it a reference (
by rice7th 3y ago
Well, it depends on what you define by passing a pointer. Is the pointer mutable (needs to modify the data it is pointing at?) or immutable? Is it a reference ("guaranteed" pointer?) Or just a plain old pointer? (const T and mut T)? Or do you want a smart pointer, like Box<T> or a unique_ptr-ish thing with a reference counted pointer via Rc<T>?
Want to pass and modify data from and to multiple threads? Yea just drop an Arc<Mutex<T>> and you're good to go.
If you just want to pass some data, even around threads, without modifying it, then a plain old borrow is your best bet. Make sure to get the lifetimes right tho!