Skip to content

Commit 10fd7b0

Browse files
authored
Merge pull request #2 from ggwpez/oty-update
Update deps
2 parents a08283c + a4586a6 commit 10fd7b0

File tree

11 files changed

+56
-88
lines changed

11 files changed

+56
-88
lines changed

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[workspace.package]
22
edition = "2021"
3-
version = "0.5.0"
3+
version = "0.5.2"
44
authors = ["Oliver Tale-Yazdi <[email protected]>"]
55
license = "GPL-3.0-only"
66
repository = "https://github.com/ggwpez/typesafe-builders"
@@ -24,7 +24,7 @@ typesafe-builders-core = { path = "typesafe-builders-core", version = "0.5.0" }
2424
typesafe-builders-derive = { path = "typesafe-builders-derive", version = "0.5.0" }
2525

2626
# External deps
27-
derive-syn-parse = { version = "0.1.5", default-features = false }
28-
proc-macro2 = { version = "1.0.56", default-features = false }
29-
quote = { version = "1.0.26", default-features = false }
30-
syn = "2.0.15"
27+
derive-syn-parse = { version = "0.2.0", default-features = false }
28+
proc-macro2 = { version = "1.0.101", default-features = false }
29+
quote = { version = "1.0.40", default-features = false }
30+
syn = "2.0.106"

MAINTAIN

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Without any un-staged changes:
22

33
```bash
4-
git tag -s -f typesafe-builders@0.4.1 -m "typesafe-builders v0.4.1"
5-
git tag -s -f typesafe-builders-core@0.4.1 -m "typesafe-builders-core v0.4.1"
6-
git tag -s -f typesafe-builders-derive@0.4.1 -m "typesafe-builders-derive v0.4.1"
4+
git tag -s -f typesafe-builders@0.5.1 -m "typesafe-builders v0.5.1"
5+
git tag -s -f typesafe-builders-core@0.5.1 -m "typesafe-builders-core v0.5.1"
6+
git tag -s -f typesafe-builders-derive@0.5.1 -m "typesafe-builders-derive v0.5.1"
77

88
cargo publish -p typesafe-builders-core && cargo publish -p typesafe-builders-derive && cargo publish -p typesafe-builders
99
```

README.md

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,27 @@ No more worrying whether the `build` call on your builder will return `Ok` or no
2727
```rust
2828
use typesafe_builders::prelude::*;
2929

30-
fn main() {
31-
#[derive(Builder)]
32-
struct Point {
33-
#[builder(constructor)]
34-
x: u8,
35-
y: u8,
36-
#[builder(optional)]
37-
z: Option<u8>,
38-
}
30+
#[derive(Builder)]
31+
struct Point {
32+
#[builder(constructor)]
33+
x: u8,
34+
y: u8,
35+
#[builder(optional)]
36+
z: Option<u8>,
37+
}
3938

40-
// `builder` requires `x` since it is marked as `constructor`.
41-
let builder = Point::builder(1);
42-
// These do not compile:
43-
// partial.x(6); // `x` is already set
44-
// partial.build(); // `y` is not set
39+
// `builder` requires `x` since it is marked as `constructor`.
40+
let builder = Point::builder(1);
41+
// These do not compile:
42+
// partial.x(6); // `x` is already set
43+
// partial.build(); // `y` is not set
4544

46-
// `build` is only available once all required fields are set:
47-
let result = builder.y(2).build();
45+
// `build` is only available once all required fields are set:
46+
let result = builder.y(2).build();
4847

49-
assert_eq!(result.x, 1);
50-
assert_eq!(result.y, 2);
51-
assert_eq!(result.z, None);
52-
}
48+
assert_eq!(result.x, 1);
49+
assert_eq!(result.y, 2);
50+
assert_eq!(result.z, None);
5351
```
5452

5553

@@ -97,12 +95,10 @@ pub struct Struct {
9795
x: u8,
9896
}
9997

100-
fn main() {
101-
// without x
102-
Struct::builder().build();
103-
// with x
104-
Struct::builder().x(4).build();
105-
}
98+
// without x
99+
Struct::builder().build();
100+
// with x
101+
Struct::builder().x(4).build();
106102
```
107103

108104
### Constructor
@@ -118,11 +114,10 @@ pub struct Struct {
118114
x: u8,
119115
}
120116

121-
fn main() {
122-
Struct::builder(4).build();
123-
// does not work:
124-
// Struct::builder(4).x(5).build();
125-
}
117+
Struct::builder(4).build();
118+
119+
// This does not compile since `x` is already set:
120+
// Struct::builder(4).x(5).build();
126121
```
127122

128123
### Decay
@@ -138,10 +133,8 @@ pub struct Struct {
138133
x: Option<u8>,
139134
}
140135

