Portable-Network-Archive / liblzma-rs

Bindings to liblzma in Rust (xz streams in Rust)
Apache License 2.0
12 stars 5 forks source link

Xz builder pattern #129

Open ikrivosheev opened 1 month ago

ikrivosheev commented 1 month ago

Hello! I have an idea. Now my code looks something like this:

let mut filters = Filters::new();
filters.lzma1_properties(properties)?;

let stream = Stream::new_raw_decoder(&filters)?;

let mut decoder = XzDecoder::new_stream(input, stream);

I think using builder pattern will improve user experience.

ChanTsune commented 1 month ago

Builder pattern, It's worth considering! However, I think we should be cautious in its implementation because there are several ways to implement the builder pattern—such as having methods consume ownership or return references—and different people have different preferences. so I'm a bit cautious about introducing it.

Whether to actually introduce the builder pattern is another matter, but I envisioned something like an XzDecoderBuilder::new().filter().build(). Do you have a more specific image in mind?

ikrivosheev commented 4 weeks ago

Well, I'll try to make a draft with examples of using.