Module viaspf::record[][src]

Expand description

A representation of SPF record data.

The data structures here constitute a faithful encoding of the ABNF in RFC 7208, section 12.

The main top-level data structure in this module is the Record struct. Record represents a syntactically valid SPF record. A Record can be parsed from a string:

use std::net::Ipv4Addr;
use viaspf::record::*;

let record = "v=spf1 mx ip4:12.34.56.78/24 -all".parse();

assert_eq!(
    record,
    Ok(Record {
        terms: vec![
            Term::Directive(Directive {
                qualifier: None,
                mechanism: Mechanism::Mx(Mx {
                    domain_spec: None,
                    prefix_len: None,
                }),
            }),
            Term::Directive(Directive {
                qualifier: None,
                mechanism: Mechanism::Ip4(Ip4 {
                    addr: Ipv4Addr::new(12, 34, 56, 78),
                    prefix_len: Some(Ip4CidrLength::new(24).unwrap()),
                }),
            }),
            Term::Directive(Directive {
                qualifier: Some(Qualifier::Fail),
                mechanism: Mechanism::All,
            }),
        ],
    })
);

Also provided as a top-level data structure is the ExplainString struct. It too can be parsed from a string.

SPF record data may be printed via Display. The string representations are the canonical SPF string representations. Thus roundtripping through parsing and printing is possible:

use viaspf::record::*;

let record_str = "v=spf1 mx -all";
assert_eq!(record_str.parse::<Record>()?.to_string(), record_str);

Structs

An a mechanism.

Macro delimiter characters.

A directive.

A domain specification.

An exists mechanism.

An explain string.

An exp modifier.

An include mechanism.

An ip4 mechanism.

An IPv4 CIDR prefix length.

An ip6 mechanism.

An IPv6 CIDR prefix length.

A macro.

A literal part of a macro string.

A macro string.

An mx mechanism.

A modifier name.

An error indicating that an ExplainString could not be parsed.

An error indicating that a Record could not be parsed.

A ptr mechanism.

An SPF record.

A redirect modifier.

An unknown modifier.

Enums

A combined IPv4 and/or IPv6 CIDR prefix length.

An escape sequence in a macro string.

A part of an explain string.

A part of a macro string that may be expanded.

The kind of a macro (macro letter).

A part of a macro string.

A mechanism.

A modifier.

A qualifier.

A term.