serenity_rich_interaction/menu/
page.rs1use crate::error::Result;
2use serenity::builder::CreateMessage;
3use std::future::Future;
4use std::pin::Pin;
5use std::sync::Arc;
6
7pub type MessageBuildOutput<'b> =
8 Pin<Box<dyn Future<Output = Result<CreateMessage<'b>>> + Send + 'b>>;
9pub type MessageBuilderFn<'b> = Arc<dyn Fn() -> MessageBuildOutput<'b> + Send + Sync>;
10
11#[derive(Clone)]
12pub enum Page<'b> {
15 Builder(MessageBuilderFn<'b>),
16 Static(CreateMessage<'b>),
17}
18
19impl<'b> Page<'b> {
20 pub fn new_builder<F: 'static>(builder_fn: F) -> Self
23 where
24 F: Fn() -> MessageBuildOutput<'b> + Send + Sync,
25 {
26 Self::Builder(Arc::new(builder_fn))
27 }
28
29 pub fn new_static(page: CreateMessage<'b>) -> Self {
31 Self::Static(page)
32 }
33
34 pub async fn get(&self) -> Result<CreateMessage<'b>> {
36 match self {
37 Page::Builder(b) => b().await,
38 Page::Static(inner) => Ok(inner.clone()),
39 }
40 }
41}