Skip to content

Commit 4efd2db

Browse files
committed
fix: correct serialization error writing configuration
1 parent 3ab7002 commit 4efd2db

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

postgresql_extensions/src/model.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use crate::Result;
22
use semver::Version;
33
use serde::{Deserialize, Serialize};
4-
use serde_json::ser::PrettyFormatter;
5-
use serde_json::Serializer;
64
#[cfg(test)]
75
use std::ffi::OsString;
86
use std::fmt::Display;
7+
#[cfg(not(feature = "tokio"))]
8+
use std::io::Write;
99
use std::path::PathBuf;
1010
#[cfg(feature = "tokio")]
1111
use tokio::io::{AsyncReadExt, AsyncWriteExt};
@@ -94,22 +94,17 @@ impl InstalledConfiguration {
9494
/// # Errors
9595
/// * If an error occurs while writing the configuration.
9696
pub async fn write<P: Into<PathBuf>>(&self, path: P) -> Result<()> {
97-
let mut buffer = Vec::new();
98-
let formatter = PrettyFormatter::with_indent(b" ");
99-
let mut serializer = Serializer::with_formatter(&mut buffer, formatter);
100-
101-
self.serialize(&mut serializer)?;
97+
let content = serde_json::to_string_pretty(&self)?;
10298

10399
#[cfg(feature = "tokio")]
104100
{
105101
let mut file = tokio::fs::File::create(path.into()).await?;
106-
file.write_all(&buffer).await?;
102+
file.write_all(content.as_bytes()).await?;
107103
}
108104
#[cfg(not(feature = "tokio"))]
109105
{
110-
let file = std::fs::File::create(path.into())?;
111-
let writer = std::io::BufWriter::new(file);
112-
serde_json::to_writer(writer, &buffer)?;
106+
let mut file = std::fs::File::create(path.into())?;
107+
file.write_all(content.as_bytes())?;
113108
}
114109
Ok(())
115110
}

0 commit comments

Comments
 (0)