Skip to content

Commit 6d9d71d

Browse files
committed
clippy
1 parent bb7dd65 commit 6d9d71d

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

crux_cli/src/codegen.rs

+25-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use anyhow::{bail, Result};
2-
use rustdoc_types::{Crate, Impl, ItemEnum, Path};
2+
use rustdoc_types::{Crate, Impl, ItemEnum, Path, Type};
33
use std::{
44
fs::File,
55
io::{stdout, IsTerminal},
@@ -35,33 +35,49 @@ pub async fn codegen(args: &CodegenArgs) -> Result<()> {
3535
let target_directory = graph.workspace().target_directory().as_std_path();
3636
let json_path = target_directory
3737
.join("doc")
38-
.join(format!("{}.json", lib.name().replace("-", "_")));
38+
.join(format!("{}.json", lib.name().replace('-', "_")));
3939

40-
let rustdoc: Crate = spawn_blocking(move || {
41-
let file = File::open(&json_path)?;
40+
let crate_: Crate = spawn_blocking(move || {
41+
let file = File::open(json_path)?;
4242
let crate_: Crate = serde_json::from_reader(file)?;
4343
Ok::<rustdoc_types::Crate, anyhow::Error>(crate_)
4444
})
4545
.await??;
4646

47-
if let Some(name) = rustdoc.index.iter().find_map(|(_k, v)| {
47+
if let Some((id, items)) = crate_.index.iter().find_map(|(_k, v)| {
4848
if let ItemEnum::Impl(Impl {
4949
trait_: Some(rustdoc_types::Path {
5050
name: trait_name, ..
5151
}),
52-
for_: rustdoc_types::Type::ResolvedPath(Path { name, .. }),
52+
for_: rustdoc_types::Type::ResolvedPath(Path { id, .. }),
53+
items,
5354
..
5455
}) = &v.inner
5556
{
56-
(trait_name == &"App".to_string()).then(|| name)
57+
(trait_name.as_str() == "App").then_some((id, items))
5758
} else {
5859
None
5960
}
6061
}) {
6162
println!(
62-
"The struct that implements crux_core::App is called {:?}",
63-
name
63+
"The struct that implements crux_core::App is {}",
64+
crate_.paths[id].path.join("::")
6465
);
66+
67+
for item in items {
68+
let assoc = &crate_.index[item];
69+
for name in &["Event", "ViewModel", "Capabilities"] {
70+
if assoc.name == Some(name.to_string()) {
71+
if let ItemEnum::AssocType {
72+
default: Some(Type::ResolvedPath(path)),
73+
..
74+
} = &assoc.inner
75+
{
76+
println!("{name} type is {}", crate_.paths[&path.id].path.join("::"))
77+
}
78+
}
79+
}
80+
}
6581
}
6682

6783
Ok(())

0 commit comments

Comments
 (0)