crux_core/capabilities/
render.rs1use std::future::Future;
4
5use facet::Facet;
6use serde::{Deserialize, Serialize};
7
8#[expect(deprecated)]
9use crate::{Capability, capability::CapabilityContext};
10use crate::{Command, Request, capability::Operation, command::NotificationBuilder};
11
12#[deprecated(
20 since = "0.16.0",
21 note = "The Render capability has been deprecated. Use render::render() with the Command API instead."
22)]
23pub struct Render<Ev> {
24 #[expect(deprecated)]
25 context: CapabilityContext<RenderOperation, Ev>,
26}
27
28#[expect(deprecated)]
29impl<Ev> Clone for Render<Ev> {
30 fn clone(&self) -> Self {
31 Self {
32 context: self.context.clone(),
33 }
34 }
35}
36
37#[derive(Facet, Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
39pub struct RenderOperation;
40
41impl Operation for RenderOperation {
42 type Output = ();
43}
44
45#[expect(deprecated)]
47impl<Ev> Render<Ev>
48where
49 Ev: 'static,
50{
51 #[must_use]
52 pub fn new(context: CapabilityContext<RenderOperation, Ev>) -> Self {
53 Self { context }
54 }
55
56 pub fn render(&self) {
59 let ctx = self.context.clone();
60 self.context.spawn(async move {
61 ctx.notify_shell(RenderOperation).await;
62 });
63 }
64}
65
66#[expect(deprecated)]
67impl<Ev> Capability<Ev> for Render<Ev> {
68 type Operation = RenderOperation;
69 type MappedSelf<MappedEv> = Render<MappedEv>;
70
71 fn map_event<F, NewEv>(&self, f: F) -> Self::MappedSelf<NewEv>
72 where
73 F: Fn(NewEv) -> Ev + Send + Sync + 'static,
74 Ev: 'static,
75 NewEv: 'static,
76 {
77 Render::new(self.context.map_event(f))
78 }
79}
80
81#[must_use]
103pub fn render_builder<Effect, Event>()
104-> NotificationBuilder<Effect, Event, impl Future<Output = ()>>
105where
106 Effect: From<Request<RenderOperation>> + Send + 'static,
107 Event: Send + 'static,
108{
109 Command::notify_shell(RenderOperation)
110}
111
112pub fn render<Effect, Event>() -> Command<Effect, Event>
115where
116 Effect: From<Request<RenderOperation>> + Send + 'static,
117 Event: Send + 'static,
118{
119 render_builder().into()
120}