pub struct ExtractError(/* private fields */);query only.Expand description
Why extraction failed, where, and what it was reading.
Its Display gives the field path, the selector and the
source, then the reason:
Product.title ("h1"): no element matches
Product.price (".price" @data-value): cannot parse "$5" as f64: invalid float literal
Product.price (".price" @data-value): <span> has no "data-value" attribute
Product.sku (@data-sku): a document has no attributes; give the field a selector or extract from an element
Cents.cents (".price"): cannot convert "$x" with parse_cents: no digits
Typo.title ("h1:hover"): invalid selector: unsupported pseudo-class ':hover' at byte 2
Card: extract_all needs a selector on the type: #[html(select = "…")]The path names the type and field. Nested structs prefix the outer field
(Product.seller.name), Vec items add their index
(Product.reviews[1].rating) and so do Dom::extract_all items
(Product[1].title). The parentheses hold the selector and the source
(@attr, html, outer_html, markdown); a text or nested field shows
only its selector, and one with neither has no parentheses. Values are
quoted and escaped like {:?}, cut short after 60 characters.
It is one pointer wide (the details are boxed), so Result<T, ExtractError> costs little on the success path.
Implementations§
Source§impl ExtractError
impl ExtractError
Sourcepub fn new(kind: ExtractErrorKind) -> Self
pub fn new(kind: ExtractErrorKind) -> Self
A new error of kind, without a path, selector or source yet.
Sourcepub fn kind(&self) -> &ExtractErrorKind
pub fn kind(&self) -> &ExtractErrorKind
What went wrong.
Sourcepub fn path(&self) -> String
pub fn path(&self) -> String
Where: the type and field path, like Product.reviews[2].rating
(empty for a value read directly, like dom.extract::<f64>()).
use domq::{ExtractError, ExtractErrorKind};
let err = ExtractError::new(ExtractErrorKind::NoMatch)
.in_field("Review", "rating")
.at_index(2)
.in_field("Product", "reviews");
assert_eq!(err.path(), "Product.reviews[2].rating");Sourcepub fn selector(&self) -> Option<&str>
pub fn selector(&self) -> Option<&str>
The selector being matched when it failed (the innermost one).
Sourcepub fn value_source(&self) -> Option<&ValueSource>
pub fn value_source(&self) -> Option<&ValueSource>
The value being read when it failed, if it got that far.
Sourcepub fn with_selector(self, selector: &str) -> Self
pub fn with_selector(self, selector: &str) -> Self
Record the selector being matched, unless the error already names one (the innermost selector is the most specific).
Sourcepub fn with_source(self, source: ValueSource) -> Self
pub fn with_source(self, source: ValueSource) -> Self
Record the value being read, unless the error already names one.
Trait Implementations§
Source§impl Clone for ExtractError
impl Clone for ExtractError
Source§impl Debug for ExtractError
impl Debug for ExtractError
Source§impl Display for ExtractError
impl Display for ExtractError
impl Eq for ExtractError
Source§impl Error for ExtractError
Available on crate feature std only.
impl Error for ExtractError
std only.1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()