From 42a1807c2b25c8c103d33f680e579362ce8e9dc7 Mon Sep 17 00:00:00 2001 From: i do not exist Date: Fri, 24 Apr 2026 01:44:03 +0300 Subject: [PATCH] fix some more doctest errors --- src/draw.rs | 36 ++++++++++++++++++++++++++---------- src/eval.rs | 4 ++-- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/draw.rs b/src/draw.rs index 98ad3ef..67ee223 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -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> $draw +} }); /// Drawable that supports dynamic dispatch. /// @@ -13,12 +29,14 @@ use crate::{*, space::*}; /// a [Draw]able. /// /// ``` -/// use tengri::{*, draw::*, space::*}; +/// use tengri::{*, draw::*}; /// struct TestScreen(bool); /// impl Screen for TestScreen { type Unit = u16; } +/// impl X for TestScreen { fn x (&self) -> u16 { 0 } } +/// impl Y for TestScreen { fn y (&self) -> u16 { 0 } } /// struct TestWidget(bool); /// impl Draw for TestWidget { -/// fn draw (&self, screen: &mut TestScreen) -> Usually> { +/// fn draw (self, screen: &mut TestScreen) -> Usually> { /// screen.0 |= self.0; /// } /// } @@ -90,11 +108,11 @@ pub const fn either (condition: bool, a: impl Draw, b: impl Draw< /// Output target. /// /// ``` -/// use tengri::draw::*; +/// use tengri::{*, draw::*}; /// /// struct TestOut>(T); /// -/// impl> Screen for TestOut { +/// impl> Screen for TestOut { /// type Unit = u16; /// fn place_at + ?Sized> (&mut self, area: T, _: D) { /// println!("placed: {area:?}"); @@ -102,11 +120,9 @@ pub const fn either (condition: bool, a: impl Draw, b: impl Draw< /// } /// } /// -/// impl Draw for String { -/// fn draw (&self, to: &mut TestOut) -> Usually> { -/// to.area_mut().set_w(self.len() as u16); -/// } -/// } +/// impl_draw!(|self: String, to: TestOut|{ +/// to.area_mut().set_w(self.len() as u16); +/// }); /// ``` pub trait Screen: Space + Send + Sync + Sized { type Unit: Coord; diff --git a/src/eval.rs b/src/eval.rs index 9e48051..c87eb56 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -59,7 +59,7 @@ macro_rules! eval_enum (( /// Interpret layout operation. /// /// ``` -/// # use tengri::{*, space::*}; +/// # use tengri::{lang::*, draw::*, eval::*}; /// struct Target { xywh: XYWH /*platform-specific*/} /// impl tengri::Out for Target { /// type Unit = u16; @@ -162,7 +162,7 @@ pub fn eval_view <'a, O: Screen + 'a, S> ( /// 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; /// impl<'b> Namespace<'b, bool> for State {}