Struct peace_core::ItemId
source · pub struct ItemId(/* private fields */);
Expand description
Unique identifier for an ItemId
, Cow<'static, str>
newtype.
Must begin with a letter or underscore, and contain only letters, numbers, and underscores.
§Examples
The following are all examples of valid ItemId
s:
let _snake = item_id!("snake_case");
let _camel = item_id!("camelCase");
let _pascal = item_id!("PascalCase");
§Design Note
TODO: Experiment with upgrades.
For backward compatibility and migrating items from old IDs to new IDs, e.g. when they were deployed with an old version of the automation software, there needs to be a way to:
- Read state using the old ID.
- Either clean up that state, or migrate that state into an Item with the new ID.
Implementations§
source§impl ItemId
impl ItemId
sourcepub fn new(s: &'static str) -> Result<Self, ItemIdInvalidFmt<'_>>
pub fn new(s: &'static str) -> Result<Self, ItemIdInvalidFmt<'_>>
Returns a new ItemId
if the given &str
is valid.
Most users should use the item_id!
macro as this provides
compile time checks and returns a const
value.
sourcepub fn is_valid_id(proposed_id: &str) -> bool
pub fn is_valid_id(proposed_id: &str) -> bool
Returns whether the provided &str
is a valid station identifier.
Methods from Deref<Target = Cow<'static, str>>§
sourcepub fn is_borrowed(&self) -> bool
🔬This is a nightly-only experimental API. (cow_is_borrowed
)
pub fn is_borrowed(&self) -> bool
cow_is_borrowed
)Returns true if the data is borrowed, i.e. if to_mut
would require additional work.
§Examples
#![feature(cow_is_borrowed)]
use std::borrow::Cow;
let cow = Cow::Borrowed("moo");
assert!(cow.is_borrowed());
let bull: Cow<'_, str> = Cow::Owned("...moo?".to_string());
assert!(!bull.is_borrowed());
sourcepub fn is_owned(&self) -> bool
🔬This is a nightly-only experimental API. (cow_is_borrowed
)
pub fn is_owned(&self) -> bool
cow_is_borrowed
)Returns true if the data is owned, i.e. if to_mut
would be a no-op.
§Examples
#![feature(cow_is_borrowed)]
use std::borrow::Cow;
let cow: Cow<'_, str> = Cow::Owned("moo".to_string());
assert!(cow.is_owned());
let bull = Cow::Borrowed("...moo?");
assert!(!bull.is_owned());