pub struct AppId(/* private fields */);Expand description
Filename-safe application identifier used as the leaf of storage paths.
Valid constructor input is non-empty lowercase ASCII letters, digits, and
single hyphens. It cannot begin or end with a hyphen and cannot contain
consecutive hyphens. Derived deserialization does not call Self::new,
so consumers of untrusted serialized AppId values must validate them.
§Examples
use ailloli_ui_app_storage::AppId;
assert_eq!(AppId::new("demo-2")?.as_str(), "demo-2");
assert!(AppId::new("Demo_2").is_err());Implementations§
Source§impl AppId
impl AppId
Sourcepub fn new(value: impl Into<String>) -> Result<Self>
pub fn new(value: impl Into<String>) -> Result<Self>
Validates and stores an application identifier.
§Errors
Returns AppStorageError::InvalidAppId for empty input, non-lowercase
ASCII letters, punctuation other than internal single hyphens, leading
or trailing hyphens, or consecutive hyphens.
§Examples
use ailloli_ui_app_storage::AppId;
assert!(AppId::new("2d-editor").is_ok());
assert!(AppId::new("-editor").is_err());Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Borrows the stored identifier.
§Examples
use ailloli_ui_app_storage::AppId;
assert_eq!(AppId::new("example")?.as_str(), "example");Sourcepub fn env_prefix(&self) -> String
pub fn env_prefix(&self) -> String
Returns the uppercase prefix used for app-specific environment variables.
ASCII alphanumeric characters are uppercased and every other character,
including the normally valid hyphen, becomes _.
§Examples
use ailloli_ui_app_storage::AppId;
assert_eq!(AppId::new("my-app")?.env_prefix(), "MY_APP");