Skip to main content

Module params

Module params 

Source
Expand description

Mechanisms for selecting parameters.

Traits and structures in this module are not normally needed by the typical user. Their purpose is to provide a systematic way, and in particular a default way, to select parameters for parameterized traits such as GammaReadParam and GammaWriteParam.

The traits and structure in this module work closely with the bitstream readers and writers in impls, which have an additional type parameter RP/WP that must implement marker traits ReadParams or WriteParams, respectively. The type is then used as a selector type to provide blanket implementations of parameterless traits in codes such as GammaRead, GammaWrite, DeltaRead, DeltaWrite, and so on.

This module provides default selector types DefaultReadParams and DefaultWriteParams which are also the default value for the parameter RP/WP in the bitstream readers and writers in crate::impls. Type-selected blanket implementations of all parameterless traits in crate::codes are provided for the bitstream readers and writers in impls. Thus, if you do not specify a value for the parameter RP/WP, you will obtain automatically the blanket implementations for parameterless traits contained in this module.

You can also define a new selector type implementing ReadParams/WriteParams and, within this crate, provide blanket implementations of the parameterless code traits for the bitstream readers and writers in crate::impls with RP/WP set to that type; a reader or writer using it then picks up those implementations instead of the ones provided here. Both the read and write blanket implementations in this module are provided specifically for DefaultReadParams/DefaultWriteParams, so a different selector does not silently inherit the defaults. Note that, because both the code traits and the bitstream types are defined in this crate, Rust’s orphan rules prevent a downstream crate from adding such implementations for its own selector type; a fully custom selector must therefore be added within this crate.

Note that the default implementations provided by this module are targeted at u32 read words and u64 write words. If you use different word sizes, you may want to write your own selector types.

§Table peek-bits checks

The read_*_param methods in each code module (e.g., GammaReadParam::read_gamma_param) verify at compile time, via const { } blocks using BitRead::PEEK_BITS, that the reader’s peek word is large enough for the table when the corresponding USE_TABLE const parameter is true. These checks are short-circuited when the table is not used, so they are only triggered for the tables actually selected.

Structs§

DefaultReadParams
A selector type for read parameters providing reasonable defaults.
DefaultWriteParams
A selector type for write parameters providing reasonable defaults.

Traits§

ReadParams
Marker trait for read-parameters selector types.
WriteParams
Marker trait for write-parameters selector types.