I want to migrate some code from C to Rust for learning purposes and to make my learning library a bit more multi-lingual.
The problem is that I know there's a way to integrate C libraries into Rust. That way I could use calloc
in Rust to allow creating my array with a range specified at runtime.
But I don't want to use calloc
here - I'd like to see the Rust way. But I really don't want to use vec!
either; I had some stupid issues with it before so I don't want to use it just yet.
Here is the code:
pub struct Canvas {
width: usize,
height: usize,
array: [char], // I want to declare its type but not its size yet
}
impl Canvas{
pub fn new (&self, width: usize, height: usize) -> Canvas {
Canvas {
width: width,
height: height,
array: calloc(width, height), // alternative to calloc ? }
}
}
I hope my question is still idiomatic to the Rust way of code.