Module username
Expand description
Utilities to work with usernames and pull information out of it.
§Username Parsing
The parse_username
function is used to parse a username and extract information from
its labels. The function takes a parser, which is used to parse the labels from the username.
The parser is expected to implement the UsernameLabelParser
trait, which has two methods:
parse_label
: This method is called for each label in the username, and is expected to return whether the label was used or ignored.build
: This method is called after all labels have been parsed, and is expected to consume the parser and store any relevant information.
The parser can be a single parser or a tuple of parsers. Tuple parsers all receive all labels,
unless wrapped by a ExclusiveUsernameParsers
, in which case the first parser that consumes
a label will stop the iteration over the parsers.
Parsers are to return UsernameLabelState::Used
in case they consumed the label, and
UsernameLabelState::Ignored
in case they did not. This way the parser-caller (e.g. parse_username
)
can decide whether to fail on ignored labels.
§Username Composing
Composing a username is the opposite of “Username Parsing”, and is used to suffix labels to a username.
Structs§
std::error::Error
returned in case composing of a username, usingComposer
went wrong, somehow.- Composer struct used to compose a username into a
String
, with labels, all separated by the givenSEPARATOR
. Empty labels aren’t allowed. - Wrapper type that can be used with a tuple of
UsernameLabelParser
s in order for it to stop iterating over the parsers once there was one that consumed the label. - Opaque string labels parsed collected using the
UsernameOpaqueLabelParser
. - A
UsernameLabelParser
which collects all labels from the username, without any specific parsing logic.
Enums§
- The parse state of a username label.
Constants§
- The default username label separator used by most built-in rama support.
Traits§
- A parser which can parse labels from a username.
- A type that can write itself as label(s) to compose into a username with labels. Often used by passing it to
compose_username
.
Functions§
- Compose a username into a username together with its labels.
- Compose a username into a username together with its labels, using a custom separator instead of the default (
DEFAULT_USERNAME_LABEL_SEPARATOR
) - Parse a username, extracting the username (first part) and passing everything else to the
UsernameLabelParser
. - Parse a username, extracting the username (first part) and passing everything else to the
UsernameLabelParser
.