Skip to content

Commit 3f98086

Browse files
committed
Merge remote-tracking branch 'upstream/main' into dpezely/subtype-naming
2 parents 287878f + ffea267 commit 3f98086

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+440
-15088
lines changed

Cargo.lock

Lines changed: 21 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ typify = { version = "0.5.0", path = "typify" }
1616
typify-impl = { version = "0.5.0", path = "typify-impl" }
1717
typify-macro = { version = "0.5.0", path = "typify-macro" }
1818

19-
assert_cmd = "2.1.1"
19+
assert_cmd = "2.1.2"
2020
chrono = { version = "0.4.42", features = ["serde"] }
21-
clap = { version = "4.5.53", features = ["derive"] }
21+
clap = { version = "4.5.54", features = ["derive"] }
2222
color-eyre = "0.6"
2323
env_logger = "0.11"
2424
expectorate = "1.2.0"
@@ -29,16 +29,16 @@ log = "0.4.29"
2929
newline-converter = "0.3.0"
3030
paste = "1.0.15"
3131
prettyplease = "0.2.37"
32-
proc-macro2 = "1.0.103"
33-
quote = "1.0.42"
32+
proc-macro2 = "1.0.105"
33+
quote = "1.0.43"
3434
regress = "0.10.5"
3535
rustfmt-wrapper = "0.2.1"
3636
schema = "0.1.0"
3737
schemars = "0.8.22"
3838
semver = "1.0.27"
3939
serde = "1.0.228"
40-
serde_json = "1.0.146"
41-
syn = { version = "2.0.111", features = ["full"] }
40+
serde_json = "1.0.149"
41+
syn = { version = "2.0.114", features = ["full"] }
4242
tempdir = "0.3.7"
4343
thiserror = "2.0.17"
4444
trybuild = "1.0.114"

cargo-typify/README.md

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@ pub enum IdOrName {
7272
Id(uuid::Uuid),
7373
Name(Name),
7474
}
75-
impl From<&IdOrName> for IdOrName {
76-
fn from(value: &IdOrName) -> Self {
77-
value.clone()
78-
}
79-
}
8075
impl std::str::FromStr for IdOrName {
8176
type Err = &'static str;
8277
fn from_str(value: &str) -> Result<Self, &'static str> {
@@ -95,12 +90,6 @@ impl std::convert::TryFrom<&str> for IdOrName {
9590
value.parse()
9691
}
9792
}
98-
impl std::convert::TryFrom<&String> for IdOrName {
99-
type Error = &'static str;
100-
fn try_from(value: &String) -> Result<Self, &'static str> {
101-
value.parse()
102-
}
103-
}
10493
impl std::convert::TryFrom<String> for IdOrName {
10594
type Error = &'static str;
10695
fn try_from(value: String) -> Result<Self, &'static str> {
@@ -139,11 +128,6 @@ impl From<Name> for String {
139128
value.0
140129
}
141130
}
142-
impl From<&Name> for Name {
143-
fn from(value: &Name) -> Self {
144-
value.clone()
145-
}
146-
}
147131
impl std::str::FromStr for Name {
148132
type Err = &'static str;
149133
fn from_str(value: &str) -> Result<Self, &'static str> {
@@ -166,12 +150,6 @@ impl std::convert::TryFrom<&str> for Name {
166150
value.parse()
167151
}
168152
}
169-
impl std::convert::TryFrom<&String> for Name {
170-
type Error = &'static str;
171-
fn try_from(value: &String) -> Result<Self, &'static str> {
172-
value.parse()
173-
}
174-
}
175153
impl std::convert::TryFrom<String> for Name {
176154
type Error = &'static str;
177155
fn try_from(value: String) -> Result<Self, &'static str> {
@@ -204,5 +182,8 @@ default). Builder output lets you write code like this:
204182
let xy: MyStruct = MyStruct::builder().x_coord(x).y_coord(y).try_into();
205183
```
206184

207-
The `--additional-derive` adds the specified derive macro to all generated
208-
types. This may be specified more than once.
185+
The `--additional-derive` option adds the specified derive macro to all generated
186+
types. This may be specified more than once.
187+
188+
The `--additional-attr` option adds the specified attribute to all generated
189+
types. This may be specified more than once.

cargo-typify/src/lib.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ pub struct CliArgs {
3131
pub no_builder: bool,
3232

3333
/// Add an additional derive macro to apply to all defined types.
34-
#[arg(short, long = "additional-derive", value_name = "derive")]
34+
#[arg(short = 'd', long = "additional-derive", value_name = "derive")]
3535
pub additional_derives: Vec<String>,
3636

37+
/// Add an additional attribute to apply to all defined types.
38+
#[arg(short = 'a', long = "additional-attr", value_name = "attr")]
39+
pub additional_attrs: Vec<String>,
40+
3741
/// The output file to write to. If not specified, the input file name will
3842
/// be used with a `.rs` extension.
3943
///
@@ -146,6 +150,10 @@ pub fn convert(args: &CliArgs) -> Result<String> {
146150
settings.with_derive(derive.clone());
147151
}
148152

153+
for attr in &args.additional_attrs {
154+
settings.with_attr(attr.clone());
155+
}
156+
149157
for CrateSpec {
150158
name,
151159
version,
@@ -197,6 +205,7 @@ mod tests {
197205
input: PathBuf::from("input.json"),
198206
builder: false,
199207
additional_derives: vec![],
208+
additional_attrs: vec![],
200209
output: Some(PathBuf::from("-")),
201210
no_builder: false,
202211
crates: vec![],
@@ -213,6 +222,7 @@ mod tests {
213222
input: PathBuf::from("input.json"),
214223
builder: false,
215224
additional_derives: vec![],
225+
additional_attrs: vec![],
216226
output: Some(PathBuf::from("some_file.rs")),
217227
no_builder: false,
218228
crates: vec![],
@@ -229,6 +239,7 @@ mod tests {
229239
input: PathBuf::from("input.json"),
230240
builder: false,
231241
additional_derives: vec![],
242+
additional_attrs: vec![],
232243
output: None,
233244
no_builder: false,
234245
crates: vec![],
@@ -245,6 +256,7 @@ mod tests {
245256
input: PathBuf::from("input.json"),
246257
builder: false,
247258
additional_derives: vec![],
259+
additional_attrs: vec![],
248260
output: None,
249261
no_builder: false,
250262
crates: vec![],
@@ -264,6 +276,7 @@ mod tests {
264276
input: PathBuf::from("input.json"),
265277
builder: false,
266278
additional_derives: vec![],
279+
additional_attrs: vec![],
267280
output: None,
268281
no_builder: false,
269282
crates: vec![],
@@ -280,6 +293,7 @@ mod tests {
280293
input: PathBuf::from("input.json"),
281294
builder: false,
282295
additional_derives: vec![],
296+
additional_attrs: vec![],
283297
output: None,
284298
no_builder: true,
285299
crates: vec![],
@@ -296,6 +310,7 @@ mod tests {
296310
input: PathBuf::from("input.json"),
297311
builder: true,
298312
additional_derives: vec![],
313+
additional_attrs: vec![],
299314
output: None,
300315
no_builder: false,
301316
crates: vec![],

0 commit comments

Comments
 (0)