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>
impl<'a> InputContext<'a>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
A context with no time zone and the Default abbreviations, as a stock installation’s
timezone_abbreviations names them.
Sourcepub const fn with_time_zone(self, zone: &'a PgTimeZone) -> Self
pub const fn with_time_zone(self, zone: &'a PgTimeZone) -> Self
The context with zone as the session’s TimeZone, which reads a timestamptz written
without an offset, and whose own abbreviations a literal may write before those of the
set.
Sourcepub const fn with_time_zone_abbreviations(
self,
abbreviations: &'a TimeZoneAbbreviations,
) -> Self
pub const fn with_time_zone_abbreviations( self, abbreviations: &'a TimeZoneAbbreviations, ) -> Self
The context with abbreviations as the session’s timezone_abbreviations.
Trait Implementations§
Source§impl<'a> Clone for InputContext<'a>
impl<'a> Clone for InputContext<'a>
impl<'a> Copy for InputContext<'a>
Source§impl<'a> Debug for InputContext<'a>
impl<'a> Debug for InputContext<'a>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more