Trait ecma402_traits::datetimeformat::DateTimeFormat
source · pub trait DateTimeFormat {
type Error: Error;
// Required methods
fn try_new<L>(
l: L,
opts: DateTimeFormatOptions
) -> Result<Self, Self::Error>
where L: Locale,
Self: Sized;
fn format<W>(&self, date: f64, writer: &mut W) -> Result
where W: Write;
}
Required Associated Types§
Required Methods§
sourcefn try_new<L>(l: L, opts: DateTimeFormatOptions) -> Result<Self, Self::Error>
fn try_new<L>(l: L, opts: DateTimeFormatOptions) -> Result<Self, Self::Error>
Creates a new DateTimeFormat.
Creation may fail, for example, if the locale-specific data is not loaded, or if the supplied options are inconsistent.
sourcefn format<W>(&self, date: f64, writer: &mut W) -> Resultwhere
W: Write,
fn format<W>(&self, date: f64, writer: &mut W) -> Resultwhere
W: Write,
Formats date
into the supplied standard writer
fmt::Write.
The original ECMA 402 function returns a string. This is likely the only
reasonably generic option in JavaScript so it is adequate. In Rust, however, it is
possible to pass in a standard formatting strategy (through writer
).
The date
holds the number of seconds (with fractional part) since the beginning of the
Unix epoch. The date is a very generic type because there is no official date-time type
in Rust.
Object Safety§
This trait is not object safe.