| Crates.io | slugify-core |
| lib.rs | slugify-core |
| version | 0.1.0 |
| created_at | 2025-09-19 11:10:41.986224+00 |
| updated_at | 2025-09-19 11:10:41.986224+00 |
| description | Fast, Unicode-aware slug generation library with multi-language bindings |
| homepage | |
| repository | https://github.com/rust-core-libs/slugify-core |
| max_upload_size | |
| id | 1846293 |
| size | 32,386 |
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.
Add this to your Cargo.toml:
[dependencies]
slugify-core = "0.1.0"
Basic example:
use slugify_core::{slugify, SlugOptions};
fn main() {
// Default options
let options = SlugOptions::default();
let slug = slugify("Hello, World! 123", &options);
println!("{}", slug); // Output: "hello-world-123"
// Custom configuration
let options = SlugOptions {
separator: '_',
max_length: Some(20),
lowercase: true,
remove_stopwords: true,
ascii_only: false,
};
let slug = slugify("The Quick Brown Fox Jumps Over", &options);
println!("{}", slug); // Output: "quick_brown_fox"
}
Build the shared library:
cargo build --release
Use in C/C++:
#include <stdio.h>
#include <stdbool.h>
// Function declarations
extern char* slugify_simple(const char* input);
extern char* slugify_with_options(const char* input, char separator,
int max_length, bool lowercase,
bool remove_stopwords, bool ascii_only);
extern void free_string(char* ptr);
int main() {
// Simple usage
char* result = slugify_simple("Hello, World!");
printf("Result: %s\n", result); // "hello-world"
free_string(result);
// Advanced usage
result = slugify_with_options("Café & Restaurant", '-', 0, true, false, true);
printf("Result: %s\n", result); // "cafe-restaurant"
free_string(result);
return 0;
}
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 |
use slugify_core::{slugify, SlugOptions};
let options = SlugOptions::default();
assert_eq!(slugify("Hello World", &options), "hello-world");
assert_eq!(slugify("Test 123", &options), "test-123");
// Preserve Unicode
let options = SlugOptions::default();
assert_eq!(slugify("Café münü", &options), "café-münü");
// ASCII transliteration
let options = SlugOptions { ascii_only: true, ..Default::default() };
assert_eq!(slugify("Café münü", &options), "cafe-munu");
let options = SlugOptions { separator: '_', ..Default::default() };
assert_eq!(slugify("Hello World", &options), "hello_world");
let options = SlugOptions { separator: '.', ..Default::default() };
assert_eq!(slugify("Hello World", &options), "hello.world");
let options = SlugOptions { max_length: Some(10), ..Default::default() };
assert_eq!(slugify("This is a very long title", &options), "this-is-a");
let options = SlugOptions { remove_stopwords: true, ..Default::default() };
assert_eq!(slugify("The quick brown fox", &options), "quick-brown-fox");
assert_eq!(slugify("A guide to programming", &options), "guide-programming");
let options = SlugOptions { lowercase: false, ..Default::default() };
assert_eq!(slugify("Hello World", &options), "Hello-World");
Slugify Core is designed for high performance:
Benchmark results on a modern CPU:
This library is designed as a core that can be easily wrapped in other languages:
All C exports are designed with safety in mind:
git clone https://github.com/rust-core-libs/slugify-core.git
cd slugify-core
cargo build
cargo build --release
cargo test
cargo doc --open
Suitable for:
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.
git checkout -b feature/amazing-feature)cargo test)git commit -am 'Add amazing feature')git push origin feature/amazing-feature)cargo fmt before committingcargo clippy and fix any warningsThis project is licensed under either of
at your option.
unicode-normalization crateunicode-segmentationBuilt with Rust.