Questions tagged [ownership]

Ownership is a core concept of Rust. The system of ownership is a set of rules that the compiler checks at compile time to manage the memory. DO NOT USE FOR THE FILE OWNER USER AND GROUP IN UNIX SYSTEMS; for that, use [permissions] instead.

The three rules of ownership in are:

  1. Each value in Rust has a variable that’s called its owner.
  2. There can only be one owner at a time.
  3. When the owner goes out of scope, the value will be dropped.

You can read more in the documentation.

742 questions
-2
votes
1 answer

If you build something valuable at a hackathon, who owns it?

Foreword: One could argue this question would be more at home on Law SE, but considering most lawyers aren't even aware of what a hackathon is, this question has a far greater chance of being properly answered here. If you disagree with that…
TheEnvironmentalist
  • 2,694
  • 2
  • 19
  • 46
-2
votes
1 answer

Create verification if user is the site owner

I am using Drupal 7 and have a content type. Simple registered users can fill out just two fields of this content type (for example, the name of the website.) But the owner of the website can also fill out the type. I need a way for the owner of…
Eri
  • 1
-3
votes
1 answer

Variable lifetime problem when passed to message channels within threads in Rust

I'm writing a Rust program that does the following: Create an array of threads to spawn, each holds a variable which stores the path of a directory: let (tx, rx) = mpsc::channel(); let handles: Vec<_> = dir_list .into_iter() …
aisuneko
  • 11
  • 4
-3
votes
1 answer

Why does cloning an Rc pointer in Rust increase its strong_count?

I have this function: use std::rc::Rc; fn rc_counter() -> Rc { let p1 = Rc::new(String::from("Hello")); println!("count {}", Rc::strong_count(&p1)); // 1 // this is an owned type not…
Yilmaz
  • 35,338
  • 10
  • 157
  • 202
-3
votes
1 answer

Rust ownership, how to return a ref for a struct?

I generate an instance A from instance B's method and managed by B, but I want return A. How to implement this? For this codes (playground link) I want generate a history for the RedPacket, managed by RedPacket (push into the Vec) and return history…
astm
  • 3
  • 1
-3
votes
1 answer

Actual uses of shared_ptr?

For me, shared_ptr seems like a lazy solution to memory management, instead of using a well thought zero overhead ownership system ofunique_ptr for owning pointers, raw pointers for observing pointers, and std::move to pass ownership around. The…
SomeProgrammer
  • 1,134
  • 1
  • 6
  • 12
-5
votes
2 answers

Pointer-like logic in Rust

I need to move n elements from one vec to another, say a and b, in a pop/push loop. The tricky part is the following: if n > 0, I want to transfer n elements from a to b. if n < 0, I want to transfer |n| elements from b to a. n == 0 isn't…
Zehanort
  • 458
  • 2
  • 10
1 2 3
49
50