Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rustdoc comparison with older version #199

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 37 additions & 15 deletions website/src/blog/bon-v3-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,35 +203,37 @@ With this attribute, you can also define fallible setters if you specify a [fall

## Better Rustdoc Output

The documentation generated for the builder was significantly improved in this release. This is all thanks to the [typestate redesign](#typestate-api) and cleanup. You've already seen a comparison of the new look of the docs generated for `bon`'s builders, but there is more.
The documentation generated for the builder was significantly improved in this release. This is all thanks to the [typestate redesign](#typestate-api) and cleanup. There was a comparison of docs with `typed-builder` higher, but let's compare docs with the previous version of `bon`

Now, if you use the [`#[builder(default)]`](../reference/builder/member/default) attribute, the default value will be automatically inserted into the documentation. Big `default = ...` expressions are formatted as code blocks.
::: info Docs by `bon` v2.3 💀 (before)

![image](https://github.com/user-attachments/assets/390858df-1614-42b1-859c-cd70871054bc){data-zoomable}
![image](https://github.com/user-attachments/assets/078548a6-96e7-4341-8541-e06744278e65){data-zoomable}

::: tip Note
:::

`bon` uses [`prettyplease`](https://docs.rs/prettyplease/latest/prettyplease/) for the formatting of these snippets, and it doesn't prettify macros such as `vec![]`, unfortunately. `Vec::from` works in the meantime.
::: info Docs by `bon` v3.0 😇 (after)

![image](https://github.com/user-attachments/assets/e63ca584-4c37-4774-8328-b6dd0edebebe){data-zoomable}

:::

There are no more generics with leading `__` in the docs. Builder macros now handle name conflicts automatically and use simpler names for generated generic parameters to make docs cleaner.

There are also **Required**/**Optional** hints in the generated setters' documentation.

There are no more generics with leading `__` in the docs. Builder macros now handle name conflicts automatically and use simpler names for generated generic parameters to make docs cleaner.
Now, if you use the [`#[builder(default)]`](../reference/builder/member/default) attribute, the default value will be automatically inserted into the documentation. Big `default = ...` expressions are formatted as code blocks.

Here is [the link](https://docs.rs/bon-sandbox/latest/bon_sandbox/attr_default/struct.ExampleBuilder.html) to the example docs shown above.
::: info Rendering defaults in the docs ([docs.rs link](https://docs.rs/bon-sandbox/latest/bon_sandbox/attr_default/struct.ExampleBuilder.html))

## Granular Docs and Visibility Overrides
![image](https://github.com/user-attachments/assets/390858df-1614-42b1-859c-cd70871054bc){data-zoomable}

There were many new attributes added to override the visibility and the documentation of various items generated by the builder macros:
:::

- [`builder_type(vis = "...", docs { ... })`](../reference/builder/top-level/builder_type)
- [`start_fn(vis = "...", docs { ... })`](../reference/builder/top-level/start_fn)
- [`finish_fn(vis = "...", docs { ... })`](../reference/builder/top-level/finish_fn)
- [`state_mod(vis = "...", docs { ... })`](../reference/builder/top-level/state_mod)
- [`setters(vis = "...", docs { ... })`](../reference/builder/member/setters)
::: tip Note

See the updated [Documenting](../guide/basics/documenting#custom-doc-attributes) page.
`bon` uses [`prettyplease`](https://docs.rs/prettyplease/latest/prettyplease/) to format these snippets, and it doesn't prettify macros such as `vec![]`, unfortunately. `Vec::from` works in the meantime.

:::

## `#[builder(required)]`

Expand Down Expand Up @@ -286,6 +288,26 @@ If you want to wrap `bon`'s macros with your own, the [`#[builder(crate)]`](../r
struct Example {}
```

## Granular Docs and Visibility Overrides

There were many new attributes added to override the visibility and the documentation of various items generated by the builder macros:

- [`builder_type(vis = "...", doc { ... })`](../reference/builder/top-level/builder_type)
- [`start_fn(vis = "...", doc { ... })`](../reference/builder/top-level/start_fn)
- [`finish_fn(vis = "...", doc { ... })`](../reference/builder/top-level/finish_fn)
- [`state_mod(vis = "...", doc { ... })`](../reference/builder/top-level/state_mod)
- [`setters(vis = "...", doc { ... })`](../reference/builder/member/setters)

The `doc` block accepts actual doc comments (not strings), for example:

```attr
#[builder(builder_type(doc {
/// Doc comments
}))]
```

See the updated [Documenting](../guide/basics/documenting#custom-doc-attributes) page.

## Other Changes

This post doesn't cover everything. See the [full changelog here](../changelog#_3-0-0-2024-11-13).
Expand Down
Loading