Trait rustyscript::worker::InnerWorker
source · pub trait InnerWorkerwhere
Self: Send,
Self::RuntimeOptions: Send + 'static + Clone,
Self::Query: Send + 'static,
Self::Response: Send + 'static,{
type Runtime;
type RuntimeOptions;
type Query;
type Response;
// Required methods
fn init_runtime(
options: Self::RuntimeOptions,
) -> Result<Self::Runtime, Error>;
fn handle_query(
runtime: &mut Self::Runtime,
query: Self::Query,
) -> Self::Response;
// Provided method
fn thread(
runtime: Self::Runtime,
rx: Receiver<Self::Query>,
tx: Sender<Self::Response>,
) { ... }
}
Expand description
An implementation of the worker trait for a specific runtime This allows flexibility in the runtime used by the worker As well as the types of queries and responses that can be used
Implement this trait for a specific runtime to use it with the worker For an example implementation, see DefaultWorker
Required Associated Types§
sourcetype Runtime
type Runtime
The type of runtime used by this worker
This can just be rustyscript::Runtime
if you don’t need to use a custom runtime
sourcetype RuntimeOptions
type RuntimeOptions
The type of options that can be used to initialize the runtime
Cannot be rustyscript::RuntimeOptions
because it is not Send
Required Methods§
sourcefn init_runtime(options: Self::RuntimeOptions) -> Result<Self::Runtime, Error>
fn init_runtime(options: Self::RuntimeOptions) -> Result<Self::Runtime, Error>
Initialize the runtime used by the worker This should return a new instance of the runtime that will respond to queries
sourcefn handle_query(
runtime: &mut Self::Runtime,
query: Self::Query,
) -> Self::Response
fn handle_query( runtime: &mut Self::Runtime, query: Self::Query, ) -> Self::Response
Handle a query sent to the worker Must always return a response of some kind
Provided Methods§
Object Safety§
This trait is not object safe.