use std::fmt::{self, Debug, Formatter};
use std::num::NonZeroUsize;
use ecow::EcoString;
use crate::engine::Engine;
use crate::foundations::{func, scope, ty, Repr};
use crate::layout::Position;
use crate::model::Numbering;
#[ty(scope)]
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
pub struct Location(u128);
impl Location {
pub fn new(hash: u128) -> Self {
Self(hash)
}
pub fn hash(self) -> u128 {
self.0
}
pub fn variant(self, n: usize) -> Self {
Self(crate::utils::hash128(&(self.0, n)))
}
}
#[scope]
impl Location {
#[func]
pub fn page(self, engine: &mut Engine) -> NonZeroUsize {
engine.introspector.page(self)
}
#[func]
pub fn position(self, engine: &mut Engine) -> Position {
engine.introspector.position(self)
}
#[func]
pub fn page_numbering(self, engine: &mut Engine) -> Option<Numbering> {
engine.introspector.page_numbering(self).cloned()
}
}
impl Debug for Location {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "Location({})", self.0)
}
}
impl Repr for Location {
fn repr(&self) -> EcoString {
"..".into()
}
}
pub trait Locatable {}
pub trait Unqueriable {}