pub struct EditorConfigFileBuilder { /* private fields */ }Expand description
Builder for generating an EditorConfig file.
§Example
use cuenv_editorconfig::{EditorConfigFile, EditorConfigSection};
let result = EditorConfigFile::builder()
.directory("/path/to/project")
.is_root(true)
.section("*", EditorConfigSection::new()
.indent_style("space")
.indent_size(4))
.generate()?;Implementations§
Source§impl EditorConfigFileBuilder
impl EditorConfigFileBuilder
Sourcepub fn directory(self, dir: impl AsRef<Path>) -> Self
pub fn directory(self, dir: impl AsRef<Path>) -> Self
Set the directory where the .editorconfig file will be generated.
Defaults to the current directory if not set.
Sourcepub const fn is_root(self, is_root: bool) -> Self
pub const fn is_root(self, is_root: bool) -> Self
Set whether this is the root .editorconfig file.
When true, adds root = true at the top of the file, which tells
editors to stop searching for .editorconfig files in parent directories.
Sourcepub fn section(
self,
pattern: impl Into<String>,
section: EditorConfigSection,
) -> Self
pub fn section( self, pattern: impl Into<String>, section: EditorConfigSection, ) -> Self
Add a section to the EditorConfig file.
Sections are output in the order they are added.
Sourcepub fn sections(
self,
sections: impl IntoIterator<Item = (impl Into<String>, EditorConfigSection)>,
) -> Self
pub fn sections( self, sections: impl IntoIterator<Item = (impl Into<String>, EditorConfigSection)>, ) -> Self
Add multiple sections to the EditorConfig file.
Sourcepub const fn dry_run(self, dry_run: bool) -> Self
pub const fn dry_run(self, dry_run: bool) -> Self
Enable dry-run mode.
When true, no files will be written. The result will indicate
what would happen with WouldCreate and WouldUpdate statuses.
Sourcepub fn header(self, header: impl Into<String>) -> Self
pub fn header(self, header: impl Into<String>) -> Self
Set a header comment for the file.
The header will be added at the top of the file with # prefixes.
Sourcepub fn generate(self) -> Result<SyncResult>
pub fn generate(self) -> Result<SyncResult>
Sourcepub fn generate_content(&self) -> String
pub fn generate_content(&self) -> String
Generate the file content as a string.