reinhardt-urls
URL routing and proxy utilities for Reinhardt framework
Overview
`reinhardt-urls` provides comprehensive URL routing and lazy loading proxy functionality for Reinhardt applications, inspired by Django's URL system.
Features
Implemented ✓
This crate provides the following modules:
-
Routers: Automatic URL routing configuration
- Django-inspired URL routing
- Automatic ViewSet URL generation
- Namespacing and versioning support
- URL reversal capabilities
- PathPattern for URL pattern matching
- DefaultRouter with automatic endpoint generation
- Custom action support (list and detail-level)
-
Routers Macros: Routing-related procedural macros
- Compile-time route validation
- Type-safe URL pattern generation
- Route registration macros
-
Proxy: Lazy loading proxy system
- Django-style SimpleLazyObject implementation
- Thread-safe lazy evaluation
- Integration with ORM for lazy model loading
- Automatic initialization on first access
- Support for complex initialization logic
- Advanced proxy features:
- Association proxies (SQLAlchemy-style)
- Scalar proxies with comparison operations
- Collection proxies for relationship management
- Query filtering and join operations
- Lazy/eager loading strategies
- Relationship caching
-
Advanced URL Pattern Matching:
- Compile-time path validation via
path!macro - Runtime pattern matching with parameter extraction
- Path constraint validation (snake_case parameters, no double slashes, etc.)
- Regex-based URL matching with named capture groups
- Compile-time path validation via
Installation
Add reinhardt to your Cargo.toml:
[]
= { = "0.1.0-alpha.1", = ["urls"] }
# For specific sub-features:
# reinhardt = { version = "0.1.0-alpha.1", features = ["urls-routers", "urls-proxy"] }
# Or use a preset:
# reinhardt = { version = "0.1.0-alpha.1", features = ["standard"] } # Recommended
# reinhardt = { version = "0.1.0-alpha.1", features = ["full"] } # All features
Then import URLs features:
use ;
use ;
use ;
Note: URLs features are included in the standard and full feature presets.
Usage
URL Routing
use ;
// Create a router
let mut router = new;
// Register ViewSet
router.register;
// Add custom routes
router.add_route;
// Match incoming requests
if let Some = router.match_request
URL Reversal
use reverse;
// Reverse URL by name
let url = reverse;
// Returns: /users/123/
// With namespace
let url = reverse;
// Returns: /api/v1/users/
Lazy Loading Proxy
use SimpleLazyObject;
// Create lazy object
let lazy_user = new;
// Access triggers initialization
let name = lazy_user.name; // Initialization happens here
Module Organization
`reinhardt-urls` is organized into the following modules:
`routers`- URL routing system`routers_macros`- Routing procedural macros`proxy`- Lazy loading proxy utilities
Using Modules
use ;
use LazyObject;
proxy
Features
Implemented ✓
Core Association Proxy (proxy.rs)
AssociationProxy<T, U>- Main proxy type for relationship traversalProxyAccessortrait - Interface for getting/setting proxy targetsProxyTargetenum - Represents scalar or collection proxy resultsScalarValueenum - Type-safe scalar value representation (String, Integer, Float, Boolean, Null)- Creator function support for new associations
- Comprehensive type conversion methods (
as_string(),as_integer(),as_float(),as_boolean())
Scalar Proxies (scalar.rs)
ScalarProxy- For one-to-one and many-to-one relationshipsScalarComparisonenum - Rich comparison operators (Eq, Ne, Gt, Gte, Lt, Lte, In, NotIn, IsNull, IsNotNull, Like, NotLike)- Async get/set operations for scalar values
- Builder methods for all comparison types
Collection Proxies (collection.rs)
CollectionProxy- For one-to-many and many-to-many relationships- Unique value support with deduplication
- Collection manipulation methods:
get_values()- Extract all values from related objectsset_values()- Replace entire collectionappend()- Add single valueremove()- Remove matching valuescontains()- Check for value existencecount()- Get collection size
- Advanced filtering:
filter()- Filter with FilterConditionfilter_by()- Filter with custom predicate
CollectionOperations- Wrapper for transformation operations (filter, map, sort, distinct)CollectionAggregations- Wrapper for aggregation operations (sum, avg, min, max)
Query Filtering (query.rs)
FilterOpenum - Filter operations (Eq, Ne, Lt, Le, Gt, Ge, In, NotIn, Contains, StartsWith, EndsWith)FilterCondition- Condition with field, operator, and valueQueryFilter- Container for multiple conditionsmatches()method for evaluating conditions against ScalarValue
Join Operations (joins.rs)
JoinConfig- Configuration for eager/lazy loadingLoadingStrategyenum - Eager, Lazy, Select strategiesNestedProxy- Multi-level relationship traversalRelationshipPath- Path representation for relationships- Helper functions:
extract_through_path()- Parse dot-separated pathsfilter_through_path()- Filter path segmentstraverse_and_extract()- Extract from nested proxiestraverse_relationships()- Navigate relationship paths
Builder Pattern (builder.rs)
ProxyBuilder<T, U>- Fluent API for proxy construction- Method chaining for configuration:
relationship()- Set relationship nameattribute()- Set attribute namecreator()- Set creator function
- Safe construction methods:
build()- Build with panic on missing configtry_build()- Build returning Option
association_proxy()helper function
Reflection System (reflection.rs)
Reflectabletrait - Core trait for runtime introspectionget_relationship()/get_relationship_mut()- Access relationshipsget_attribute()/set_attribute()- Access attributesget_relationship_attribute()/set_relationship_attribute()- Nested accesshas_relationship()/has_attribute()- Existence checks
ProxyCollectiontrait - Unified collection interface- Generic implementation for
Vec<T> - Methods:
items(),add(),remove(),contains(),len(),clear()
- Generic implementation for
AttributeExtractortrait - Scalar value extraction interface- Helper functions:
downcast_relationship()- Type-safe downcastingextract_collection_values()- Bulk value extraction
Error Handling
ProxyErrorenum with comprehensive error types:RelationshipNotFound- Missing relationshipAttributeNotFound- Missing attributeTypeMismatch- Type conversion errorsInvalidConfiguration- Configuration errorsDatabaseError- Database operation errorsSerializationError- Serialization errors
ProxyResult<T>type alias for Result with ProxyError
License
Licensed under the BSD 3-Clause License.