kube-rs / k8s-pb

Playing with Kubernetes protobufs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

optional builder patterns

clux opened this issue · comments

This is a possible feature for a much later if we get things working.

One of the things that I found was ugly with k8s-openapi was the need to structs everywhere with optionals so you ended up with ..Default::default() everywhere (leading people to use json!)

Maybe it's worth exploring builders everywhere: https://github.com/idanarye/rust-typed-builder seems to handle options well and require you fill in only required fields (which in kubernetes should be very few). Teo might also have opinions here, he wrote a builder crate.

What we could do in the future (if this gets off the ground) is to optionally #[derive(TypeBuilder)] for the structs.

Possibly a bit heavy, I know Arnav rejected proposals at more ergonomic apis before because of crate size (already heavy enough to compile everything), but that's possibly something we could aid by providing ways to limit the size of the crate (like only exposing the structs for the api groups that you are interested in for instance).

Anyway. This is a note to self for later.

Yeah, I was thinking the same. Hate using json!. I was considering to propose adding derive_builder to k8s-openapi, but got busy. I didn't know it was rejected before.

In addition to Option, I'd love to have Into setters (e.g., no more "name".to_owned()).

Didn't know about typed_builder crate, looks great.

Definitely a good point about Into, that's a big pain point..