Skip to main content

find_new_name

Function find_new_name 

Source
pub fn find_new_name(taken: &HashSet<String>, base: &str) -> String
Expand description

Searches for a new name that doesn’t conflict with taken names.

§Arguments

  • taken - A set of names that are already taken
  • base - The base name to use

§Returns

The original name if available, otherwise base_2, base_3, etc.

§Example

use polyglot_sql::helper::find_new_name;
use std::collections::HashSet;

let taken = HashSet::from(["col".to_string(), "col_2".to_string()]);
assert_eq!(find_new_name(&taken, "col"), "col_3");
assert_eq!(find_new_name(&taken, "other"), "other");