Skip to content

Commit

Permalink
refactor(ast_tools): TypeDef::name return a &str (#6776)
Browse files Browse the repository at this point in the history
It's generally an anti-pattern for functions to return `&String`. `&str` is preferable.
  • Loading branch information
overlookmotel committed Oct 22, 2024
1 parent 09d2df1 commit d2b8f50
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tasks/ast_tools/src/generators/ast_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl Generator for AstKindGenerator {
.into_iter()
.filter(|def| {
let is_visitable = def.visitable();
let is_blacklisted = BLACK_LIST.contains(&def.name().as_str());
let is_blacklisted = BLACK_LIST.contains(&def.name());
is_visitable && !is_blacklisted
})
.map(|def| {
Expand Down
4 changes: 2 additions & 2 deletions tasks/ast_tools/src/generators/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
markers::VisitArg,
output,
schema::{EnumDef, GetIdent, StructDef, ToType, TypeDef},
util::{StrExt, ToIdent, TokenStreamExt, TypeWrapper},
util::{StrExt, TokenStreamExt, TypeWrapper},
Generator, GeneratorOutput,
};

Expand Down Expand Up @@ -187,7 +187,7 @@ impl<'a> VisitBuilder<'a> {
let (ident, as_type) = {
debug_assert!(def.visitable(), "{def:?}");

let ident = def.name().to_ident();
let ident = def.ident();
let as_type = def.to_type();

(ident, if collection { parse_quote!(Vec<'a, #as_type>) } else { as_type })
Expand Down
2 changes: 1 addition & 1 deletion tasks/ast_tools/src/schema/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl TypeDef {
with_either!(self, it => it.id)
}

pub fn name(&self) -> &String {
pub fn name(&self) -> &str {
with_either!(self, it => &it.name)
}

Expand Down

0 comments on commit d2b8f50

Please sign in to comment.