pub struct AppIdentity { /* private fields */ }Expand description
Builder-style application identity validated before a runtime is started.
An unset field is distinct from an explicitly empty string: both are
rejected, but with different AppIdentityError variants. Builder calls
replace the previous value.
§Examples
use ailloli_ui_core::{AppIcon, AppIdentity};
let identity = AppIdentity::new()
.id("org.example.paint")
.name("Paint")
.icon(AppIcon::from_static_svg(b"<svg/>", "assets/icon.svg"));
assert_eq!(identity.id_str(), Some("org.example.paint"));
assert_eq!(identity.validate()?.name(), "Paint");Implementations§
Source§impl AppIdentity
impl AppIdentity
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an identity with all three required fields unset.
§Examples
use ailloli_ui_core::AppIdentity;
assert_eq!(AppIdentity::new().id_str(), None);Sourcepub fn id(self, id: impl Into<String>) -> Self
pub fn id(self, id: impl Into<String>) -> Self
Sets the candidate reverse-DNS application identifier.
Grammar validation is deferred to Self::validate.
§Examples
use ailloli_ui_core::AppIdentity;
assert_eq!(AppIdentity::new().id("org.example.paint").id_str(), Some("org.example.paint"));Sourcepub fn name(self, name: impl Into<String>) -> Self
pub fn name(self, name: impl Into<String>) -> Self
Sets the public application name, replacing any previous value.
Surrounding whitespace is trimmed during Self::validate.
§Examples
use ailloli_ui_core::AppIdentity;
assert_eq!(AppIdentity::new().name(" Paint ").name_str(), Some(" Paint "));Sourcepub fn icon(self, icon: AppIcon) -> Self
pub fn icon(self, icon: AppIcon) -> Self
Sets the default application icon, replacing any previous value.
§Examples
use ailloli_ui_core::{AppIcon, AppIdentity};
let identity = AppIdentity::new().icon(AppIcon::from_static_svg(b"<svg/>", "icon.svg"));
assert_eq!(identity.app_icon().unwrap().bytes(), b"<svg/>");Sourcepub fn name_str(&self) -> Option<&str>
pub fn name_str(&self) -> Option<&str>
Returns the unvalidated display name, including surrounding whitespace.
§Examples
use ailloli_ui_core::AppIdentity;
assert_eq!(AppIdentity::new().name(" Paint ").name_str(), Some(" Paint "));Sourcepub fn app_icon(&self) -> Option<&AppIcon>
pub fn app_icon(&self) -> Option<&AppIcon>
Returns the configured icon, or None when Self::icon was not called.
§Examples
use ailloli_ui_core::AppIdentity;
assert!(AppIdentity::new().app_icon().is_none());Sourcepub fn validate(&self) -> Result<ValidatedAppIdentity, AppIdentityError>
pub fn validate(&self) -> Result<ValidatedAppIdentity, AppIdentityError>
Validates all required fields and returns an independent owned identity.
The display name is trimmed. The builder itself is only borrowed and can be corrected or reused after a failed validation.
§Errors
Returns the corresponding Missing* variant for an unset field,
AppIdentityError::EmptyName for an all-whitespace name, or an
identifier validation error described by ApplicationId::parse.
§Examples
use ailloli_ui_core::{AppIcon, AppIdentity};
let identity = AppIdentity::new().id("org.example.paint").name(" Paint ")
.icon(AppIcon::from_static_svg(b"<svg/>", "icon.svg"));
assert_eq!(identity.validate()?.name(), "Paint");Trait Implementations§
Source§impl Clone for AppIdentity
impl Clone for AppIdentity
Source§fn clone(&self) -> AppIdentity
fn clone(&self) -> AppIdentity
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more