mod.rs


Overview

The [mod.rs](/projects/287/67778) file serves as a central module declaration and re-export hub for a collection of submodules related to string handling and Unicode processing within the project. It organizes and conditionally includes different implementations optimized for various CPU architectures (such as AVX512), as well as scalar and Unicode-specific functionality.

This file primarily:

This modularization supports scalability and maintainability of string processing code by separating concerns into specialized modules while exposing a clean API surface.


Modules

avx512

pystr

pyunicode_new

scalar


Publicly Re-exported Items

The following items from `pystr` are made available outside this module:

pub(crate) use pystr::{set_str_create_fn, PyStr, PyStrSubclass};

Implementation Details


Interaction with Other Parts of the System


Summary

Module

Purpose

Publicly Re-exported?

`avx512`

AVX512 optimized string operations

No

`pystr`

Core Python-like string type and helpers

Yes (`set_str_create_fn`, `PyStr`, `PyStrSubclass`)

`pyunicode_new`

New Unicode handling implementations

No

`scalar`

Scalar (non-vectorized) implementations

No


Mermaid Class Diagram

The following diagram illustrates the relationship between the main types and functions exposed by this module, focusing on the `PyStr` and `PyStrSubclass` entities and their interaction via the `set_str_create_fn` function.

classDiagram
    class PyStr {
        +new(value: &str) PyStr
        +to_string() String
        // ... other string methods
    }

    class PyStrSubclass {
        // Helper/trait for subclassing PyStr
    }

    class set_str_create_fn {
        +fn(create_fn: fn(&str) -> PyStr)
    }

    set_str_create_fn ..> PyStr : configures creation
    PyStrSubclass <|-- PyStr : supports subclassing

Example Usage

use crate::pystr::{PyStr, set_str_create_fn};

// Define a custom string creation function
fn custom_create(s: &str) -> PyStr {
    // Custom logic, e.g., logging or modifying input
    PyStr::new(s)
}

fn main() {
    // Set the custom string creation function
    set_str_create_fn(custom_create);

    // Create a PyStr instance
    let my_string = PyStr::new("Hello from PyStr");
    println!("{}", my_string.to_string());
}

End of Documentation for mod.rs