Struct parse_mediawiki_sql::utils::NamespaceMap
source · [−]pub struct NamespaceMap { /* private fields */ }
utils
only.Implementations
sourceimpl NamespaceMap
impl NamespaceMap
sourcepub fn from_site_info(site_info: SiteInfo) -> Result<NamespaceMap, Error>
pub fn from_site_info(site_info: SiteInfo) -> Result<NamespaceMap, Error>
Creates a NamespaceMap
from a SiteInfo
.
sourcepub fn from_path(path: &Path) -> Result<NamespaceMap, Error>
pub fn from_path(path: &Path) -> Result<NamespaceMap, Error>
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, AL>(
namespaces: NS,
namespace_aliases: AL
) -> Result<NamespaceMap, Error>where
NS: IntoIterator<Item = NamespaceInfo>,
AL: IntoIterator<Item = NamespaceAlias>,
pub fn from_namespaces_and_namespace_aliases<NS, AL>(
namespaces: NS,
namespace_aliases: AL
) -> Result<NamespaceMap, Error>where
NS: IntoIterator<Item = NamespaceInfo>,
AL: IntoIterator<Item = NamespaceAlias>,
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, NI, AL>(
namespaces: NS,
namespace_aliases: AL
) -> Result<NamespaceMap, Error>where
NS: IntoIterator<Item = NI>,
NI: IntoIterator<Item = (String, String)>,
AL: IntoIterator<Item = (String, i32)>,
pub fn from_iters<NS, NI, AL>(
namespaces: NS,
namespace_aliases: AL
) -> Result<NamespaceMap, Error>where
NS: IntoIterator<Item = NI>,
NI: IntoIterator<Item = (String, String)>,
AL: IntoIterator<Item = (String, i32)>,
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>(reader: R) -> Result<NamespaceMap, Error>where
R: Read,
pub fn from_reader<R>(reader: R) -> Result<NamespaceMap, Error>where
R: Read,
Creates a NamespaceMap
by parsing the contents of a Read
type that contains the JSON
representation of a SiteInfoResponse
.
sourcepub fn from_json<S>(json: S) -> Result<NamespaceMap, Error>where
S: AsRef<str>,
pub fn from_json<S>(json: S) -> Result<NamespaceMap, Error>where
S: AsRef<str>,
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<'b, N>(&'a self, namespace: N) -> Option<&'a NamespaceInfo>where
N: Into<Namespace<'b>>,
pub fn get_info<'b, N>(&'a self, namespace: N) -> Option<&'a NamespaceInfo>where
N: Into<Namespace<'b>>,
Returns the attributes of the namespace when given a valid namespace ID or name or alias.
sourcepub fn get_id<'b, N>(&'a self, namespace: N) -> Option<i32>where
N: Into<Namespace<'b>>,
pub fn get_id<'b, N>(&'a self, namespace: N) -> Option<i32>where
N: Into<Namespace<'b>>,
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<'b, N>(&'a self, namespace: N) -> Option<&'a str>where
N: Into<Namespace<'b>>,
pub fn get_name<'b, N>(&'a self, namespace: N) -> Option<&'a str>where
N: Into<Namespace<'b>>,
Returns the local name of the namespace when given a valid namespace ID or name or alias.
sourcepub fn get_case<'b, N>(&'a self, namespace: N) -> Option<&'a str>where
N: Into<Namespace<'b>>,
pub fn get_case<'b, N>(&'a self, namespace: N) -> Option<&'a str>where
N: Into<Namespace<'b>>,
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<'b, N>(&'a self, namespace: N) -> Option<&'a str>where
N: Into<Namespace<'b>>,
pub fn get_canonical_name<'b, N>(&'a self, namespace: N) -> Option<&'a str>where
N: Into<Namespace<'b>>,
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<'b, N>(&'a self, namespace: N) -> Option<bool>where
N: Into<Namespace<'b>>,
pub fn is_capitalized<'b, N>(&'a self, namespace: N) -> Option<bool>where
N: Into<Namespace<'b>>,
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.
Trait Implementations
sourceimpl Clone for NamespaceMap
impl Clone for NamespaceMap
sourcefn clone(&self) -> NamespaceMap
fn clone(&self) -> NamespaceMap
1.0.0 · sourceconst fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read more