Struct mwbot::TitleCodec
pub struct TitleCodec { /* private fields */ }
Expand description
The TitleCodec
is responsible for parsing, normalizing and formatting
Title
s. See the crate-level documentation for an example of how to
construct one.
Implementations§
§impl TitleCodec
impl TitleCodec
pub fn new_title(&self, input: &str) -> Result<Title, Error>
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>
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>
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
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
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
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
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>
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>,
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>
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,
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>
pub fn from_json<S>(json: S) -> Result<TitleCodec, Error>
Creates a TitleCodec
by parsing the JSON representation of a [SiteInfoResponse
].
pub fn from_site_info(site_info: SiteInfo) -> Result<TitleCodec, Error>
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
impl Clone for TitleCodec
§fn clone(&self) -> TitleCodec
fn clone(&self) -> TitleCodec
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more