Skip to main content

mirage_engine/
holds.rs

1//! What proves that a game's set holds a type, what proves that its input
2//! set seats an action, and the marker every set trait is sealed by.
3
4/// Proves that a set holds `T`, and turns a `T` into it.
5///
6/// Written by [`meshes!`](crate::meshes),
7/// [`surface_styles!`](crate::surface_styles) and
8/// [`post_effects!`](crate::post_effects) for every type they name. Every
9/// call that takes a value of a game's own set is bound by it:
10/// [`draw`](crate::FrameContext::draw), both `prepare` calls,
11/// [`Instance::surface_style`](crate::mesh::Instance::surface_style),
12/// [`set_surface_style`](crate::FrameContext::set_surface_style) and
13/// [`set_post_effect`](crate::FrameContext::set_post_effect). A game spells
14/// one bound per type, in its own code that draws, or sets a style or
15/// effect, for any [`Game`](crate::Game).
16///
17/// ```
18/// use mirage_engine::prelude::*;
19///
20/// fn draw_cube<G: Game>(ctx: &mut FrameContext<'_, G>, at: Vec3)
21/// where
22///     G::Meshes: Holds<Cube>,
23/// {
24///     ctx.draw(Cube.at(at));
25/// }
26/// ```
27pub trait Holds<T>: From<T> {}
28
29/// Proves that one of an [`InputActions`](crate::InputActions) set's three
30/// kinds seats `A`.
31///
32/// Written by the engine for every input set, so a game writes it for none
33/// of its own. The input queries,
34/// [`rebind`](crate::FrameContext::rebind) and
35/// [`bindings`](crate::FrameContext::bindings) are bound by it. `B` is the
36/// kind's binding type; it keeps the three kinds apart, since nothing
37/// proves a set's three kinds are three different types.
38pub trait Seats<A, B> {}
39
40/// [`Meshes`](crate::Meshes), [`ShaderValues`](crate::ShaderValues),
41/// [`SurfaceStyles`](crate::SurfaceStyles) and
42/// [`PostEffects`](crate::PostEffects) are sealed by this, which the set
43/// macros write for every set they write and
44/// [`ShaderValues`](macro@crate::ShaderValues) for every value struct, so
45/// nothing outside the engine implements a set trait.
46#[doc(hidden)]
47pub trait Sealed {}