pub fn parse_policy_by_value(
binary_policy: Vec<u8>,
) -> Result<(Unvalidated<ByValue<Vec<u8>>>, Vec<u8>), Error>
Expand description
Parses binary_policy
by value; that is, copies underlying binary data out in addition to
building up parser output structures. This function returns
(unvalidated_parser_output, binary_policy)
on success, or an error if parsing failed. Note
that the second component of the success case contains precisely the same bytes as the input.
This function depends on a uniformity of interface between the “by value” and “by reference”
strategies, but also requires an unvalidated_parser_output
type that is independent of the
binary_policy
lifetime. Taken together, these requirements demand the “move-in + move-out”
interface for binary_policy
.
If the caller does not need access to the binary policy when parsing fails, but does need to retain both the parsed output and the binary policy when parsing succeeds, the code will look something like:
let (unvalidated_policy, binary_policy) = parse_policy_by_value(binary_policy)?;
If the caller does need access to the binary policy when parsing fails and needs to retain both parsed output and the binary policy when parsing succeeds, the code will look something like:
let (unvalidated_policy, _) = parse_policy_by_value(binary_policy.clone())?;
If the caller does not need to retain both the parsed output and the binary policy, then
parse_policy_by_reference
should be used instead.