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] methodextract-from-table- enable the [Table] trait and the [extract_from_table] methodfacet030-unstable-ConfigandVersionwill derive fromFacetso that they can be examined or serialized that way.facet032-unstable-ConfigandVersionwill derive fromFacetso that they can be examined or serialized that way.toml-boml1- implement the [Table] trait for theTomlTabletype from thebomlcrate so that [extract_from_table] may be used for values of that type.
Note that the facet032-unstable feature builds the facet crate with
its alloc feature enabled regardless of whether the alloc feature is
enabled for the media-type-version crate itself.
Structs§
- Config
- Runtime configuration for the media-type-version library.
- Config
Builder - Build the runtime configuration.
- Version
- The extracted format version.
Enums§
- Error
- An error that occurred while processing the media type string.
Constants§
- FEATURES
- The features supported by this version of the library.
Functions§
- extract
- Extract the format version from a media type string.