pub trait WorldComputable<F: CompilerFeat>:
Any
+ Send
+ Sync
+ Sized {
type Output: Send + Sync + 'static;
// Required method
fn compute(graph: &Arc<WorldComputeGraph<F>>) -> Result<Self::Output>;
}
Expand description
A world computable trait.
Required Associated Types§
Required Methods§
Sourcefn compute(graph: &Arc<WorldComputeGraph<F>>) -> Result<Self::Output>
fn compute(graph: &Arc<WorldComputeGraph<F>>) -> Result<Self::Output>
The computation implementation.
§Example
The example shows that a computation can depend on specific world implementation. It computes the system font that only works on the system world.
use std::sync::Arc;
use tinymist_std::error::prelude::*;
use tinymist_world::{WorldComputeGraph, WorldComputable};
use tinymist_world::font::FontResolverImpl;
use tinymist_world::system::SystemCompilerFeat;
pub struct SystemFontsOnce {
fonts: Arc<FontResolverImpl>,
}
impl WorldComputable<SystemCompilerFeat> for SystemFontsOnce {
type Output = Self;
fn compute(graph: &Arc<WorldComputeGraph<SystemCompilerFeat>>) -> Result<Self> {
Ok(Self {
fonts: graph.snap.world.font_resolver.clone(),
})
}
}
/// Computes the system fonts.
fn compute_system_fonts(graph: &Arc<WorldComputeGraph<SystemCompilerFeat>>) {
let _fonts = graph.compute::<SystemFontsOnce>().expect("font").fonts.clone();
}
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.