|
1 | 1 | use crate::Result; |
2 | 2 | use semver::Version; |
3 | 3 | use serde::{Deserialize, Serialize}; |
4 | | -use serde_json::ser::PrettyFormatter; |
5 | | -use serde_json::Serializer; |
6 | 4 | #[cfg(test)] |
7 | 5 | use std::ffi::OsString; |
8 | 6 | use std::fmt::Display; |
| 7 | +#[cfg(not(feature = "tokio"))] |
| 8 | +use std::io::Write; |
9 | 9 | use std::path::PathBuf; |
10 | 10 | #[cfg(feature = "tokio")] |
11 | 11 | use tokio::io::{AsyncReadExt, AsyncWriteExt}; |
@@ -94,22 +94,17 @@ impl InstalledConfiguration { |
94 | 94 | /// # Errors |
95 | 95 | /// * If an error occurs while writing the configuration. |
96 | 96 | 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)?; |
102 | 98 |
|
103 | 99 | #[cfg(feature = "tokio")] |
104 | 100 | { |
105 | 101 | let mut file = tokio::fs::File::create(path.into()).await?; |
106 | | - file.write_all(&buffer).await?; |
| 102 | + file.write_all(content.as_bytes()).await?; |
107 | 103 | } |
108 | 104 | #[cfg(not(feature = "tokio"))] |
109 | 105 | { |
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())?; |
113 | 108 | } |
114 | 109 | Ok(()) |
115 | 110 | } |
|
0 commit comments