Skip to main content

SlugConfig

Struct SlugConfig 

Source
pub struct SlugConfig<A: ActiveModelTrait> { /* private fields */ }
Expand description

Which columns a slug is built from and stored in, and when it is generated.

Implementations§

Source§

impl<A: ActiveModelTrait> SlugConfig<A>

Source

pub fn new( sources: impl IntoIterator<Item = <<A as ActiveModelTrait>::Entity as EntityTrait>::Column>, target: <<A as ActiveModelTrait>::Entity as EntityTrait>::Column, ) -> Self

Builds the slug from sources (joined with a space, in order) into target.

Defaults: generated on create, kept on update, unique across the whole table.

Source

pub fn options(self, options: SlugOptions) -> Self

Separator, length, suffixes and transliteration.

Source

pub const fn on_create(self, enabled: bool) -> Self

Generate the slug when a row is inserted. Default: on.

Source

pub const fn on_update(self, enabled: bool) -> Self

Regenerate the slug when a source column changes on update. Default: off, because changing a slug breaks every link to the old URL.

Source

pub const fn prevent_overwrite(self, enabled: bool) -> Self

Keep a slug that is already filled in, for example typed by an editor. Default: off.

Source

pub fn skip_when( self, skip: impl Fn(&A) -> bool + Send + Sync + 'static, ) -> Self

Leave the slug alone when skip returns true, e.g. for drafts.

Source

pub fn scope( self, scope: impl Fn(&A) -> Condition + Send + Sync + 'static, ) -> Self

Makes the slug unique only among rows matching the returned condition, e.g. within one category or tenant.

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

// "hello" can exist once per category.
let config = SlugConfig::new([posts::Column::Title], posts::Column::Slug).scope(
    |post: &posts::ActiveModel| {
        // `try_as_ref` is `None` when the column is not set on this model.
        match post.category_id.try_as_ref() {
            Some(category) => Condition::all().add(posts::Column::CategoryId.eq(*category)),
            None => Condition::all(),
        }
    },
);

Auto Trait Implementations§

§

impl<A> !RefUnwindSafe for SlugConfig<A>

§

impl<A> !UnwindSafe for SlugConfig<A>

§

impl<A> Forget for SlugConfig<A>

§

impl<A> Freeze for SlugConfig<A>

§

impl<A> Move for SlugConfig<A>

§

impl<A> Send for SlugConfig<A>
where RawVecInner: Send, <<A as ActiveModelTrait>::Entity as EntityTrait>::Column: Send, BoxRaw<dyn Fn(&str, u32) -> String + Send + Sync>: Send, BoxRaw<dyn Transliterator>: Send, BoxRaw<dyn Fn(&A) -> bool + Send + Sync>: Send, BoxRaw<dyn Fn(&A) -> Condition + Send + Sync>: Send,

§

impl<A> Sync for SlugConfig<A>
where RawVecInner: Sync, <<A as ActiveModelTrait>::Entity as EntityTrait>::Column: Sync, BoxRaw<dyn Fn(&str, u32) -> String + Send + Sync>: Sync, BoxRaw<dyn Transliterator>: Sync, BoxRaw<dyn Fn(&A) -> bool + Send + Sync>: Sync, BoxRaw<dyn Fn(&A) -> Condition + Send + Sync>: Sync,

§

impl<A> Unpin for SlugConfig<A>
where *const u8 is !null: Unpin, <<A as ActiveModelTrait>::Entity as EntityTrait>::Column: Unpin, Box<dyn Fn(&str, u32) -> String + Send + Sync>: Unpin, Box<dyn Transliterator>: Unpin, Box<dyn Fn(&A) -> bool + Send + Sync>: Unpin, Box<dyn Fn(&A) -> Condition + Send + Sync>: Unpin,

§

impl<A> UnsafeUnpin for SlugConfig<A>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more