DelSkayn / rquickjs

High level bindings to the quickjs javascript engine
MIT License
431 stars 58 forks source link

Add a way to skip property when deriving Trace #280

Closed Sytten closed 3 months ago

Sytten commented 3 months ago

Sometimes you use structs from third party libraries where adding Trace is impossible. My take on that is to wrap the object in my own object something like:

#[derive(Clone)]
#[rquickjs::class]
pub struct Request {
    inner: http1::Request,
}

impl<'js> Trace<'js> for Request {
    fn trace<'a>(&self, _tracer: Tracer<'a, 'js>) {}
}

It would be nice if there was #[qjs(skip)] in the struct, so I could continue to derive Trace. Something like:

#[derive(Clone, Trace)]
#[rquickjs::class]
pub struct Request {
    #[qjs(skip)]
    inner: proxy_http1::Request,
    other: String,
}
Sytten commented 3 months ago

Also it looks like Option doesn't derive Tracer

DelSkayn commented 3 months ago

There should be an attribute to skip deriving trace for a field. If you add the attribute #[qjs(skip_trace)] it should skip that field.

I will add an implementation for option to the library.

Sytten commented 3 months ago

@DelSkayn Done, check the PR :)