Struct AppIdentity

Source
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

Source

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);
Source

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"));
Source

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 "));
Source

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/>");
Source

pub fn id_str(&self) -> Option<&str>

Returns the unvalidated identifier, or None when Self::id was not called.

§Examples
use ailloli_ui_core::AppIdentity;
assert_eq!(AppIdentity::new().id("org.example.paint").id_str(), Some("org.example.paint"));
Source

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 "));
Source

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());
Source

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

Source§

fn clone(&self) -> AppIdentity

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AppIdentity

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AppIdentity

Source§

fn default() -> AppIdentity

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.