Trait ModuleWrite

Source
pub trait ModuleWrite<H: TaskHandle>: ModuleRead<H> + ModuleWriteSealed<H>
where Self::Task: MutationAccess<ScriptNode, H, RandomState>,
{ // Provided methods fn edit( &mut self, span: impl ToSpan, text: impl AsRef<str>, ) -> ModuleResult<()> { ... } fn completions(&mut self, site: impl ToSite) -> ModuleResult<Completions> { ... } }
Expand description

A set of write functions and exclusive read functions for the ScriptModule content.

This trait is implemented by the ModuleWriteGuard object. The trait is sealed, meaning it cannot be implemented outside of this crate.

Provided Methods§

Source

fn edit(&mut self, span: impl ToSpan, text: impl AsRef<str>) -> ModuleResult<()>

Mutates the source code text of the script module.

The span argument specifies the source code range that you want to rewrite. It can be an absolute Unicode character range, such as 10..20, a line-column range like Position::new(10, 3)..Position::new(12, 4), or a ScriptOrigin instance.

The text argument specifies the string you want to insert in place of the spanned range. It can be an empty string if you want to erase a fragment of the source code.

The underlying algorithm incrementally patches the internal representation of the script module, localized to the spanned fragment. In most cases, this process is quite fast, even with large source code. Therefore, it is acceptable to call this function on each end-user keystroke.

The function returns a ModuleError::Cursor error if the provided span is not valid for this module.

Source

fn completions(&mut self, site: impl ToSite) -> ModuleResult<Completions>

Returns a Completions description object that describes potential completions for the script module’s source code at the specified site position.

The site argument specifies the location of the end-user cursor. It can be an absolute Unicode character offset, such as 10, or a line-column offset.

The function returns a ModuleError::Cursor error if the provided site is not valid for this module.

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§