pub trait SemanticTransform: Send + Sync {
// Required methods
fn identity(&self) -> TransformIdentity;
fn apply(
&self,
context: &mut SemanticTransformContext<'_>,
input: &FrozenProgram,
) -> Result<Box<[ProgramValue]>, SemanticTransformError>;
}Expand description
Object-safe transformation over immutable semantic programs and bindings.
§Examples
use tenferro_runtime::program::{
FrozenProgram, ProgramValue, SemanticTransform, SemanticTransformContext,
SemanticTransformError, TransformIdentity,
};
struct Identity;
impl SemanticTransform for Identity {
fn identity(&self) -> TransformIdentity {
TransformIdentity::from_bytes([7; 16])
}
fn apply(
&self,
context: &mut SemanticTransformContext<'_>,
input: &FrozenProgram,
) -> Result<Box<[ProgramValue]>, SemanticTransformError> {
Ok(context
.import_program(input, input.program.outputs())?
.roots()
.into())
}
}
fn accepts_object_safe(_: &dyn SemanticTransform) {}
accepts_object_safe(&Identity);Required Methods§
Sourcefn identity(&self) -> TransformIdentity
fn identity(&self) -> TransformIdentity
Return caller-stable identity including transform configuration.
Sourcefn apply(
&self,
context: &mut SemanticTransformContext<'_>,
input: &FrozenProgram,
) -> Result<Box<[ProgramValue]>, SemanticTransformError>
fn apply( &self, context: &mut SemanticTransformContext<'_>, input: &FrozenProgram, ) -> Result<Box<[ProgramValue]>, SemanticTransformError>
Import/build into the supplied fresh destination and return local roots.
§Errors
Implementations return SemanticTransformError::Build for validated
builder/import failures or SemanticTransformError::Rejected when
their semantic policy does not support the input. The compiler driver
additionally reports SemanticTransformError::ForeignReturnedValue,
SemanticTransformError::DroppedBindings, or
SemanticTransformError::Finish after this callback returns.