pub struct Date {
pub year: Option<i32>,
pub month: Option<u32>,
pub day: Option<u32>,
}
Expand description
Represents a date.
Fields§
§year: Option<i32>
The year of the date.
month: Option<u32>
The month of the date.
day: Option<u32>
The day of the date.
Implementations§
Source§impl Date
impl Date
Sourcepub fn new(year: Option<i32>, month: Option<u32>, day: Option<u32>) -> Self
pub fn new(year: Option<i32>, month: Option<u32>, day: Option<u32>) -> Self
Creates a new date.
Sourcepub fn format(&self, format: &str) -> String
pub fn format(&self, format: &str) -> String
Formats the date according to the given format string.
The format string can contain the following placeholders:
{year}
,{yyyy}
,{yy}
,{y}
,{YEAR}
,{YYYY}
,{YY}
,{Y}
: Year{month}
,{mon}
,{mm}
,{m}
,{MONTH}
,{MON}
,{MM}
,{M}
: Month{day}
,{dd}
,{d}
,{DAY}
,{DD}
,{D}
: Day
§Arguments
format
- A string slice that holds the format pattern.
§Example
let date = Date { year: Some(2023), month: Some(10), day: Some(5) };
let formatted = date.format("{yyyy}-{mm}-{dd}");
assert_eq!(formatted, "2023-10-05");
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Date
impl<'de> Deserialize<'de> for Date
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Date
Auto Trait Implementations§
impl Freeze for Date
impl RefUnwindSafe for Date
impl Send for Date
impl Sync for Date
impl Unpin for Date
impl UnwindSafe for Date
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string
, but without panic on OOM.