pub trait AsKey: Sized {
// Required methods
fn as_filename_str(&self) -> Cow<'_, str>;
fn try_from_filename_str(file_name: &str) -> Option<Self>;
// Provided method
fn verified_as_filename_str(&self) -> Cow<'_, str> { ... }
}Expand description
A type that can be used as the key (i.e. converted to a file name)
in a KeyVal database.
Required Methods§
Sourcefn as_filename_str(&self) -> Cow<'_, str>
fn as_filename_str(&self) -> Cow<'_, str>
Types implementing this trait can’t have failing conversions!
If you want to use a key type with a fallible conversion, it
must have a conversion to a custom type that implements AsKey,
and that conversion will need to be fallible. The result
must never start with a . (leading dot is used for temporary
files), or contain the / or \0 characters, must be at
least 1 and at most 254 bytes long, and should never contain
control characters (this could make it a pain for people to
use command line tools to work with the databases).
Sourcefn try_from_filename_str(file_name: &str) -> Option<Self>
fn try_from_filename_str(file_name: &str) -> Option<Self>
Must convert the output of as_filename_str back into a Self
equal to the original self. If not possible (e.g. a human
placed an invalid file), return None.
Provided Methods§
Sourcefn verified_as_filename_str(&self) -> Cow<'_, str>
fn verified_as_filename_str(&self) -> Cow<'_, str>
Calls as_filename_str and asserts that the result complies
to the rules mentioned above, panics if it does not.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.