pub struct SkipBlank<A = Same>(/* private fields */);Expand description
Leaves no value for blank strings.
Strings and lexical atoms that are empty or only
whitespace (as defined by str::trim) are skipped: they leave the
slot as it is. Everything else is deserialized with the adapter A
(by default Same). Serialization uses the inner adapter.
Sequences and collections leave out elements without a value, which
makes this an adapter for their elements: Vec<SkipBlank> drops the
blank elements, in sequences as well as for keys that are given more
than once (like tag=&tag=a in a query string or the whitespace between
elements in XML). It can be combined with TrimWhitespace (which
trims the other values) and Separated:
use deser::adapters::{Separated, SkipBlank, TrimWhitespace};
use deser::Deserialize;
#[derive(Deserialize)]
pub struct Config {
// `a, ,b,` is `["a", "b"]`
#[deser(as = Separated<',', SkipBlank<TrimWhitespace>>)]
hosts: Vec<String>,
// blank values are missing, which is `None`
#[deser(as = SkipBlank<Option<_>>)]
name: Option<String>,
}For values that are not elements a blank string is a missing value: an
optional is None, other types report the missing field (unless they
have a default).