mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-07-01 05:29:05 +02:00
resource: use serde feature of enumflags2 crate
This commit is contained in:
parent
0842cb4ec2
commit
ba86dc8c06
3 changed files with 4 additions and 22 deletions
|
@ -6,12 +6,11 @@ mod legacy_block_types;
|
|||
use std::collections::HashMap;
|
||||
|
||||
use enumflags2::{bitflags, BitFlags};
|
||||
|
||||
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[bitflags]
|
||||
#[repr(u8)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
|
||||
pub enum BlockFlag {
|
||||
Opaque,
|
||||
Grass,
|
||||
|
@ -21,29 +20,11 @@ pub enum BlockFlag {
|
|||
Water,
|
||||
}
|
||||
|
||||
fn serialize_block_flags<S>(flags: &BitFlags<BlockFlag>, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
flags.bits().serialize(serializer)
|
||||
}
|
||||
fn deserialize_block_flags<'de, D>(deserializer: D) -> Result<BitFlags<BlockFlag>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let bits = u8::deserialize(deserializer)?;
|
||||
BitFlags::<BlockFlag>::from_bits(bits).map_err(de::Error::custom)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub struct Color(pub [u8; 3]);
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
pub struct BlockType {
|
||||
#[serde(
|
||||
serialize_with = "serialize_block_flags",
|
||||
deserialize_with = "deserialize_block_flags"
|
||||
)]
|
||||
pub flags: BitFlags<BlockFlag>,
|
||||
pub color: Color,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue