Skip to content

Consider adding trait-level short_title fallback to title #575

@caugner

Description

@caugner

Context

The PageLike trait's short_title() method returns Option<&str>, requiring every call site to manually fall back to title() via .unwrap_or().

Current behavior

Every call site already applies the same pattern:

  • crates/rari-doc/src/helpers/title.rs:68root_doc.short_title().unwrap_or(root_doc.title())
  • crates/rari-doc/src/helpers/subpages.rs:27-28 — sorting uses .unwrap_or(a.title())
  • crates/rari-doc/src/html/links.rs:78 — link rendering uses .unwrap_or(page.title())

Proposal

Add a default method to the PageLike trait (or equivalent) that encapsulates this fallback, reducing repetition and preventing inconsistencies:

fn short_title_or_title(&self) -> &str {
    self.short_title().unwrap_or(self.title())
}

This is a low-priority cleanup item — the current approach works correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions