Skip to main content

Module normalizer

Module normalizer 

Source
Expand description

Metadata normalization for backward compatibility Metadata normalization for symbol attributes

This module provides normalization of legacy metadata keys to canonical forms, enabling backward compatibility while transitioning to standardized metadata keys.

§Design Principles

  1. User Convenience: Short forms (async) map to canonical (is_async) for easier queries
  2. No Data Loss: Unknown keys are preserved without modification
  3. Last-Wins Semantics: If both short and canonical keys exist, canonical wins
  4. Transparent: Plugins use canonical keys (is_async); normalizer handles user input

§Usage

use sqry_core::normalizer::MetadataNormalizer;
use std::collections::HashMap;

let mut raw_metadata = HashMap::new();
raw_metadata.insert("async".to_string(), "true".to_string());        // Short form
raw_metadata.insert("is_static".to_string(), "true".to_string());    // Canonical form
raw_metadata.insert("custom_key".to_string(), "value".to_string());  // Unknown

let normalizer = MetadataNormalizer::new();
let normalized = normalizer.normalize(raw_metadata);

assert_eq!(normalized.get("is_async"), Some(&"true".to_string()));   // Normalized to canonical
assert_eq!(normalized.get("is_static"), Some(&"true".to_string()));  // Preserved
assert_eq!(normalized.get("custom_key"), Some(&"value".to_string()));// Preserved

§Mapping Strategy

The normalizer uses a static mapping table. User-friendly short forms map TO the canonical keys defined in sqry_core::metadata::keys:

  • asyncis_async (matches metadata::keys::IS_ASYNC)
  • staticis_static (matches metadata::keys::IS_STATIC)
  • constis_const (matches metadata::keys::IS_CONST)
  • finalis_final (matches metadata::keys::IS_FINAL)
  • abstractis_abstract (matches metadata::keys::IS_ABSTRACT)
  • And more…

Keys already in canonical form (is_async) or not in the mapping table are preserved as-is.

Structs§

MetadataNormalizer
Metadata normalizer for query convenience