pub struct Operation {
    pub content: String,
    pub start_position: Position,
    pub op_type: OperationType,
}
Expand description

An Operation describe a text edition at a specific start position.

An Operation can be of 2 types: either Insert or Delete, testifying of the fact that we either inserted or deleted the provided text content, starting at a given x/y position.

Fields

content: Stringstart_position: Positionop_type: OperationType

Implementations

Append the argument string to the Operation content

Return the position the cursor would be at the end of the Operation.

Examples:

  • an insert of “rust” starting at {0, 0} would return an end position of {3, 0}
  • an insert of “rust\nrocks” starting at {0, 0} would return an end position of {4, 1}
  • a deletion of “tsur” starting at {3, 0} would return an end position of {0, 0}
  • a deletion of “skcor\ntsur” starting at {1, 4} would return an end position of {0, 0}

Note: this one took a long time to get right but seems to work. Check unit tests in doubt!

Trait Implementations

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.