olxgroup-oss / libvips-rust-bindings

Rust bindings for libvips
MIT License
95 stars 41 forks source link

Optional values for command options #8

Closed savtrip closed 1 year ago

savtrip commented 4 years ago

Hey @augustocdias,

I am to using options with the libvips commands and noticed you must specify every single option. I am forced to specify options that I want to leave as the default values programmed into libvips. For example, for arrayjoin I want to only change the value for across but I am forced to change all the other optional values. A current work around, I give a bad value for the options I do not want so libvips ignores them, e.g. hspacing I give a value of 0.

My question, did you design it this way on purpose or did bindgen force you to specify all the options?

savtrip commented 4 years ago

I noticed #5 pointed this out already. I understand rust forces a user to specify all values for a struct, however, a possible solution, make each value into an Option<T> value. Therefore, if a value is specified within each Option then add it as a param to the C function binding, else, do not add the param.

augustocdias commented 4 years ago

All structs implement the Default trait. All the default values for non String types are given by the introspection output from libvips. You can specify the ones you want and set the rest to default like this:

ArrayjoinOptions { across: 10, .. ArrayjoinOptions::Default() } 

The only problem I see is for the ones that are Strings (they have no specified defaults in the introspection output). In that case I believe your option is a good idea.