Struct wikipedia::Wikipedia

source ·
pub struct Wikipedia<A: HttpClient> {
    pub client: A,
    pub pre_language_url: String,
    pub post_language_url: String,
    pub language: String,
    pub search_results: u32,
    pub images_results: String,
    pub links_results: String,
    pub categories_results: String,
}

Fields§

§client: A

HttpClient struct.

§pre_language_url: String

Url is created by concatenating pre_language_url + language + post_language_url.

§post_language_url: String§language: String§search_results: u32

Number of results to fetch when searching.

§images_results: String

Number of images to fetch in each request when calling get_images. The iterator will go through all of them, fetching pages of this size. It can be the string “max” to fetch as many as possible on every request.

§links_results: String

Like images_results, for links and references.

§categories_results: String

Like images_results, for categories.

Implementations§

source§

impl<A: HttpClient> Wikipedia<A>

source

pub fn new(client: A) -> Self

Creates a new object using the provided client and default values.

source

pub fn get_languages(&self) -> Result<Vec<(String, String)>>

Returns a list of languages in the form of (identifier, language), for example [(“en”, “English”), (“es”, “Español”)]

source

pub fn base_url(&self) -> String

Returns the api url

source

pub fn set_base_url(&mut self, base_url: &str)

Updates the url format. The substring {language} will be replaced with the selected language.

source

pub fn search(&self, query: &str) -> Result<Vec<String>>

Searches for a string and returns a list of relevant page titles.

Examples
extern crate wikipedia;

let wiki = wikipedia::Wikipedia::<wikipedia::http::default::Client>::default();
let results = wiki.search("keyboard").unwrap();
assert!(results.contains(&"Computer keyboard".to_owned()));
source

pub fn geosearch( &self, latitude: f64, longitude: f64, radius: u16 ) -> Result<Vec<String>>

Search articles within radius meters of latitude and longitude.

Examples
extern crate wikipedia;

let wiki = wikipedia::Wikipedia::<wikipedia::http::default::Client>::default();
let results = wiki.geosearch(40.750556,-73.993611, 20).unwrap();
assert!(results.contains(&"Madison Square Garden".to_owned()));
source

pub fn random_count(&self, count: u8) -> Result<Vec<String>>

Fetches count random articles’ title.

source

pub fn random(&self) -> Result<Option<String>>

Fetches a random article’s title.

source

pub fn page_from_title<'a>(&'a self, title: String) -> Page<'a, A>

Creates a new Page given a title.

source

pub fn page_from_pageid<'a>(&'a self, pageid: String) -> Page<'a, A>

Creates a new Page given a pageid.

Trait Implementations§

source§

impl<A: HttpClient + Clone> Clone for Wikipedia<A>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<A: Debug + HttpClient> Debug for Wikipedia<A>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<A: HttpClient + Default> Default for Wikipedia<A>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<A> RefUnwindSafe for Wikipedia<A>where A: RefUnwindSafe,

§

impl<A> Send for Wikipedia<A>where A: Send,

§

impl<A> Sync for Wikipedia<A>where A: Sync,

§

impl<A> Unpin for Wikipedia<A>where A: Unpin,

§

impl<A> UnwindSafe for Wikipedia<A>where A: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more