pub struct NameFixer { /* private fields */ }Expand description
Dictionary-based helper that adapts names to guarantee they’re unique.
Implementations§
Source§impl NameFixer
impl NameFixer
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new instance of NameFixer pre-filled with reserved words of the Rust language, so that variables don’t have a forbidden name.
See new_empty() for a version that isn’t pre-filled with reserved words.
Sourcepub fn add(&mut self, name: String)
pub fn add(&mut self, name: String)
Adds a name to the internal dictionary without checking whether it already existed or not. Use this method to pre-fill existing names.
Sourcepub fn remove(&mut self, name: &str) -> bool
pub fn remove(&mut self, name: &str) -> bool
Removes a name from the internal dictionary. Returns true if the name was in the dictionary.
Sourcepub fn contains(&self, name: &str) -> bool
pub fn contains(&self, name: &str) -> bool
Checks if a name is already in the internal dictionary.
Sourcepub fn get_unique_name(&mut self, name: String) -> String
pub fn get_unique_name(&mut self, name: String) -> String
Returns name if it’s unique, or adds a suffix number first to make sure it’s unique.
Sourcepub fn get_unique_name_num(&mut self, name: String) -> String
pub fn get_unique_name_num(&mut self, name: String) -> String
Returns name followed by “1” if it’s unique, or adds another incremental suffix number to make sure it’s unique.
Sourcepub fn get_unique_name_unum(&mut self, name: String) -> String
pub fn get_unique_name_unum(&mut self, name: String) -> String
Returns name followed by “_1” if it’s unique, or finds another incremental suffix number to make sure it’s unique.
Sourcepub fn add_number(s: &mut String, num: usize)
pub fn add_number(s: &mut String, num: usize)
Adds _{num} or {num} to the string depending on its last character, whether it’s respectivelly a digit or not.
Used if we want to make sure a digit isn’t added to an identifier ending with a number, which would make it confusing.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for NameFixer
impl RefUnwindSafe for NameFixer
impl Send for NameFixer
impl Sync for NameFixer
impl Unpin for NameFixer
impl UnwindSafe for NameFixer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<S> BuildFrom<S> for S
impl<S> BuildFrom<S> for S
Source§fn build_from(source: S) -> S
fn build_from(source: S) -> S
Source§impl<S, T> BuildInto<T> for Swhere
T: BuildFrom<S>,
impl<S, T> BuildInto<T> for Swhere
T: BuildFrom<S>,
Source§fn build_into(self) -> T
fn build_into(self) -> T
Calls T::from(self) to convert a [S] into a [T].