NameFixer

Struct NameFixer 

Source
pub struct NameFixer { /* private fields */ }
Expand description

Dictionary-based helper that adapts names to guarantee they’re unique.

Implementations§

Source§

impl NameFixer

Source

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.

Source

pub fn new_empty() -> Self

Creates a new instance of NameFixer that is not pre-filled with Rust reserved words. This name fixer can be used when the names will be prefixed or postfixed in a way that guarantees they’re not forbidden.

See new() for the safer version pre-filled with reserved words.

Source

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.

Source

pub fn remove(&mut self, name: &str) -> bool

Removes a name from the internal dictionary. Returns true if the name was in the dictionary.

Source

pub fn contains(&self, name: &str) -> bool

Checks if a name is already in the internal dictionary.

Source

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.

Source

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.

Source

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.

Source

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§

Source§

impl Clone for NameFixer

Source§

fn clone(&self) -> NameFixer

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NameFixer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<S> BuildFrom<S> for S

Source§

fn build_from(source: S) -> S

Converts to this type from the input type.
Source§

impl<S, T> BuildInto<T> for S
where T: BuildFrom<S>,

Source§

fn build_into(self) -> T

Calls T::from(self) to convert a [S] into a [T].

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<S, T> TryBuildInto<T> for S
where T: TryBuildFrom<S>,

Source§

type Error = <T as TryBuildFrom<S>>::Error

The type returned in the event of a conversion error.
Source§

fn try_build_into(self) -> Result<T, <T as TryBuildFrom<S>>::Error>

Performs the conversion.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.