141-
fn main() {
142-
// Use `4` instead of `Some(4)`
143-
Struct::builder().x(4).build();
144-
}
136+
// You can use `4` now instead of `Some(4)`:
137+
Struct::builder().x(4).build();
145138
```
146139

147140
# How does it work?
@@ -188,9 +181,7 @@ pub struct Struct<'a, 'b, 'c> {
188181
x: &'a Box<&'b Option<&'c str>>, // yikes
189182
}
190183

191-
fn main() {
192-
Struct::builder().x(&Box::new(&Some("hi"))).build();
193-
}
184+
Struct::builder().x(&Box::new(&Some("hi"))).build();
194185
```
195186

196187
### Generics
@@ -207,9 +198,7 @@ mod other {
207198
}
208199
}
209200

210-
fn main() {
211-
other::Struct::<u8>::builder().y(Some(4)).build();
212-
}
201+
other::Struct::<u8>::builder().y(Some(4)).build();
213202
```
214203

215204
### Const Generics
@@ -226,9 +215,7 @@ mod other {
226215
}
227216
}
228217

229-
fn main() {
230-
other::Struct::<1>::builder().x([1]).build();
231-
}
218+
other::Struct::<1>::builder().x([1]).build();
232219
```
233220

234221
# TODOs

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[toolchain]
2-
channel = "nightly-2023-05-04"
2+
channel = "nightly-2025-09-01"
33
components = [ "rustfmt", "clippy" ]
44
profile = "minimal"

typesafe-builders-core/src/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,8 @@ struct ParsedFieldAttr {
5151

5252
pub fn impl_derive_builder(ast: &syn::DeriveInput) -> syn::Result<proc_macro2::TokenStream> {
5353
let syn::Data::Struct(ref s) = ast.data else {
54-
return Err(syn::Error::new_spanned(
55-
ast,
56-
"derive(Builder) can only be used on structs",
57-
));
58-
};
54+
return Err(syn::Error::new_spanned(ast, "derive(Builder) can only be used on structs"));
55+
};
5956
let mut user_generics_def = Vec::<&syn::GenericParam>::new();
6057
let mut user_generics_impl = Vec::<proc_macro2::TokenStream>::new();
6158
let mut user_generics_alias = Vec::<proc_macro2::TokenStream>::new();

typesafe-builders/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ typesafe-builders-core.workspace = true
1818
typesafe-builders-derive.workspace = true
1919

2020
[dev-dependencies]
21-
trybuild = "1.0.80"
21+
trybuild = "1.0.90"

typesafe-builders/tests/ui/reject/builder_priv.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ error[E0603]: struct `Struct` is private
77
note: the struct `Struct` is defined here
88
--> tests/ui/reject/builder_priv.rs:5:2
99
|
10-
5 | struct Struct {
10+
5 | struct Struct {
1111
| ^^^^^^^^^^^^^

typesafe-builders/tests/ui/reject/field_attr/ctor/missing_arg.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ error[E0061]: this function takes 1 argument but 0 arguments were supplied
22
--> tests/ui/reject/field_attr/ctor/missing_arg.rs:10:2
33
|
44
10 | Struct::builder().build();
5-
| ^^^^^^^^^^^^^^^-- an argument of type `u8` is missing
5+
| ^^^^^^^^^^^^^^^-- argument #1 of type `u8` is missing
66
|
77
note: associated function defined here
88
--> tests/ui/reject/field_attr/ctor/missing_arg.rs:3:10
99
|
10-
3 | #[derive(Builder)]
10+
3 | #[derive(Builder)]
1111
| ^^^^^^^
1212
...
13-
6 | x: u8,
13+
6 | x: u8,
1414
| -----
1515
= note: this error originates in the derive macro `Builder` (in Nightly builds, run with -Z macro-backtrace for more info)
1616
help: provide the argument
1717
|
1818
10 | Struct::builder(/* u8 */).build();
19-
| ~~~~~~~~~~
19+
| ++++++++

typesafe-builders/tests/ui/reject/field_missing_required_2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use typesafe_builders::prelude::*;
2-
31
//! `Option` is *not* treated as optional.
42
3+
use typesafe_builders::prelude::*;
4+
55
#[derive(Builder)]
66
struct Struct {
77
x: Option<u8>,

typesafe-builders/tests/ui/reject/field_missing_required_2.stderr

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,7 @@
1-
error[E0753]: expected outer doc comment
2-
--> tests/ui/reject/field_missing_required_2.rs:3:1
3-
|
4-
3 | //! `Option` is *not* treated as optional.
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
...
7-
6 | / struct Struct {
8-
7 | | x: Option<u8>,
9-
8 | | }
10-
| |_- the inner doc comment doesn't annotate this struct
11-
|
12-
help: to annotate the struct, change the doc comment from inner to outer style
13-
|
14-
3 | /// `Option` is *not* treated as optional.
15-
| ~
16-
171
error[E0599]: no method named `build` found for struct `GenericStructBuilder<false>` in the current scope
18-
--> tests/ui/reject/field_missing_required_2.rs:11:20
19-
|
20-
5 | #[derive(Builder)]
2+
--> tests/ui/reject/field_missing_required_2.rs:11:20
3+
|
4+
5 | #[derive(Builder)]
215
| ------- method `build` not found for this struct
226
...
237
11 | Struct::builder().build();

0 commit comments

Comments
 (0)