From 9f3e21628231f3fa91ab8ff45872a76e7e11fcc4 Mon Sep 17 00:00:00 2001 From: tslil Date: Tue, 21 Oct 2025 20:36:01 +0100 Subject: Having a time with passing functions around, really feels like i'm fighting the language --- rprt-engine/src/selection_function.rs | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 rprt-engine/src/selection_function.rs (limited to 'rprt-engine/src/selection_function.rs') diff --git a/rprt-engine/src/selection_function.rs b/rprt-engine/src/selection_function.rs new file mode 100644 index 0000000..6f05650 --- /dev/null +++ b/rprt-engine/src/selection_function.rs @@ -0,0 +1,43 @@ +use crate::buffer::BufferID; +use crate::selection::{Interval, Selection, VectoriseError}; +use crate::state::EditorState; +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum SFError {} + +struct SFComponents { + niladic: Box Result>, + monadic_rank0: Box Result>, + monadic_rank1: Box Result>, + dyadic: Option Result>>, +} + +pub struct SelectionFunction { + niladic: Box Result>, + monadic: Box Result>, + dyadic: Option Result>>, +} + +impl From for SelectionFunction> { + fn from(sfc: SFComponents) -> Self { + let dyadic: Option _>> = + if let Some(func) = sfc.dyadic { + Some(Box::new( + move |editor_state: &EditorState, left: &Selection, right: &Selection| { + (func)(editor_state, left, right).map_err(VectoriseError::ProcessingError) + }, + )) + } else { + None + }; + + Self { + niladic: Box::new(move |editor_state: &EditorState| { + (sfc.niladic)(editor_state).map_err(VectoriseError::ProcessingError) + }), + monadic: Box::new(Selection::vectorise(sfc.monadic_rank0, sfc.monadic_rank1)), + dyadic: dyadic, + } + } +} -- cgit v1.2.3