Skip to content

Instantly share code, notes, and snippets.

@polymonster
Last active April 22, 2022 19:14
Show Gist options
  • Save polymonster/68674ddcab96f8855a009fd9e48d8bb7 to your computer and use it in GitHub Desktop.
Save polymonster/68674ddcab96f8855a009fd9e48d8bb7 to your computer and use it in GitHub Desktop.
Vec<T, const N: usize>
pub struct Vec<T, const N: usize> {
v: [T; N]
}
impl<T, const N: usize> Vec<T, N> where T: std::ops::AddAssign + std::fmt::Display {
fn print(&self) {
for i in 0..N {
print!("{}, ", self.v[i]);
}
print!("\n");
}
}
fn main() {
let v2 = Vec::<f32, 2> {
v: [6.0, 9.0]
};
v2.print();
let v3 = Vec::<f32, 3> {
v: [6.0, 9.0, 8.0]
};
v3.print();
let v4 = Vec::<f32, 4> {
v: [6.0, 9.0, 8.0, 4.0]
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment