Open quadrupleslap opened 6 years ago
The dimension fields are meant to be read-only. It is unfortunate that this is not enforced.
When you call a method with &self
, Rust borrows the entire object. This means it's not possible to get a writeable buffer via fn buf(&mut self)
and then read dimensions via fn width(&self)
, since the first call "locks" the entire object.
Fair enough, but why can't the user read the width first if they need it, and then write? Or why not proxy the width and height getters through the writable buffer? This (probably useless) flexibility doesn't seem worth it.
OK, I think I can make it work with enough high-level functionality added, so that it will be rare to need to read these properties.
I've added indexing img[(x,y)]
, so that img.buf[y*img.stride + x]
is not needed.
pixels and rows iterators are done.
I still use raw buf
to:
After all the assertions in the code, it's weird that the fields are public, since anyone could change them right afterwards, placing the object in an invalid state. Maybe make it harder for people to shoot themselves in the foot by using private fields and getters (and maybe setters, if necessary)?