pub struct Directive {
pub span: Span,
pub leading_comments: Vec<String>,
pub trailing_comment: Option<String>,
pub kind: DirectiveKind,
}Expand description
A single chrony directive with its source location and comments.
Each directive carries its original source location (Span), any leading comments
(comment lines immediately preceding the directive), an optional trailing comment
(inline comment after the directive), and the parsed directive body (DirectiveKind).
Comments are preserved for lossless round-trip serialization.
§Examples
use chrony_confile::ChronyConfig;
let config: ChronyConfig = "# My NTP server\nserver ntp.example.com iburst # preferred\n".parse()?;
let directive = config.directives().next().unwrap();
assert_eq!(directive.leading_comments[0], "My NTP server");
assert_eq!(directive.trailing_comment.as_deref(), Some("preferred"));Fields§
§span: SpanSource location of the directive.
leading_comments: Vec<String>Comments on lines immediately preceding the directive.
trailing_comment: Option<String>An inline comment after the directive, if present.
kind: DirectiveKindThe parsed directive body.
Implementations§
Source§impl Directive
impl Directive
Sourcepub fn new(kind: DirectiveKind, span: Span) -> Self
pub fn new(kind: DirectiveKind, span: Span) -> Self
Creates a new directive with the given kind and source span.
Sourcepub fn with_leading_comment(self, comment: impl Into<String>) -> Self
pub fn with_leading_comment(self, comment: impl Into<String>) -> Self
Builder-style method to add a leading comment.
Sourcepub fn with_trailing_comment(self, comment: impl Into<String>) -> Self
pub fn with_trailing_comment(self, comment: impl Into<String>) -> Self
Builder-style method to add a trailing comment.
Trait Implementations§
Source§impl From<Directive> for ConfigNode
impl From<Directive> for ConfigNode
Source§impl From<DirectiveKind> for Directive
impl From<DirectiveKind> for Directive
Source§fn from(kind: DirectiveKind) -> Self
fn from(kind: DirectiveKind) -> Self
Converts to this type from the input type.
impl StructuralPartialEq for Directive
Auto Trait Implementations§
impl Freeze for Directive
impl RefUnwindSafe for Directive
impl Send for Directive
impl Sync for Directive
impl Unpin for Directive
impl UnsafeUnpin for Directive
impl UnwindSafe for Directive
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