2 releases

0.1.1 Oct 9, 2024
0.1.0 Sep 2, 2024

#12 in #wikipedia

Download history 142/week @ 2024-08-29 21/week @ 2024-09-05 12/week @ 2024-09-12 10/week @ 2024-09-19 9/week @ 2024-09-26 89/week @ 2024-10-03 80/week @ 2024-10-10 3/week @ 2024-10-17

186 downloads per month

MIT license

94KB
2K SLoC

wikipedia-rs-wasm

Crates.io

Access wikipedia articles from Rust.

This is an alteration of the crate wikipedia to make it able to compile to wasm and should still work for other platforms.

The only downsides are anything returning an iterator actually returns a custom iterator that can use an async next which means no for loops and that your program will be all async but if it is going to be in wasm it probably was going to be anyway.

Also, the four tests that this crate fails the original crate also fails.

Example

use wikipedia_wasm::{Wikipedia, http};

#[tokio::main]
async fn main()
{
    let wiki = Wikipedia::<http::default::Client>::default();
    let page = wiki.page_from_title("World War II".to_string());
    let content = page.get_content().await.unwrap();
    assert!(content.starts_with("World War II or the Second World War (1 September 1939 – 2 September 1945)"));
}

Problem

The original crate used reqwest's blocking feature which cannot compile to wasm because of the internet's single thread nature or something like that.

Solution

  • Make most functions async
  • Make an async iterator

Original Crate by seppo0010

Dependencies

~0.8–12MB
~139K SLoC