Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

GitHub

This documentation is part of the "Projects with Books" initiative at zenOSmosis.

The source code for this project is available on GitHub.

Utility Functions & Accessors

Loading…

Utility Functions & Accessors

Relevant source files

Purpose and Scope

This document covers the utility functions and helper modules provided by the utils module in the Rust sec-fetcher application. These utilities provide cross-cutting functionality used throughout the codebase, including data structure transformations, runtime mode detection, and collection extensions. Additionally, it documents the internal data extraction patterns used by the network layer to process complex SEC JSON responses.

Sources: src/utils.rs:1-9


Module Overview

The utils module is organized as a collection of focused sub-modules. The module uses Rust’s re-export pattern to provide a clean public API for environment detection and collection manipulation.

Sub-modulePrimary ExportPurpose
is_development_modeis_development_mode()Runtime environment detection for configuration and logging.
is_interactive_modeis_interactive_mode(), set_interactive_mode_override()Detects if the app is running in a TTY or should simulate one.
vec_extensionsVecExtensions traitExtension methods for Vec<T> used in data processing.

Sources: src/utils.rs:1-9


Interactive Mode Management

The interactive mode utilities manage application state related to user interaction, controlling whether the application should prompt for user input or run in automated mode (e.g., CI/CD or piped output).

Implementation Details

The is_interactive_mode function checks the environment and standard streams to determine the session type:

  1. Override Check : It first looks for the INTERACTIVE_MODE_OVERRIDE environment variable. Values "1"/"true" force interactive mode; "0"/"false" force non-interactive src/utils/is_interactive_mode.rs:8-28
  2. Terminal Detection : If no override exists, it uses std::io::IsTerminal to check if both stdin and stdout are connected to a terminal src/utils/is_interactive_mode.rs:30-32

Function Signatures

src/utils/is_interactive_mode.rs21 src/utils/is_interactive_mode.rs62

Usage Scenarios

Scenariois_interactive_mode() is trueis_interactive_mode() is false
Missing ConfigPrompt user for email/API keysExit with error message
ProgressRender dynamic progress barsLog static status updates
PipingWarning if output is not redirectedClean data output for grep/jq

Sources: src/utils/is_interactive_mode.rs:1-76


Data Accessors and Parsing Patterns

While not a standalone “accessor” module, the codebase implements standardized internal functions to extract data from SEC JSON structures (DataFrames-like objects in Python, but raw serde_json::Value in Rust).

Submission Parsing Logic

The fetch_cik_submissions module contains specialized logic to flatten the SEC’s columnar JSON format into a vector of strongly-typed models.

graph TD
    subgraph "SEC JSON Structure"
        JSON["Root JSON Object"]
Filings["'filings' Object"]
Recent["'recent' Block (Columnar)"]
Files["'files' Array (Pagination)"]
end

    subgraph "Logic: extract_filings_from_block"
        Zip["itertools::izip!"]
Acc["accessionNumber[]"]
Form["form[]"]
Doc["primaryDocument[]"]
Date["filingDate[]"]
end

    subgraph "Output Space"
        Model["Vec&lt;CikSubmission&gt;"]
end

 
   JSON --> Filings
 
   Filings --> Recent
 
   Filings --> Files
 
   Recent --> Acc & Form & Doc & Date
    Acc & Form & Doc &
 Date --> Zip
 
   Zip --> Model
 
   Files -.->|Recursively Fetch| JSON

Key Accessor Functions

Sources: src/network/fetch_cik_submissions.rs:10-177


Utility Function Relationships

This diagram maps the relationship between utility functions and the higher-level system components that consume them.

Sources: src/utils.rs:1-9 src/network/fetch_cik_submissions.rs:1-178

graph LR
    subgraph "Utility Layer (src/utils/)"
        IsDev["is_development_mode()"]
IsInt["is_interactive_mode()"]
VecExt["VecExtensions"]
end

    subgraph "Network Layer (src/network/)"
        Client["SecClient"]
SubParser["parse_cik_submissions_json()"]
end

    subgraph "App Logic"
        Config["ConfigManager"]
Main["main.rs / CLI"]
end

 
   IsDev --> Config
 
   IsInt --> Main
 
   VecExt --> SubParser
 
   SubParser --> Client

Development Mode Detection

The is_development_mode utility is a simple toggle used to gate features that should not be active in production, such as test fixture generation or bypasses for rate limiting in local mock environments.

Usage in Configuration

The ConfigManager and SecClient utilize these flags to determine if they should load production SEC endpoints or local mock servers during integration testing tests/sec_client_tests.rs:7-23

Sources: src/utils.rs:1-2 tests/sec_client_tests.rs:1-23


Vector Extensions Trait

The VecExtensions trait provides ergonomic helpers for common operations performed on lists of SEC data, such as deduplication or specialized filtering before rendering.

Trait Definition Pattern

src/utils/vec_extensions.rs:1-10 (referenced via src/utils.rs:7-8)

Sources: src/utils.rs:7-8

Dismiss

Refresh this wiki

Enter email to refresh