Skip to main content

Directive

Struct Directive 

Source
pub struct Directive {
    pub name: String,
    pub name_span: Span,
    pub args: Vec<Argument>,
    pub block: Option<Block>,
    pub span: Span,
    pub trailing_comment: Option<Comment>,
    pub leading_whitespace: String,
    pub space_before_terminator: String,
    pub trailing_whitespace: String,
}
Expand description

A directive — either a simple directive (listen 80;) or a block directive (server { … }).

The span covers the entire directive from the first character of the name to the terminating ; or closing }.

Fields§

§name: String

Directive name (e.g. "server", "listen", "more_set_headers").

§name_span: Span

Span of the directive name token.

§args: Vec<Argument>

Arguments following the directive name.

§block: Option<Block>

Block body, present for block directives like server { … }.

§span: Span

Span covering the entire directive (name through terminator).

§trailing_comment: Option<Comment>

Optional comment at the end of the directive line.

§leading_whitespace: String

Leading whitespace before the directive name (for indentation checking)

§space_before_terminator: String

Whitespace before the terminator (; or {)

§trailing_whitespace: String

Trailing whitespace after the terminator (; or {) to end of line

Implementations§

Source§

impl Directive

Source

pub fn is(&self, name: &str) -> bool

Check if this directive has a specific name

Source

pub fn first_arg(&self) -> Option<&str>

Get the first argument value as a string (useful for simple directives)

Source

pub fn first_arg_is(&self, value: &str) -> bool

Check if the first argument equals a specific value

Trait Implementations§

Source§

impl Clone for Directive

Source§

fn clone(&self) -> Directive

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Directive

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Directive

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Directive, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl DirectiveExt for Box<Directive>

Source§

fn is(&self, name: &str) -> bool

Check if the directive has the given name.
Source§

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

Get the first argument’s string value, if any.
Source§

fn first_arg_is(&self, value: &str) -> bool

Check if the first argument equals the given value.
Source§

fn arg_at(&self, index: usize) -> Option<&str>

Get the argument at the given index.
Source§

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

Get the last argument’s string value, if any.
Source§

fn has_arg(&self, value: &str) -> bool

Check if any argument equals the given value.
Source§

fn arg_count(&self) -> usize

Return the number of arguments.
Source§

fn line(&self) -> usize

Get the start line number (1-based).
Source§

fn column(&self) -> usize

Get the start column number (1-based).
Source§

fn full_start_offset(&self) -> usize

Get the byte offset including leading whitespace.
Source§

fn replace_with(&self, new_text: &str) -> Fix

Create a Fix that replaces this directive with new text, preserving indentation.
Source§

fn delete_line(&self) -> Fix

Create a Fix that deletes this directive’s line.
Source§

fn insert_after(&self, new_text: &str) -> Fix

Create a Fix that inserts a new line after this directive, matching indentation.
Source§

fn insert_after_many(&self, lines: &[&str]) -> Fix

Create a Fix that inserts multiple new lines after this directive.
Source§

fn insert_before(&self, new_text: &str) -> Fix

Create a Fix that inserts a new line before this directive, matching indentation.
Source§

fn insert_before_many(&self, lines: &[&str]) -> Fix

Create a Fix that inserts multiple new lines before this directive.
Source§

impl DirectiveExt for Directive

Source§

fn is(&self, name: &str) -> bool

Check if the directive has the given name.
Source§

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

Get the first argument’s string value, if any.
Source§

fn first_arg_is(&self, value: &str) -> bool

Check if the first argument equals the given value.
Source§

fn arg_at(&self, index: usize) -> Option<&str>

Get the argument at the given index.
Source§

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

Get the last argument’s string value, if any.
Source§

fn has_arg(&self, value: &str) -> bool

Check if any argument equals the given value.
Source§

fn arg_count(&self) -> usize

Return the number of arguments.
Source§

fn line(&self) -> usize

Get the start line number (1-based).
Source§

fn column(&self) -> usize

Get the start column number (1-based).
Source§

fn full_start_offset(&self) -> usize

Get the byte offset including leading whitespace.
Source§

fn replace_with(&self, new_text: &str) -> Fix

Create a Fix that replaces this directive with new text, preserving indentation.
Source§

fn delete_line(&self) -> Fix

Create a Fix that deletes this directive’s line.
Source§

fn insert_after(&self, new_text: &str) -> Fix

Create a Fix that inserts a new line after this directive, matching indentation.
Source§

fn insert_after_many(&self, lines: &[&str]) -> Fix

Create a Fix that inserts multiple new lines after this directive.
Source§

fn insert_before(&self, new_text: &str) -> Fix

Create a Fix that inserts a new line before this directive, matching indentation.
Source§

fn insert_before_many(&self, lines: &[&str]) -> Fix

Create a Fix that inserts multiple new lines before this directive.
Source§

impl Serialize for Directive

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,