kenz-gelsoft / wxRust2

re-exploration Rust binding to wx
MIT License
77 stars 10 forks source link

added from trait to wx::ArrayString and updated sample code #185

Closed ahenshaw closed 1 year ago

ahenshaw commented 1 year ago

I've added a "From" trait to wx::ArrayString that allows it to be initialized by any type that implements IntoIterator and for any item that implements the Display trait. This allowed me to clean up a lot of code in the samples.

So, instead of

let x = wx::ArrayString::new()
x.add("1");
x.add("1");

you can just do : let x = wx::ArrayString::from(["1", "2"]);

or even better: let x = ["1", "2"].into(); when the compiler can figure out that x is an ArrayString (which happens a lot in the sample code).

You can also do things like: wx::RadioBox::builder(Some(&self.base)).choices((1..3).into()).build() because integer types implement the Display trait.

kenz-gelsoft commented 1 year ago

Thank you for contributing again.

I intended to keep this library very thin as much as I can, but adding From impl to manually implemented binding of wxArray<wxString> is good idea.

Converting from Display trait may have a little overhead, so let me think a bit, please.

kenz-gelsoft commented 1 year ago

Thanks a lot!