pub struct Title { /* private fields */ }
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 sitenamespace
: Numerical ID corresponding to a MediaWiki namespacedbkey
: Page name, with underscores instead of spacesfragment
: Optional anchor for a specific section
// ns1 is Talk, so this is [[Talk:Main Page]]
let title = unsafe { Title::new_unchecked(1, "Main_Page".into()) };
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".into());
assert_eq!(title.fragment(), Some("Section 1"));
Implementations
sourceimpl Title
impl Title
sourcepub unsafe fn new_unchecked(namespace: i32, dbkey: String) -> Self
pub unsafe fn new_unchecked(namespace: i32, dbkey: String) -> Self
Create a new Title
from a namespace ID
and database key (title without the namespace prefix),
with no validation on the namespace or text parts.
Good if you’re getting the title from a trusted place like the API.
The dbkey
should have underscores
and be normalized and sanitized
as if it has been processed by TitleCodec::new_title
.
The namespace must exist in the TitleCodec
or NamespaceMap
that will format this title.
Safety
If the namespace doesn’t exist in the TitleCodec
or NamespaceMap
,
some methods, like TitleCodec::to_pretty
, will panic.
If the dbkey
hasn’t been normalized and sanitized,
the ordering implementations ( Eq
, PartialEq
, Ord
, PartialOrd
)
for the Title
aren’t guaranteed to give the correct results.
sourcepub fn with_fragment(self, fragment: String) -> Self
pub fn with_fragment(self, fragment: String) -> Self
Set a fragment.
sourcepub fn remove_fragment(self) -> Self
pub fn remove_fragment(self) -> Self
Remove the fragment.
sourcepub fn is_local_interwiki(&self) -> bool
pub fn is_local_interwiki(&self) -> bool
Whether this title was created via a local interwiki link.
sourcepub fn is_local_page(&self) -> bool
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.
sourcepub fn is_category(&self) -> bool
pub fn is_category(&self) -> bool
Whether this title refers to a category.
Trait Implementations
sourceimpl Ord for Title
impl Ord for Title
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
sourceimpl PartialOrd<Title> for Title
impl PartialOrd<Title> for Title
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more