From bdb360ed1d25fa42b3743723321be298e500519f Mon Sep 17 00:00:00 2001 From: thelearnerofcode Date: Sat, 11 Nov 2017 11:23:49 -0500 Subject: Support integer font size in config (#886) Fixes #882 --- src/config.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/config.rs b/src/config.rs index 768b5579..4cde0f0a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1260,28 +1260,28 @@ impl Default for Delta { } } -trait DeserializeFromF32 : Sized { - fn deserialize_from_f32<'a, D>(D) -> ::std::result::Result +trait DeserializeSize : Sized { + fn deserialize<'a, D>(D) -> ::std::result::Result where D: serde::de::Deserializer<'a>; } -impl DeserializeFromF32 for Size { - fn deserialize_from_f32<'a, D>(deserializer: D) -> ::std::result::Result +impl DeserializeSize for Size { + fn deserialize<'a, D>(deserializer: D) -> ::std::result::Result where D: serde::de::Deserializer<'a> { use std::marker::PhantomData; - struct FloatVisitor<__D> { + struct NumVisitor<__D> { _marker: PhantomData<__D>, } - impl<'a, __D> Visitor<'a> for FloatVisitor<__D> + impl<'a, __D> Visitor<'a> for NumVisitor<__D> where __D: serde::de::Deserializer<'a> { type Value = f64; fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str("f64") + f.write_str("f64 or u64") } fn visit_f64(self, value: f64) -> ::std::result::Result @@ -1289,10 +1289,16 @@ impl DeserializeFromF32 for Size { { Ok(value) } + + fn visit_u64(self, value: u64) -> ::std::result::Result + where E: ::serde::de::Error + { + Ok(value as f64) + } } deserializer - .deserialize_f64(FloatVisitor::{ _marker: PhantomData }) + .deserialize_any(NumVisitor::{ _marker: PhantomData }) .map(|v| Size::new(v as _)) } } @@ -1315,7 +1321,7 @@ pub struct Font { pub bold: FontDescription, // Font size in points - #[serde(deserialize_with="DeserializeFromF32::deserialize_from_f32")] + #[serde(deserialize_with="DeserializeSize::deserialize")] pub size: Size, /// Extra spacing per character -- cgit v1.2.3-54-g00ecf