Despite the fact that i recently increased my overall knowledge about rust and borrow checker considerably by reading dozens of documents and videos, and fixed several of my basic issues with closure and threads with the help of the community i still struggle to get my opensource project to work. it seems that using closures in concurrent threads is way above my current rust skill level. The project is small so i though maybe it's better to ask someone to have a look.
The problem is i can comfortably use closures in concurrent threads but when i try to do the same with a level of abstraction and some crates, rust starts complaining about the closure life time, mismatched types, etc
Here is what my programs does
it monitors the clipboard and if its content is text clears it after few seconds but keeps the value in a sort of history. there is also a hotkey that will restore the last text in history into the clipboard.
- There is module clipboard_holder with ClipboardHolder struc that is responsible with managing the history. ClipboardHolder has a method that returns a closure that can be used in threads for send the clipboard content using crossbeam channel.
clipboard holder also spawns a thread internally to receive clipboard texts sent by the crossbeam channel's senders
- There is a thread that calls a function in the clipboard module to monitors clipboard and calls the clipboard holder closure before clearing the to send its content to clipboard holder
- In the main thread there is also a hotkey listener that is supposed the call clipboard holder for restoring the last clipboard content (it only prints something right now)
I wand to make the closure that calls the ClipboardHolder as flexible as possible so i can use it in several different concurrent threads and pass it inside other functions as well
i hope someone can have a look and help me out
In the last commit i tried to add more abstraction and use 'a suggested in the forum (Callback calling a type method), it did solve my abstraction problem but now i get another error
this is exactly the kind of problem i have. it works in an isolated example but as i as move it to my problem i get encounter errors. previously i use 'static and box but that also did solve all the issues
implicit elided lifetime not allowed here
project page : https://github.com/sinasalek/clipboard_guardian