From 5b53ff197b58099e5cae8ea4d3658804b1496294 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 6 Nov 2023 14:02:45 -0600 Subject: [PATCH] refactor(edit): Remove 'use' for optional mods --- crates/toml_edit/src/document.rs | 3 +-- crates/toml_edit/src/error.rs | 13 +++++++------ crates/toml_edit/src/key.rs | 21 ++++++++++++++------- crates/toml_edit/src/value.rs | 3 +-- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/crates/toml_edit/src/document.rs b/crates/toml_edit/src/document.rs index 67dd293d..a0d6e5ee 100644 --- a/crates/toml_edit/src/document.rs +++ b/crates/toml_edit/src/document.rs @@ -1,6 +1,5 @@ use std::str::FromStr; -use crate::parser; use crate::table::Iter; use crate::{Item, RawString, Table}; @@ -83,7 +82,7 @@ impl FromStr for Document { /// Parses a document from a &str fn from_str(s: &str) -> Result { - let mut d = parser::parse_document(s)?; + let mut d = crate::parser::parse_document(s)?; d.despan(); Ok(d) } diff --git a/crates/toml_edit/src/error.rs b/crates/toml_edit/src/error.rs index 1e03d9ab..82c9d245 100644 --- a/crates/toml_edit/src/error.rs +++ b/crates/toml_edit/src/error.rs @@ -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 { @@ -16,7 +11,13 @@ pub struct TomlError { } impl TomlError { - pub(crate) fn new(error: ParseError, 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(); diff --git a/crates/toml_edit/src/key.rs b/crates/toml_edit/src/key.rs index 86d54dc2..33ee1c65 100644 --- a/crates/toml_edit/src/key.rs +++ b/crates/toml_edit/src/key.rs @@ -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; @@ -128,13 +125,13 @@ impl Key { } fn try_parse_simple(s: &str) -> Result { - 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, 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); } @@ -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), + ) } } diff --git a/crates/toml_edit/src/value.rs b/crates/toml_edit/src/value.rs index 62eb30c7..38edc613 100644 --- a/crates/toml_edit/src/value.rs +++ b/crates/toml_edit/src/value.rs @@ -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}; @@ -236,7 +235,7 @@ impl FromStr for Value { /// Parses a value from a &str fn from_str(s: &str) -> Result { - parser::parse_value(s) + crate::parser::parse_value(s) } }