fnentry( &mutself, key:&'deKeyRef, )->Result<implEntryVisitor<'de>,Self::Error> { letcoord=matchkey.as_str(){ "x"=>&mutself.x, "y"=>&mutself.y, // Ignore this key by returning `None`. Its value will still be // validated syntactically during parsing, but we don't need to // visit it. _=>returnOk(None), }; // Visit this key's value by returning `Some`. Ok(Some(CoordVisitor{coord})) } }
fnbare_item( self, bare_item:BareItemFromInput<'de>, )->Result<implParameterVisitor<'de>,Self::Error>{ ifletBareItemFromInput::Integer(v)=bare_item{ *self.coord=i64::from(v); // Ignore the item's parameters by returning `Ignored`. The // parameters will still be validated syntactically during parsing, // but we don't need to visit them. // // We could return `None` instead to ignore the parameters only // some of the time, returning `Some(visitor)` otherwise. Ok(Ignored) }else{ Err(NotAnInteger) } } }
impl<'de>EntryVisitor<'de>forCoordVisitor<'_>{ fninner_list(self)->Result<implInnerListVisitor<'de>,Self::Error>{ // Use `Never` to enforce at the type level that this method will only // return `Err`, as our coordinate must be a single integer, not an // inner list. Err::<Never,_>(NotAnInteger) } }
/// A visitor whose methods are called during parameter parsing. /// /// The lifetime `'de` is the lifetime of the input. pubtrait ParameterVisitor<'de> { /// The error type that can be returned if some error occurs during parsing. type Error: Error;
/// Called after a parameter has been parsed. /// /// Parsing will be terminated early if an error is returned. /// /// Note: Per [RFC 9651], when duplicate parameter keys are encountered in /// the same scope, all but the last instance are ignored. Implementations /// of this trait must respect that requirement in order to comply with the /// specification. For example, if parameters are stored in a map, earlier /// values for a given parameter key must be overwritten by later ones. /// /// [RFC 9651]: <https://httpwg.org/specs/rfc9651.html#parse-param> /// /// # Errors /// The error result should report the reason for any failed validation. fn parameter(
&mutself,
key: &'de KeyRef,
value: BareItemFromInput<'de>,
) -> Result<(), Self::Error>;
/// Called after all parameters have been parsed. /// /// Parsing will be terminated early if an error is returned. /// /// # Errors /// The error result should report the reason for any failed validation. fn finish(self) -> Result<(), Self::Error> where Self: Sized,
{
Ok(())
}
}
/// A visitor whose methods are called during item parsing. /// /// The lifetime `'de` is the lifetime of the input. /// /// Use this trait with /// [`Parser::parse_item_with_visitor`][crate::Parser::parse_item_with_visitor]. pubtrait ItemVisitor<'de> { /// The error type that can be returned if some error occurs during parsing. type Error: Error;
/// Called after a bare item has been parsed. /// /// The returned visitor is used to handle the bare item's parameters. /// See [the module documentation](crate::visitor#discarding-irrelevant-parts) /// for guidance on discarding parameters. /// /// Parsing will be terminated early if an error is returned. /// /// # Errors /// The error result should report the reason for any failed validation. fn bare_item( self,
bare_item: BareItemFromInput<'de>,
) -> Result<impl ParameterVisitor<'de>, Self::Error>;
}
/// A visitor whose methods are called during inner-list parsing. /// /// The lifetime `'de` is the lifetime of the input. pubtrait InnerListVisitor<'de> { /// The error type that can be returned if some error occurs during parsing. type Error: Error;
/// Called before an item has been parsed. /// /// The returned visitor is used to handle the bare item. /// /// Parsing will be terminated early if an error is returned. /// /// # Errors /// The error result should report the reason for any failed validation. fn item(&mutself) -> Result<impl ItemVisitor<'de>, Self::Error>;
/// Called after all inner-list items have been parsed. /// /// The returned visitor is used to handle the inner list's parameters. /// See [the module documentation](crate::visitor#discarding-irrelevant-parts) /// for guidance on discarding parameters. /// /// Parsing will be terminated early if an error is returned. /// /// # Errors /// The error result should report the reason for any failed validation. fn finish(self) -> Result<impl ParameterVisitor<'de>, Self::Error>;
}
/// A visitor whose methods are called during entry parsing. /// /// The lifetime `'de` is the lifetime of the input. pubtrait EntryVisitor<'de>: ItemVisitor<'de> { /// Called before an inner list has been parsed. /// /// The returned visitor is used to handle the inner list. /// /// Parsing will be terminated early if an error is returned. /// /// # Errors /// The error result should report the reason for any failed validation. fn inner_list(self) -> Result<impl InnerListVisitor<'de>, Self::Error>;
}
/// A visitor whose methods are called during dictionary parsing. /// /// The lifetime `'de` is the lifetime of the input. /// /// Use this trait with /// [`Parser::parse_dictionary_with_visitor`][crate::Parser::parse_dictionary_with_visitor]. pubtrait DictionaryVisitor<'de> { /// The error type that can be returned if some error occurs during parsing. type Error: Error;
/// Called after a dictionary key has been parsed. /// /// The returned visitor is used to handle the associated value. /// See [the module documentation](crate::visitor#discarding-irrelevant-parts) /// for guidance on discarding entries. /// /// Parsing will be terminated early if an error is returned. /// /// Note: Per [RFC 9651], when duplicate dictionary keys are encountered in /// the same scope, all but the last instance are ignored. Implementations /// of this trait must respect that requirement in order to comply with the /// specification. For example, if dictionary entries are stored in a map, /// earlier values for a given dictionary key must be overwritten by later /// ones. /// /// [RFC 9651]: <https://httpwg.org/specs/rfc9651.html#parse-dictionary> /// /// # Errors /// The error result should report the reason for any failed validation. fn entry(&mutself, key: &'de KeyRef) -> Result<impl EntryVisitor<'de>, Self::Error>;
}
/// A visitor whose methods are called during list parsing. /// /// The lifetime `'de` is the lifetime of the input. /// /// Use this trait with /// [`Parser::parse_list_with_visitor`][crate::Parser::parse_list_with_visitor]. pubtrait ListVisitor<'de> { /// The error type that can be returned if some error occurs during parsing. type Error: Error;
/// Called before a list entry has been parsed. /// /// The returned visitor is used to handle the entry. /// /// Parsing will be terminated early if an error is returned. /// /// # Errors /// The error result should report the reason for any failed validation. fn entry(&mutself) -> Result<impl EntryVisitor<'de>, Self::Error>;
}
/// A visitor that can be used to silently discard structured-field parts. /// /// Note that the discarded parts are still validated during parsing: syntactic /// errors in the input still cause parsing to fail even when this type is used, /// [as required by RFC 9651](https://httpwg.org/specs/rfc9651.html#strict). /// /// See [the module documentation](crate::visitor#discarding-irrelevant-parts) /// for example usage. #[derive(Clone, Copy, Debug, Default)] pubstruct Ignored;
impl<'de> ParameterVisitor<'de> for Ignored { type Error = Infallible;
/// A visitor that cannot be instantiated, but can be used as a type in /// situations guaranteed to return an error `Result`, analogous to /// [`std::convert::Infallible`]. /// /// When [`!`] is stabilized, this type will be replaced with an alias for it. #[derive(Clone, Copy, Debug)] pubenum Never {}
impl<'de> ParameterVisitor<'de> for Never { type Error = Infallible;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.