Cargo Features

axum-serde has no features set by default.

[dependencies]
axum-serde = { version = "0.7.0", features = ["full", "yaml", "msgpack", "toml", "xml", "xml_encoding", "sonic", "cbor"] }
full = cbor, msgpack, sonic, toml, xml, yaml
yaml full?

Enables serde_yaml

Affects axum-serde::yaml

msgpack full?

Enables rmp-serde

Affects axum-serde::msgpack

toml full?

Enables toml

Affects axum-serde::toml

xml full? xml_encoding?

Enables quick-xml

Affects axum-serde::xml

xml_encoding = xml

Enables encoding of quick-xml

quick-xml:

Enables support of non-UTF-8 encoded documents. Encoding will be inferred from the XML declaration if it is found, otherwise UTF-8 is assumed.

Currently, only ASCII-compatible encodings are supported. For example, UTF-16 will not work (therefore, quick-xml is not standard compliant).

Thus, quick-xml supports all encodings of encoding_rs except these:

You should stop processing a document when one of these encodings is detected, because generated events can be wrong and do not reflect a real document structure!

Because these are the only supported encodings that are not ASCII compatible, you can check for them:

use quick_xml::events::Event;
use quick_xml::reader::Reader;

let xml = to_utf16le_with_bom(r#"<?xml encoding='UTF-16'><element/>"#);
let mut reader = Reader::from_reader(xml.as_ref());
reader.config_mut().trim_text(true);

let mut buf = Vec::new();
let mut unsupported = false;
loop {
    if !reader.decoder().encoding().is_ascii_compatible() {
        unsupported = true;
        break;
    }
    buf.clear();
    match reader.read_event_into(&mut buf).unwrap() {
        Event::Eof => break,
        _ => {}
    }
}
assert_eq!(unsupported, true);

This restriction will be eliminated once issue #158 is resolved.

sonic full?

Enables sonic-rs

Affects axum-serde::sonic

cbor full?

Enables ciborium

Affects axum-serde::cbor