mikros: Make FileWriteMode a struct to allow both truncate and append at once
This commit is contained in:
parent
7005510bc0
commit
a40ff11ecc
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
mod errno;
|
mod errno;
|
||||||
|
|
||||||
use serde::{Serialize, Serializer, ser::SerializeTupleVariant};
|
use serde::{Serialize, Serializer, ser::{SerializeTupleVariant, SerializeStruct}};
|
||||||
|
|
||||||
#[stable(feature = "mikros", since = "1.80.0")]
|
#[stable(feature = "mikros", since = "1.80.0")]
|
||||||
pub use errno::Errno;
|
pub use errno::Errno;
|
||||||
@ -27,10 +27,9 @@ pub enum FileCreationMode {
|
|||||||
|
|
||||||
#[stable(feature = "mikros", since = "1.80.0")]
|
#[stable(feature = "mikros", since = "1.80.0")]
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum FileWriteMode {
|
pub struct FileWriteMode {
|
||||||
Start,
|
pub truncate: bool,
|
||||||
Truncate,
|
pub append: bool,
|
||||||
Append
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "mikros", since = "1.80.0")]
|
#[stable(feature = "mikros", since = "1.80.0")]
|
||||||
@ -99,11 +98,10 @@ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|||||||
where
|
where
|
||||||
S: Serializer,
|
S: Serializer,
|
||||||
{
|
{
|
||||||
match self {
|
let mut ser = serializer.serialize_struct("FileWriteMode", 2)?;
|
||||||
Self::Start => serializer.serialize_unit_variant("FileWriteMode", 0, "Start"),
|
ser.serialize_field("truncate", &self.truncate)?;
|
||||||
Self::Truncate => serializer.serialize_unit_variant("FileWriteMode", 1, "Truncate"),
|
ser.serialize_field("append", &self.append)?;
|
||||||
Self::Append => serializer.serialize_unit_variant("FileWriteMode", 2, "Append"),
|
ser.end()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,11 +374,9 @@ fn get_open_mode(&self) -> io::Result<FileOpenMode> {
|
|||||||
(true, false) => FileCreationMode::Create,
|
(true, false) => FileCreationMode::Create,
|
||||||
(_, true) => FileCreationMode::ForceCreate,
|
(_, true) => FileCreationMode::ForceCreate,
|
||||||
};
|
};
|
||||||
let wr_mode = match (self.append, self.truncate) {
|
let wr_mode = FileWriteMode {
|
||||||
(false, false) => FileWriteMode::Start,
|
truncate: self.truncate,
|
||||||
(false, true) => FileWriteMode::Truncate,
|
append: self.append,
|
||||||
(true, false) => FileWriteMode::Append,
|
|
||||||
(true, true) => unreachable!()
|
|
||||||
};
|
};
|
||||||
match self.read {
|
match self.read {
|
||||||
false => Ok(FileOpenMode::Write(wr_mode, cr_mode)),
|
false => Ok(FileOpenMode::Write(wr_mode, cr_mode)),
|
||||||
|
Loading…
Reference in New Issue
Block a user