Struct ServerManager

Source
pub struct ServerManager<F> { /* private fields */ }
Expand description

Title: ServerManager structure for managing the server process

Parameters:

  • None

Returns:

  • None

This structure encapsulates the server management operations and holds the user-provided configuration and the server function.

Implementations§

Source§

impl<F, Fut> ServerManager<F>
where F: Fn() -> Fut, Fut: Future<Output = ()>,

Source

pub fn new(config: ServerManagerConfig, server_fn: F) -> ServerManager<F>

Create a new ServerManager instance

Parameters:

  • config: The server configuration containing PID file path and log paths.
  • server_fn: A closure representing the asynchronous server function.

Returns:

  • ServerManager<F>: A new instance of ServerManager.
Source

pub async fn start(&self)

Start the server in foreground mode

Parameters:

  • None

Returns:

  • (): No return value.

This function writes the current process ID to the PID file specified in the configuration and then runs the server function asynchronously.

Source

pub fn stop(&self) -> Result<(), Box<dyn Error>>

Stop the server

Parameters:

  • None

Returns:

  • ServerManagerResult: Operation result.

This function reads the process ID from the PID file and attempts to kill the process using a SIGTERM signal.

Source

pub fn start_daemon(&self) -> Result<(), Box<dyn Error>>

Start the server in daemon (background) mode on Unix platforms. Start the server in daemon mode on non-Unix platforms

Parameters:

  • None

Returns:

  • ServerManagerResult: Operation result.

This function returns an error because daemon mode is not supported on non-Unix platforms.

Source

pub fn hot_restart(&self, run_args: &[&str]) -> Result<(), Box<dyn Error>>

Start the server with hot-reloading using cargo-watch

Parameters:

  • run_args: Arguments to pass to cargo-watch.

Returns:

  • ServerManagerResult: Operation result.

This function checks for cargo-watch installation, installs it if missing, and then uses it to run the server with hot-reloading.

Source

pub fn hot_restart_wait(&self, run_args: &[&str]) -> Result<(), Box<dyn Error>>

Start the server with hot-reloading using cargo-watch and exit immediately

Parameters:

  • run_args: Arguments to pass to cargo-watch.

Returns:

  • ServerManagerResult: Operation result.

Same as hot_restart but does not wait for the process to finish.

Auto Trait Implementations§

§

impl<F> Freeze for ServerManager<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for ServerManager<F>
where F: RefUnwindSafe,

§

impl<F> Send for ServerManager<F>
where F: Send,

§

impl<F> Sync for ServerManager<F>
where F: Sync,

§

impl<F> Unpin for ServerManager<F>
where F: Unpin,

§

impl<F> UnwindSafe for ServerManager<F>
where F: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T