tinymist_world

Trait WorldComputable

Source
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§

Source

type Output: Send + Sync + 'static

Required Methods§

Source

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.

Implementors§

Source§

impl<F: CompilerFeat> WorldComputable<F> for DiagnosticsTask

Source§

impl<F: CompilerFeat, D> WorldComputable<F> for CompilationTask<D>
where D: Document + Send + Sync + 'static,

Source§

type Output = Option<Warned<Result<Arc<D>, EcoVec<SourceDiagnostic>>>>

Source§

impl<F: CompilerFeat, D> WorldComputable<F> for OptionDocumentTask<D>
where D: Document + Send + Sync + 'static,

Source§

impl<F: CompilerFeat, T: Send + Sync + 'static> WorldComputable<F> for ConfigTask<T>