mirror of
https://github.com/danbulant/robotparser-rs
synced 2026-07-06 03:30:37 +00:00
Correct the usage of RefCell.borrow
This commit is contained in:
parent
7c7f09012e
commit
6153773f24
1 changed files with 10 additions and 10 deletions
20
src/lib.rs
20
src/lib.rs
|
|
@ -72,8 +72,8 @@ impl Entry {
|
||||||
/// check if this entry applies to the specified agent
|
/// check if this entry applies to the specified agent
|
||||||
fn applies_to(&self, useragent: &str) -> bool {
|
fn applies_to(&self, useragent: &str) -> bool {
|
||||||
let ua = useragent.split("/").nth(0).unwrap_or("");
|
let ua = useragent.split("/").nth(0).unwrap_or("");
|
||||||
let useragents = self.useragents.borrow().clone();
|
let useragents = self.useragents.borrow();
|
||||||
for agent in &useragents {
|
for agent in &*useragents {
|
||||||
if agent == "*" {
|
if agent == "*" {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -89,8 +89,8 @@ impl Entry {
|
||||||
/// - our agent applies to this entry
|
/// - our agent applies to this entry
|
||||||
/// - filename is URL decoded
|
/// - filename is URL decoded
|
||||||
fn allowance(&self, filename: &str) -> bool {
|
fn allowance(&self, filename: &str) -> bool {
|
||||||
let rulelines = self.rulelines.borrow().clone();
|
let rulelines = self.rulelines.borrow();
|
||||||
for line in &rulelines {
|
for line in &*rulelines {
|
||||||
if line.applies_to(filename) {
|
if line.applies_to(filename) {
|
||||||
return line.allowance
|
return line.allowance
|
||||||
}
|
}
|
||||||
|
|
@ -109,13 +109,13 @@ impl Entry {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_useragent(&self, useragent: &str) -> bool {
|
fn has_useragent(&self, useragent: &str) -> bool {
|
||||||
let useragents = self.useragents.borrow().clone();
|
let useragents = self.useragents.borrow();
|
||||||
useragents.contains(&useragent.to_owned())
|
useragents.contains(&useragent.to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_empty(&self) -> bool {
|
fn is_empty(&self) -> bool {
|
||||||
let useragents = self.useragents.borrow().clone();
|
let useragents = self.useragents.borrow();
|
||||||
let rulelines = self.rulelines.borrow().clone();
|
let rulelines = self.rulelines.borrow();
|
||||||
useragents.is_empty() && rulelines.is_empty()
|
useragents.is_empty() && rulelines.is_empty()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -303,14 +303,14 @@ impl RobotFileParser {
|
||||||
ref u if !u.is_empty() => u.to_owned(),
|
ref u if !u.is_empty() => u.to_owned(),
|
||||||
_ => "/".to_owned(),
|
_ => "/".to_owned(),
|
||||||
};
|
};
|
||||||
let entries = self.entries.borrow().clone();
|
let entries = self.entries.borrow();
|
||||||
for entry in &entries {
|
for entry in &*entries {
|
||||||
if entry.applies_to(useragent) {
|
if entry.applies_to(useragent) {
|
||||||
return entry.allowance(&url_str);
|
return entry.allowance(&url_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// try the default entry last
|
// try the default entry last
|
||||||
let default_entry = self.default_entry.borrow().clone();
|
let default_entry = self.default_entry.borrow();
|
||||||
if !default_entry.is_empty() {
|
if !default_entry.is_empty() {
|
||||||
return default_entry.allowance(&url_str);
|
return default_entry.allowance(&url_str);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue