Skip to main content

ConfigExt

Trait ConfigExt 

Source
pub trait ConfigExt {
    // Required methods
    fn all_directives(&self) -> AllDirectives<'_>;
    fn all_directives_with_context(&self) -> AllDirectivesWithContextIter<'_> ;
    fn is_included_from(&self, context: &str) -> bool;
    fn is_included_from_http(&self) -> bool;
    fn is_included_from_http_server(&self) -> bool;
    fn is_included_from_http_location(&self) -> bool;
    fn is_included_from_stream(&self) -> bool;
    fn immediate_parent_context(&self) -> Option<&str>;
}
Expand description

Extension trait for Config providing iteration and include-context helpers.

This trait is automatically available when using use nginx_lint_plugin::prelude::*.

§Traversal

Two traversal methods are provided:

§Include Context

When nginx-lint processes include directives, the included file’s Config receives an include_context field recording the parent block names. For example, a file included from http { server { include conf.d/*.conf; } } would have include_context = ["http", "server"].

The is_included_from_* methods check this context:

use nginx_lint_plugin::prelude::*;

let mut config = nginx_lint_plugin::parse_string("server { listen 80; }").unwrap();
assert!(!config.is_included_from_http());

// Simulate being included from http context
config.include_context = vec!["http".to_string()];
assert!(config.is_included_from_http());

Required Methods§

Source

fn all_directives(&self) -> AllDirectives<'_>

Iterate over all directives recursively.

Traverses the entire config tree depth-first, yielding each Directive.

Source

fn all_directives_with_context(&self) -> AllDirectivesWithContextIter<'_>

Iterate over all directives with parent context information.

Each item is a DirectiveWithContext that includes the parent block stack. This is the recommended traversal method for most plugins, as it allows checking whether a directive is inside a specific block (e.g., http, server).

Source

fn is_included_from(&self, context: &str) -> bool

Check if this config is included from within a specific context.

Source

fn is_included_from_http(&self) -> bool

Check if this config is included from within http context.

Source

fn is_included_from_http_server(&self) -> bool

Check if this config is included from within http > server context.

Source

fn is_included_from_http_location(&self) -> bool

Check if this config is included from within http > ... > location context.

Source

fn is_included_from_stream(&self) -> bool

Check if this config is included from within stream context.

Source

fn immediate_parent_context(&self) -> Option<&str>

Get the immediate parent context (last element in include_context).

Implementors§