Allow construct CustomFormat outside the crate
Unified · Split
| @@ -20,8 +20,7 @@ pub enum Sign { · 19 unmodified lines | |||
| 20 | /// Various ways to describe a time format. | 20 | /// Various ways to describe a time format. |
| 21 | #[derive(Debug, Clone, Copy)] | 21 | #[derive(Debug, Clone, Copy)] |
| 22 | pub enum Format { | 22 | pub enum Format { |
| 23 | /// A custom format limited to what's in the | 23 | /// A custom format limited to what's in the [`format`](mod@format) submodule. |
| 24 | /// [`format`](mod@crate::time::format) submodule. | ||
| 25 | Custom(CustomFormat), | 24 | Custom(CustomFormat), |
| 26 | /// The seconds since 1970, also known as unix epoch, like `1660874655`. | 25 | /// The seconds since 1970, also known as unix epoch, like `1660874655`. |
| 27 | Unix, | 26 | Unix, |
| @@ -33,6 +32,13 @@ pub enum Format { · 5 unmodified lines | |||
| 33 | #[derive(Clone, Copy, Debug)] | 32 | #[derive(Clone, Copy, Debug)] |
| 34 | pub struct CustomFormat(pub(crate) &'static str); | 33 | pub struct CustomFormat(pub(crate) &'static str); |
| 35 | 34 | ||
| 35 | impl CustomFormat { | ||
| 36 | /// Create a new custom `format` suitable for use with the [`jiff`] crate. | ||
| 37 | pub const fn new(format: &'static str) -> Self { | ||
| 38 | Self(format) | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 36 | impl From<CustomFormat> for Format { | 42 | impl From<CustomFormat> for Format { |
| 37 | fn from(custom_format: CustomFormat) -> Format { | 43 | fn from(custom_format: CustomFormat) -> Format { |
| 38 | Format::Custom(custom_format) | 44 | Format::Custom(custom_format) |