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§
source§impl 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§
source§impl Ord for Title
impl Ord for Title
source§impl PartialEq for Title
impl PartialEq for Title
source§impl PartialOrd for Title
impl PartialOrd for Title
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read more