Types and Stuffs

There are three main entry points to Encoding.

Encoding is a single character encoding.
It contains encode and decode methods for converting String to Vec<u8> and vice versa.
For the error handling, they receive traps (EncoderTrap and DecoderTrap respectively)
which replace any error with some string (e.g. U+FFFD) or sequence (e.g. ?).
You can also use EncoderTrap::Strict and DecoderTrap::Strict traps to stop on an error.

There are two ways to get Encoding:

encoding::all has static items for every supported encoding.
You should use them when the encoding would not change or only handful of them are required.
Combined with link-time optimization, any unused encoding would be discarded from the binary.

encoding::label has functions to dynamically get an encoding from given string ("label").
They will return a static reference to the encoding,
which type is also known as EncodingRef.
It is useful when a list of required encodings is not available in advance,
but it will result in the larger binary and missed optimization opportunities.

RawEncoder is an experimental incremental encoder.
At each step of raw_feed, it receives a slice of string
and emits any encoded bytes to a generic ByteWriter (normally Vec<u8>).
It will stop at the first error if any, and would return a CodecError struct in that case.
The caller is responsible for calling raw_finish at the end of encoding process.

RawDecoder is an experimental incremental decoder.
At each step of raw_feed, it receives a slice of byte sequence
and emits any decoded characters to a generic StringWriter (normally String).
Otherwise it is identical to RawEncoders.

One should prefer Encoding::{encode,decode} as a primary interface.
RawEncoder and RawDecoder is experimental and can change substantially.
See the additional documents on encoding::types module for more information on them.

Supported Encodings

Encoding covers all encodings specified by WHATWG Encoding Standard and some more:

EUC-JP and Windows code page 932 (shift_jis,
since it's the most widespread extension to Shift_JIS)

ISO-2022-JP with asymmetric JIS X 0212 support
(Note: this is not yet up to date to the current standard)

GBK

GB 18030

Big5-2003 with HKSCS-2008 extensions

Encodings that were originally specified by WHATWG Encoding Standard:

HZ

ISO 8859-1 (distinct from Windows code page 1252)

Parenthesized names refer to the encoding's primary name assigned by WHATWG Encoding Standard.

Many legacy character encodings lack the proper specification,
and even those that have a specification are highly dependent of the actual implementation.
Consequently one should be careful when picking a desired character encoding.
The only standards reliable in this regard are WHATWG Encoding Standard and
vendor-provided mappings from the Unicode consortium.
Whenever in doubt, look at the source code and specifications for detailed explanations.