Skip to main content

Operation

Trait Operation 

Source
pub trait Operation {
    type Args: Clone;
    type Session: Default + 'static;

    // Required methods
    fn new_args<S: Scalar>(&self, before: &Part<S>) -> Self::Args;
    fn apply<S: Scalar>(
        &self,
        part: Part<S>,
        operation_id: &str,
        args: &Self::Args,
    ) -> GeopResult<Part<S>>;
    fn form<'a, S: Scalar>(
        &self,
        before: &'a Part<S>,
        args: &Self::Args,
        session: &Self::Session,
        selection: &[String],
    ) -> Form<'a, S, Self::Args, Self::Session>;

    // Provided methods
    fn set<S: Scalar>(
        &self,
        before: &Part<S>,
        args: &mut Self::Args,
        session: &mut Self::Session,
        selection: &mut Vec<String>,
        key: &str,
        value: Value,
    ) { ... }
    fn event<S: Scalar>(
        &self,
        before: &Part<S>,
        args: &mut Self::Args,
        session: &mut Self::Session,
        selection: &mut Vec<String>,
        event: &CanvasEvent<S>,
    ) { ... }
}
Expand description

One kind of operation on a Part.

Required Associated Types§

Source

type Args: Clone

Everything a step needs, as plain, serializable design data.

Source

type Session: Default + 'static

The temporary state of editing a step beyond its arguments — () for every operation whose form says all there is to it. Starts afresh whenever an editor opens a step.

Required Methods§

Source

fn new_args<S: Scalar>(&self, before: &Part<S>) -> Self::Args

The arguments of a new step inserted after before: sensible defaults, taking what before holds into account.

Source

fn apply<S: Scalar>( &self, part: Part<S>, operation_id: &str, args: &Self::Args, ) -> GeopResult<Part<S>>

Applies the operation as the program step operation_id, consuming part and returning the part it produces. Everything the operation creates is named after operation_id (see the crate docs), so the id has to be unique within a program.

On error no part is returned — a caller that still needs the original should clone it first.

Source

fn form<'a, S: Scalar>( &self, before: &'a Part<S>, args: &Self::Args, session: &Self::Session, selection: &[String], ) -> Form<'a, S, Self::Args, Self::Session>

What a step shows while it is edited against before: its fields — numbers, choices, entities to pick — each with what setting it does, and what it draws, with selection the keys of its visuals selected. Never fails: an editor needs the form most exactly when the arguments do not build, so whatever is wrong is said in it.

Its setters may capture before, never the arguments: they are handed the arguments to change (see Operation::set).

Provided Methods§

Source

fn set<S: Scalar>( &self, before: &Part<S>, args: &mut Self::Args, session: &mut Self::Session, selection: &mut Vec<String>, key: &str, value: Value, )

The field key of the form set to value: typed or chosen in the dialog, picked in the viewport, dragged as a handle — by the setter the form gave it (see Form).

Source

fn event<S: Scalar>( &self, before: &Part<S>, args: &mut Self::Args, session: &mut Self::Session, selection: &mut Vec<String>, event: &CanvasEvent<S>, )

A pointer or key event the editor passed on (see CanvasEvent). Only an operation that draws in a canvas of its own, like a sketch, needs these.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§