d-unsed / ruru

Native Ruby extensions written in Rust
MIT License
832 stars 40 forks source link

Change conversion methods to take objects by values #61

Open d-unsed opened 7 years ago

d-unsed commented 7 years ago

The following methods should take self by value, because technically they return the same Ruby objects converted to another Rust type.

For example:

let fixnum = some_object.try_convert_into::<Fixnum>();

some_object should be consumed by convert_into, because fixnum and some_object correspond to the same object in Ruby.

danielpclark commented 6 years ago

Just curious about the Object::try_convert_into<T: VerifiedObject>(self) -> Result<T> scenario. Would taking ownership be bad in this case when the type isn't what you try for the first time? If the result is an Err(Error) because it's a different type the ownership would already be consumed… right?

CodesInChaos commented 6 years ago

@danielpclark The usual workaround is returning the original value as part of the error.