Struct Title

Source
pub struct Title { /* private fields */ }
Available on crate feature utils only.
Expand description

Represents a MediaWiki title. A title can be broken down into the following attributes: [[interwiki:ns:db_key#fragment]].

  • interwiki: Optional prefix pointing to another site
  • namespace: Numerical ID corresponding to a MediaWiki namespace
  • dbkey: Page name, with underscores instead of spaces
  • fragment: Optional anchor for a specific section
// ns1 is Talk, so this is [[Talk:Main Page]]
let title = Title::new_unchecked(1, "Main_Page");
assert_eq!(title.namespace(), 1);
assert_eq!(title.dbkey(), "Main_Page");
assert!(title.interwiki().is_none());
assert!(title.fragment().is_none());
let title = title.with_fragment("Section 1");
assert_eq!(title.fragment(), Some("Section 1"));

Implementations§

Source§

impl Title

Source

pub fn new_unchecked(namespace: i32, text: &str) -> Title

Create a new Title, with no validation on the namespace or text parts. Good if you’re getting the title from a trusted place like the API. If the namespace does not exist in the TitleCodec this is used with it can result in panics.

Note that text is supposed to be the database key, with no namespace prefix.

Source

pub fn with_fragment(self, fragment: &str) -> Title

Set a fragment.

Source

pub fn remove_fragment(self) -> Title

Remove the fragment.

Source

pub fn namespace(&self) -> i32

Get the namespace ID.

Source

pub fn dbkey(&self) -> &str

Get the dbkey.

Source

pub fn fragment(&self) -> Option<&str>

Get the fragment, if there is one.

Source

pub fn interwiki(&self) -> Option<&str>

Get the interwiki, if there is one.

Source

pub fn is_local_interwiki(&self) -> bool

Whether this title was created via a local interwiki link.

Source

pub fn is_local_page(&self) -> bool

If the title is a local page that could exist, basically not an interwiki link, nor a fragment-only link, nor a special page.

Source

pub fn is_file(&self) -> bool

Whether this title refers to a file.

Source

pub fn is_category(&self) -> bool

Whether this title refers to a category.

Trait Implementations§

Source§

impl Clone for Title

Source§

fn clone(&self) -> Title

Returns a duplicate 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 Title

Source§

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

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

impl Ord for Title

Source§

fn cmp(&self, other: &Title) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Title

Source§

fn eq(&self, other: &Title) -> 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 PartialOrd for Title

Source§

fn partial_cmp(&self, other: &Title) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for Title

Source§

impl StructuralPartialEq for Title

Auto Trait Implementations§

§

impl Freeze for Title

§

impl RefUnwindSafe for Title

§

impl Send for Title

§

impl Sync for Title

§

impl Unpin for Title

§

impl UnwindSafe for Title

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, dest: *mut u8)

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V