pub struct SettingsService { /* private fields */ }Expand description
Settings service - main interface for accessing and managing settings
Implementations§
Source§impl SettingsService
impl SettingsService
pub fn new( registry: Arc<FrozenSettingsRegistry>, meta: Arc<dyn MetaAdapter>, cache_size: usize, ) -> Self
Sourcepub async fn get(
&self,
tn_id: TnId,
key: &str,
) -> ClResult<Option<SettingValue>>
pub async fn get( &self, tn_id: TnId, key: &str, ) -> ClResult<Option<SettingValue>>
Get setting value with full resolution (tenant -> global -> default).
Three distinct outcomes:
Ok(Some(value))— value resolved (stored or default)Ok(None)— wildcard-namespace key with no stored value (legitimate absence; wildcard registrations declare a namespace, not fixed keys)Err(SettingNotFound)— exact-match key with no default and not configured (programmer/configuration error)Err(other)— transient adapter or deserialization error
Sourcepub async fn get_raw(
&self,
tn_id: TnId,
key: &str,
) -> ClResult<Option<SettingValue>>
pub async fn get_raw( &self, tn_id: TnId, key: &str, ) -> ClResult<Option<SettingValue>>
Get the raw stored value at a single level without fallback.
Unlike get, this does not consult the schema default or the global
row when querying a tenant — it only returns the value stored in the
row keyed by (tn_id, key). Useful for the UI to distinguish “no
per-tenant override” from “explicit override that happens to equal
the global value”.
Returns Ok(None) when no row exists at that level. Bypasses cache
because the cache stores resolved values, not raw rows.
Sourcepub async fn set<S: AsRef<str>>(
&self,
tn_id: TnId,
key: &str,
value: SettingValue,
roles: &[S],
) -> ClResult<Setting>
pub async fn set<S: AsRef<str>>( &self, tn_id: TnId, key: &str, value: SettingValue, roles: &[S], ) -> ClResult<Setting>
Set setting value with validation and permission checks
The roles parameter should be the authenticated user’s roles
Sourcepub async fn delete(&self, tn_id: TnId, key: &str) -> ClResult<bool>
pub async fn delete(&self, tn_id: TnId, key: &str) -> ClResult<bool>
Delete a setting (falls back to next level)
Sourcepub async fn clear<S: AsRef<str>>(
&self,
tn_id: TnId,
key: &str,
roles: &[S],
) -> ClResult<()>
pub async fn clear<S: AsRef<str>>( &self, tn_id: TnId, key: &str, roles: &[S], ) -> ClResult<()>
Clear (unset) a setting with the same role-gating and scope checks as
set. Use this instead of calling MetaAdapter::update_setting(..., None)
directly when the caller is acting on behalf of an authenticated user —
it keeps audit trails and permission checks consistent across set/clear.
Sourcepub async fn validate_required_settings(&self) -> ClResult<()>
pub async fn validate_required_settings(&self) -> ClResult<()>
Validate that all required settings (no default and not optional) are configured
Sourcepub async fn get_string(&self, tn_id: TnId, key: &str) -> ClResult<String>
pub async fn get_string(&self, tn_id: TnId, key: &str) -> ClResult<String>
Type-safe getters (required - returns error if not found)
pub async fn get_int(&self, tn_id: TnId, key: &str) -> ClResult<i64>
pub async fn get_bool(&self, tn_id: TnId, key: &str) -> ClResult<bool>
pub async fn get_json(&self, tn_id: TnId, key: &str) -> ClResult<Value>
Sourcepub async fn get_string_opt(
&self,
tn_id: TnId,
key: &str,
) -> ClResult<Option<String>>
pub async fn get_string_opt( &self, tn_id: TnId, key: &str, ) -> ClResult<Option<String>>
Type-safe optional getters (returns None if not found or has no default) Still returns error if setting exists but has wrong type
pub async fn get_int_opt(&self, tn_id: TnId, key: &str) -> ClResult<Option<i64>>
pub async fn get_bool_opt( &self, tn_id: TnId, key: &str, ) -> ClResult<Option<bool>>
pub async fn get_json_opt( &self, tn_id: TnId, key: &str, ) -> ClResult<Option<Value>>
Sourcepub fn registry(&self) -> &Arc<FrozenSettingsRegistry> ⓘ
pub fn registry(&self) -> &Arc<FrozenSettingsRegistry> ⓘ
Get reference to registry (for listing all settings)
Sourcepub async fn list_by_prefix(
&self,
tn_id: TnId,
prefixes: &[String],
) -> ClResult<Vec<(String, SettingValue, &SettingDefinition)>>
pub async fn list_by_prefix( &self, tn_id: TnId, prefixes: &[String], ) -> ClResult<Vec<(String, SettingValue, &SettingDefinition)>>
List stored settings by prefix with definition metadata
This queries the database for actual stored settings matching the prefixes, then resolves each against the registry (supporting wildcard patterns like “ui.*”). Global settings are merged with tenant-specific settings (tenant overrides global).
Sourcepub async fn list_by_prefix_at(
&self,
tn_id: TnId,
prefixes: &[String],
) -> ClResult<Vec<(String, SettingValue, &SettingDefinition)>>
pub async fn list_by_prefix_at( &self, tn_id: TnId, prefixes: &[String], ) -> ClResult<Vec<(String, SettingValue, &SettingDefinition)>>
List stored settings at exactly one level (no merge, no fallback).
Used by the list handler when an explicit level= is requested.
Auto Trait Implementations§
impl !RefUnwindSafe for SettingsService
impl !UnwindSafe for SettingsService
impl Freeze for SettingsService
impl Send for SettingsService
impl Sync for SettingsService
impl Unpin for SettingsService
impl UnsafeUnpin for SettingsService
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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