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
-1
votes
1 answer

Understand the design decision of ownership in Rust

I am trying to understand the usage of ownership in Rust. So from what I can understand, ownership is a runtime mechanism which enforces the programmers to think further and prevent some unexpected and unnoticed read-write hazards or so. But my…
lllllllllllll
  • 8,519
  • 9
  • 45
  • 80
-1
votes
1 answer

Changing user ownership to match group?

I mistakenly ran chown -R admin / on Centos 6 Is there any command to change user to match group? I think this should be a fix since by default user=group? P.S. An OS reinstall can fix this, but I am looking for alternate solutions to avoid this.
-1
votes
1 answer

Verify client's script from creator's site in PHP

I made a website for someone and want to retain ownership to the site even if the client has the script, just like verifying if you purchased a script and are using it on just one domain. I want to make sure that one domain cannot share a script's…
-1
votes
1 answer

WINAPI - Close mutex without being the owner

I'm trying to close a mutex in another application. I'm using the WinAPI ("windows.h"). Here's my code to close this mutex: DWORD pid = 0; hMyWnd = FindWindow(NULL, "TheFamousWindowName"); GetWindowThreadProcessId(hMyWnd, &pid); HANDLE hProc =…
DatGeoudon
  • 342
  • 3
  • 15
-1
votes
1 answer

Rust borrowing/ownership

I'm using tcod-rs. Each method used to draw to the RootConsole takes a mutable reference. The central loop is a while loop that waits for the window to close, and clears the screen, draws, and then flushes. The "check for window close" method also…
Alexis Dumas
  • 1,299
  • 11
  • 30
-1
votes
1 answer

Function, mutable borrow

I am trying to understand the ownership system. To test it, I wanted to make a function that borrows a Vec, adds a value to it and returns that value: fn test(v1: &mut Vec) -> i32 { *v1.push(10); v1[3] } fn main() { let…
-1
votes
1 answer

Using : and :: in C++ without confusing

Both : and :: punctuations in C++ can bind ownership of function within class, or subclass within base class. But it's not fully clear when to use each in general, and which to put in header and which in cpp source files (if this is a matter of…
-1
votes
2 answers

changed ownership on mysql files. How can I recover database?

I am using digitalocean VPS. Accidentally I changed all files' ownership to www-data on my server. How can I get my mysql database copy from this server?
-1
votes
1 answer

CentOS: force files ownership after FTP upload

here is my issue. We are on a CentOS Linux VPS and we have a Wordpress web site. Since Wordpress PID needs to run with the same PID of Apache and since I need an FTP user to connect sometimes, I have manually created an FTP user and then I have…
Etnok
  • 1
-2
votes
1 answer

What's the reason behind this design of rust?

Why does the below code not compile ? I know that you can't leave any variable partially initialised but i do initialise in the next line, So is it that it's difficult for compiler to infer that ( though i don't really think that ) or is it for some…
Darshan V
  • 198
  • 9
-2
votes
1 answer

About ownership of Rust

I have a question about ownership of Rust. I don't have used Rust but I know that Rust have a ownership concept and Rust manages memory by ownership. I learned that Rust prevents to access to invalid memory in compile time. If there is code as…
jjw
  • 282
  • 3
  • 20
-2
votes
1 answer

Changing enum value of struct in iterator

pub struct Server { devices: Vec, } pub struct Device { configuration: Configuration, } pub enum Configuration { Gradient { stops: Vec, brightness: f32, duration: i32, random_starting_point:…
trpouh
  • 175
  • 2
  • 11
-2
votes
1 answer

Is there a way to create a Box from a Vec that implements the Read trait?

I'm writing a piece of code that using the lopdf crate writes a PDF on a Vec. Then I want to print the PDF via the IPP crate but it requires a Box that I'm not able to create I've tried many things, but I'm always stuck with ownerships…
-2
votes
1 answer

Shell Script Need to run as a root user

I have shell scripts like below for changing/switch to another ISP connection. #!/bin/bash /sbin/route add default gw 192.168.1 /sbin/route del default gw 192.168.1.2 /sbin/route del default gw 192.168.1.3 /sbin/route -n I have root access to my…
-2
votes
2 answers

In Rust, how can I make this code less repetitive?

The goal is to write a function that gets two paths, input_dir and output_dir, and convertes all markdown files from input_dir to html files in output_dir. I finally managed to get it to run but it was rather frustrating. The parts that should be…
koehr
  • 769
  • 1
  • 8
  • 20
1 2 3
49
50