robotparser_fork/parser/
warning_reason.rs1use std::fmt;
2use std::num::{ParseFloatError, ParseIntError};
3use url::ParseError as ParseUrlError;
4
5#[derive(Clone, Debug)]
6pub enum WarningReason {
8 InvalidDirectiveFormat,
10 DirectiveKeyIsEmpty,
12 UnsupportedDirectiveKey(String),
14 UserAgentCannotBeEmpty,
16 DirectiveWithoutUserAgent,
18 ParseCrawlDelayError(ParseFloatError),
20 WrongRequestRateFormat,
22 ParseRequestRate(ParseIntError),
24 ParseUrl(ParseUrlError),
26 WrongCleanParamFormat,
30 IgnoredCleanParams(Vec<String>),
34 WrongPathFormat,
36}
37
38impl fmt::Display for WarningReason {
40 fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
41 match self {
42 Self::InvalidDirectiveFormat => {
43 write!(f, "Invalid directive format.")
44 },
45 Self::DirectiveKeyIsEmpty => {
46 write!(f, "Directive key is empty.")
47 },
48 Self::UnsupportedDirectiveKey(key) => {
49 write!(f, "Directive key `{}` is not suppored by this parser.", key)
50 },
51 Self::UserAgentCannotBeEmpty => {
52 write!(f, "Passed directive key is `User-Agent` and passed value is empty.")
53 },
54 Self::DirectiveWithoutUserAgent => {
55 write!(f, "It is impossible to process this directive before `User-Agent` directive has not been processed.")
56 },
57 Self::ParseCrawlDelayError(err) => {
58 write!(f, "It is impossible to process the `Crawl-Delay` directive because of an error when parsing a floating point number: {}", err)
59 },
60 Self::WrongRequestRateFormat => {
61 write!(f, "Incorrect format of the `Request-Rate` directive")
62 },
63 Self::ParseRequestRate(err) => {
64 write!(f, "Incorrect format of the `Request-Rate` directive: {}", err)
65 },
66 Self::ParseUrl(err) => {
67 write!(f, "Parsing URL error: {}", err)
68 },
69 Self::WrongCleanParamFormat => {
70 write!(f, "Incorrect format of the `Clean-Param` directive.")
71 },
72 Self::IgnoredCleanParams(ref params) => {
73 write!(f, "Directive `Clean-Param` directive has incorrect parameters: {:?}", params)
74 },
75 Self::WrongPathFormat => {
76 write!(f, "Error in URL path format.")
77 },
78 }
79 }
80}