pub struct Admin { /* private fields */ }Expand description
Builder for the admin. Register models with .model::<M>(), then
hand it to the router via register_admin_routes.
Implementations§
Source§impl Admin
impl Admin
Sourcepub fn new() -> Self
pub fn new() -> Self
Constructs a new Admin with the framework’s core entries
pre-seeded. As of Phase 2 the only core entry is User, which
the schema exporter must always describe so external tooling
can reason about authentication tables. Project models are
added on top via Self::model / Self::model_with_search.
Sourcepub fn site_branding(self, branding: SiteBranding) -> Self
pub fn site_branding(self, branding: SiteBranding) -> Self
Override the default RustIO branding. Project-facing API; the
builder pattern matches .model() / .model_with_search() so
chains read naturally.
Sourcepub fn branding(&self) -> &SiteBranding
pub fn branding(&self) -> &SiteBranding
Read-only access to the active branding — handlers and context builders use this to thread brand strings into templates.
Sourcepub fn accent_color(self, color: impl Into<String>) -> Self
pub fn accent_color(self, color: impl Into<String>) -> Self
1.8.2 — set the admin chrome’s accent colour (one-line shortcut
for theme(AdminTheme { accent: ..., ..Default::default() })).
Hex form, with or without the leading # ("#1e6ba8" and
"1e6ba8" both work).
Drives a runtime <style> block in admin/base.html that
overrides every Tailwind utility baking the framework’s default
teal as a literal RGB value (bg-brand-600, text-brand-700,
link colour, selection colour, focus rings, the --ds-color-accent
CSS variable). No Tailwind rebuild required.
Malformed input (wrong length, non-hex characters) is accepted
silently — the renderer falls back to the framework default at
hex-to-RGB conversion time. This avoids panicking the admin path
over a config typo; future versions may add a Result-returning
builder for stricter operators.
Sourcepub fn theme(self, theme: AdminTheme) -> Self
pub fn theme(self, theme: AdminTheme) -> Self
1.8.2 — set the entire admin chrome palette in one call.
Re-skins the topbar, sidebar, body background, surface cards,
body text, muted text, and hairlines by overriding the
framework’s --rio-* design tokens at render time. See
AdminTheme for the field-by-field contract.
Sourcepub fn accent(&self) -> &str
pub fn accent(&self) -> &str
1.8.2 — read-only access to the configured accent colour
(#rrggbb). Used by BaseContext to populate the render
context; projects rarely need to call this directly.
Sourcepub fn active_theme(&self) -> &AdminTheme
pub fn active_theme(&self) -> &AdminTheme
1.8.2 — read-only access to the active full theme. Used by
BaseContext to populate the override <style> block.
pub fn model<M>(self) -> Selfwhere
M: AdminModel + Model,
Sourcepub fn model_with_search<M>(self, indexer: Indexer) -> Self
pub fn model_with_search<M>(self, indexer: Indexer) -> Self
Register a model and wire it into an async search indexer. Every create/update/delete pushes the row into the indexer’s queue — the actual HTTP round-trip to Meilisearch happens in the background.
pub fn entries(&self) -> &[AdminEntry]
Sourcepub fn user_profile_extension<F, Fut>(self, ext: F) -> Selfwhere
F: Fn(Db, UserProfile) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<Vec<UserProfileSection>>> + Send + 'static,
pub fn user_profile_extension<F, Fut>(self, ext: F) -> Selfwhere
F: Fn(Db, UserProfile) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<Vec<UserProfileSection>>> + Send + 'static,
Phase 10/c — register a project-specific extension that contributes
extra sections to the built-in user profile page. The closure is
invoked on every render of GET /admin/users/:id (Overview tab);
it receives the Db handle and the loaded crate::auth::UserProfile
(no password_hash) and returns a Vec<UserProfileSection>.
Sections render in the order returned, immediately after the core
profile show-grid.
Zero-config baseline: don’t call this method, and the extension area
stays empty. Projects that need richer layout than key-value rows
override the {% block project_user_fields %} template block in
templates/admin/user_view.html (extending admin/base.html).
let admin = Admin::new()
.user_profile_extension(|_db, user| Box::pin(async move {
Ok(vec![rustio_core::admin::UserProfileSection {
label: "Account".into(),
rows: vec![rustio_core::admin::UserProfileRow {
label: "Display name".into(),
value: user.full_name.unwrap_or(user.email),
}],
}])
}));pub fn find(&self, admin_name: &str) -> Option<&AdminEntry>
Sourcepub async fn seed_permissions(&self, db: &Db) -> Result<()>
pub async fn seed_permissions(&self, db: &Db) -> Result<()>
Register the canonical (add/change/delete/view) permissions for
every model. Call during startup after init_tables.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Admin
impl !RefUnwindSafe for Admin
impl Send for Admin
impl Sync for Admin
impl Unpin for Admin
impl UnsafeUnpin for Admin
impl !UnwindSafe for Admin
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
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>
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>
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