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§
§impl Title
impl Title
pub unsafe fn new_unchecked(namespace: i32, dbkey: String) -> Title
pub unsafe fn new_unchecked(namespace: i32, dbkey: String) -> Title
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.
pub fn with_fragment(self, fragment: String) -> Title
pub fn with_fragment(self, fragment: String) -> Title
Set a fragment.
pub fn remove_fragment(self) -> Title
pub fn remove_fragment(self) -> Title
Remove the fragment.
pub fn is_local_interwiki(&self) -> bool
pub fn is_local_interwiki(&self) -> bool
Whether this title was created via a local interwiki link.
pub 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.
pub fn is_category(&self) -> bool
pub fn is_category(&self) -> bool
Whether this title refers to a category.
Trait Implementations§
§impl Ord for Title
impl Ord for Title
§impl PartialOrd for Title
impl PartialOrd for Title
impl Eq for Title
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.