pub struct Unit { /* private fields */ }Expand description
The Unit application context.
This object wraps the libunit library, which talks to the Unit server over
shared memory and a unix socket in order to receive data about requests.
This object is not Send nor Sync, and cannot be sent to other
threads.
However, multiple objects of this type may be created; additional Unit
objects will automatically be linked to the first through a global mutex,
and will be able to receive and process requests in other threads.
The first context is internally wrapped in an Arc, shared among all
instances Unit and will be deallocated when the last Unit object is
dropped.
Implementations§
Source§impl Unit
impl Unit
Sourcepub fn new() -> Result<Self, UnitInitError>
pub fn new() -> Result<Self, UnitInitError>
Create a new Unit context capable of receiving and handling requests on the current thread.
If called after a previous Unit was constructed but already received
a QUIT event from the Unit server, this will return a no-op Unit
instance whose Unit::run method will immediately return.
If called after a previous Unit failed to initialize, this will
return the same initialization failure.
Sourcepub fn set_request_handler(&mut self, f: impl UnitService + 'static)
pub fn set_request_handler(&mut self, f: impl UnitService + 'static)
Set a request handler for the Unit application.
The handler must be an object that implements the UnitService trait.
This trait is automatically implemented for functions or lambda
functions that take a Request object and return a
UnitResult<()>.
Sourcepub fn run(&mut self)
pub fn run(&mut self)
Enter the main event loop, handling requests on this thread until the Unit server exits or requests a restart.
This may be executed in parallel with other threads that call
Unit::run()