Make the boxed errors Send

[?]
Jan 12, 2022, 8:21 PM
AVLXUT3ROXQ2PLLTB5XHPBY2BI5PQRRFJTG2GGZTL7K4VEZZXF3AC

Dependencies

  • [2] LPVC545K Get the scraper part of this program working
  • [3] RNW6D777 Minor tidy
  • [4] YCWYAX6K Functions for scraping names integrated enough to test (they don't work yet)
  • [5] PQ4BG3ZJ The web scrape functions
  • [6] AV73DYWQ Initial functions for using sqlite in async environment
  • [7] KUANIPWF Add function for adding name to database
  • [8] C376NCOV Prevent flooding the website (still need to better mimic browser requests)
  • [*] HMOBTVJ4 Initialize crate and add expected dependencies

Change contents

  • edit in src/names_database.rs at line 1
    [3.42]
    [3.0]
    use crate::DynResult;
  • replacement in src/names_database.rs at line 29
    [3.754][3.754:806]()
    ) -> Result<Self, Box<dyn std::error::Error>> {
    [3.754]
    [3.131]
    ) -> DynResult<Self> {
  • replacement in src/names_database.rs at line 44
    [3.171][3.171:286]()
    pub async fn add_name(
    &self,
    name: String,
    ) -> Result<i64, Box<dyn std::error::Error>> {
    [3.171]
    [3.286]
    pub async fn add_name(&self, name: String) -> DynResult<i64> {
  • replacement in src/names_database.rs at line 67
    [3.1155][3.1155:1229]()
    Ok(Err(e)) => Err(Box::new(e) as Box<dyn std::error::Error>),
    [3.1155]
    [3.1229]
    Ok(Err(e)) => Err(Box::new(e) as crate::DynError),
  • replacement in src/names_database.rs at line 78
    [3.1526][3.1526:1575]()
    ) -> Result<U, Box<dyn std::error::Error>> {
    [3.1526]
    [3.1575]
    ) -> DynResult<U> {
  • edit in src/main.rs at line 8
    [3.73]
    [3.73]
    type DynError = Box<dyn std::error::Error + Send + Sync>;
    type DynResult<A> = Result<A, DynError>;
  • replacement in src/main.rs at line 28
    [3.2026][3.223:283]()
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
    [3.2026]
    [3.340]
    async fn main() -> DynResult<()> {
  • replacement in src/main.rs at line 35
    [3.444][2.113:226]()
    async fn run(
    &self,
    db: &AsyncConnection,
    ) -> Result<(), Box<dyn std::error::Error>> {
    [3.444]
    [3.1548]
    async fn run(&self, db: &AsyncConnection) -> DynResult<()> {
  • edit in src/gather.rs at line 1
    [3.87]
    [3.796]
    use crate::DynResult;
  • replacement in src/gather.rs at line 29
    [2.592][2.592:651]()
    let (delay, page) = match fetch.next().await {
    [2.592]
    [2.651]
    match fetch.next().await {
  • replacement in src/gather.rs at line 32
    [2.712][2.712:761]()
    (120, Vec::with_capacity(0))
    [2.712]
    [3.1123]
    tokio::time::sleep(std::time::Duration::new(120, 0)).await;
  • replacement in src/gather.rs at line 37
    [3.1280][2.793:987]()
    Ok(Some(page)) => (5, page),
    };
    for (name, gender) in page {
    if filter.allow(&gender) {
    tx.send(name).await.unwrap();
    [3.1280]
    [2.987]
    Ok(Some(page)) => {
    let wait =
    tokio::time::sleep(std::time::Duration::new(5, 0));
    for (name, gender) in page {
    if filter.allow(&gender) {
    tx.send(name).await.unwrap();
    }
    }
    wait.await;
  • replacement in src/gather.rs at line 47
    [2.1005][3.1280:1294](),[3.1280][3.1280:1294](),[3.1294][2.1006:1080]()
    }
    tokio::time::sleep(std::time::Duration::new(delay, 0)).await;
    [2.1005]
    [3.141]
    };
  • replacement in src/gather.rs at line 70
    [2.1455][2.1455:1570]()
    async fn next(
    &mut self,
    ) -> Result<Option<Vec<(String, Gender)>>, Box<dyn std::error::Error>> {
    [2.1455]
    [2.1570]
    async fn next(&mut self) -> DynResult<Option<Vec<(String, Gender)>>> {
  • replacement in src/gather.rs at line 128
    [2.4053][2.4053:4390]()
    (names, action.map(|url| {
    if url.starts_with("http") {
    String::from(url)
    } else {
    format!("https://babynames.com{}", url)
    }
    }), Some(form))
    [2.4053]
    [2.4390]
    (
    names,
    action.map(|url| {
    if url.starts_with("http") {
    String::from(url)
    } else {
    format!("https://babynames.com{}", url)
    }
    }),
    Some(form),
    )