Skip to content

Commit

Permalink
chore: Upgrade toml_edit
Browse files Browse the repository at this point in the history
  • Loading branch information
epage authored and sunshowers committed Jan 23, 2025
1 parent d129112 commit 368f8fb
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 51 deletions.
39 changes: 6 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cargo-guppy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ itertools = "0.14.0"
pathdiff = { version = "0.2.3", features = ["camino"] }
serde = { version = "1.0.216", features = ["derive"] }
serde_json = "1.0.134"
toml_edit = "0.17.1"
toml_edit = "0.22.2"
guppy-workspace-hack.workspace = true
10 changes: 5 additions & 5 deletions cargo-guppy/src/mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::{
mem,
path::{Path, MAIN_SEPARATOR},
};
use toml_edit::{Document, Item, Table, Value};
use toml_edit::{DocumentMut, Item, Table, Value};

#[derive(Debug, Parser)]
pub struct MvOptions {
Expand Down Expand Up @@ -512,10 +512,10 @@ fn update_root_toml(
Ok(())
}

fn read_toml(manifest_path: &Utf8Path) -> Result<Document> {
fn read_toml(manifest_path: &Utf8Path) -> Result<DocumentMut> {
let toml = fs::read_to_string(manifest_path)
.wrap_err_with(|| eyre!("error while reading manifest {}", manifest_path))?;
toml.parse::<Document>()
toml.parse::<DocumentMut>()
.wrap_err_with(|| eyre!("error while parsing manifest {}", manifest_path))
}

Expand All @@ -526,10 +526,10 @@ fn replace_decorated(dest: &mut Value, new_value: impl Into<Value>) -> Value {
// Copy over the decor from dest into new_value.
let new_decor = new_value.decor_mut();
if let Some(prefix) = decor.prefix() {
new_decor.set_prefix(prefix);
new_decor.set_prefix(prefix.clone());
}
if let Some(suffix) = decor.suffix() {
new_decor.set_suffix(suffix);
new_decor.set_suffix(suffix.clone());
}

mem::replace(dest, new_value)
Expand Down
2 changes: 1 addition & 1 deletion tools/hakari/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ serde = { version = "1.0.216", features = ["derive"], optional = true }
tabular = { version = "0.2.0", features = ["ansi-cell"], optional = true }
target-spec = { version = "3.3.1", path = "../../target-spec" }
toml = { version = "0.5.11", optional = true }
toml_edit = "0.17.1"
toml_edit = "0.22.2"
twox-hash = { version = "1.6.3", default-features = false }
guppy-workspace-hack.workspace = true

Expand Down
20 changes: 11 additions & 9 deletions tools/hakari/src/cli_ops/workspace_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use guppy::{
use owo_colors::{OwoColorize, Style};
use std::{borrow::Cow, cmp::Ordering, collections::BTreeMap, error, fmt, fs, io, io::Write};
use toml_edit::{
Array, Document, Formatted, InlineTable, Item, Table, TableLike, TomlError, Value,
Array, DocumentMut, Formatted, InlineTable, Item, Table, TableLike, TomlError, Value,
};

/// Represents a set of write operations to the workspace.
Expand Down Expand Up @@ -231,7 +231,7 @@ impl<'g> WorkspaceOp<'g, '_> {

fn get_workspace_members_array<'doc>(
root_toml_path: &Utf8Path,
doc: &'doc mut Document,
doc: &'doc mut DocumentMut,
) -> Result<&'doc mut Array, ApplyError> {
let doc_table = doc.as_table_mut();
let workspace_table = match doc_table.get_mut("workspace") {
Expand Down Expand Up @@ -373,7 +373,7 @@ impl<'g> WorkspaceOp<'g, '_> {

fn get_or_insert_dependencies_table<'doc>(
manifest_path: &Utf8Path,
doc: &'doc mut Document,
doc: &'doc mut DocumentMut,
) -> Result<&'doc mut dyn TableLike, ApplyError> {
let doc_table = doc.as_table_mut();

Expand Down Expand Up @@ -406,8 +406,10 @@ impl<'g> WorkspaceOp<'g, '_> {

fn decorate(existing: &Value, new: impl Into<Value>) -> Value {
let decor = existing.decor();
new.into()
.decorated(decor.prefix().unwrap_or(""), decor.suffix().unwrap_or(""))
new.into().decorated(
decor.prefix().cloned().unwrap_or_default(),
decor.suffix().cloned().unwrap_or_default(),
)
}

// Always write out paths with forward slashes, including on Windows.
Expand Down Expand Up @@ -445,18 +447,18 @@ fn canonical_rel_path(
// Read/write functions
// ---

fn read_toml(manifest_path: &Utf8Path) -> Result<Document, ApplyError> {
fn read_toml(manifest_path: &Utf8Path) -> Result<DocumentMut, ApplyError> {
let toml = fs::read_to_string(manifest_path)
.map_err(|err| ApplyError::io("error reading TOML file", manifest_path, err))?;
toml.parse::<Document>()
toml.parse::<DocumentMut>()
.map_err(|err| ApplyError::toml("error deserializing TOML file", manifest_path, err))
}

fn write_contents(contents: &[u8], path: &Utf8Path) -> Result<(), ApplyError> {
write_atomic(path, |file| file.write_all(contents))
}

fn write_document(document: &Document, path: &Utf8Path) -> Result<(), ApplyError> {
fn write_document(document: &DocumentMut, path: &Utf8Path) -> Result<(), ApplyError> {
write_atomic(path, |file| write!(file, "{}", document))
}

Expand Down Expand Up @@ -777,7 +779,7 @@ mod tests {
WorkspaceHackLineStyle::WorkspaceDotted,
"../../path".into(),
);
let mut document = Document::new();
let mut document = DocumentMut::new();
document
.as_table_mut()
.insert("workspace-hack", Item::Value(Value::InlineTable(itable)));
Expand Down
4 changes: 2 additions & 2 deletions tools/hakari/src/toml_out.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::{
error, fmt,
hash::{Hash, Hasher},
};
use toml_edit::{Array, Document, InlineTable, Item, Table, Value};
use toml_edit::{Array, DocumentMut, InlineTable, Item, Table, Value};
use twox_hash::XxHash64;

/// Options for Hakari TOML output.
Expand Down Expand Up @@ -304,7 +304,7 @@ pub(crate) fn write_toml(
.expect("hakari package is in workspace")
});

let mut document = Document::new();
let mut document = DocumentMut::new();

// Remove the leading newline from the first visual table to match what older versions of
// hakari did.
Expand Down

0 comments on commit 368f8fb

Please sign in to comment.