pub struct DateFormat {
pub formatter: String,
}
Expand description
The format a DateStr will be printed
Fields§
§formatter: String
The format to be used
Implementations§
Source§impl DateFormat
impl DateFormat
Sourcepub fn from_string<T: ToString>(
format: T,
separator: Option<char>,
) -> Result<DateFormat, DateErrors>
pub fn from_string<T: ToString>( format: T, separator: Option<char>, ) -> Result<DateFormat, DateErrors>
Creates a DateFormat from String or a &str
This method will try to create a DateFormat from any type that implements the ToString type, although is mainly oriented to String and string slices.
§Example:
let format: DateFormat = DateFormat::from_string("YYYY-MM-DD", None).unwrap();
assert_eq!(format.formatter, "YYYY-MM-DD");
Above code will create a new DateFormat object. If none is passed as separator, it defaults to a dash (‘-’).
§Example returning error:
let format: Result<DateFormat, DateErrors> = DateFormat::from_string("2020_10_20", Some('/'));
assert!(format.is_err());
When the separator is not explicitly specified, it will give an error if it’s not a dash.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DateFormat
impl RefUnwindSafe for DateFormat
impl Send for DateFormat
impl Sync for DateFormat
impl Unpin for DateFormat
impl UnwindSafe for DateFormat
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