imgref icon indicating copy to clipboard operation
imgref copied to clipboard

Why are the fields public?

Open quadrupleslap opened this issue 8 years ago • 4 comments

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)?

quadrupleslap avatar Jul 27 '17 16:07 quadrupleslap

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.

kornelski avatar Jul 27 '17 17:07 kornelski

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.

quadrupleslap avatar Jul 27 '17 17:07 quadrupleslap

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.

kornelski avatar Jul 28 '17 02:07 kornelski

pixels and rows iterators are done.

I still use raw buf to:

  • mutably split the buffer.
  • process in parallel using rayon

kornelski avatar Dec 14 '17 03:12 kornelski