rust_prelude_plus/lib.rs
1//! # Rust Prelude Plus
2//!
3//! A library that implements higher-order functions similar to functional programming patterns
4//! (map, filter, fold, etc.) but built on top of the `key-paths-core` and `key-paths-derive` crates.
5//! The library provides type-safe, composable operations on nested data structures.
6//!
7//! ## Features
8//!
9//! - **Type-safe keypath operations**: All operations maintain Rust's compile-time guarantees
10//! - **Composable functions**: Chain operations together for complex transformations
11//! - **Collection operations**: Extended methods for working with collections and keypaths
12//! - **Error handling**: Proper error handling for invalid keypath access
13//! - **Performance**: Minimal overhead with zero-cost abstractions where possible
14//! - **Async support**: Optional async/await support for I/O operations
15//! - **Parallel processing**: Optional parallel processing for large collections
16//! - **Memory efficient**: Uses `Rc` and `Arc` to avoid unnecessary cloning
17//! - **Lazy evaluation**: Iterator-based operations for memory efficiency
18//!
19//! ## Quick Start
20//!
21//! ```rust
22//! use rust_prelude_plus::prelude::*;
23//! use key_paths_derive::Keypath;
24//! use std::rc::Rc;
25//!
26//! #[derive(Keypath, Debug, Clone)]
27//! struct Person {
28//! name: String,
29//! age: u32,
30//! }
31//!
32//! let people = vec![
33//! Rc::new(Person { name: "Alice".to_string(), age: 30 }),
34//! Rc::new(Person { name: "Bob".to_string(), age: 25 }),
35//! ];
36//!
37//! // Filter people by age and extract their names (lazy evaluation)
38//! let young_people_names: Vec<String> = people
39//! .iter()
40//! .filter_by_keypath(Person::age(), |&age| age < 30)
41//! .map_keypath(Person::name(), |name| name.clone())
42//! .collect();
43//!
44//! println!("Young people: {:?}", young_people_names);
45//! ```
46//!
47//! ## Advanced Usage
48//!
49//! ### Lazy Evaluation with Iterators
50//!
51//! ```rust
52//! use rust_prelude_plus::prelude::*;
53//! use key_paths_derive::Keypath;
54//! use std::rc::Rc;
55//!
56//! #[derive(Keypath, Debug, Clone)]
57//! struct Product {
58//! name: String,
59//! price: f64,
60//! category: String,
61//! }
62//!
63//! let products = vec![
64//! Rc::new(Product { name: "Laptop".to_string(), price: 999.99, category: "Electronics".to_string() }),
65//! Rc::new(Product { name: "Book".to_string(), price: 19.99, category: "Books".to_string() }),
66//! ];
67//!
68//! // Lazy evaluation - no intermediate collections created
69//! let expensive_electronics: Vec<String> = products
70//! .iter()
71//! .filter_by_keypath(Product::category(), |cat| cat == "Electronics")
72//! .filter_by_keypath(Product::price(), |&price| price > 100.0)
73//! .map_keypath(Product::name(), |name| name.clone())
74//! .collect();
75//! ```
76//!
77//! ### Memory Efficient Operations
78//!
79//! ```rust
80//! use rust_prelude_plus::prelude::*;
81//! use key_paths_derive::Keypath;
82//! use std::rc::Rc;
83//!
84//! #[derive(Keypath, Debug, Clone)]
85//! struct User {
86//! id: u32,
87//! name: String,
88//! email: String,
89//! }
90//!
91//! let users = vec![
92//! Rc::new(User { id: 1, name: "Alice".to_string(), email: "alice@example.com".to_string() }),
93//! Rc::new(User { id: 2, name: "Bob".to_string(), email: "bob@example.com".to_string() }),
94//! ];
95//!
96//! // Memory efficient - uses Rc to avoid cloning
97//! let user_emails: Vec<String> = users
98//! .iter()
99//! .map_keypath(User::email(), |email| email.clone())
100//! .collect();
101//! ```
102
103pub mod error;
104pub mod higher_order;
105pub mod traits;
106pub mod composable;
107pub mod collections;
108pub mod parallel;
109pub mod async_ops;
110
111/// Re-exports for convenient usage
112pub mod prelude {
113 pub use crate::error::*;
114 pub use crate::higher_order::*;
115 pub use crate::traits::*;
116 pub use crate::composable::{pipe, chain_keypath_ops, when_keypath, unless_keypath, KeyPathsChain, ComposableIterator};
117 pub use crate::collections::{KeyPathsCollectionExt, specialized};
118
119 #[cfg(feature = "parallel")]
120 pub use crate::parallel::*;
121
122 #[cfg(feature = "async")]
123 pub use crate::async_ops::*;
124}
125
126/// Version information
127pub const VERSION: &str = env!("CARGO_PKG_VERSION");