Byron / Byron/pulldown-cmark-to-cmark

Idea: consider using "builder pattern" for `Options` struct to prevent breaking changes in additions

Open
#19 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
63
Forks
46
PR merge metrics
No merged PRs in 30d

Description

I think it might be valuable to consider using "builder pattern" for the `Options` struct (and perhaps `State` as well) to prevent breaking changes in additions (e.g. #17). It would mean you could easily add more options to these structs without it being a breaking change because all fields would be private for `Options`.

See https://doc.rust-lang.org/1.0.0/style/ownership/builders.html

### Example (consuming builder)

API:

```rust
let options = Options::default()
.newlines_after_headline(2)
.newlines_after_paragraph(3);
```

Implementation

```rust
struct Options {
newlines_after_headline: usize,
newlines_after_paragraph: usize,
..
}

impl Options {
fn newlines_after_headline(mut self, value: usize) -> Self {
self.newlines_after_headline = value;
self
}

fn newlines_after_paragraph(mut self, value: usize) -> Self {
self.newlines_after_paragraph = value;
self
}

..
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.