archlinux / alpm.rs

Rust bindings for libalpm
GNU General Public License v3.0
112 stars 21 forks source link

Lifetime on callbacks #25

Closed UhhhWaitWhat closed 2 years ago

UhhhWaitWhat commented 2 years ago

Hi everybody,

Is there a possibility to make the callbacks (e.g. the params passed to set_log_cb) have a shorter lifetime (e.g. the lifetime of the Alpm instance) than 'static? I don't know enough about libalpm itself to know if this is a possibility and if we have a guarantee of the callbacks never being called after the handle is destroyed. But as far as I see it, the moment the Alpm instance is dropped, it takes all the callbacks with it anyways, right?

The reason I am asking is, that a 'static lifetime prevents me from doing pretty much anything but logging the passed log messages. If I'd like to send the messages to a database, suddenly my database handle needs to have a static lifetime etc.

If this is an extremely nonsensical and/or impossible idea, please just disregard it :)

Thanks for your work on this library,

Florian

Morganamilo commented 2 years ago

It should be possible but I avoided it for simplicity and to avoid a lifetime bound on the Alpm struct.

Currently you can use rc and refcell to achieve this sp doesn't that not work for you?

UhhhWaitWhat commented 2 years ago

Yeah I guess an Rc should work, it just... doesn't feel great :D

But I get your bid for simplicity, so I'll do with what I have. Thank you for the quick response.