pub struct NamespaceMap { /* private fields */ }
Implementations§
Source§impl NamespaceMap
impl NamespaceMap
Sourcepub fn from_site_info(site_info: SiteInfo) -> Result<Self>
pub fn from_site_info(site_info: SiteInfo) -> Result<Self>
Creates a NamespaceMap
from a SiteInfo
.
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 NamespaceMap
by parsing the contents of a JSON or GZipped JSON file
like siteinfo-namespaces.json.gz
or siteinfo-namespaces.json
in the Wikimedia dumps.
If the file extension is gz
, decompresses from the GZip format before decoding the JSON.
Sourcepub fn from_namespaces_and_namespace_aliases<NS: IntoIterator<Item = NamespaceInfo>, AL: IntoIterator<Item = NamespaceAlias>>(
namespaces: NS,
namespace_aliases: AL,
) -> Result<Self>
pub fn from_namespaces_and_namespace_aliases<NS: IntoIterator<Item = NamespaceInfo>, AL: IntoIterator<Item = NamespaceAlias>>( namespaces: NS, namespace_aliases: AL, ) -> Result<Self>
Constructs a NamespaceMap
from an iterator yielding NamespaceInfo
s
and an iterator yielding NamespaceAlias
es.
§Errors
If the namespacealiases
field contains any id
s that are not found in the namespaces
field of the SiteInfo
,
fails and returns Err(Error::UnknownAliases(unrecognized_ids))
.
Sourcepub fn from_iters<NS: IntoIterator<Item = NI>, NI: IntoIterator<Item = (String, String)>, AL: IntoIterator<Item = (String, i32)>>(
namespaces: NS,
namespace_aliases: AL,
) -> Result<Self>
pub fn from_iters<NS: IntoIterator<Item = NI>, NI: IntoIterator<Item = (String, String)>, AL: IntoIterator<Item = (String, i32)>>( namespaces: NS, namespace_aliases: AL, ) -> Result<Self>
Create a NamespaceMap
from two iterators. The first iterator represents
namespaces and contains (key, value): (String, String)
tuples that represent the fields
of a NamespaceInfo
. The second contains (alias, id): (String, i32)
tuples
that each represent a NamespaceAlias
.
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 NamespaceMap
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 NamespaceMap
by parsing the JSON representation of a SiteInfoResponse
.
Sourcepub fn get_by_id(&self, id: i32) -> Option<&NamespaceInfo>
pub fn get_by_id(&self, id: i32) -> Option<&NamespaceInfo>
Returns the attributes of the namespace when given a valid namespace ID.
Sourcepub fn get_info<'a, 'b, N: Into<Namespace<'b>>>(
&'a self,
namespace: N,
) -> Option<&'a NamespaceInfo>
pub fn get_info<'a, 'b, N: Into<Namespace<'b>>>( &'a self, namespace: N, ) -> Option<&'a NamespaceInfo>
Returns the attributes of the namespace when given a valid namespace ID or name or alias.
Sourcepub fn get_id<'a, 'b, N: Into<Namespace<'b>>>(
&'a self,
namespace: N,
) -> Option<i32>
pub fn get_id<'a, 'b, N: Into<Namespace<'b>>>( &'a self, namespace: N, ) -> Option<i32>
Returns the ID of the namespace when given a valid namespace ID or name or alias. In case of an ID, this unnecessarily looks up the ID in the map.
Equivalent of Language::getNsIndex()
.
Sourcepub fn get_name<'a, 'b, N: Into<Namespace<'b>>>(
&'a self,
namespace: N,
) -> Option<&'a str>
pub fn get_name<'a, 'b, N: Into<Namespace<'b>>>( &'a self, namespace: N, ) -> Option<&'a str>
Returns the local name of the namespace when given a valid namespace ID or name or alias.
Sourcepub fn all_namespaces(&self) -> Vec<i32>
pub fn all_namespaces(&self) -> Vec<i32>
Returns all known namespaces’ ID.
Sourcepub fn get_case<'a, 'b, N: Into<Namespace<'b>>>(
&'a self,
namespace: N,
) -> Option<&'a str>
pub fn get_case<'a, 'b, N: Into<Namespace<'b>>>( &'a self, namespace: N, ) -> Option<&'a str>
Returns case-sensitivity of the first letter of titles in the namespace when given a valid namespace ID or name or alias.
Sourcepub fn get_canonical_name<'a, 'b, N: Into<Namespace<'b>>>(
&'a self,
namespace: N,
) -> Option<&'a str>
pub fn get_canonical_name<'a, 'b, N: Into<Namespace<'b>>>( &'a self, namespace: N, ) -> Option<&'a str>
Returns canonical name for a namespace ID or name or alias, if it is valid and if that namespace has a canonical name.
Sourcepub fn is_capitalized<'a, 'b, N: Into<Namespace<'b>>>(
&'a self,
namespace: N,
) -> Option<bool>
pub fn is_capitalized<'a, 'b, N: Into<Namespace<'b>>>( &'a self, namespace: N, ) -> Option<bool>
Whether the first letter of titles in the namespace is always capitalized.
Equivalent of NamespaceInfo::isCapitalized()
.
Sourcepub fn to_pretty(&self, title: &Title) -> Option<String>
pub fn to_pretty(&self, title: &Title) -> Option<String>
Get the title with namespace in pretty aka text form (spaces).
Fragments will not be included.
Returns None
if the title’s namespace is not in the map.
Sourcepub fn to_underscores(&self, title: &Title) -> Option<String>
pub fn to_underscores(&self, title: &Title) -> Option<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.
Returns None
if the title’s namespace is not in the map
Sourcepub fn to_pretty_with_fragment(&self, title: &Title) -> Option<String>
pub fn to_pretty_with_fragment(&self, title: &Title) -> Option<String>
Get the title with namespace in pretty aka text form (spaces), with the fragment, if one exists, appended.
Returns None
if the title’s namespace is not in the map.
Sourcepub fn display_title<'map: 'title, 'title>(
&'map self,
title: &'title Title,
whitespace: TitleWhitespace,
include_fragment: bool,
) -> Option<impl Display + 'title>
pub fn display_title<'map: 'title, 'title>( &'map self, title: &'title Title, whitespace: TitleWhitespace, include_fragment: bool, ) -> Option<impl Display + 'title>
Get a Display
able object that represents a title with namespace
in pretty aka text form (spaces),
with the fragment, if one exists, appended.
Returns None
if the title’s namespace is not in the map.
Trait Implementations§
Source§impl Clone for NamespaceMap
impl Clone for NamespaceMap
Source§fn clone(&self) -> NamespaceMap
fn clone(&self) -> NamespaceMap
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more