#![cfg_attr(docs, feature(doc_cfg))]
#[cfg(feature = "parsing")]
#[cfg_attr(docs, doc(cfg(feature = "parsing")))]
mod codec;
mod display;
mod error;
mod interwiki_set;
#[cfg(feature = "parsing")]
#[cfg_attr(docs, doc(cfg(feature = "parsing")))]
mod ip;
#[cfg(feature = "parsing")]
#[cfg_attr(docs, doc(cfg(feature = "parsing")))]
mod ipv6;
mod namespace_map;
#[cfg(feature = "parsing")]
#[cfg_attr(docs, doc(cfg(feature = "parsing")))]
mod php;
mod site_info;
#[cfg(feature = "parsing")]
pub use codec::TitleCodec;
pub use error::Error;
pub use interwiki_set::InterwikiSet;
pub use namespace_map::NamespaceMap;
pub use site_info::{
Interwiki, NamespaceAlias, NamespaceInfo, Response as SiteInfoResponse,
SiteInfo,
};
pub type Result<T, E = Error> = std::result::Result<T, E>;
const NS_MAIN: i32 = 0;
const NS_FILE: i32 = 6;
const NS_CATEGORY: i32 = 14;
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub struct Title {
namespace: i32,
dbkey: String,
fragment: Option<String>,
interwiki: Option<String>,
local_interwiki: bool,
}
impl Title {
pub fn new_unchecked(namespace: i32, text: &str) -> Self {
Self {
namespace,
dbkey: text.replace(' ', "_"),
fragment: None,
interwiki: None,
local_interwiki: false,
}
}
pub fn with_fragment(mut self, fragment: &str) -> Self {
self.fragment = Some(fragment.to_string());
self
}
pub fn remove_fragment(mut self) -> Self {
self.fragment = None;
self
}
pub fn namespace(&self) -> i32 {
self.namespace
}
pub fn dbkey(&self) -> &str {
&self.dbkey
}
pub fn fragment(&self) -> Option<&str> {
self.fragment.as_deref()
}
pub fn interwiki(&self) -> Option<&str> {
self.interwiki.as_deref()
}
pub fn is_local_interwiki(&self) -> bool {
self.local_interwiki
}
pub fn is_local_page(&self) -> bool {
self.interwiki.is_none()
&& !self.dbkey.is_empty()
&& self.namespace >= 0
}
pub fn is_file(&self) -> bool {
self.namespace == NS_FILE
}
pub fn is_category(&self) -> bool {
self.namespace == NS_CATEGORY
}
}