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
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>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Eq for Title
impl StructuralEq for Title
impl StructuralPartialEq for Title
Auto Trait Implementations
impl RefUnwindSafe for Title
impl Send for Title
impl Sync for Title
impl Unpin for Title
impl UnwindSafe for Title
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more