pub struct TitleCodec { /* private fields */ }
parsing
only.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§
Source§impl TitleCodec
impl TitleCodec
Sourcepub fn new_title(&self, input: &str) -> Result<Title>
pub fn new_title(&self, input: &str) -> Result<Title>
Create a new title by parsing the provided input.
Sourcepub fn new_title_with_namespace(
&self,
input: &str,
default_namespace: i32,
) -> Result<Title>
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.
Sourcepub fn new_title_from_database(
&self,
namespace: i32,
dbkey: &str,
) -> Result<Title>
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.
Sourcepub fn namespace_map(&self) -> &NamespaceMap
pub fn namespace_map(&self) -> &NamespaceMap
Get a reference to the underlying NamespaceMap
to get information about namespaces.
Sourcepub 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.
Sourcepub 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.
Sourcepub 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.
Sourcepub fn new(
namespace_map: NamespaceMap,
interwiki_set: InterwikiSet,
local_interwiki_set: InterwikiSet,
main_page: String,
lang: String,
legal_title_chars: String,
) -> Result<Self>
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.
Sourcepub 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>
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.
Sourcepub fn from_path(path: &Path) -> Result<Self>
Available on crate feature utils
only.
pub fn from_path(path: &Path) -> Result<Self>
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.
Sourcepub fn from_reader<R: Read>(reader: R) -> Result<Self>
Available on crate feature utils
only.
pub fn from_reader<R: Read>(reader: R) -> Result<Self>
utils
only.Creates a TitleCodec
by parsing the contents of a Read
type that contains the JSON
representation of a SiteInfoResponse
.
Sourcepub fn from_json<S: AsRef<str>>(json: S) -> Result<Self>
Available on crate feature utils
only.
pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self>
utils
only.Creates a TitleCodec
by parsing the JSON representation of a SiteInfoResponse
.
Sourcepub fn from_site_info(site_info: SiteInfo) -> Result<Self>
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
impl Clone for TitleCodec
Source§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