Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving vs borrowing #60

Open
d-unsed opened this issue Jan 10, 2017 · 1 comment
Open

Moving vs borrowing #60

d-unsed opened this issue Jan 10, 2017 · 1 comment

Comments

@d-unsed
Copy link
Owner

d-unsed commented Jan 10, 2017

Consider the following example:

let string = RString::new("Some string");
let mut array = Array::new();

// Moves `string` into `array` similarly to `vec.push()` in Rust
array.push(string);

// ... `string` cannot be used, because it's moved

vs

string = 'Some string'
array = []

# Takes a reference of the `string`
array.push(string)

# `string` can be used
string.concat(" mutated")

array.inspect # => ['Some string mutated']

It needs to be decided whether to take objects references (Ruby way) or by values (Rust way).

@d-unsed d-unsed added this to the v1.0 milestone Jan 10, 2017
@d-unsed d-unsed changed the title Move vs Reference Moving vs borrowing Jan 10, 2017
@danielpclark
Copy link
Contributor

danielpclark commented Feb 1, 2018

I think having the Rust way is preferable. We can manage the context of ownership like we normally would in Rust. We can let each language behave in their own way and this won't lead to surprises. I like being able to define the ownership in my own programs.

Ruby internally has most objects act as CoW.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants