on master help sign in
Use serde attribute to rename to lowercase
17473b5Gokul Soumya
helix-view/src/graphics.rs+3−27
@@ -1,12 +1,12 @@
1−use anyhow::{anyhow, Error};
2use bitflags::bitflags;
1use bitflags::bitflags;
3−use serde::de::{self, Deserialize, Deserializer};
2+use serde::Deserialize;
4use std::{
3use std::{
5 cmp::{max, min},
4 cmp::{max, min},
6 str::FromStr,
5 str::FromStr,
7};
6};
8
7
9−#[derive(Debug, Clone, Copy, PartialEq)]
8+#[derive(Debug, Clone, Copy, PartialEq, Deserialize)]
9+#[serde(rename_all = "lowercase")]
10/// UNSTABLE
10/// UNSTABLE
11pub enum CursorKind {
11pub enum CursorKind {
12 /// █
12 /// █
@@ -25,30 +25,6 @@ impl Default for CursorKind {
25 }
25 }
26}
26}
27
27
28−impl FromStr for CursorKind {
29− type Err = Error;
30−
31− fn from_str(s: &str) -> Result<Self, Self::Err> {
32− match s {
33− "bar" => Ok(Self::Bar),
34− "block" => Ok(Self::Block),
35− "underline" => Ok(Self::Underline),
36− _ => Err(anyhow!("Invalid cursor '{}'", s)),
37− }
38− }
39−}
40−
41−// toml deserializer doesn't seem to recognize string as enum
42−impl<'de> Deserialize<'de> for CursorKind {
43− fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
44− where
45− D: Deserializer<'de>,
46− {
47− let s = String::deserialize(deserializer)?;
48− s.parse().map_err(de::Error::custom)
49− }
50−}
51−
52#[derive(Debug, Clone, PartialEq, Eq, Hash)]
28#[derive(Debug, Clone, PartialEq, Eq, Hash)]
53pub struct Margin {
29pub struct Margin {
54 pub vertical: u16,
30 pub vertical: u16,