rust_lodash/lib.rs
1/*!
2# Lodash-RS: High-Performance Rust Collection Library
3
4A type-safe, high-performance Rust implementation of Lodash collection methods with zero-cost abstractions.
5
6## Features
7
8- **100% API Compatible**: Complete compatibility with Lodash collection methods
9- **Type Safe**: Leverages Rust's type system for compile-time safety
10- **Zero-Cost Abstractions**: No runtime overhead compared to hand-written code
11- **Chainable**: Support for fluent method chaining
12- **Async Support**: Built-in async/await support for all operations
13- **Parallel Processing**: Automatic parallelization for large collections
14- **Memory Safe**: Guaranteed memory safety with no data races
15- **WASM Compatible**: Full WebAssembly support for browser usage
16
17## Quick Start
18
19```rust
20use rust_lodash::prelude::*;
21
22// Basic usage
23let doubled = map(&[1, 2, 3, 4], |x| x * 2);
24assert_eq!(doubled, vec![2, 4, 6, 8]);
25
26// Chainable operations
27let result = chain(&[1, 2, 3, 4, 5])
28 .filter(|x| x % 2 == 0)
29 .map(|x| x * 3)
30 .collect();
31assert_eq!(result, vec![6, 12]);
32
33// Async operations (requires async feature)
34// let async_result = map_async(&[1, 2, 3], |x| async move { x * 2 }).await;
35// assert_eq!(async_result, vec![2, 4, 6]);
36```
37
38## Architecture
39
40The library is organized into several modules:
41
42- `collection`: Core collection methods (iteration, query, transform, operations)
43- `chain`: Fluent method chaining system
44- `utils`: Utility functions and type conversions
45- `extensions`: Advanced features (parallel processing, WASM support)
46
47## Performance
48
49Lodash-RS is designed for maximum performance:
50
51- **SIMD Optimizations**: Automatic vectorization for numeric operations
52- **Parallel Processing**: Multi-threaded execution for large datasets
53- **Zero-Copy Operations**: Minimal memory allocation and copying
54- **Cache-Friendly**: Optimized memory layout for better cache performance
55
56## Safety
57
58- **Memory Safe**: No buffer overflows, use-after-free, or data races
59- **Type Safe**: Compile-time type checking prevents runtime errors
60- **Panic-Free**: All operations handle edge cases gracefully
61- **Error Handling**: Comprehensive error types with proper propagation
62*/
63
64// #![cfg_attr(not(feature = "std"), no_std)]
65#![warn(missing_docs, clippy::all, clippy::pedantic)]
66#![allow(clippy::module_name_repetitions)]
67
68// Core modules
69pub mod collection;
70pub mod chain;
71pub mod utils;
72pub mod extensions;
73
74// Re-exports for convenience
75pub mod prelude {
76 //! Prelude module containing the most commonly used items.
77
78 // Core types
79 pub use crate::collection::Collection;
80 pub use crate::chain::Chain;
81
82 // Iteration methods
83 pub use crate::collection::iteration::{
84 each, for_each, map, filter, reduce, reduce_right, for_each_right,
85 };
86
87 // Query methods
88 pub use crate::collection::query::{
89 find, find_last, includes, every, some, count_by, partition,
90 };
91
92 // Transform methods
93 pub use crate::collection::transform::{
94 group_by, key_by, invoke, sort_by, order_by,
95 };
96
97 // Collection operations
98 pub use crate::collection::operation::{
99 shuffle, sample, sample_size, size,
100 };
101
102 // Chain operations
103 pub use crate::chain::chain;
104
105 #[cfg(feature = "async")]
106 pub use crate::chain::chain_async;
107
108 // Async versions
109 #[cfg(feature = "async")]
110 pub use crate::collection::async_support::{
111 map_async, filter_async, reduce_async, for_each_async,
112 };
113
114 // Parallel versions
115 #[cfg(feature = "parallel")]
116 pub use crate::extensions::parallel::{
117 map_parallel, filter_parallel, reduce_parallel,
118 };
119
120 // Error types
121 pub use crate::utils::error::{LodashError, Result};
122}
123
124// Version information
125/// The version of the rust-lodash crate.
126pub const VERSION: &str = env!("CARGO_PKG_VERSION");
127
128// Feature detection
129#[cfg(feature = "async")]
130pub const HAS_ASYNC: bool = true;
131
132#[cfg(not(feature = "async"))]
133/// Whether async features are enabled.
134pub const HAS_ASYNC: bool = false;
135
136#[cfg(feature = "parallel")]
137pub const HAS_PARALLEL: bool = true;
138
139#[cfg(not(feature = "parallel"))]
140/// Whether parallel processing features are enabled.
141pub const HAS_PARALLEL: bool = false;
142
143#[cfg(feature = "wasm")]
144pub const HAS_WASM: bool = true;
145
146#[cfg(not(feature = "wasm"))]
147/// Whether WebAssembly features are enabled.
148pub const HAS_WASM: bool = false;