pub struct IdentStr(/* private fields */);Expand description
A borrowed identifier.
An identifier is the name of an entity (module, resource, function, etc) in Move.
A valid identifier consists of an ASCII string which satisfies any of the conditions:
- The first character is a letter and the remaining characters are letters, digits or underscores.
- The first character is an underscore, and there is at least one further letter, digit or underscore.
The spec for allowed identifiers is similar to Rust’s spec (as of version 1.38).
Allowed identifiers are currently restricted to ASCII due to unresolved issues with Unicode normalization. See Rust issue #55467 and the associated RFC for some discussion. Unicode identifiers may eventually be supported once these issues are worked out.
This module only determines allowed identifiers at the bytecode level. Move source code will
likely be more restrictive than even this, with a “raw identifier” escape hatch similar to
Rust’s r# identifiers.
Among other things, identifiers are used to:
- specify keys for lookups in storage
- do cross-module lookups while executing transactions
Implementations§
Source§impl IdentStr
impl IdentStr
pub fn new(s: &str) -> Result<&Self, InvalidIdentifierError>
Sourcepub const fn cast(s: &'static str) -> &'static Self
pub const fn cast(s: &'static str) -> &'static Self
Compile-time validated constructor from static string slice.
§Example
Creating a valid static or const IdentStr:
use moverox_types::IdentStr;
const VALID_IDENT: &'static IdentStr = IdentStr::cast("MyCoolIdentifier");
const THING_NAME: &'static str = "thing_name";
const THING_IDENT: &'static IdentStr = IdentStr::cast(THING_NAME);In contrast, creating an invalid IdentStr will fail at compile time:
use moverox_types::IdentStr;
const INVALID_IDENT: &'static IdentStr = IdentStr::cast("123Foo"); // Fails to compile!