Expand description
media-type-version - extract the format version from a media type string
§Overview
The media-type-version library is designed to be used as the first step in
parsing structured data, e.g. configuration files, serialized classes, etc.
The caller extracts the media type string (e.g. a JSON "mediaType": "..." key) and
passes it in for parsing.
The caller then decides what to do with the extracted version information -
is this version supported, what fields are expected to be there, should any
extraneous fields produce errors, and so on.
The main entry point is the extract function which is passed two parameters:
a Config object defining the expected media type prefix and suffix, and
a media type string to parse.
On success, it returns a Version object, basically a tuple of a major and
minor version numbers.
§Media type string format
The media type string is expected to be in a <prefix>.vX.Y<suffix> format, with
a fixed prefix and suffix.
The prefix will usually be a vendor-specific media type.
The version part consists of two unsigned integer numbers.
The suffix, if used, may correspond to the file format.
A sample media type string identifying a TOML configuration file for
a text-processing program could be
vnd.ringlet.textproc.publync.config/publync.v0.2+toml
§Crate features
-
alloc- enable the [Error::into_owned_error] method -
facet-unstable-ConfigandVersionwill derive fromFacetso that they can be examined or serialized that way.Note that the
facet-unstablefeature adds a pinned version dependency on whatever version of thefacetcrate is current at the time of release of themedia-type-versioncrate! If this feature is activated, it is strongly recommended to have a pinned version dependency onmedia-type-versionitself!
Re-exports§
Modules§
- defs
- Common definitions for the media-type-version library.
Functions§
- extract
- Extract the format version from a media type string.