Skip to main content

ContentEntity

Trait ContentEntity 

Source
pub(crate) trait ContentEntity:
    Clone
    + PartialEq
    + Into<EntitySnapshot> {
    const ENTITY_TYPE: ContentEntityType;

    // Required methods
    fn id(&self) -> Uuid;
    fn course_id(&self) -> Uuid;
    fn label(&self) -> &str;
    fn narrow(snapshot: &EntitySnapshot) -> Option<&Self>;
    async fn load_live(
        conn: &mut PgConnection,
        ids: &[Uuid],
    ) -> ModelResult<HashMap<Uuid, Self>>;
    async fn lock_rows(conn: &mut PgConnection, ids: &[Uuid]) -> ModelResult<()>;

    // Provided method
    fn parent(&self) -> Option<EntityKey> { ... }
}
Expand description

What models know about one kind of content entity, implemented by its snapshot type, so that code over every kind dispatches on ContentEntityType once.

Required Associated Constants§

Required Methods§

Source

fn id(&self) -> Uuid

The entity’s id; the course id for course settings.

Source

fn course_id(&self) -> Uuid

Source

fn label(&self) -> &str

Source

fn narrow(snapshot: &EntitySnapshot) -> Option<&Self>

The snapshot, if it is of this kind.

Source

async fn load_live( conn: &mut PgConnection, ids: &[Uuid], ) -> ModelResult<HashMap<Uuid, Self>>

The live entities with the ids, as load_live_many has them, by id.

Source

async fn lock_rows(conn: &mut PgConnection, ids: &[Uuid]) -> ModelResult<()>

Locks the entities’ rows until the transaction ends. Soft-deleted rows are locked too: a publish can restore them. ids must be sorted, so that concurrent lockers take the rows in the same order.

Provided Methods§

Source

fn parent(&self) -> Option<EntityKey>

The chapter or module the entity is placed in; None for entities of the course itself.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl ContentEntity for ChapterSnapshot

Source§

const ENTITY_TYPE: ContentEntityType = ContentEntityType::Chapter

Source§

impl ContentEntity for CourseDefaultReviewConfigSnapshot

Source§

const ENTITY_TYPE: ContentEntityType = ContentEntityType::CourseDefaultReviewConfig

Source§

impl ContentEntity for CourseSettingsSnapshot

Source§

const ENTITY_TYPE: ContentEntityType = ContentEntityType::CourseSettings

Source§

impl ContentEntity for GlossaryTermSnapshot

Source§

const ENTITY_TYPE: ContentEntityType = ContentEntityType::GlossaryTerm

Source§

impl ContentEntity for ModuleSnapshot

Source§

const ENTITY_TYPE: ContentEntityType = ContentEntityType::Module

Source§

impl ContentEntity for PageSnapshot

Source§

const ENTITY_TYPE: ContentEntityType = ContentEntityType::Page

Source§

impl ContentEntity for ReferenceSnapshot

Source§

const ENTITY_TYPE: ContentEntityType = ContentEntityType::Reference