fix some more doctest errors

This commit is contained in:
i do not exist 2026-04-24 01:44:03 +03:00
parent e074712459
commit 42a1807c2b
2 changed files with 28 additions and 12 deletions

View file

@ -1,4 +1,20 @@
use crate::{*, space::*}; use crate::*;
pub use crate::space::*;
/// Implement the [Draw] trait for a particular drawable and [Screen].
///
/// ```
/// use tengri::{*, draw::*, term::*};
/// struct MyDrawable;
/// impl_draw!(|self: MyDrawable, to: Tui|{
/// todo!()
/// });
/// ```
#[macro_export] macro_rules! impl_draw ((|
$self:ident:$Self:ty, $to:ident:$To:ty
|$draw:block)=>{ impl Draw<$To> for $Self {
fn draw ($self, $to: &mut $To) -> Usually<XYWH<u16>> $draw
} });
/// Drawable that supports dynamic dispatch. /// Drawable that supports dynamic dispatch.
/// ///
@ -13,12 +29,14 @@ use crate::{*, space::*};
/// a [Draw]able. /// a [Draw]able.
/// ///
/// ``` /// ```
/// use tengri::{*, draw::*, space::*}; /// use tengri::{*, draw::*};
/// struct TestScreen(bool); /// struct TestScreen(bool);
/// impl Screen for TestScreen { type Unit = u16; } /// impl Screen for TestScreen { type Unit = u16; }
/// impl X<u16> for TestScreen { fn x (&self) -> u16 { 0 } }
/// impl Y<u16> for TestScreen { fn y (&self) -> u16 { 0 } }
/// struct TestWidget(bool); /// struct TestWidget(bool);
/// impl Draw<TestScreen> for TestWidget { /// impl Draw<TestScreen> for TestWidget {
/// fn draw (&self, screen: &mut TestScreen) -> Usually<XYWH<u16>> { /// fn draw (self, screen: &mut TestScreen) -> Usually<XYWH<u16>> {
/// screen.0 |= self.0; /// screen.0 |= self.0;
/// } /// }
/// } /// }
@ -90,11 +108,11 @@ pub const fn either <T: Screen> (condition: bool, a: impl Draw<T>, b: impl Draw<
/// Output target. /// Output target.
/// ///
/// ``` /// ```
/// use tengri::draw::*; /// use tengri::{*, draw::*};
/// ///
/// struct TestOut<T: Screen<Unit = u16>>(T); /// struct TestOut<T: Screen<Unit = u16>>(T);
/// ///
/// impl<T: Screen<Unit = u16>> Screen<T> for TestOut { /// impl<T: Screen<Unit = u16>> Screen for TestOut {
/// type Unit = u16; /// type Unit = u16;
/// fn place_at <D: Draw<Self> + ?Sized> (&mut self, area: T, _: D) { /// fn place_at <D: Draw<Self> + ?Sized> (&mut self, area: T, _: D) {
/// println!("placed: {area:?}"); /// println!("placed: {area:?}");
@ -102,11 +120,9 @@ pub const fn either <T: Screen> (condition: bool, a: impl Draw<T>, b: impl Draw<
/// } /// }
/// } /// }
/// ///
/// impl Draw<Screen> for String { /// impl_draw!(|self: String, to: TestOut<u16>|{
/// fn draw (&self, to: &mut TestOut) -> Usually<XYWH<u16>> {
/// to.area_mut().set_w(self.len() as u16); /// to.area_mut().set_w(self.len() as u16);
/// } /// });
/// }
/// ``` /// ```
pub trait Screen: Space<Self::Unit> + Send + Sync + Sized { pub trait Screen: Space<Self::Unit> + Send + Sync + Sized {
type Unit: Coord; type Unit: Coord;

View file

@ -59,7 +59,7 @@ macro_rules! eval_enum ((
/// Interpret layout operation. /// Interpret layout operation.
/// ///
/// ``` /// ```
/// # use tengri::{*, space::*}; /// # use tengri::{lang::*, draw::*, eval::*};
/// struct Target { xywh: XYWH<u16> /*platform-specific*/} /// struct Target { xywh: XYWH<u16> /*platform-specific*/}
/// impl tengri::Out for Target { /// impl tengri::Out for Target {
/// type Unit = u16; /// type Unit = u16;
@ -162,7 +162,7 @@ pub fn eval_view <'a, O: Screen + 'a, S> (
/// Interpret TUI-specific layout operation. /// Interpret TUI-specific layout operation.
/// ///
/// ``` /// ```
/// use tengri::{lang::{Namespace, Interpret}, term::Tui, ratatui::prelude::Color}; /// use tengri::{lang::*, term::*, eval::*, ratatui::prelude::Color};
/// ///
/// struct State; /// struct State;
/// impl<'b> Namespace<'b, bool> for State {} /// impl<'b> Namespace<'b, bool> for State {}