Skip to content

Instantly share code, notes, and snippets.

@jaytaph
Created May 5, 2026 16:10
Show Gist options
  • Select an option

  • Save jaytaph/14c035168d6463298dd7e1ed9585ec96 to your computer and use it in GitHub Desktop.

Select an option

Save jaytaph/14c035168d6463298dd7e1ed9585ec96 to your computer and use it in GitHub Desktop.
//! Type aliases for deeply nested associated types.
//!
//! The engine is parameterised over a single `C: ModuleConfiguration` type that carries all
//! concrete implementations (CSS engine, document, layouter, render backend, …) as associated
//! types. Because those implementations are themselves traits with their own associated types,
//! reaching a leaf type at a call site requires chains like:
//!
//! ```text
//! <<C as HasLayouter>::LayoutTree as LayoutTree<C>>::NodeId
//! ```
//!
//! These aliases give every leaf type a short, unambiguous name so that function signatures,
//! struct fields, and `where` clauses stay readable while the engine is still evolving.
//!
//! # Usage
//!
//! Import whichever aliases you need; a glob import is fine inside a single module:
//!
//! ```rust,ignore
//! use gosub_interface::config::types::{LayoutNodeId, CssStylesheet};
//! ```
//!
//! # Why aliases instead of extra associated types on the `Has*` traits?
//!
//! Adding shortcut associated types directly to `Has*` traits is cleaner at call sites
//! (`C::CssStylesheet`) but requires every concrete `Config` implementation to spell out the
//! redundant mapping, and the boilerplate grows with every new trait. Stable Rust has no
//! associated-type defaults, so aliases in this module are the zero-boilerplate alternative:
//! adding a new shortcut is one line here and zero lines everywhere else.
use crate::config::{HasCssSystem, HasFontManager, HasLayouter, HasRenderBackend, HasRenderTree};
use crate::css3::CssSystem;
use crate::font::FontManager;
use crate::layout::{LayoutTree, Layouter};
use crate::render_backend::RenderBackend;
use crate::render_tree::RenderTree;
// CSS
pub type CssStylesheet<C> = <<C as HasCssSystem>::CssSystem as CssSystem>::Stylesheet;
pub type CssPropertyMap<C> = <<C as HasCssSystem>::CssSystem as CssSystem>::PropertyMap;
pub type CssProperty<C> = <<C as HasCssSystem>::CssSystem as CssSystem>::Property;
pub type CssValue<C> = <<C as HasCssSystem>::CssSystem as CssSystem>::Value;
// Layout
pub type LayoutNodeId<C> = <<C as HasLayouter>::LayoutTree as LayoutTree<C>>::NodeId;
pub type LayoutNode<C> = <<C as HasLayouter>::LayoutTree as LayoutTree<C>>::Node;
pub type NodeLayout<C> = <<C as HasLayouter>::Layouter as Layouter<C>>::Layout;
pub type LayoutCache<C> = <<C as HasLayouter>::Layouter as Layouter<C>>::Cache;
pub type TextLayout<C> = <<C as HasLayouter>::Layouter as Layouter<C>>::TextLayout;
// Render backend
pub type RenderScene<C> = <<C as HasRenderBackend>::RenderBackend as RenderBackend>::Scene;
pub type RenderColor<C> = <<C as HasRenderBackend>::RenderBackend as RenderBackend>::Color;
pub type RenderBrush<C> = <<C as HasRenderBackend>::RenderBackend as RenderBackend>::Brush;
pub type RenderBorder<C> = <<C as HasRenderBackend>::RenderBackend as RenderBackend>::Border;
pub type RenderImage<C> = <<C as HasRenderBackend>::RenderBackend as RenderBackend>::Image;
pub type SvgRenderer<C> = <<C as HasRenderBackend>::RenderBackend as RenderBackend>::SVGRenderer;
pub type BackendFontManager<C> = <<C as HasRenderBackend>::RenderBackend as RenderBackend>::FontManager;
// Font
pub type FontInfo<C> = <<C as HasFontManager>::FontManager as FontManager>::FontInfo;
// Render tree
pub type RenderNodeId<C> = <<C as HasRenderTree>::RenderTree as RenderTree<C>>::NodeId;
pub type RenderNode<C> = <<C as HasRenderTree>::RenderTree as RenderTree<C>>::Node;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment