Struct mwbot::TitleCodec

pub struct TitleCodec { /* private fields */ }
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§

§

impl TitleCodec

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

Create a new title by parsing the provided input.

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

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.

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

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

pub fn namespace_map(&self) -> &NamespaceMap

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

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.

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.

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.

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

Construct a new TitleCodec using the given fields.

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

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

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

pub fn from_path(path: &Path) -> Result<TitleCodec, Error>

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.

pub fn from_reader<R>(reader: R) -> Result<TitleCodec, Error>
where R: Read,

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

pub fn from_json<S>(json: S) -> Result<TitleCodec, Error>
where S: AsRef<str>,

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

pub fn from_site_info(site_info: SiteInfo) -> Result<TitleCodec, Error>

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§

§

impl Clone for TitleCodec

§

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
§

impl Debug for TitleCodec

§

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

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> 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 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,

§

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>,

§

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>,

§

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