Skip to main content

Module sfv

Module sfv 

Source
Expand description

Structured Field Values (RFC 9651): Items, Lists, and Dictionaries with every bare item type, parsed into borrowed views.

The parser follows RFC 9651 section 4.2 exactly, as a loop with explicit state; inner lists cannot nest, so there is no recursion. A field is accepted or refused as a whole, as section 4.2 requires. Every limit of section 3 is enforced through Limits, whose defaults meet each minimum.

§Examples

use parse_net::sfv::{self, BareItem, Member};

let site = sfv::parse_item(b"same-origin")?;
assert_eq!(site.bare, BareItem::Token("same-origin"));

let prio = sfv::parse_dictionary(b"u=1, i")?;
assert!(matches!(prio.get("u"), Some(Member::Item(i)) if i.bare == BareItem::Integer(1)));
assert!(matches!(prio.get("i"), Some(Member::Item(i)) if i.bare == BareItem::Boolean(true)));

let list = sfv::parse_list(b"(\"foo\" \"bar\");lvl=5, abc;a=?0")?;
assert_eq!(list.len(), 2);
let Some(Member::InnerList(inner)) = list.iter().next() else { unreachable!() };
assert_eq!(inner.len(), 2);

Structs§

ByteSeq
A Byte Sequence: the base64 text between the colons.
Decimal
A Decimal in thousandths: at most 12 integer and 3 fractional digits.
DictIter
The members of a validated Dictionary.
Dictionary
A validated Dictionary. Every member is kept in order; a repeated key’s last value wins in get and index_into.
DictionaryLines
Several field lines read as one Dictionary.
DisplayString
A Display String: the percent-encoded text between the quotes, validated as UTF-8 during the parse.
InnerIter
The items of a validated InnerList.
InnerList
An inner list: items in parentheses, and its own parameters.
Item
An item: a bare item and its parameters.
List
A validated List.
ListIter
The members of a validated List.
ListLines
Several field lines read as one List.
ParamIter
The parameters of a validated SfParams.
Parser
The configurable parser.
SfParams
Parameters of an item or an inner list. A repeated key keeps every occurrence; get takes the last, as RFC 9651 requires.
SfString
A String: the content between the quotes, only \" and \\ escapes.

Enums§

BareItem
A bare item (RFC 9651 section 3.3).
Member
A list or dictionary member.

Traits§

Visitor
Receives a parse as events: the single-pass form, for callers that read one key or count items without building a view.

Functions§

parse_dictionary
Parses a Dictionary with the default Limits (RFC 9651 section 4.2.2).
parse_dictionary_lines
Parses several field lines as one Dictionary with the default Limits.
parse_item
Parses an Item with the default Limits (RFC 9651 section 4.2.3).
parse_list
Parses a List with the default Limits (RFC 9651 section 4.2.1).
parse_list_lines
Parses several field lines as one List with the default Limits.