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§

ComposeError
std::error::Error returned in case composing of a username, using Composer went wrong, somehow.
Composer
Composer struct used to compose a username into a String, with labels, all separated by the given SEPARATOR. Empty labels aren’t allowed.
ExclusiveUsernameParsers
Wrapper type that can be used with a tuple of UsernameLabelParsers in order for it to stop iterating over the parsers once there was one that consumed the label.
UsernameLabels
Opaque string labels parsed collected using the UsernameOpaqueLabelParser.
UsernameOpaqueLabelParser
A UsernameLabelParser which collects all labels from the username, without any specific parsing logic.

Enums§

UsernameLabelState
The parse state of a username label.

Constants§

DEFAULT_USERNAME_LABEL_SEPARATOR
The default username label separator used by most built-in rama support.

Traits§

UsernameLabelParser
A parser which can parse labels from a username.
UsernameLabelWriter
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_username
Compose a username into a username together with its labels.
compose_username_with_separator
Compose a username into a username together with its labels, using a custom separator instead of the default (DEFAULT_USERNAME_LABEL_SEPARATOR)
parse_username
Parse a username, extracting the username (first part) and passing everything else to the UsernameLabelParser.
parse_username_with_separator
Parse a username, extracting the username (first part) and passing everything else to the UsernameLabelParser.