mwtitle

Struct 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<&'a 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 all_namespaces(&self) -> Vec<i32>

Returns all known namespaces’ ID.

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

Source§

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>,

Source§

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>,

Source§

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.