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

Change conversion methods to take objects by values #61

Open
3 tasks
d-unsed opened this issue Jan 10, 2017 · 2 comments
Open
3 tasks

Change conversion methods to take objects by values #61

d-unsed opened this issue Jan 10, 2017 · 2 comments

Comments

@d-unsed
Copy link
Owner

d-unsed commented Jan 10, 2017

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

  • Object::to

    Object::to<T: Object>(&self) -> T

    changes to

    Object::convert_into<T: Object>(self) -> T
  • Object::try_convert_to

    Object::try_convert_to<T: VerifiedObject>(&self) -> Result<T>

    changes to

    Object::try_convert_into<T: VerifiedObject>(self) -> Result<T>
  • Object::to_any_object()

    Object::to_any_object(&self) -> AnyObject

    changes to

    Object::into_any_object(&self) -> AnyObject

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
Copy link
Contributor

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
Copy link

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

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

3 participants