quickjs-rs icon indicating copy to clipboard operation
quickjs-rs copied to clipboard

Consider using `scopeguard` crate

Open ghost opened this issue 4 years ago • 2 comments

Recently I've discovered scopeguard crate. It allows to do RAII-style cleanup of resources similarly to what DroppableValue structure does, but also provides a nice defer! macro to do it in a slightly less verbose way, similar to defer keyword in Go.

@theduke what do you think about replacing DroppableValue to usage of defer! macro from scopeguard crate?

ghost avatar Sep 21 '19 11:09 ghost

I'd rather rather remove DroppableValue and extend the types like OwnedValue(/Ref) (https://github.com/theduke/quickjs-rs/blob/master/src/bindings.rs#L475).

I actually wanted to wrap all types coming out of quickjs immediately with custom types. I didn't do it yet because I wrote them requiring a reference to bindings::Context and it would have needed some refactoring to instead just hold a raw reference to _sys::Context in order to be constructable from within callbacks.

theduke avatar Sep 21 '19 12:09 theduke

@theduke something like this? https://github.com/HiRoFa/quickjs_es_runtime/blob/master/src/quickjs_utils/properties.rs

andrieshiemstra avatar Apr 20 '21 11:04 andrieshiemstra