Created
January 17, 2019 15:09
-
-
Save kthwaite/84a92750f67b81f83b1b539f8b01e304 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#[macro_export] | |
macro_rules! associated_idx_type { | |
($base_type: ty, $id_type :ident) => { | |
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] | |
pub struct $id_type(pub usize); | |
impl ops::Index<$id_type> for Vec<$base_type> { | |
type Output = $base_type; | |
fn index(&self, index: $id_type) -> &$base_type { | |
&self[index.0] | |
} | |
} | |
impl<'a> ops::Index<&'a $id_type> for Vec<$base_type> { | |
type Output = $base_type; | |
fn index(&self, index: &$id_type) -> &$base_type { | |
&self[index.0] | |
} | |
} | |
impl<'a> ops::IndexMut<&'a $id_type> for Vec<$base_type> { | |
fn index_mut(&mut self, index: &$id_type) -> &mut $base_type { | |
&mut self[index.0] | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment