pub struct Config {
pub directives: Vec<Directive>,
}Expand description
Root configuration node
Represents a complete NGINX configuration file or a logical section.
Fields§
§directives: Vec<Directive>Top-level directives
Implementations§
Source§impl Config
impl Config
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new empty configuration
§Examples
use nginx_discovery::ast::Config;
let config = Config::new();
assert!(config.directives.is_empty());Sourcepub fn with_directives(directives: Vec<Directive>) -> Self
pub fn with_directives(directives: Vec<Directive>) -> Self
Create a configuration with directives
§Examples
use nginx_discovery::ast::{Config, Directive};
let directives = vec![
Directive::simple("user", vec!["nginx".to_string()]),
];
let config = Config::with_directives(directives);
assert_eq!(config.directives.len(), 1);Sourcepub fn add_directive(&mut self, directive: Directive)
pub fn add_directive(&mut self, directive: Directive)
Add a directive to the configuration
Sourcepub fn find_directives(&self, name: &str) -> Vec<&Directive>
pub fn find_directives(&self, name: &str) -> Vec<&Directive>
Find all directives with a given name (non-recursive)
§Examples
use nginx_discovery::ast::{Config, Directive};
let config = Config::with_directives(vec![
Directive::simple("user", vec!["nginx".to_string()]),
Directive::simple("worker_processes", vec!["auto".to_string()]),
]);
let users = config.find_directives("user");
assert_eq!(users.len(), 1);Sourcepub fn find_directives_mut(&mut self, name: &str) -> Vec<&mut Directive>
pub fn find_directives_mut(&mut self, name: &str) -> Vec<&mut Directive>
Find all directives with a given name (mutable, non-recursive)
Sourcepub fn find_directives_recursive(&self, name: &str) -> Vec<&Directive>
pub fn find_directives_recursive(&self, name: &str) -> Vec<&Directive>
Recursively find all directives with a given name
This searches through the entire configuration tree, including directives nested in blocks.
§Examples
use nginx_discovery::ast::{Config, Directive};
let server = Directive::block(
"server",
vec![],
vec![
Directive::simple("access_log", vec!["/var/log/nginx/access.log".to_string()]),
],
);
let config = Config::with_directives(vec![
Directive::simple("access_log", vec!["/var/log/nginx/main.log".to_string()]),
server,
]);
let logs = config.find_directives_recursive("access_log");
assert_eq!(logs.len(), 2); // Found bothSourcepub fn count_directives(&self) -> usize
pub fn count_directives(&self) -> usize
Count total number of directives (including nested)
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Config
impl<'de> Deserialize<'de> for Config
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Config
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more