#[repr(transparent)]pub struct MonthIndex(pub f32);
Expand description
0-based Month representation.
Internally stores the month as f32
in the range 0.0..=11.0
, corresponding to:
0.0
-> January (Morning Star)1.0
-> February (Sun’s Dawn)11.0
-> December (Evening Star)
§Example
use commonlibsse_ng::re::Calendar::MonthIndex;
let month = MonthIndex::new(0.0);
assert_eq!(month.to_clamp_month(), Some(1)); // 1-based month
let month = MonthIndex::new(11.0);
assert_eq!(month.to_clamp_month(), Some(12)); // Evening Star
let month = MonthIndex::new(12.0);
assert_eq!(month.to_clamp_month(), None); // Out of range
Tuple Fields§
§0: f32
Implementations§
Source§impl MonthIndex
impl MonthIndex
Sourcepub const fn new(value: f32) -> Self
pub const fn new(value: f32) -> Self
Creates a new MonthIndex
instance with the specified value.
§Example
let month = MonthIndex::new(5.0);
assert_eq!(month.0, 5.0);
Sourcepub const fn to_clamp_month(self) -> Option<u32>
pub const fn to_clamp_month(self) -> Option<u32>
Returns the 1-based month (1..=12) if the value is valid, otherwise None
.
0.0
→1
(January)11.0
→12
(December)
Returns None
if the value is out of the valid range (0.0..=11.0
).
§Example (Boundary Tests)
assert_eq!(MonthIndex::new(0.0).to_clamp_month(), Some(1)); // Morning Star
assert_eq!(MonthIndex::new(11.0).to_clamp_month(), Some(12)); // Evening Star
assert_eq!(MonthIndex::new(12.0).to_clamp_month(), None); // Out of range
assert_eq!(MonthIndex::new(-1.0).to_clamp_month(), None); // Out of range
Sourcepub const fn to_enum(self) -> Option<MonthInGame>
pub const fn to_enum(self) -> Option<MonthInGame>
Converts MonthIndex
into MonthInGame
enum if the value is valid.
Returns None
if the value is out of range (0.0..=11.0
).
§Example
let month = MonthIndex::new(0.0);
assert_eq!(month.to_enum(), Some(MonthInGame::MorningStar));
let invalid_month = MonthIndex::new(12.0);
assert_eq!(invalid_month.to_enum(), None);
Trait Implementations§
Source§impl Clone for MonthIndex
impl Clone for MonthIndex
Source§fn clone(&self) -> MonthIndex
fn clone(&self) -> MonthIndex
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for MonthIndex
impl Debug for MonthIndex
Source§impl Default for MonthIndex
impl Default for MonthIndex
Source§fn default() -> MonthIndex
fn default() -> MonthIndex
Returns the “default value” for a type. Read more
Source§impl From<MonthInGame> for MonthIndex
impl From<MonthInGame> for MonthIndex
Source§fn from(month: MonthInGame) -> Self
fn from(month: MonthInGame) -> Self
Converts to this type from the input type.
Source§impl PartialEq for MonthIndex
impl PartialEq for MonthIndex
Source§impl TryFrom<MonthIndex> for MonthInGame
impl TryFrom<MonthIndex> for MonthInGame
impl Copy for MonthIndex
impl StructuralPartialEq for MonthIndex
Auto Trait Implementations§
impl Freeze for MonthIndex
impl RefUnwindSafe for MonthIndex
impl Send for MonthIndex
impl Sync for MonthIndex
impl Unpin for MonthIndex
impl UnwindSafe for MonthIndex
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