Struct StrftimeItems
struct StrftimeItems<'a> { ... }
Parsing iterator for strftime-like format strings.
See the format::strftime module for supported formatting
specifiers.
StrftimeItems is used in combination with more low-level methods such as format::parse()
or format_with_items.
If formatting or parsing date and time values is not performance-critical, the methods
parse_from_str and format on types such as DateTime are easier to
use.
Implementations
impl<'a> StrftimeItems<'a>
const fn new(s: &'a str) -> StrftimeItems<'a>Creates a new parsing iterator from a
strftime-like format string.Errors
While iterating
Item::Errorwill be returned if the format string contains an invalid or unrecognized formatting specifier.Example
use *; let strftime_parser = new; // %F: year-month-day (ISO 8601) const ISO8601_YMD_ITEMS: & = &; assert!;fn parse(self: Self) -> Result<Vec<Item<'a>>, ParseError>Parse format string into a
Vecof formattingItem's.If you need to format or parse multiple values with the same format string, it is more efficient to convert it to a
Vecof formattingItem's than to re-parse the format string on every use.The
format_with_itemsmethods onDateTime,NaiveDateTime,NaiveDateandNaiveTimeaccept the result for formatting.format::parse()can make use of it for parsing.Errors
Returns an error if the format string contains an invalid or unrecognized formatting specifier.
Example
use ; use NaiveDate; let fmt_items = new.parse?; let datetime = from_ymd_opt.unwrap.and_hms_opt.unwrap; // Formatting assert_eq!; // Parsing let mut parsed = new; parse?; let parsed_dt = parsed.to_naive_datetime_with_offset?; assert_eq!; # Ok::fn parse_to_owned(self: Self) -> Result<Vec<Item<'static>>, ParseError>Parse format string into a
VecofItem's that contain no references to slices of the format string.A
Veccreated withStrftimeItems::parsecontains references to the format string, binding the lifetime of theVecto that string.StrftimeItems::parse_to_ownedwill convert the references to owned types.Errors
Returns an error if the format string contains an invalid or unrecognized formatting specifier.
Example
use ; use NaiveDate; let fmt_items = format_items?; let datetime = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!; # Ok::
impl<'a> Clone for StrftimeItems<'a>
fn clone(self: &Self) -> StrftimeItems<'a>
impl<'a> Debug for StrftimeItems<'a>
fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result
impl<'a> Freeze for StrftimeItems<'a>
impl<'a> Iterator for StrftimeItems<'a>
fn next(self: &mut Self) -> Option<Item<'a>>
impl<'a> RefUnwindSafe for StrftimeItems<'a>
impl<'a> Send for StrftimeItems<'a>
impl<'a> Sync for StrftimeItems<'a>
impl<'a> Unpin for StrftimeItems<'a>
impl<'a> UnwindSafe for StrftimeItems<'a>
impl<I> IntoIterator for StrftimeItems<'a>
fn into_iter(self: Self) -> I
impl<T> Any for StrftimeItems<'a>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for StrftimeItems<'a>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for StrftimeItems<'a>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for StrftimeItems<'a>
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for StrftimeItems<'a>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for StrftimeItems<'a>
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for StrftimeItems<'a>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for StrftimeItems<'a>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for StrftimeItems<'a>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>