Repository: nushell/nushell
File: crates/nu-protocol/src/engine/engine_state.rs (Rust)

Code before:

    pub fn get_span_contents(&self, span: Span) -> &[u8] {
        for file in &self.files {
            if file.covered_span.contains_span(span) {
                return &file.content
                    [(span.start - file.covered_span.start)..(span.end - file.covered_span.start)];
            }
        }
        &[0u8; 0]
    }

    // If the span's content starts with the given prefix, return two subspans
    // corresponding to this prefix, and the rest of the content.
    pub fn span_match_prefix(&self, span: Span, prefix: &[u8]) -> Option<(Span, Span)> {
        let contents = self.get_span_contents(span);

        if contents.starts_with(prefix) {
            span.split_at(prefix.len())
        } else {
            None
        }
    }

    // If the span's content ends with the given postfix, return two subspans
    // corresponding to the rest of the content, and this postfix.
    pub fn span_match_postfix(&self, span: Span, prefix: &[u8]) -> Option<(Span, Span)> {
        let contents = self.get_span_contents(span);

        if contents.ends_with(prefix) {
            span.split_at(span.len() - prefix.len())
        } else {
            None
        }
    }

    /// Get the global config from the engine state.
    ///
    /// Use [`Stack::get_config()`] instead whenever the `Stack` is available, as it takes into
    /// account local changes to `$env.config`.
    pub fn get_config(&self) -> &Arc<Config> {
        &self.config
    }

    pub fn set_config(&mut self, conf: impl Into<Arc<Config>>) {
        let conf = conf.into();

        #[cfg(feature = "plugin")]
        if conf.plugin_gc != self.config.plugin_gc {
            // Make plugin GC config changes take effect immediately.
            self.update_plugin_gc_configs(&conf.plugin_gc);
        }

Review comment (suggestion):
```suggestion
    /// If the span's content ends with the given postfix, return two subspans
    /// corresponding to the rest of the content, and this postfix.
    pub fn span_match_postfix(&self, span: Span, prefix: &[u8]) -> Option<(Span, Span)> {
```

Code after:

    pub fn get_span_contents(&self, span: Span) -> &[u8] {
        for file in &self.files {
            if file.covered_span.contains_span(span) {
                return &file.content
                    [(span.start - file.covered_span.start)..(span.end - file.covered_span.start)];
            }
        }
        &[0u8; 0]
    }

    /// If the span's content starts with the given prefix, return two subspans
    /// corresponding to this prefix, and the rest of the content.
    pub fn span_match_prefix(&self, span: Span, prefix: &[u8]) -> Option<(Span, Span)> {
        let contents = self.get_span_contents(span);

        if contents.starts_with(prefix) {
            span.split_at(prefix.len())
        } else {
            None
        }
    }

    /// If the span's content ends with the given postfix, return two subspans
    /// corresponding to the rest of the content, and this postfix.
    pub fn span_match_postfix(&self, span: Span, prefix: &[u8]) -> Option<(Span, Span)> {
        let contents = self.get_span_contents(span);

        if contents.ends_with(prefix) {
            span.split_at(span.len() - prefix.len())
        } else {
            None
        }
    }

    /// Get the global config from the engine state.
    ///
    /// Use [`Stack::get_config()`] instead whenever the `Stack` is available, as it takes into
    /// account local changes to `$env.config`.
    pub fn get_config(&self) -> &Arc<Config> {
        &self.config
    }

    pub fn set_config(&mut self, conf: impl Into<Arc<Config>>) {
        let conf = conf.into();

        #[cfg(feature = "plugin")]
        if conf.plugin_gc != self.config.plugin_gc {
            // Make plugin GC config changes take effect immediately.
            self.update_plugin_gc_configs(&conf.plugin_gc);
        }