[glsl-out] Use fmt::Writer instead of io::Writer

This commit is contained in:
Gordon-F 2021-04-20 14:52:06 +03:00 committed by Dzmitry Malyshau
parent 446f5dad6f
commit c37ae5e2a0
4 changed files with 12 additions and 25 deletions

View File

@ -237,23 +237,12 @@ fn main() {
_ => unreachable!(),
};
let file = fs::OpenOptions::new()
.write(true)
.truncate(true)
.create(true)
.open(output_path)
.unwrap();
let mut writer = glsl::Writer::new(file, &module, info.as_ref().unwrap(), &params.glsl)
.unwrap_pretty();
writer
.write()
.map_err(|e| {
fs::remove_file(output_path).unwrap();
e
})
.unwrap();
let mut buffer = String::new();
let mut writer =
glsl::Writer::new(&mut buffer, &module, info.as_ref().unwrap(), &params.glsl)
.unwrap_pretty();
writer.write().unwrap();
fs::write(output_path, buffer).unwrap();
}
#[cfg(feature = "dot-out")]
"dot" => {

View File

@ -3,7 +3,7 @@ use crate::{
Binding, Bytes, Handle, ImageClass, ImageDimension, Interpolation, Sampling, ScalarKind,
ShaderStage, StorageClass, StorageFormat, Type, TypeInner,
};
use std::io::Write;
use std::fmt::Write;
bitflags::bitflags! {
/// Structure used to encode a set of additions to glsl that aren't supported by all versions

View File

@ -57,7 +57,7 @@ use features::FeaturesManager;
use std::{
cmp::Ordering,
fmt,
io::{Error as IoError, Write},
fmt::{Error as FmtError, Write},
};
use thiserror::Error;
@ -271,8 +271,8 @@ type BackendResult = Result<(), Error>;
#[derive(Debug, Error)]
pub enum Error {
/// A error occurred while writing to the output
#[error("I/O error")]
IoError(#[from] IoError),
#[error("Format error")]
FmtError(#[from] FmtError),
/// The specified [`Version`](Version) doesn't have all required [`Features`](super)
///
/// Contains the missing [`Features`](Features)

View File

@ -189,14 +189,12 @@ fn check_output_glsl(
entry_point: ep_name.to_string(),
};
let mut buffer = Vec::new();
let mut buffer = String::new();
let mut writer = glsl::Writer::new(&mut buffer, module, info, &options).unwrap();
writer.write().unwrap();
let string = String::from_utf8(buffer).unwrap();
let ext = format!("{:?}.glsl", stage);
fs::write(destination.with_extension(&ext), string).unwrap();
fs::write(destination.with_extension(&ext), buffer).unwrap();
}
#[cfg(feature = "hlsl-out")]