Module mwbot::generators

source ·
Available on crate feature generators only.
Expand description

§Page generators

Page generators are used to get lists of pages to operate on. For example, you could get a list of pages in a category or pages that use a specific template.

Most generators return a Page, but others may return other types, for example Revisions returns revision metadata.

§Basic usage

All generators follow the same basic structure:

  • a new() constructor that takes mandatory parameters
  • optional functions to supply optional parameters
  • a generate() function to start fetching pages

Rust has mediocre support for asynchronous iterators, so we take the approach of spawning a background task to fetch pages and use a channel to pass the results back. (This is why generators don’t work in WebAssembly.)

§Example

To fetch a list of pages in the category Free software programmed in Rust:

use mwbot::generators::{categories::CategoryMembers, Generator};

let bot = Bot::from_default_config().await.unwrap();
let mut generator = CategoryMembers::new("Category:Free software programmed in Rust");
let mut pages = generator.generate(&bot);
while let Some(page) = pages.recv().await {
    let page = page?;
    println!("{}", page.title());
}

Modules§

Structs§

  • Get pages that transclude the given template

Enums§

Traits§

  • Derivable trait that implements a straightforward builder to construct API parameters to generate a list of pages. Using the MediaWiki API’s generator feature, it preloads basic metadata about pages to speed up initial processing.
  • Trait to represent a value that can be an API parameter value.

Functions§

Derive Macros§

  • macro to implement the Generator trait