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:
all_directives()- Simple recursive iteration over all directivesall_directives_with_context()- Iteration with parent block context (e.g., know if a directive is insidehttp,server,location)
§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§
Sourcefn all_directives(&self) -> AllDirectives<'_>
fn all_directives(&self) -> AllDirectives<'_>
Iterate over all directives recursively.
Traverses the entire config tree depth-first, yielding each Directive.
Sourcefn all_directives_with_context(&self) -> AllDirectivesWithContextIter<'_> ⓘ
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).
Sourcefn is_included_from(&self, context: &str) -> bool
fn is_included_from(&self, context: &str) -> bool
Check if this config is included from within a specific context.
Sourcefn is_included_from_http(&self) -> bool
fn is_included_from_http(&self) -> bool
Check if this config is included from within http context.
Sourcefn is_included_from_http_server(&self) -> bool
fn is_included_from_http_server(&self) -> bool
Check if this config is included from within http > server context.
Sourcefn is_included_from_http_location(&self) -> bool
fn is_included_from_http_location(&self) -> bool
Check if this config is included from within http > ... > location context.
Sourcefn is_included_from_stream(&self) -> bool
fn is_included_from_stream(&self) -> bool
Check if this config is included from within stream context.
Sourcefn immediate_parent_context(&self) -> Option<&str>
fn immediate_parent_context(&self) -> Option<&str>
Get the immediate parent context (last element in include_context).