Skip to main content

InputContext

Struct InputContext 

Source
pub struct InputContext<'a> { /* private fields */ }
Expand description

The session state PostgreSQL’s input functions read, which the caller supplies.

use sql_values::{DateTimeError, InputContext, PgTimeZone, PgTimestampTz, TimeZoneAbbreviations};

let rome = PgTimeZone::parse("Europe/Rome").unwrap();
let local = "2026-07-01 12:00:00";
assert_eq!(
    PgTimestampTz::parse(local, InputContext::new()),
    Err(DateTimeError::NeedsTimeZone),
);
let at = PgTimestampTz::parse(local, InputContext::new().with_time_zone(&rome)).unwrap();
assert_eq!(at.to_string(), "2026-07-01 10:00:00+00");

// `EST` is New York's time in `Default` and Brisbane's in `Australia`.
let australia = TimeZoneAbbreviations::bundled("Australia").unwrap();
let context = InputContext::new().with_time_zone_abbreviations(australia);
let est = PgTimestampTz::parse("2026-07-01 12:00 EST", context).unwrap();
assert_eq!(est.to_string(), "2026-07-01 02:00:00+00");

Implementations§

Source§

impl<'a> InputContext<'a>

Source

pub const fn new() -> Self

A context with no time zone, no DateStyle order and no current time, and the Default abbreviations, as a stock installation’s timezone_abbreviations names them.

Source

pub const fn with_time_zone(self, zone: &'a PgTimeZone) -> Self

The context with zone as the session’s TimeZone, which reads a timestamptz or timetz written without an offset, and whose own abbreviations a literal may write before those of the set.

Source

pub const fn with_time_zone_abbreviations( self, abbreviations: &'a TimeZoneAbbreviations, ) -> Self

The context with abbreviations as the session’s timezone_abbreviations.

Source

pub const fn with_date_order(self, order: DateOrder) -> Self

The context with order as the field order of the session’s DateStyle, which reads a date written in numbers alone such as 01/02/2026.

Source

pub const fn with_now(self, now: PgTimestampTz) -> Self

The context with now as the transaction’s start, which now, today, tomorrow and yesterday read, in the context’s time zone, and whose date a timetz without a date takes its zone’s offset on. An infinite now reads as DateTimeError::TimestampOutOfRange, as no transaction starts at one.

Trait Implementations§

Source§

impl<'a> Clone for InputContext<'a>

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<'a> Copy for InputContext<'a>

Source§

impl<'a> Debug for InputContext<'a>

Source§

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

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

impl Default for InputContext<'_>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Forget for InputContext<'a>

§

impl<'a> Freeze for InputContext<'a>

§

impl<'a> RefUnwindSafe for InputContext<'a>

§

impl<'a> Send for InputContext<'a>

§

impl<'a> Sync for InputContext<'a>

§

impl<'a> Unpin for InputContext<'a>

§

impl<'a> UnsafeUnpin for InputContext<'a>

§

impl<'a> UnwindSafe for InputContext<'a>

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 = !

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.