Pumpkin/pumpkin-protocol/src/codec/optional_int.rs
Alexander Medvedev fb13004b47 fix: apply clippy lints to workspace
also add contributors to /pumpkin command

Co-Authored-By: Fyor <90567841+fyordev@users.noreply.github.com>
Co-Authored-By: MartV0 <34748938+martv0@users.noreply.github.com>
Co-Authored-By: FabseGP <fabsegp@fabseman.space>
2026-01-28 00:52:47 +01:00

15 lines
418 B
Rust

use serde::{Serialize, Serializer};
use crate::codec::var_int::VarInt;
#[derive(Debug, Clone, Copy)]
pub struct OptionalInt(pub Option<i32>);
impl Serialize for OptionalInt {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
// Vanilla logic: empty is 0, otherwise value + 1
let val = self.0.map_or(0, |id| id + 1);
VarInt(val).serialize(serializer)
}
}