Skip to main content

HealthCheck

Struct HealthCheck 

Source
pub struct HealthCheck {
    pub component_type: String,
    pub status: HealthStatus,
    pub output: Option<String>,
    pub time: Option<String>,
}
Expand description

Individual component check result (RFC 8458 §4).

Used as values in ReadinessResponse::checks. Map key format: "<component>:<measurement>", e.g. "postgres:connection".

Requires std or alloc (fields contain String).

Fields§

§component_type: String

Component type, e.g. "datastore", "component", "system".

§status: HealthStatus

Check result status.

§output: Option<String>

Human-readable output or error message. Omitted when absent.

§time: Option<String>

RFC 3339 timestamp of when this check was last performed. Omitted when absent.

Implementations§

Source§

impl HealthCheck

Source

pub fn pass(component_type: impl Into<String>) -> Self

Create a passing component check.

§Examples
use api_bones::health::{HealthCheck, HealthStatus};

let check = HealthCheck::pass("datastore");
assert_eq!(check.status, HealthStatus::Pass);
assert_eq!(check.component_type, "datastore");
assert!(check.output.is_none());
Source

pub fn fail( component_type: impl Into<String>, output: impl Into<String>, ) -> Self

Create a failing component check with an error message.

§Examples
use api_bones::health::{HealthCheck, HealthStatus};

let check = HealthCheck::fail("datastore", "connection timeout");
assert_eq!(check.status, HealthStatus::Fail);
assert_eq!(check.output.as_deref(), Some("connection timeout"));
Source

pub fn warn( component_type: impl Into<String>, output: impl Into<String>, ) -> Self

Create a warn-level component check with a message.

§Examples
use api_bones::health::{HealthCheck, HealthStatus};

let check = HealthCheck::warn("datastore", "high latency");
assert_eq!(check.status, HealthStatus::Warn);
assert_eq!(check.output.as_deref(), Some("high latency"));
Source

pub fn with_time(self, time: impl Into<String>) -> Self

Attach an RFC 3339 timestamp to this check result.

§Examples
use api_bones::health::HealthCheck;

let check = HealthCheck::pass("datastore")
    .with_time("2026-01-01T00:00:00Z");
assert_eq!(check.time.as_deref(), Some("2026-01-01T00:00:00Z"));
Source

pub fn builder() -> HealthCheckBuilder<(), ()>

Return a typed builder for constructing a HealthCheck.

Required fields (component_type and status) must be set before calling HealthCheckBuilder::build; the compiler enforces this via typestate.

§Example
use api_bones::health::{HealthCheck, HealthStatus};

let check = HealthCheck::builder()
    .component_type("datastore")
    .status(HealthStatus::Pass)
    .build();
assert_eq!(check.status, HealthStatus::Pass);

Trait Implementations§

Source§

impl Clone for HealthCheck

Source§

fn clone(&self) -> HealthCheck

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HealthCheck

Source§

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

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

impl<'de> Deserialize<'de> for HealthCheck

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for HealthCheck

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,