Skip to main content

Timeout

Struct Timeout 

Source
pub struct Timeout {
    pub pool: Option<Duration>,
    pub connect: Option<Duration>,
    pub write: Option<Duration>,
    pub read: Option<Duration>,
    pub total: Option<Duration>,
}
Expand description

Phase-aware timeout configuration for a request.

Each field is optional. When None, the corresponding phase has no timeout. When a field is Some(duration), the phase will fail with crate::Error::Timeout if it exceeds the given duration.

§Enforcement

  • pool: enforced via tokio::time::timeout around the pool acquire.
  • read: on Hyper/UDS routes, response-header waiting is bounded after request-body completion; response-body progress is enforced per chunk by a wrapper stream and resets on each arrival. Experimental HTTP/3 currently applies this field to response-body chunks only.
  • write: enforced per chunk by a wrapper stream that fires Error::Timeout { phase: Write } when the request body producer does not yield a chunk within the configured duration. Resets on every chunk delivery. Only applies to streamed request bodies; buffered bodies complete synchronously.
  • total: absolute wall-clock deadline from logical request start through response-body EOF/trailers. Enforced around the transport future and retained on the response body; never restarted per chunk, decode selection, redirect hop, retry attempt, or first body poll.
  • connect: enforced by wrapping the underlying connector with a timeout that bounds DNS resolution, TCP connect, and TLS handshake. Fires Error::Timeout { phase: Connect } if the connection is not established within the configured duration.

§Default

The default Timeout has all phases disabled (all None).

§Examples

use std::time::Duration;
use eggfetch_core::Timeout;

// All phases get 5 seconds.
let t = Timeout::from_secs(5);

// Only read and total are configured.
let t = Timeout {
    read: Some(Duration::from_secs(30)),
    total: Some(Duration::from_secs(60)),
    ..Timeout::default()
};

Fields§

§pool: Option<Duration>

Time allowed to wait for a connection slot from the pool.

§connect: Option<Duration>

Time allowed to establish TCP connection and TLS handshake. Includes DNS resolution when performed as part of connect. Enforced by wrapping the underlying connector with a deadline.

§write: Option<Duration>

Time allowed for the request body producer to yield each frame. Applies to high-level streamed request bodies and the native http_body::Body execution surface.

§read: Option<Duration>

Time allowed for response headers after request-body completion and between response-body chunks. The body timer starts on first body poll and resets on every chunk. Experimental HTTP/3 currently applies this field to response-body progress only.

§total: Option<Duration>

Optional wall-clock cap across the entire request lifecycle.

Implementations§

Source§

impl Timeout

Source

pub fn disabled() -> Self

Create a timeout with all phases disabled.

This is the same as Timeout::default().

Source

pub fn from_secs(secs: u64) -> Self

Create a timeout where pool, connect, write, and read each get the given duration.

The total timeout is not set. Use Timeout::builder or the struct literal syntax to set it explicitly.

§Examples
use eggfetch_core::Timeout;

let t = Timeout::from_secs(5);
assert_eq!(t.pool, Some(std::time::Duration::from_secs(5)));
assert_eq!(t.connect, Some(std::time::Duration::from_secs(5)));
assert_eq!(t.write, Some(std::time::Duration::from_secs(5)));
assert_eq!(t.read, Some(std::time::Duration::from_secs(5)));
assert!(t.total.is_none());
Source

pub fn compat() -> Self

Create an HTTPX-compatible timeout configuration.

HTTPX 0.28.1 uses 5 seconds for each operational phase. It does not define a request-wide wall-clock timeout, so total remains unset. Set total explicitly when an EggFetch-native outer deadline is desired.

§Examples
use std::time::Duration;
use eggfetch_core::Timeout;

let t = Timeout::compat();
assert_eq!(t.pool, Some(Duration::from_secs(5)));
assert_eq!(t.connect, Some(Duration::from_secs(5)));
assert_eq!(t.write, Some(Duration::from_secs(5)));
assert_eq!(t.read, Some(Duration::from_secs(5)));
assert!(t.total.is_none());
Source

pub fn native() -> Self

Create eggfetch-native timeout defaults.

Uses 30 seconds for pool, connect, write, and read phases with no total timeout. This is appropriate for general-purpose use where the caller controls overall deadlines.

§Examples
use std::time::Duration;
use eggfetch_core::Timeout;

let t = Timeout::native();
assert_eq!(t.pool, Some(Duration::from_secs(30)));
assert_eq!(t.connect, Some(Duration::from_secs(30)));
assert_eq!(t.write, Some(Duration::from_secs(30)));
assert_eq!(t.read, Some(Duration::from_secs(30)));
assert!(t.total.is_none());
Source

pub fn builder() -> TimeoutBuilder

Create a TimeoutBuilder for configuring individual phases.

Source

pub fn has_any(&self) -> bool

Returns true if any phase has a timeout set.

Trait Implementations§

Source§

impl Clone for Timeout

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Timeout

Source§

impl Debug for Timeout

Source§

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

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

impl Default for Timeout

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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