Module intern

Module intern 

Source
Expand description

String interning for efficient field name storage.

This module provides string interning to reduce memory allocations when the same field names are used across many filters. Interned strings share memory, making cloning essentially free.

§When to Use

String interning is most beneficial when:

  • The same field names are used in many filters
  • Field names come from dynamic sources (not &'static str)
  • You’re building complex query trees with repeated field references

For static field names (&'static str), use them directly - they’re already “interned” by the compiler with zero overhead.

§Examples

§Using Pre-defined Field Names

use prax_query::intern::fields;
use prax_query::{Filter, FilterValue};

// Common field names are pre-defined as constants
let filter = Filter::Equals(fields::ID.into(), FilterValue::Int(42));
let filter = Filter::Equals(fields::EMAIL.into(), FilterValue::String("test@example.com".into()));
let filter = Filter::Gt(fields::CREATED_AT.into(), FilterValue::String("2024-01-01".into()));

§Interning Dynamic Strings

use prax_query::intern::{intern, intern_cow};
use prax_query::{Filter, FilterValue, FieldName};

// Intern a dynamic string - subsequent calls return the same Arc<str>
let field1 = intern("dynamic_field");
let field2 = intern("dynamic_field");
// field1 and field2 point to the same memory

// Use interned string directly in filters
let filter = Filter::Equals(intern_cow("user_id"), FilterValue::Int(1));

Modules§

fields
Pre-defined common field name constants.

Functions§

clear_interned
Clear all interned strings from the thread-local cache.
intern
Intern a string, returning a reference-counted pointer.
intern_cow
Intern a string and return it as a Cow<'static, str>.
interned_count
Get the number of currently interned strings.