Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworking nufmt #7

Merged
merged 5 commits into from
May 30, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
✨ standarized Config with minimal defaults
  • Loading branch information
AucaCoyan committed May 25, 2023
commit dca0413905fd9533279dff9d01bb433bf00e4227
33 changes: 25 additions & 8 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
/// options available to the formatter
use anyhow::Result;

/// Configurations available to the formatter
pub struct Config {
/// number of spaces of indent
/// Number of spaces of indent.
pub tab_spaces: usize,
/// max amount of characters per line
/// # Maximum width of each line.
/// Default: 100
/// Maximum width of each line.
pub max_width: usize,
/// number of lines bafore and after a custom command
/// Number of lines bafore and after a custom command.
pub margin: usize,
}

impl Default for Config {
fn default() -> Self {
Config {
tab_spaces: 2,
max_width: 100,
tab_spaces: 4,
max_width: 80,
margin: 1,
}
}
}

impl Config {
/// Creates a new config. You need to pass every field to create the config.
/// You cannot skip any field yet.
pub fn new(tab_spaces: usize, max_width: usize, margin: usize) -> Self {
Config {
tab_spaces: tab_spaces,
max_width: max_width,
margin: margin,
}
}
}

/// Returns a default config.
pub fn load_config(/* file_path: Option<&Path> */) -> Result<Config> {
Ok(Config::default())
}