Skip to content

Commit

Permalink
refactor(edit): Remove 'use' for optional mods
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Nov 6, 2023
1 parent 52b5c6f commit 5b53ff1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
3 changes: 1 addition & 2 deletions crates/toml_edit/src/document.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::str::FromStr;

use crate::parser;
use crate::table::Iter;
use crate::{Item, RawString, Table};

Expand Down Expand Up @@ -83,7 +82,7 @@ impl FromStr for Document {

/// Parses a document from a &str
fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut d = parser::parse_document(s)?;
let mut d = crate::parser::parse_document(s)?;
d.despan();
Ok(d)
}
Expand Down
13 changes: 7 additions & 6 deletions crates/toml_edit/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
use std::error::Error as StdError;
use std::fmt::{Display, Formatter, Result};

use crate::parser::prelude::*;

use winnow::error::ContextError;
use winnow::error::ParseError;

/// Type representing a TOML parse error
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct TomlError {
Expand All @@ -16,7 +11,13 @@ pub struct TomlError {
}

impl TomlError {
pub(crate) fn new(error: ParseError<Input<'_>, ContextError>, mut original: Input<'_>) -> Self {
pub(crate) fn new(
error: winnow::error::ParseError<
crate::parser::prelude::Input<'_>,
winnow::error::ContextError,
>,
mut original: crate::parser::prelude::Input<'_>,
) -> Self {
use winnow::stream::Stream;

let offset = error.offset();
Expand Down
21 changes: 14 additions & 7 deletions crates/toml_edit/src/key.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use std::borrow::Cow;
use std::str::FromStr;

use crate::encode::{to_string_repr, StringStyle};
use crate::parser;
use crate::parser::key::is_unquoted_char;
use crate::repr::{Decor, Repr};
use crate::InternalString;

Expand Down Expand Up @@ -128,13 +125,13 @@ impl Key {
}

fn try_parse_simple(s: &str) -> Result<Key, crate::TomlError> {
let mut key = parser::parse_key(s)?;
let mut key = crate::parser::parse_key(s)?;
key.despan(s);
Ok(key)
}

fn try_parse_path(s: &str) -> Result<Vec<Key>, crate::TomlError> {
let mut keys = parser::parse_key_path(s)?;
let mut keys = crate::parser::parse_key_path(s)?;
for key in &mut keys {
key.despan(s);
}
Expand Down Expand Up @@ -227,10 +224,20 @@ impl FromStr for Key {
}

fn to_key_repr(key: &str) -> Repr {
if key.as_bytes().iter().copied().all(is_unquoted_char) && !key.is_empty() {
if key
.as_bytes()
.iter()
.copied()
.all(crate::parser::key::is_unquoted_char)
&& !key.is_empty()
{
Repr::new_unchecked(key)
} else {
to_string_repr(key, Some(StringStyle::OnelineSingle), Some(false))
crate::encode::to_string_repr(
key,
Some(crate::encode::StringStyle::OnelineSingle),
Some(false),
)
}
}

Expand Down
3 changes: 1 addition & 2 deletions crates/toml_edit/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::str::FromStr;
use toml_datetime::*;

use crate::key::Key;
use crate::parser;
use crate::repr::{Decor, Formatted};
use crate::{Array, InlineTable, InternalString, RawString};

Expand Down Expand Up @@ -236,7 +235,7 @@ impl FromStr for Value {

/// Parses a value from a &str
fn from_str(s: &str) -> Result<Self, Self::Err> {
parser::parse_value(s)
crate::parser::parse_value(s)
}
}

Expand Down

0 comments on commit 5b53ff1

Please sign in to comment.