Update to new struct version of FileWriteMode
Some checks failed
CI / Test suite (push) Has been cancelled
CI / Test suite (windows) (push) Has been cancelled
CI / Rust ${{matrix.rust}} (beta) (push) Has been cancelled
CI / Rust ${{matrix.rust}} (stable) (push) Has been cancelled
CI / Rust nightly ${{matrix.os == 'windows' && '(windows)' || ''}} (ubuntu) (push) Has been cancelled
CI / Rust nightly ${{matrix.os == 'windows' && '(windows)' || ''}} (windows) (push) Has been cancelled
CI / Rust ${{matrix.rust}} (1.31.0) (push) Has been cancelled
CI / Rust ${{matrix.rust}} (1.34.0) (push) Has been cancelled
CI / Rust 1.56.0 (push) Has been cancelled
CI / Rust 1.36.0 (push) Has been cancelled
CI / Minimal versions (push) Has been cancelled
CI / Documentation (push) Has been cancelled
CI / Clippy (push) Has been cancelled
CI / Miri (push) Has been cancelled
CI / Outdated (push) Has been cancelled
Some checks failed
CI / Test suite (push) Has been cancelled
CI / Test suite (windows) (push) Has been cancelled
CI / Rust ${{matrix.rust}} (beta) (push) Has been cancelled
CI / Rust ${{matrix.rust}} (stable) (push) Has been cancelled
CI / Rust nightly ${{matrix.os == 'windows' && '(windows)' || ''}} (ubuntu) (push) Has been cancelled
CI / Rust nightly ${{matrix.os == 'windows' && '(windows)' || ''}} (windows) (push) Has been cancelled
CI / Rust ${{matrix.rust}} (1.31.0) (push) Has been cancelled
CI / Rust ${{matrix.rust}} (1.34.0) (push) Has been cancelled
CI / Rust 1.56.0 (push) Has been cancelled
CI / Rust 1.36.0 (push) Has been cancelled
CI / Minimal versions (push) Has been cancelled
CI / Documentation (push) Has been cancelled
CI / Clippy (push) Has been cancelled
CI / Miri (push) Has been cancelled
CI / Outdated (push) Has been cancelled
This commit is contained in:
parent
f5700b61ad
commit
166ba8912e
@ -3269,6 +3269,8 @@ variant_identifier! {
|
|||||||
FILE_WRITE_MODE_VARIANTS
|
FILE_WRITE_MODE_VARIANTS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "mikros")]
|
||||||
|
const FILE_WRITE_MODE_FIELDS: &[&str] = &["truncate", "append"];
|
||||||
|
|
||||||
#[cfg(target_os = "mikros")]
|
#[cfg(target_os = "mikros")]
|
||||||
impl<'de> Deserialize<'de> for std::os::mikros::FileWriteMode {
|
impl<'de> Deserialize<'de> for std::os::mikros::FileWriteMode {
|
||||||
@ -3276,7 +3278,58 @@ impl<'de> Deserialize<'de> for std::os::mikros::FileWriteMode {
|
|||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
deserializer.deserialize_enum("FileWriteMode", &["Start", "Truncate", "Append"], FileWriteModeVisitor)
|
deserializer.deserialize_struct("FileWriteMode", FILE_WRITE_MODE_FIELDS, FileWriteModeVisitor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "mikros")]
|
||||||
|
enum FileWriteModeField {
|
||||||
|
Truncate,
|
||||||
|
Append,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "mikros")]
|
||||||
|
impl<'de> Deserialize<'de> for FileWriteModeField {
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
struct FileWriteModeFieldVisitor;
|
||||||
|
|
||||||
|
impl Visitor<'_> for FileWriteModeFieldVisitor {
|
||||||
|
type Value = FileWriteModeField;
|
||||||
|
|
||||||
|
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
formatter.write_str("`truncate` or `append`")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
|
||||||
|
where
|
||||||
|
E: Error,
|
||||||
|
{
|
||||||
|
match value {
|
||||||
|
"truncate" => Ok(FileWriteModeField::Truncate),
|
||||||
|
"append" => Ok(FileWriteModeField::Append),
|
||||||
|
_ => Err(Error::unknown_field(value, FILE_WRITE_MODE_FIELDS)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_bytes<E>(self, value: &[u8]) -> Result<Self::Value, E>
|
||||||
|
where
|
||||||
|
E: Error,
|
||||||
|
{
|
||||||
|
match value {
|
||||||
|
b"truncate" => Ok(FileWriteModeField::Truncate),
|
||||||
|
b"append" => Ok(FileWriteModeField::Append),
|
||||||
|
_ => {
|
||||||
|
let value = crate::__private::from_utf8_lossy(value);
|
||||||
|
Err(Error::unknown_field(&*value, FILE_WRITE_MODE_FIELDS))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deserializer.deserialize_identifier(FileWriteModeFieldVisitor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3288,22 +3341,62 @@ impl<'de> Visitor<'de> for FileWriteModeVisitor {
|
|||||||
type Value = std::os::mikros::FileWriteMode;
|
type Value = std::os::mikros::FileWriteMode;
|
||||||
|
|
||||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
formatter.write_str("FileWriteMode")
|
formatter.write_str("struct FileWriteMode")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_enum<A>(self, data: A) -> Result<Self::Value, A::Error>
|
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
|
||||||
where
|
where
|
||||||
A: EnumAccess<'de>,
|
A: SeqAccess<'de>,
|
||||||
{
|
{
|
||||||
match tri!(data.variant()) {
|
let truncate: bool = match tri!(seq.next_element()) {
|
||||||
(FileWriteModeKind::Start,v) => v.unit_variant().map(|_| std::os::mikros::FileWriteMode::Start),
|
Some(value) => value,
|
||||||
(FileWriteModeKind::Truncate,v) => v.unit_variant().map(|_| std::os::mikros::FileWriteMode::Truncate),
|
None => {
|
||||||
(FileWriteModeKind::Append,v) => v.unit_variant().map(|_| std::os::mikros::FileWriteMode::Append),
|
return Err(Error::invalid_length(0, &self));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let append: bool = match tri!(seq.next_element()) {
|
||||||
|
Some(value) => value,
|
||||||
|
None => {
|
||||||
|
return Err(Error::invalid_length(1, &self));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Ok(std::os::mikros::FileWriteMode{truncate, append})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
|
||||||
|
where
|
||||||
|
A: MapAccess<'de>,
|
||||||
|
{
|
||||||
|
let mut truncate: Option<bool> = None;
|
||||||
|
let mut append: Option<bool> = None;
|
||||||
|
while let Some(key) = tri!(map.next_key()) {
|
||||||
|
match key {
|
||||||
|
FileWriteModeField::Truncate => {
|
||||||
|
if truncate.is_some() {
|
||||||
|
return Err(<A::Error as Error>::duplicate_field("truncate"));
|
||||||
|
}
|
||||||
|
truncate = Some(tri!(map.next_value()));
|
||||||
|
}
|
||||||
|
FileWriteModeField::Append => {
|
||||||
|
if append.is_some() {
|
||||||
|
return Err(<A::Error as Error>::duplicate_field("append"));
|
||||||
|
}
|
||||||
|
append = Some(tri!(map.next_value()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
let truncate = match truncate {
|
||||||
|
Some(truncate) => truncate,
|
||||||
|
None => return Err(<A::Error as Error>::missing_field("truncate")),
|
||||||
|
};
|
||||||
|
let append = match append {
|
||||||
|
Some(append) => append,
|
||||||
|
None => return Err(<A::Error as Error>::missing_field("append")),
|
||||||
|
};
|
||||||
|
Ok(std::os::mikros::FileWriteMode{truncate, append})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(target_os = "mikros")]
|
#[cfg(target_os = "mikros")]
|
||||||
struct FileOpenModeTupleVisitor;
|
struct FileOpenModeTupleVisitor;
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
use crate::lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
use crate::ser::{Error, Serialize, SerializeTuple, SerializeTupleVariant, Serializer};
|
use crate::ser::{Error, Serialize, SerializeTuple, Serializer};
|
||||||
|
|
||||||
|
#[cfg(target_os = "mikros")]
|
||||||
|
use crate::ser::{SerializeTupleVariant, SerializeStruct};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -1134,11 +1137,10 @@ impl Serialize for std::os::mikros::FileWriteMode {
|
|||||||
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()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user