nvim_api/types/
command_infos.rs1use nvim_types::{
2 conversion::{self, FromObject},
3 serde::Deserializer,
4 Function,
5 Object,
6};
7use serde::{
8 de::{self, Error},
9 Deserialize,
10};
11
12use super::{CommandAddr, CommandArgs, CommandNArgs, CommandRange};
13
14#[non_exhaustive]
15#[derive(Clone, Debug, Eq, PartialEq, Hash, Deserialize)]
16pub struct CommandInfos {
17 pub addr: Option<CommandAddr>,
19
20 pub bang: bool,
22
23 pub bar: bool,
25
26 pub callback: Option<Function<CommandArgs, ()>>,
28
29 pub complete: Option<String>,
31
32 pub complete_arg: Option<String>,
34
35 #[serde(deserialize_with = "parse_count")]
37 pub count: Option<u32>,
38
39 pub definition: Option<String>,
41
42 pub keepscript: bool,
45
46 pub name: String,
48
49 #[serde(default)]
51 pub nargs: CommandNArgs,
52
53 pub range: Option<CommandRange>,
55
56 pub register: bool,
59
60 pub script_id: i32,
62}
63
64fn parse_count<'de, D>(deserializer: D) -> Result<Option<u32>, D::Error>
65where
66 D: de::Deserializer<'de>,
67{
68 Option::<String>::deserialize(deserializer)?
69 .map(|count| {
70 count.parse().map_err(|err: std::num::ParseIntError| {
71 D::Error::custom(err.to_string())
72 })
73 })
74 .transpose()
75}
76
77impl FromObject for CommandInfos {
78 fn from_object(obj: Object) -> Result<Self, conversion::Error> {
79 Self::deserialize(Deserializer::new(obj)).map_err(Into::into)
80 }
81}