Skip to content

Commit

Permalink
refactor(ast_tools): shorten code (#6924)
Browse files Browse the repository at this point in the history
Pure refactor.
  • Loading branch information
overlookmotel committed Oct 26, 2024
1 parent 73ab6fb commit e4a5936
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions tasks/ast_tools/src/derives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,20 @@ pub trait Derive {
|mut acc, (def, stream)| {
let module_path = def.module_path();
let krate = module_path.split("::").next().unwrap();
if !acc.contains_key(krate) {
acc.insert(krate, Default::default());
}
let streams = acc.get_mut(krate).expect("We checked this right above!");
let streams = acc.entry(krate).or_default();
streams.0.insert(module_path);
streams.1.push(stream);
acc
},
)
.into_iter()
.sorted_by(|lhs, rhs| lhs.0.cmp(rhs.0))
.fold(Vec::new(), |mut acc, (path, (modules, streams))| {
.fold(Vec::new(), |mut acc, (krate, (modules, streams))| {
let mut modules = Vec::from_iter(modules);
modules.sort_unstable();

let output = Output::Rust {
path: output_path(
format!("crates/{}", path.split("::").next().unwrap()).as_str(),
&filename,
),
path: output_path(&format!("crates/{krate}"), &filename),
tokens: Self::template(
modules,
streams.into_iter().fold(TokenStream::new(), |mut acc, it| {
Expand Down

0 comments on commit e4a5936

Please sign in to comment.