Struct mwtitle::NamespaceMap

source ·
pub struct NamespaceMap { /* private fields */ }

Implementations§

source§

impl NamespaceMap

source

pub fn from_site_info(site_info: SiteInfo) -> Result<Self>

Creates a NamespaceMap from a SiteInfo.

source

pub fn from_path(path: &Path) -> Result<Self>

Available on crate feature 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.

source

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 NamespaceInfos and an iterator yielding NamespaceAliases.

Errors

If the namespacealiases field contains any ids that are not found in the namespaces field of the SiteInfo, fails and returns Err(Error::UnknownAliases(unrecognized_ids)).

source

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.

source

pub fn from_reader<R: Read>(reader: R) -> Result<Self>

Available on crate feature utils only.

Creates a NamespaceMap by parsing the contents of a Read type that contains the JSON representation of a SiteInfoResponse.

source

pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self>

Available on crate feature utils only.

Creates a NamespaceMap by parsing the JSON representation of a SiteInfoResponse.

source

pub fn get_by_id(&self, id: i32) -> Option<&NamespaceInfo>

Returns the attributes of the namespace when given a valid namespace ID.

source

pub fn get_info<'a, 'b, N: Into<Namespace<'b>>>( &'a self, namespace: N ) -> Option<&NamespaceInfo>

Returns the attributes of the namespace when given a valid namespace ID or name or alias.

source

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().

source

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.

source

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.

source

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.

source

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().

source

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.

source

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

source

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.

source

pub fn display_title<'map: 'title, 'title>( &'map self, title: &'title Title, whitespace: TitleWhitespace, include_fragment: bool ) -> Option<impl Display + 'title>

Get a Displayable 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

source§

fn clone(&self) -> NamespaceMap

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
source§

impl Debug for NamespaceMap

source§

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

Formats the value using the given formatter. Read more
source§

impl PartialEq for NamespaceMap

source§

fn eq(&self, other: &NamespaceMap) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for NamespaceMap

source§

impl StructuralEq for NamespaceMap

source§

impl StructuralPartialEq for NamespaceMap

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.

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.