pub struct Usecase(/* private fields */);Expand description
A validated, case-sensitive name for an Objectstore workload.
Names must be 3–64 ASCII characters from [A-Za-z0-9_-]. Any permitted
character may appear in any position, including names consisting entirely of
underscores or hyphens. Names are never normalized.
Construction and deserialization both validate the name. The contents cannot be mutated after construction.
use objectstore_types::usecase::Usecase;
let name = Usecase::new("debug-files")?;
assert_eq!(name.as_str(), "debug-files");
assert!(Usecase::new("testing/org=999/injected").is_err());Use Usecase::from_static for statically known names and Usecase::new
for dynamic names.
Implementations§
Source§impl Usecase
impl Usecase
Sourcepub fn new(name: impl AsRef<str>) -> Result<Self, InvalidUsecaseName>
pub fn new(name: impl AsRef<str>) -> Result<Self, InvalidUsecaseName>
Creates a validated usecase name from a borrowed or owned string.
Use Self::from_static for statically defined names.
§Errors
Returns InvalidUsecaseName if the name violates the rules on
Usecase.
Sourcepub const fn from_static(name: &'static str) -> Self
pub const fn from_static(name: &'static str) -> Self
Creates a usecase name from a name known at compile time.
Use Self::new for dynamic names. The name is stored without
allocating, so the result can initialize a static:
use objectstore_types::usecase::Usecase;
static ATTACHMENTS: Usecase = Usecase::from_static("attachments");
assert_eq!(ATTACHMENTS.as_str(), "attachments");§Panics
Panics if the name violates the rules on Usecase. In a const
context, this panic is reported as a compile error:
use objectstore_types::usecase::Usecase;
static BROKEN: Usecase = Usecase::from_static("attachments/v2");