plotlib icon indicating copy to clipboard operation
plotlib copied to clipboard

Could make BoxPlot a Cow?

Open simonrw opened this issue 6 years ago • 1 comments

https://github.com/milliams/plotlib/blob/c732707b9bb29d51d42485d321df96d9d4d3d4b0/src/boxplot.rs#L57-L60

vs

pub enum Cow<'a, B> where
    B: 'a + ToOwned + ?Sized,  {
    Borrowed(&'a B),
    Owned(<B as ToOwned>::Owned),
}

This struct exactly matches the std::borrow::Cow type. Unless extra functionality is required, the stdlib type should probably be used.

simonrw avatar Apr 15 '18 21:04 simonrw

Indeed it looks like API wise it would work as a replacement. However, I'm not sure if it makes sense semantically. The reason I was using the BoxData enum was to allow users of the BoxPlot representation to either move their data into the boxplot or simply have it referenced. It's not really intended to allow copy-on-write semantics.

It's still very undecided how the API for taking data from the user and putting it into some plotlib-internal data type should look. Currently BoxPlot is the only one that works like that and it was a bit of an experiment. We'll probably want consistent sematics across all the representations where possible.

Also, I haven't had much experience with Rust's managed pointers and COW types. Everything I've done so far has been simple ownership (with a ref references and Vecs) so it's possible I'm missing something.

milliams avatar Apr 21 '18 16:04 milliams