-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2aa1fb8
commit 57db83e
Showing
4 changed files
with
81 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use crate::Id; | ||
|
||
#[derive(Debug, Default)] | ||
pub enum MaybeData<Data> { | ||
Data(Data), | ||
Id(Id), | ||
#[default] | ||
None, | ||
} | ||
|
||
impl<Data> MaybeData<Data> { | ||
#[inline] | ||
pub fn data(&self) -> Option<&Data> { | ||
match self { | ||
MaybeData::Data(data) => Some(data), | ||
MaybeData::Id(_id) => None, | ||
MaybeData::None => None, | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn data_mut(&mut self) -> Option<&mut Data> { | ||
match self { | ||
MaybeData::Data(data) => Some(data), | ||
MaybeData::Id(_id) => None, | ||
MaybeData::None => None | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn id(&self) -> Option<&Id> { | ||
match self { | ||
MaybeData::Data(_data) => None, | ||
MaybeData::Id(id) => Some(id), | ||
MaybeData::None => None, | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn id_mut(&mut self) -> Option<&mut Id> { | ||
match self { | ||
MaybeData::Data(_data) => None, | ||
MaybeData::Id(id) => Some(id), | ||
MaybeData::None => None, | ||
} | ||
} | ||
} |