I'm fairly new to rust and I can't find any documentation that lists the best practices when it comes to consuming Tokio inside a library crate.
I have a library crate that uses Tokio internally and needs to spawn tasks. Now,
- Is the crate supposed to be given an instance of a Tokio runtime when called?
- If so, how do you check that it has been configured properly for your needs?
- If not, how do you deal with a custom executor as part of the crate? (i.e. making sure it doesn't conflict with something else)
- What happens when other executors are involved, says the final binary uses
futures::executor
orasync-std
? - When using future abstractions and exposing future traits as part of my API, does it matter which crate these are coming from? (e.g. I see a lot of things prefer
futures::Stream
overtokio::stream::Stream
) - Is there anything that helps abstracting the above and understood by most framework? (e.g. traits like
futures::task::Spawn
) - Does it my crate API need to be
async
if I don't have an internal runtime?