Skip to content

bernlu/derive_index

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

derive_index

proc_macro library to derive indexing into Vectors with newtypes.

Usage

Given a newtype like this:

struct NewType(usize);  // define a struct with inner type that can index something (e.g. Vec<f64>)

using derive_index one can derive indexing into Vec and Vec<Option>

use derive_index::Index;
#[derive(Index)]
#[index_type(f64)]  // index into Vec<f64> and Vec<Option<f64>>
struct NewType(usize);

This will expand into

impl std::ops::Index<NewType> for Vec<f64> {
    type Output = f64;
    fn index(&self, index: NewType) -> &Self::Output {
        self.index(index.0)
    }
}

and corresponding implementations for IndexMut and Vec<Option<f64>>.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages