summaryrefslogtreecommitdiff
path: root/src/func
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-01-06 12:41:42 +0100
committerLaurenz <laurmaedje@gmail.com>2020-01-06 12:41:42 +0100
commit2ee5810fecb96a8d4e0d078faecc8c91096d6881 (patch)
tree702c746a3021f5034e1b31cd07e8fadba0e4dd7a /src/func
parentbd384a2a633e21cd7deff7ed2a29a9c03a63a20e (diff)
Asyncify font loading 🪐
Diffstat (limited to 'src/func')
-rw-r--r--src/func/macros.rs17
-rw-r--r--src/func/mod.rs5
2 files changed, 18 insertions, 4 deletions
diff --git a/src/func/macros.rs b/src/func/macros.rs
index 2da219bc..a89156b7 100644
--- a/src/func/macros.rs
+++ b/src/func/macros.rs
@@ -108,9 +108,20 @@ macro_rules! function {
// (2-arg) Parse a layout-definition with all arguments.
(@layout $type:ident | layout($this:ident, $ctx:pat) $code:block) => {
- impl $crate::func::LayoutFunc for $type {
- fn layout(&$this, $ctx: LayoutContext) -> LayoutResult<Commands> {
- Ok($code)
+ impl LayoutFunc for $type {
+ fn layout<'a, 'life0, 'life1, 'async_trait>(
+ &'a $this,
+ $ctx: LayoutContext<'life0, 'life1>
+ ) -> std::pin::Pin<Box<
+ dyn std::future::Future<Output = LayoutResult<Commands<'a>>> + 'async_trait
+ >>
+ where
+ 'a: 'async_trait,
+ 'life0: 'async_trait,
+ 'life1: 'async_trait,
+ Self: 'async_trait,
+ {
+ Box::pin(async move { Ok($code) })
}
}
};
diff --git a/src/func/mod.rs b/src/func/mod.rs
index 427e5b6f..a0875cf9 100644
--- a/src/func/mod.rs
+++ b/src/func/mod.rs
@@ -4,6 +4,7 @@ use std::any::Any;
use std::collections::HashMap;
use std::fmt::{self, Debug, Formatter};
+use async_trait::async_trait;
use self::prelude::*;
#[macro_use]
@@ -24,6 +25,7 @@ pub mod prelude {
pub use Command::*;
}
+
/// Types representing functions that are parsed from source code.
pub trait ParseFunc {
type Meta: Clone;
@@ -43,12 +45,13 @@ pub trait ParseFunc {
/// The trait `[LayoutFuncBounds]` is automatically implemented for types which
/// can be used as functions, that is, all types which fulfill the bounds `Debug
/// + PartialEq + 'static`.
+#[async_trait(?Send)]
pub trait LayoutFunc: LayoutFuncBounds {
/// Layout this function in a given context.
///
/// Returns a sequence of layouting commands which describe what the
/// function is doing.
- fn layout(&self, ctx: LayoutContext) -> LayoutResult<Commands>;
+ async fn layout<'a>(&'a self, ctx: LayoutContext<'_, '_>) -> LayoutResult<Commands<'a>>;
}
impl dyn LayoutFunc {