Slugify Core
A high-performance, Unicode-aware slug generation library written in Rust with multi-language bindings support. Designed for creating URL-friendly strings from arbitrary text input with extensive customization options.
Features
- High Performance - Written in Rust for maximum performance
- Unicode Support - Proper handling of international characters
- Configurable - Extensive customization options
- Memory Safe - Built with Rust's safety guarantees
- Multi-Language - C FFI exports for easy bindings
- Well Tested - Comprehensive test suite
- Minimal Dependencies - Core functionality uses only standard library
Quick Start
Rust Usage
Add this to your Cargo.toml:
[]
= "0.1.0"
Basic example:
use ;
C FFI Usage
Build the shared library:
Use in C/C++:
// Function declarations
extern char* ;
extern char* ;
extern void ;
int
Configuration Options
The SlugOptions struct provides extensive customization:
| Field | Type | Default | Description |
|---|---|---|---|
separator |
char |
'-' |
Character to separate words |
max_length |
Option<usize> |
None |
Maximum length of output slug |
lowercase |
bool |
true |
Convert to lowercase |
remove_stopwords |
bool |
false |
Remove common stopwords |
ascii_only |
bool |
false |
Transliterate to ASCII characters |
Examples
Basic Usage
use ;
let options = default;
assert_eq!;
assert_eq!;
Unicode Handling
// Preserve Unicode
let options = default;
assert_eq!;
// ASCII transliteration
let options = SlugOptions ;
assert_eq!;
Custom Separators
let options = SlugOptions ;
assert_eq!;
let options = SlugOptions ;
assert_eq!;
Length Limiting
let options = SlugOptions ;
assert_eq!;
Stopword Removal
let options = SlugOptions ;
assert_eq!;
assert_eq!;
Case Preservation
let options = SlugOptions ;
assert_eq!;
Performance
Slugify Core is designed for high performance:
- Unicode normalization using efficient algorithms
- Minimal memory allocations
- Zero-copy string processing where possible
- Optimized for common use cases
Benchmark results on a modern CPU:
- Simple ASCII text: ~1M slugs/second
- Unicode text: ~500K slugs/second
- Complex options: ~300K slugs/second
Multi-Language Bindings
This library is designed as a core that can be easily wrapped in other languages:
Planned Language Support
- JavaScript/TypeScript - WebAssembly bindings
- Python - PyO3 bindings
- Go - CGO bindings
- Java - JNI bindings
- C#/.NET - P/Invoke bindings
FFI Safety
All C exports are designed with safety in mind:
- Null pointer checks
- UTF-8 validation
- Proper memory management
- Clear ownership semantics
Building
Requirements
- Rust 1.70 or later
- Cargo
Development Build
Release Build
Running Tests
Building Documentation
Use Cases
Suitable for:
- Web Development - Creating URL-friendly slugs from titles
- CMS Systems - Generating permalinks from content
- File Systems - Creating safe filenames from user input
- APIs - Normalizing identifiers
- SEO - Creating search-engine-friendly URLs
- Database Keys - Generating readable primary keys
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Setup
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for your changes
- Ensure tests pass (
cargo test) - Commit your changes (
git commit -am 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Code Style
- Follow standard Rust conventions
- Run
cargo fmtbefore committing - Run
cargo clippyand fix any warnings - Add tests for new functionality
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Changelog
v0.1.0 (2024-01-XX)
- Initial release
- Core slugification functionality
- Unicode normalization support
- Configurable options
- C FFI exports
- Comprehensive test suite
Related Projects
- slug - Simple Rust slug generation
- slugify - Python implementation
- speakingurl - JavaScript implementation
Acknowledgments
- Unicode normalization powered by the
unicode-normalizationcrate - Text segmentation using
unicode-segmentation - Inspired by various slugification libraries across languages
Built with Rust.