Last active
August 29, 2015 13:57
-
-
Save gavinb/9924137 to your computer and use it in GitHub Desktop.
Trying template types
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
use std::num::{Zero}; | |
use std::vec::Vec; | |
use std::mem::size_of; | |
pub struct Image<T> { | |
width: uint, | |
height: uint, | |
// ... | |
buffer: Vec<T>, | |
} | |
impl<T: Zero, Clone> Image<T> { | |
fn stride_for_type(w: uint, ch: uint) -> uint { | |
let sz = size_of::<T>(); | |
//... | |
3*w*sz | |
} | |
fn new(w: uint, h: uint) -> Image<T> { | |
let s = Image::<T>::stride_for_type(w, 3); | |
Image { | |
width: w, | |
height: h, | |
buffer: Vec::from_elem(s*h, Zero::zero()), | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The error message: