Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn into a library #4

Open
vimalloc opened this issue May 13, 2016 · 1 comment
Open

Turn into a library #4

vimalloc opened this issue May 13, 2016 · 1 comment

Comments

@vimalloc
Copy link
Owner

vimalloc commented May 13, 2016

Make the relay portion of this a library, where you can register callback handlers for incoming data. This is totally unnecessary for the app I'm building, but I think it would have a few benefits for learning rust, namely

  1. How to build and use a library.
  2. Dealing with threading so users can send messages independently of recving them
@vimalloc
Copy link
Owner Author

Need a way to register callback functions. Without knowing anything about how rust could acomplish this, my first thought is storing functions in a key/value mapping. Every function will need to have a signature like:

fn some_callback(hdata: HData, Option<<some_generic_box_pointer>>)

The hdata is obvious, that is the contents of the message. The generic box pointer then is less so. If they have a callback method, they may need some additional state to handle it. In the case of playing a sound on highlight, I wouldn't need it, so Option would be None. But if they were wanting to keep track of, say, who you have unread messages from, or really anything more complex then playing a sound, they will probably need some external state. Passing it back to the function call seems better then making them use a global somewhere. Although, maybe there is a better way to do all this, I'm just thinking here. Maybe something with traits could help? Dunno.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant