Skip to main content

Env

Struct Env 

Source
pub struct Env { /* private fields */ }
Expand description

A parsed .env / .properties document, backed by a lossless CST.

Implementations§

Source§

impl Env

Source

pub fn syntax(&self) -> &SyntaxNode<EnvLang>

Access the underlying syntax tree.

Source

pub fn set(&mut self, key: &str, value: &Value) -> Result<(), EditError>

Set the entry key to a scalar, format-preserving. If key doesn’t exist, a new key=value line is appended.

Source

pub fn value_at(&self, key: &str) -> Option<Value>

The string value of key, or None.

Source

pub fn delete(&mut self, key: &str) -> Result<(), EditError>

Delete key, removing its whole line (a missing key is a no-op).

Trait Implementations§

Source§

impl Document for Env

Source§

fn to_source(&self) -> String

Byte-identical serialization for an unedited document (the round-trip invariant). Reflects in-place edits once mutation lands.
Source§

fn to_value(&self) -> Value

Project to the value model for querying and conversion. Trivia (comments, layout) is dropped - this is the data-model view, not the source view.
Source§

fn features(&self) -> &'static [Feature]

The format’s capabilities.
Source§

fn apply(&mut self, expr: &Expr) -> Result<Vec<String>, EditError>

Apply a mutation expression (assignment / del) in place, format-preserving. Query expressions should be evaluated against Document::to_value instead; use Expr::is_mutation to choose. Returns any non-fatal warnings (e.g. a multi-document select predicate that could not be evaluated against some document, so that document was skipped) for the CLI to surface; an empty vec on a clean edit.
Source§

fn has_comments(&self) -> bool

Whether the source contains any comments - used to warn on conversion, which drops them.
Source§

fn to_commented(&self) -> Option<Commented>

Project to the comment-annotated value model (Commented) so conversion can carry comments across formats. Shape and order must match Document::to_value exactly (same keys, same merge/resolution rules) - the CLI pairs the two projections by position. None means the format doesn’t extract comments; conversion then falls back to the plain value path and warns that comments were dropped.
Source§

fn set_comment( &mut self, path: &[Step], kind: CommentKind, text: &str, ) -> Result<Vec<String>, EditError>

Set the kind comment on the node at path to text (raw, unwrapped), format-preserving: only that comment’s bytes change, or one comment line is inserted. Multi-line head/foot text is wrapped to the document’s envelope by the implementation. Returns any warnings (a layout that had to expand to hold the comment, or a kind remapped to one the format supports). The default rejects - comment editing is added per format.
Source§

fn delete_comment( &mut self, path: &[Step], kind: CommentKind, ) -> Result<(), EditError>

Delete the kind comment on the node at path (a miss is a no-op). The default rejects - added per format alongside Document::set_comment.
Source§

fn to_values(&self) -> Vec<Value>

Project to one value per top-level document. Only YAML has a multi-document stream (----separated); every other format is a single document, so the default is [to_value()]. The CLI evaluates a query against each in turn and concatenates the results, so .kind over a multi-doc stream yields one result per document.
Source§

fn to_commented_all(&self) -> Vec<Commented>

One comment-annotated projection per top-level document (the comment analogue of Document::to_values). Only YAML has multiple; the default is the single Document::to_commented, so a comment query maps over every document of a multi-document stream.
Source§

fn source_slice(&self, path: &[Step]) -> Vec<String>

The original source text of each node selected by path, in document order (aligned 1:1 with crate::eval’s results for the same path). This is the format-preserving “get”: a structural query returns the exact bytes Read more
Source§

fn inner_format(&self) -> Option<&'static str>

The name of the format a query should default its output to, when this document’s own format isn’t itself emittable. A lens (frontmatter) is not an output format, so a query over it renders in the underlying block’s format ("yaml"/"toml"/"json") instead. None (the default) means “my own format is the natural output” - the ordinary case.
Source§

fn set_comment_in_doc( &mut self, doc: usize, path: &[Step], kind: CommentKind, text: &str, ) -> Result<Vec<String>, EditError>

Set the kind comment at path, scoped to a single document of a multi-document stream (used by bulk comments |= f, where each new comment derives from that comment’s own text and so must not leak across documents). Single-document formats have one document, so the default ignores doc and sets it the ordinary way.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Env

§

impl !Send for Env

§

impl !Sync for Env

§

impl !UnwindSafe for Env

§

impl Freeze for Env

§

impl Unpin for Env

§

impl UnsafeUnpin for Env

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> 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, 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.