JonasKruckenberg / tauri-sys

Bindings to the Tauri API for projects using wasm-bindgen
Apache License 2.0
84 stars 21 forks source link

Should `Builder` methods return `self`? #11

Closed bicarlsen closed 1 year ago

bicarlsen commented 1 year ago

In thinking about the ergonomics of the library, would it be nice for Builder methods -- e.g. FileDialogBuilder.set_default_path -- to return self?

This would allow method chaining turning, e.g.

let mut dialog = FileDialogBuilder::new();
dialog.set_title("Pick a file");
let file = dialog.pick_file().await;

into

let file = FileDialogBuilder::new()
    .set_title("Pick a file")
    .pick_file()
    .await;
JonasKruckenberg commented 1 year ago

All builders (I think) are now non-consuming so it's a bit more tricky to do that, we cannot just return Self from methods, since we borrow &mut self.

But I'm thinking we can just make the final method take an &self instead of self since we never need ownership of the builder anyway 🤔 it just feels a bit weird to have the final method of a builder take &self but that's alright I guess

JonasKruckenberg commented 1 year ago

Update, it makes total sense for the final methods of each builder to only take immutable references to the builder bc all the js methods have to clone anyway

bicarlsen commented 1 year ago

Looks much more ergonomic now :)

JonasKruckenberg commented 1 year ago

Merged 😄