mwtitle

Struct TitleCodec

Source
pub struct TitleCodec { /* private fields */ }
Available on crate feature parsing only.
Expand description

The TitleCodec is responsible for parsing, normalizing and formatting Titles. See the crate-level documentation for an example of how to construct one.

Implementations§

Source§

impl TitleCodec

Source

pub fn new_title(&self, input: &str) -> Result<Title>

Create a new title by parsing the provided input.

Source

pub fn new_title_with_namespace( &self, input: &str, default_namespace: i32, ) -> Result<Title>

Create a new title by parsing the provided input. If the title has no namespace part, then the namespace specified by default_namespace is used instead.

Source

pub fn new_title_from_database( &self, namespace: i32, dbkey: &str, ) -> Result<Title>

Create a new title from the numerical database ID and title portion, usually obtained directly from the database.

Source

pub fn namespace_map(&self) -> &NamespaceMap

Get a reference to the underlying NamespaceMap to get information about namespaces.

Source

pub fn to_pretty(&self, title: &Title) -> String

Get the title with namespace in pretty aka text form (spaces).

Fragments will not be included.

§Panics

This will panic if the Title is in a namespace that this TitleCodec is unaware of.

Source

pub fn to_underscores(&self, title: &Title) -> String

Get the title with namespace in underscore aka dbkey form. This is potentially useful when you want to make a database query.

Fragments will not be included.

§Panics

This will panic if the Title is in a namespace that this TitleCodec is unaware of.

Source

pub fn to_pretty_with_fragment(&self, title: &Title) -> String

Get the title with namespace in pretty aka text form (spaces), with the fragment, if one exists, appended.

§Panics

This will panic if the Title is in a namespace that this TitleCodec is unaware of.

Source

pub fn new( namespace_map: NamespaceMap, interwiki_set: InterwikiSet, local_interwiki_set: InterwikiSet, main_page: String, lang: String, legal_title_chars: String, ) -> Result<Self>

Construct a new TitleCodec using the given fields.

In most cases it is easier to do so from one of the siteinfo methods.

Source

pub fn new_from_iters<N: IntoIterator<Item = NamespaceInfo>, A: IntoIterator<Item = NamespaceAlias>, I: IntoIterator<Item = Interwiki>>( namespaces: N, namespace_aliases: A, interwikis: I, main_page: String, lang: String, legal_title_chars: String, ) -> Result<Self>

Create a new TitleCodec getting namespaces, namespace aliases, and interwikis from iterators.

Source

pub fn from_path(path: &Path) -> Result<Self>

Available on crate feature utils only.

Creates a TitleCodec by parsing the contents of a JSON or GZipped JSON file.

Will accept the siteinfo-namespaces.json.gz file from in the Wikimedia dumps. If the file extension is gz, decompresses from the GZip format before deserializing the JSON; otherwise attempts to deserialize the file contents directly.

Source

pub fn from_reader<R: Read>(reader: R) -> Result<Self>

Available on crate feature utils only.

Creates a TitleCodec by parsing the contents of a Read type that contains the JSON representation of a SiteInfoResponse.

Source

pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self>

Available on crate feature utils only.

Creates a TitleCodec by parsing the JSON representation of a SiteInfoResponse.

Source

pub fn from_site_info(site_info: SiteInfo) -> Result<Self>

Create a new TitleCodec using the provided SiteInfo.

The SiteInfo must include a non-empty interwiki_map field to enable the resulting TitleCodec to correctly parse titles with interwikis, but an empty interwiki_map is not an error.

Trait Implementations§

Source§

impl Clone for TitleCodec

Source§

fn clone(&self) -> TitleCodec

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 Debug for TitleCodec

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.