Skip to main content

HyperProcess

Struct HyperProcess 

Source
pub struct HyperProcess { /* private fields */ }
Expand description

A running Hyper server instance.

This struct manages the lifecycle of a local Hyper server process using a callback connection for reliable shutdown. The server is automatically shut down when this object is dropped.

§Callback Connection (Dead Man’s Switch)

Unlike traditional process management that relies on signals, HyperProcess maintains a TCP connection to the Hyper server. When this connection is closed (either explicitly or because the client process exits), Hyper automatically shuts down gracefully.

This provides several benefits:

  • No orphan processes: If your application crashes, Hyper shuts down automatically
  • Graceful shutdown: Hyper can flush data and clean up properly
  • Cross-platform: Works reliably on macOS, Linux, and Windows

§Example

use hyperdb_api::{HyperProcess, Result};

fn main() -> Result<()> {
    // Start a Hyper server (auto-detect hyperd location)
    let hyper = HyperProcess::new(None, None)?;

    println!("Hyper server running at: {}", hyper.endpoint().unwrap());

    // Server automatically shuts down when `hyper` goes out of scope
    // via the callback connection mechanism
    Ok(())
}

Implementations§

Source§

impl HyperProcess

Source

pub fn new( hyper_path: Option<&Path>, parameters: Option<&Parameters>, ) -> Result<Self>

Starts a new Hyper server instance.

This method:

  1. Creates a callback listener on an ephemeral port
  2. Starts the hyperd process with the callback connection address
  3. Waits for Hyper to connect back and provide its listen endpoint
§Arguments
  • hyper_path - Optional path to the hyperd executable. If None, searches in common locations (HYPERD_PATH env var, then known build output paths).
  • parameters - Optional parameters for the server.
§Errors

Returns an error if:

  • The hyperd executable cannot be found
  • The callback listener cannot be created
  • The server fails to start
  • Hyper doesn’t connect back within the timeout (30 seconds)
§Example
use hyperdb_api::{HyperProcess, Result};
use std::path::Path;

fn main() -> Result<()> {
    // Auto-detect hyperd location
    let hyper = HyperProcess::new(None, None)?;

    // Or specify explicit path
    let hyper2 = HyperProcess::new(
        Some(Path::new("/path/to/hyperd")),
        None,
    )?;
    Ok(())
}
Source

pub fn endpoint(&self) -> Option<&str>

Returns the libpq endpoint for connecting to this instance.

The endpoint is in the format “host:port” (e.g., “localhost:54321”).

Returns None if the process was started in gRPC-only mode. Use grpc_endpoint for gRPC connections.

Source

pub fn require_endpoint(&self) -> Result<&str>

Returns the libpq endpoint, or an error if not available.

This is a convenience method to avoid unwrap() calls when you need the endpoint and want proper error handling.

§Errors

Returns an error if this process was started in gRPC-only mode.

§Example
use hyperdb_api::{HyperProcess, Result};

fn main() -> Result<()> {
    let hyper = HyperProcess::new(None, None)?;
    let endpoint = hyper.require_endpoint()?; // No unwrap() needed!
    println!("Server running at: {}", endpoint);
    Ok(())
}
Source

pub fn grpc_endpoint(&self) -> Option<&str>

Returns the gRPC endpoint for connecting to this instance.

The endpoint is in the format “host:port” (e.g., “127.0.0.1:7484”).

Returns None if the process was started in libpq-only mode.

Source

pub fn require_grpc_endpoint(&self) -> Result<&str>

Returns the gRPC endpoint, or an error if not available.

This is a convenience method to avoid unwrap() calls when you need the gRPC endpoint and want proper error handling.

§Errors

Returns an error if this process was started in libpq-only mode.

Source

pub fn grpc_url(&self) -> Option<String>

Returns the gRPC endpoint as a full URL suitable for gRPC clients.

Returns the endpoint prefixed with “http://” (e.g., “http://127.0.0.1:7484”). Returns None if the process was started in libpq-only mode.

Source

pub fn require_grpc_url(&self) -> Result<String>

Returns the gRPC URL, or an error if not available.

This is a convenience method to avoid unwrap() calls when you need the gRPC URL and want proper error handling.

§Errors

Returns an error if this process was started in libpq-only mode.

Source

pub fn listen_mode(&self) -> ListenMode

Returns the listen mode this process was started with.

Source

pub fn transport_mode(&self) -> TransportMode

Returns the transport mode this process was started with.

Source

pub fn connection_endpoint(&self) -> Option<&ConnectionEndpoint>

Returns the connection endpoint for this process.

This returns a ConnectionEndpoint that can be used to connect to this Hyper instance via TCP, Unix Domain Socket, or Named Pipe.

Source

pub fn log_dir(&self) -> Option<&Path>

Returns the log directory where hyperd writes its log files.

The log file is typically hyperd.log within this directory. Returns None if the log directory could not be determined (e.g., default parameters were disabled and no log_dir was specified).

This is useful for setting up QueryStatsProvider implementations that parse the Hyper log file.

Source

pub fn socket_directory(&self) -> Option<&Path>

Returns the socket directory used for UDS connections (Unix only).

Returns None if the process is using TCP or if no socket directory was created.

Source

pub fn pid(&self) -> Option<u32>

Returns the process ID of the Hyper server.

Source

pub fn is_running(&self) -> bool

Returns whether the Hyper server process is still running.

Source

pub fn shutdown_timeout(self, timeout: Duration) -> Result<()>

Shuts down the Hyper server gracefully with a timeout.

This closes the callback connection, which signals Hyper to shut down gracefully. If Hyper doesn’t exit within the timeout, it will be forcefully terminated.

§Arguments
  • timeout - Maximum time to wait for graceful shutdown before force-killing.
§Errors

Returns an error if the shutdown fails.

Source

pub fn shutdown_graceful(self) -> Result<()>

Shuts down the Hyper server gracefully, waiting indefinitely.

This closes the callback connection and waits for Hyper to exit. Use shutdown_timeout if you need a timeout.

§Errors

Returns an error if the shutdown fails.

Trait Implementations§

Source§

impl Debug for HyperProcess

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for HyperProcess

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for HyperProcess

Auto Trait Implementations§

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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
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<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> Allocation for T
where T: RefUnwindSafe + Send + Sync,