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>
impl<A: ActiveModelTrait> SlugConfig<A>
Sourcepub fn new(
sources: impl IntoIterator<Item = <<A as ActiveModelTrait>::Entity as EntityTrait>::Column>,
target: <<A as ActiveModelTrait>::Entity as EntityTrait>::Column,
) -> Self
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.
Sourcepub fn options(self, options: SlugOptions) -> Self
pub fn options(self, options: SlugOptions) -> Self
Separator, length, suffixes and transliteration.
Sourcepub const fn on_create(self, enabled: bool) -> Self
pub const fn on_create(self, enabled: bool) -> Self
Generate the slug when a row is inserted. Default: on.
Sourcepub const fn on_update(self, enabled: bool) -> Self
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.
Sourcepub const fn prevent_overwrite(self, enabled: bool) -> Self
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.
Sourcepub fn skip_when(
self,
skip: impl Fn(&A) -> bool + Send + Sync + 'static,
) -> Self
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.
Sourcepub fn scope(
self,
scope: impl Fn(&A) -> Condition + Send + Sync + 'static,
) -> Self
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>where
*const u8 is !null: Freeze,
PhantomData<<<A as ActiveModelTrait>::Entity as EntityTrait>::Column>: Freeze,
<<A as ActiveModelTrait>::Entity as EntityTrait>::Column: Freeze,
PhantomData<u8>: Freeze,
*const dyn Fn(&str, u32) -> String + Send + Sync is !null: Freeze,
PhantomData<dyn Fn(&str, u32) -> String + Send + Sync>: Freeze,
PhantomData<String>: Freeze,
*const dyn Transliterator is !null: Freeze,
PhantomData<dyn Transliterator>: Freeze,
*const dyn Fn(&A) -> bool + Send + Sync is !null: Freeze,
PhantomData<dyn Fn(&A) -> bool + Send + Sync>: Freeze,
*const dyn Fn(&A) -> Condition + Send + Sync is !null: Freeze,
PhantomData<dyn Fn(&A) -> Condition + Send + Sync>: Freeze,
impl<A> Move for SlugConfig<A>
impl<A> Send for SlugConfig<A>
impl<A> Sync for SlugConfig<A>
impl<A> Unpin for SlugConfig<A>
impl<A> UnsafeUnpin for SlugConfig<A>where
*const u8 is !null: UnsafeUnpin,
PhantomData<<<A as ActiveModelTrait>::Entity as EntityTrait>::Column>: UnsafeUnpin,
<<A as ActiveModelTrait>::Entity as EntityTrait>::Column: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const dyn Fn(&str, u32) -> String + Send + Sync is !null: UnsafeUnpin,
PhantomData<dyn Fn(&str, u32) -> String + Send + Sync>: UnsafeUnpin,
PhantomData<String>: UnsafeUnpin,
*const dyn Transliterator is !null: UnsafeUnpin,
PhantomData<dyn Transliterator>: UnsafeUnpin,
*const dyn Fn(&A) -> bool + Send + Sync is !null: UnsafeUnpin,
PhantomData<dyn Fn(&A) -> bool + Send + Sync>: UnsafeUnpin,
*const dyn Fn(&A) -> Condition + Send + Sync is !null: UnsafeUnpin,
PhantomData<dyn Fn(&A) -> Condition + Send + Sync>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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