Skip to content
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion cargo-typify/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn main() -> Result<()> {
format!("Failed to write output to file: {}", output_path.display())
})?;
} else {
print!("{}", contents);
print!("{contents}");
}

Ok(())
Expand Down
32 changes: 8 additions & 24 deletions cargo-typify/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use tempdir::TempDir;

#[test]
fn test_simple() {
use assert_cmd::Command;

let input = concat!(env!("CARGO_MANIFEST_DIR"), "/../example.json");

let temp = TempDir::new("cargo-typify").unwrap();
Expand All @@ -14,7 +12,7 @@ fn test_simple() {

let output_file = temp.path().join("simple.rs");

let mut cmd = Command::cargo_bin("cargo-typify").unwrap();
let mut cmd = assert_cmd::cargo::cargo_bin_cmd!("cargo-typify");
cmd.args(["typify", input_file.to_str().unwrap()])
.assert()
.success();
Expand All @@ -26,14 +24,12 @@ fn test_simple() {

#[test]
fn test_default_output() {
use assert_cmd::Command;

let input = concat!(env!("CARGO_MANIFEST_DIR"), "/../example.json");

let temp = TempDir::new("cargo-typify").unwrap();
let output_file = temp.path().join("output.rs");

let mut cmd = Command::cargo_bin("cargo-typify").unwrap();
let mut cmd = assert_cmd::cargo::cargo_bin_cmd!("cargo-typify");
cmd.args(["typify", input, "--output", output_file.to_str().unwrap()])
.assert()
.success();
Expand All @@ -45,11 +41,9 @@ fn test_default_output() {

#[test]
fn test_no_builder_stdout() {
use assert_cmd::Command;

let input = concat!(env!("CARGO_MANIFEST_DIR"), "/../example.json");

let mut cmd = Command::cargo_bin("cargo-typify").unwrap();
let mut cmd = assert_cmd::cargo::cargo_bin_cmd!("cargo-typify");

let output = cmd
.args(["typify", input, "--no-builder", "--output", "-"])
Expand All @@ -65,14 +59,12 @@ fn test_no_builder_stdout() {

#[test]
fn test_builder() {
use assert_cmd::Command;

let input = concat!(env!("CARGO_MANIFEST_DIR"), "/../example.json");

let temp = TempDir::new("cargo-typify").unwrap();
let output_file = temp.path().join("output.rs");

let mut cmd = Command::cargo_bin("cargo-typify").unwrap();
let mut cmd = assert_cmd::cargo::cargo_bin_cmd!("cargo-typify");
cmd.args([
"typify",
input,
Expand All @@ -90,14 +82,12 @@ fn test_builder() {

#[test]
fn test_derive() {
use assert_cmd::Command;

let input = concat!(env!("CARGO_MANIFEST_DIR"), "/../example.json");

let temp = TempDir::new("cargo-typify").unwrap();
let output_file = temp.path().join("output.rs");

let mut cmd = Command::cargo_bin("cargo-typify").unwrap();
let mut cmd = assert_cmd::cargo::cargo_bin_cmd!("cargo-typify");
cmd.args([
"typify",
input,
Expand All @@ -117,14 +107,12 @@ fn test_derive() {

#[test]
fn test_multi_derive() {
use assert_cmd::Command;

let input = concat!(env!("CARGO_MANIFEST_DIR"), "/../example.json");

let temp = TempDir::new("cargo-typify").unwrap();
let output_file = temp.path().join("output.rs");

let mut cmd = Command::cargo_bin("cargo-typify").unwrap();
let mut cmd = assert_cmd::cargo::cargo_bin_cmd!("cargo-typify");
cmd.args([
"typify",
input,
Expand All @@ -146,9 +134,7 @@ fn test_multi_derive() {

#[test]
fn test_help() {
use assert_cmd::Command;

let mut cmd = Command::cargo_bin("cargo-typify").unwrap();
let mut cmd = assert_cmd::cargo::cargo_bin_cmd!("cargo-typify");

let output = cmd.args(["typify", "--help"]).output().unwrap();

Expand All @@ -161,14 +147,12 @@ fn test_help() {

#[test]
fn test_btree_map() {
use assert_cmd::Command;

let input = concat!(env!("CARGO_MANIFEST_DIR"), "/../example.json");

let temp = TempDir::new("cargo-typify").unwrap();
let output_file = temp.path().join("output.rs");

let mut cmd = Command::cargo_bin("cargo-typify").unwrap();
let mut cmd = assert_cmd::cargo::cargo_bin_cmd!("cargo-typify");
cmd.args([
"typify",
input,
Expand Down
4 changes: 2 additions & 2 deletions example-build/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include!(concat!(env!("OUT_DIR"), "/codegen.rs"));

#[test]
fn test_main() {
main()
main();
}

fn main() {
Expand All @@ -21,5 +21,5 @@ fn main() {
fruits: vec![String::from("apple"), String::from("mango")],
vegetables: vec![veg],
};
println!("{:?}", veggies);
println!("{veggies:?}");
}
6 changes: 3 additions & 3 deletions example-macro/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import_types!(

#[test]
fn test_main() {
main()
main();
}

fn main() {
Expand All @@ -35,7 +35,7 @@ fn main() {
fruits: vec![String::from("apple"), String::from("mango")],
vegetables: vec![veg],
};
println!("{:?}", veggies);
println!("{veggies:?}");
let fov = FruitOrVeg::Fruit(MyFruit { seeds: () });
println!("{:?}", fov);
println!("{fov:?}");
}
31 changes: 14 additions & 17 deletions typify-impl/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl TypeSpace {
// new name for the inner type; otherwise, the inner type
// can just have this name.
let inner_type_name = match &type_name {
Name::Required(name) => Name::Suggested(format!("{}Inner", name)),
Name::Required(name) => Name::Suggested(format!("{name}Inner")),
_ => type_name,
};
self.convert_option(inner_type_name, metadata, &ss)
Expand Down Expand Up @@ -807,7 +807,7 @@ impl TypeSpace {
if let Some(pattern) = &validation.pattern {
let _ = regress::Regex::new(pattern).map_err(|e| Error::InvalidSchema {
type_name: type_name.clone().into_option(),
reason: format!("invalid pattern '{}' {}", pattern, e),
reason: format!("invalid pattern '{pattern}' {e}"),
})?;
self.uses_regress = true;
}
Expand Down Expand Up @@ -883,7 +883,7 @@ impl TypeSpace {
)),

Some(unhandled) => {
info!("treating a string format '{}' as a String", unhandled);
info!("treating a string format '{unhandled}' as a String");
Ok((TypeEntryDetails::String.into(), metadata))
}
}
Expand Down Expand Up @@ -1088,9 +1088,8 @@ impl TypeSpace {
// Use NonZero types for minimum 1
if min == Some(1.) {
return Ok((TypeEntry::new_integer(nz_ty), metadata));
} else {
return Ok((TypeEntry::new_integer(ty), metadata));
}
return Ok((TypeEntry::new_integer(ty), metadata));
}

if min.is_none() {
Expand Down Expand Up @@ -1342,13 +1341,13 @@ impl TypeSpace {
ref_name: &str,
) -> Result<(TypeEntry, &'a Option<Box<Metadata>>)> {
if !ref_name.starts_with('#') {
panic!("external references are not supported: {}", ref_name);
panic!("external references are not supported: {ref_name}");
}
let key = ref_key(ref_name);
let type_id = self
.ref_to_id
.get(&key)
.unwrap_or_else(|| panic!("$ref {} is missing", ref_name));
.unwrap_or_else(|| panic!("$ref {ref_name} is missing"));
Ok((
TypeEntryDetails::Reference(type_id.clone()).into(),
metadata,
Expand Down Expand Up @@ -1701,7 +1700,7 @@ impl TypeSpace {
serde_json::Value::Null
| serde_json::Value::Array(_)
| serde_json::Value::Object(_) => {
panic!("unhandled type for `not` construction: {}", v)
panic!("unhandled type for `not` construction: {v}")
}
})
.collect::<BTreeSet<_>>();
Expand Down Expand Up @@ -1742,8 +1741,7 @@ impl TypeSpace {
}

_ => panic!(
"multiple implied types for an un-typed enum {:?} {:?}",
instance_types, enum_values,
"multiple implied types for an un-typed enum {instance_types:?} {enum_values:?}",
),
}
}
Expand Down Expand Up @@ -1780,7 +1778,7 @@ impl TypeSpace {
self.id_for_schema(rest_name, &Schema::Bool(true))?.0
};
let start = items.iter().enumerate().map(|(ii, item_schema)| {
let item_name = type_name.append(&format!("item{}", ii));
let item_name = type_name.append(&format!("item{ii}"));
Ok(self.id_for_schema(item_name, item_schema)?.0)
});
let rest = (items.len()..*max_items as usize).map(|_| Ok(rest_id.clone()));
Expand All @@ -1794,7 +1792,7 @@ impl TypeSpace {
.take(*max_items as usize)
.enumerate()
.map(|(ii, item_schema)| {
let item_name = type_name.append(&format!("item{}", ii));
let item_name = type_name.append(&format!("item{ii}"));
Ok(self.id_for_schema(item_name, item_schema)?.0)
})
.collect::<Result<_>>()?;
Expand Down Expand Up @@ -1831,7 +1829,7 @@ impl TypeSpace {
contains: None,
} => {
let item_type_name = match get_type_name(&type_name, metadata) {
Some(s) => Name::Suggested(format!("{}Item", s)),
Some(s) => Name::Suggested(format!("{s}Item")),
None => Name::Unknown,
};
let (type_id, _) = self.id_for_schema(item_type_name, item.as_ref())?;
Expand Down Expand Up @@ -1864,7 +1862,7 @@ impl TypeSpace {

_ => Err(Error::InvalidSchema {
type_name: type_name.into_option(),
reason: format!("unhandled array validation {:#?}", validation),
reason: format!("unhandled array validation {validation:#?}"),
}),
}
}
Expand Down Expand Up @@ -1924,7 +1922,7 @@ impl TypeSpace {
};

let inner_type_name = match get_type_name(&type_name, &schema.metadata) {
Some(s) => Name::Suggested(format!("{}Inner", s)),
Some(s) => Name::Suggested(format!("{s}Inner")),
None => Name::Unknown,
};

Expand Down Expand Up @@ -2042,8 +2040,7 @@ impl TypeSpace {
}
(1, None) => unreachable!(),
_ => panic!(
"multiple implied types for an un-typed enum {:?} {:?}",
instance_types, enum_values,
"multiple implied types for an un-typed enum {instance_types:?} {enum_values:?}",
),
}
}
Expand Down
10 changes: 5 additions & 5 deletions typify-impl/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,12 @@ impl TypeEntry {
TypeEntryDetails::Integer(name) => {
if let Some(value) = default.as_u64() {
if name.starts_with(STD_NUM_NONZERO_PREFIX) {
Some(format!("defaults::default_nzu64::<{}, {}>", name, value))
Some(format!("defaults::default_nzu64::<{name}, {value}>"))
} else {
Some(format!("defaults::default_u64::<{}, {}>", name, value))
Some(format!("defaults::default_u64::<{name}, {value}>"))
}
} else if let Some(value) = default.as_i64() {
Some(format!("defaults::default_i64::<{}, {}>", name, value))
Some(format!("defaults::default_i64::<{name}, {value}>"))
} else {
panic!()
}
Expand All @@ -366,14 +366,14 @@ impl TypeEntry {
self,
)
});
let fn_name = sanitize(&format!("{}_{}", type_name, prop_name), Case::Snake);
let fn_name = sanitize(&format!("{type_name}_{prop_name}"), Case::Snake);
let fn_ident = format_ident!("{}", fn_name);
let def = quote! {
pub(super) fn #fn_ident() -> #n {
#value
}
};
(format!("defaults::{}", fn_name), Some(def))
(format!("defaults::{fn_name}"), Some(def))
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions typify-impl/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ impl TypeSpace {
// Fall back to `VariantN` naming.
.unwrap_or_else(|| {
(0..subschemas.len())
.map(|idx| format!("Variant{}", idx))
.map(|idx| format!("Variant{idx}"))
.collect()
});

Expand Down Expand Up @@ -1253,7 +1253,7 @@ mod tests {
.maybe_option(Name::Unknown, &None, &subschemas)
.unwrap();

assert_eq!(type_entry.details, TypeEntryDetails::Option(TypeId(1)))
assert_eq!(type_entry.details, TypeEntryDetails::Option(TypeId(1)));
}

#[test]
Expand Down Expand Up @@ -1346,11 +1346,11 @@ mod tests {
.unwrap()
.ends_with(variant.ident_name.as_ref().unwrap()));
}
_ => panic!("{:#?}", type_entry),
_ => panic!("{type_entry:#?}"),
}
}
}
_ => panic!("{:#?}", type_entry),
_ => panic!("{type_entry:#?}"),
}
}

Expand Down Expand Up @@ -1435,7 +1435,7 @@ mod tests {
tag_type: EnumTagType::Untagged,
..
}) => {}
_ => panic!("{:#?}", type_entry),
_ => panic!("{type_entry:#?}"),
}
}

Expand Down
Loading