Skip to content

Commit 46a5db6

Browse files
authored
feat: make name_to_type public (#14)
1 parent 053a81c commit 46a5db6

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/analysis.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,35 @@ impl<'a> Analysis<'a> {
15281528
}
15291529
}
15301530

1531-
fn name_to_type(opts: &AnalysisOptions, name: &str) -> Option<Type> {
1531+
/// Converts a type name string to its corresponding [`Type`] variant.
1532+
///
1533+
/// This function performs case-insensitive matching for built-in type names and checks
1534+
/// against custom types defined in the analysis options.
1535+
///
1536+
/// # Returns
1537+
///
1538+
/// * `Some(Type)` - If the name matches a built-in type or custom type
1539+
/// * `None` - If the name doesn't match any known type
1540+
///
1541+
/// # Built-in Type Mappings
1542+
///
1543+
/// The following type names are recognized (case-insensitive):
1544+
/// - `"string"` → [`Type::String`]
1545+
/// - `"int"` or `"float64"` → [`Type::Number`]
1546+
/// - `"boolean"` → [`Type::Bool`]
1547+
/// - `"date"` → [`Type::Date`]
1548+
/// - `"time"` → [`Type::Time`]
1549+
/// - `"datetime"` → [`Type::DateTime`]
1550+
///
1551+
/// # Examples
1552+
///
1553+
/// ```ignore
1554+
/// let opts = AnalysisOptions::default();
1555+
/// assert_eq!(name_to_type(&opts, "String"), Some(Type::String));
1556+
/// assert_eq!(name_to_type(&opts, "INT"), Some(Type::Number));
1557+
/// assert_eq!(name_to_type(&opts, "unknown"), None);
1558+
/// ```
1559+
pub fn name_to_type(opts: &AnalysisOptions, name: &str) -> Option<Type> {
15321560
if name.eq_ignore_ascii_case("string") {
15331561
Some(Type::String)
15341562
} else if name.eq_ignore_ascii_case("int") || name.eq_ignore_ascii_case("float64") {

0 commit comments

Comments
 (0)