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>

Title: 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)

Title: 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>>

Title: Stop the server

Parameters:

  • None

Returns:

  • Result<(), Box<dyn std::error::Error>>: 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. Title: Start the server in daemon mode on non-Unix platforms

Parameters:

  • None

Returns:

  • Result<(), Box<dyn std::error::Error>>: Operation result.

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

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, 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, 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.