Skip to main content

Sluggable

Trait Sluggable 

Source
pub trait Sluggable: ActiveModelTrait + Send {
    // Required method
    fn slug_config() -> SlugConfig<Self>;
}
Expand description

Gives an ActiveModel an automatically generated slug.

use sea_orm::entity::prelude::*;
use sea_orm_sluggable::{SlugConfig, Sluggable};

impl Sluggable for categories::ActiveModel {
    fn slug_config() -> SlugConfig<Self> {
        SlugConfig::new([categories::Column::Title], categories::Column::Slug)
    }
}

#[async_trait::async_trait]
impl ActiveModelBehavior for categories::ActiveModel {
    async fn before_save<C: ConnectionTrait>(self, db: &C, insert: bool) -> Result<Self, DbErr> {
        // "Rust for PHP developers" -> "rust-for-php-developers",
        // or "rust-for-php-developers-1" when that one is taken.
        Ok(sea_orm_sluggable::fill_slug(self, db, insert).await?)
    }
}

Required Methods§

Source

fn slug_config() -> SlugConfig<Self>

Where the slug comes from, where it goes, and how it is built.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§