mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 11:46:42 +01:00
This commit is contained in:
parent
a9619ab9ce
commit
8bfd1a23a1
2 changed files with 14 additions and 5 deletions
|
|
@ -14,3 +14,8 @@ pub type Perhaps<T> = Result<Option<T>, Box<dyn Error>>;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait Has<T>: Send + Sync {
|
||||||
|
fn get (&self) -> &T;
|
||||||
|
fn get_mut (&mut self) -> &mut T;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,17 @@ use std::sync::{Arc, atomic::{AtomicUsize, Ordering::Relaxed}};
|
||||||
|
|
||||||
pub trait HasSize<E: Output> {
|
pub trait HasSize<E: Output> {
|
||||||
fn size (&self) -> &Measure<E>;
|
fn size (&self) -> &Measure<E>;
|
||||||
|
fn width (&self) -> usize {
|
||||||
|
self.size().w()
|
||||||
|
}
|
||||||
|
fn height (&self) -> usize {
|
||||||
|
self.size().w()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export] macro_rules! has_size {
|
impl<E: Output, T: Has<Measure<E>>> HasSize<E> for T {
|
||||||
(<$E:ty>|$self:ident:$Struct:ident$(<$($L:lifetime),*$($T:ident$(:$U:path)?),*>)?|$cb:expr) => {
|
fn size (&self) -> &Measure<E> {
|
||||||
impl $(<$($L),*$($T $(: $U)?),*>)? HasSize<$E> for $Struct $(<$($L),*$($T),*>)? {
|
self.get()
|
||||||
fn size (&$self) -> &Measure<$E> { $cb }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue