From a40ff11ecca6fb9c5467ddbd53aece7b9444094d Mon Sep 17 00:00:00 2001 From: pjht Date: Sun, 17 Nov 2024 21:43:52 -0600 Subject: [PATCH] mikros: Make FileWriteMode a struct to allow both truncate and append at once --- library/std/src/os/mikros/mod.rs | 18 ++++++++---------- library/std/src/sys/pal/mikros/fs.rs | 8 +++----- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/library/std/src/os/mikros/mod.rs b/library/std/src/os/mikros/mod.rs index fad0564f867..90e733c0c62 100644 --- a/library/std/src/os/mikros/mod.rs +++ b/library/std/src/os/mikros/mod.rs @@ -11,7 +11,7 @@ mod errno; -use serde::{Serialize, Serializer, ser::SerializeTupleVariant}; +use serde::{Serialize, Serializer, ser::{SerializeTupleVariant, SerializeStruct}}; #[stable(feature = "mikros", since = "1.80.0")] pub use errno::Errno; @@ -27,10 +27,9 @@ pub enum FileCreationMode { #[stable(feature = "mikros", since = "1.80.0")] #[derive(Copy, Clone, Debug, PartialEq, Eq)] -pub enum FileWriteMode { - Start, - Truncate, - Append +pub struct FileWriteMode { + pub truncate: bool, + pub append: bool, } #[stable(feature = "mikros", since = "1.80.0")] @@ -99,11 +98,10 @@ fn serialize(&self, serializer: S) -> Result where S: Serializer, { - match self { - Self::Start => serializer.serialize_unit_variant("FileWriteMode", 0, "Start"), - Self::Truncate => serializer.serialize_unit_variant("FileWriteMode", 1, "Truncate"), - Self::Append => serializer.serialize_unit_variant("FileWriteMode", 2, "Append"), - } + let mut ser = serializer.serialize_struct("FileWriteMode", 2)?; + ser.serialize_field("truncate", &self.truncate)?; + ser.serialize_field("append", &self.append)?; + ser.end() } } diff --git a/library/std/src/sys/pal/mikros/fs.rs b/library/std/src/sys/pal/mikros/fs.rs index 58081f3a276..f05d1e19244 100644 --- a/library/std/src/sys/pal/mikros/fs.rs +++ b/library/std/src/sys/pal/mikros/fs.rs @@ -374,11 +374,9 @@ fn get_open_mode(&self) -> io::Result { (true, false) => FileCreationMode::Create, (_, true) => FileCreationMode::ForceCreate, }; - let wr_mode = match (self.append, self.truncate) { - (false, false) => FileWriteMode::Start, - (false, true) => FileWriteMode::Truncate, - (true, false) => FileWriteMode::Append, - (true, true) => unreachable!() + let wr_mode = FileWriteMode { + truncate: self.truncate, + append: self.append, }; match self.read { false => Ok(FileOpenMode::Write(wr_mode, cr_mode)),