servo / rust-mozjs

DEPRECATED - moved to servo/mozjs instead.
Mozilla Public License 2.0
293 stars 122 forks source link

Implement `AsHandle` and `AsHandleMut` traits. #320

Closed ejpbruel closed 7 years ago

ejpbruel commented 7 years ago

Several types in rust-mozjs, such as Heap, PersistentRooted, and RootedGuard, represent a rooted value. A common property of rooted values is that a handle can be obtained to it. Rather than implement this property separately for each of these types, we should abstract it out into these two traits.

This has several advantages: for instance, one can write functions that take any rooted value as
argument, regardless of how it is implemented, and then obtain a handle to it. Additionally, it
allows one to implement these traits for newtypes which underlying type is a rooted value.

This change is Reviewable

jimblandy commented 7 years ago

I suggested AsHandle and AsHandleMut because they would help write generic code that could take a reference to any value that could provide a handle, rather than making the callers extract the handles themselves. It seems analogous to the way the std::fs functions accept any argument that implements AsRef<Path>.

bors-servo commented 7 years ago

:umbrella: The latest upstream changes (presumably #328) made this pull request unmergeable. Please resolve the merge conflicts.

jdm commented 7 years ago

Closing due to lack of activity.