From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- third_party/rust/plist/src/uid.rs | 97 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 third_party/rust/plist/src/uid.rs (limited to 'third_party/rust/plist/src/uid.rs') diff --git a/third_party/rust/plist/src/uid.rs b/third_party/rust/plist/src/uid.rs new file mode 100644 index 0000000000..f2e107993a --- /dev/null +++ b/third_party/rust/plist/src/uid.rs @@ -0,0 +1,97 @@ +use std::fmt; + +/// A plist `uid` value. These are found exclusively in plists created by `NSKeyedArchiver`. +#[derive(Clone, Copy, Eq, Hash, PartialEq)] +pub struct Uid { + value: u64, +} + +impl Uid { + /// Creates a new `Uid` containing the given value. + pub fn new(value: u64) -> Uid { + Uid { value } + } + + /// Returns the value as a `u64`. + pub fn get(self) -> u64 { + self.value + } +} + +impl fmt::Debug for Uid { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + self.value.fmt(f) + } +} + +#[cfg(feature = "serde")] +pub mod serde_impls { + use serde::{ + de::{Deserialize, Deserializer, Error, Visitor}, + ser::{Serialize, Serializer}, + }; + use std::fmt; + + use crate::Uid; + + pub const UID_NEWTYPE_STRUCT_NAME: &str = "PLIST-UID"; + + impl Serialize for Uid { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + serializer.serialize_newtype_struct(UID_NEWTYPE_STRUCT_NAME, &self.get()) + } + } + + struct UidNewtypeVisitor; + + impl<'de> Visitor<'de> for UidNewtypeVisitor { + type Value = Uid; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("a plist uid") + } + + fn visit_u64(self, v: u64) -> Result + where + E: Error, + { + UidU64Visitor.visit_u64(v) + } + + fn visit_newtype_struct(self, deserializer: D) -> Result + where + D: Deserializer<'de>, + { + deserializer.deserialize_u64(UidU64Visitor) + } + } + + struct UidU64Visitor; + + impl<'de> Visitor<'de> for UidU64Visitor { + type Value = Uid; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("a plist uid") + } + + fn visit_u64(self, v: u64) -> Result + where + E: Error, + { + Ok(Uid::new(v)) + } + } + + impl<'de> Deserialize<'de> for Uid { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + deserializer.deserialize_newtype_struct(UID_NEWTYPE_STRUCT_NAME, UidNewtypeVisitor) + } + } +} -- cgit v1.2.3