1use core::fmt::Debug;
4
5pub use nvim_oxi::api::opts;
6pub use nvim_oxi::api::types;
7use nvim_oxi::api::types::LogLevel;
8
9use crate::dict;
10
11pub trait Notifiable: Debug {
16 fn to_msg(&self) -> impl AsRef<str>;
17}
18
19impl<T: Notifiable + ?Sized> Notifiable for &T {
20 fn to_msg(&self) -> impl AsRef<str> {
21 (*self).to_msg()
22 }
23}
24
25impl Notifiable for color_eyre::Report {
26 fn to_msg(&self) -> impl AsRef<str> {
27 self.to_string()
28 }
29}
30
31impl Notifiable for String {
32 fn to_msg(&self) -> impl AsRef<str> {
33 self
34 }
35}
36
37impl Notifiable for &str {
38 fn to_msg(&self) -> impl AsRef<str> {
39 self
40 }
41}
42
43pub fn error<N: Notifiable>(notifiable: N) {
45 if let Err(err) = nvim_oxi::api::notify(notifiable.to_msg().as_ref(), LogLevel::Error, &dict! {}) {
46 nvim_oxi::dbg!(format!("cannot notify error | msg={notifiable:?} error={err:#?}"));
47 }
48}
49
50pub fn warn<N: Notifiable>(notifiable: N) {
52 if let Err(err) = nvim_oxi::api::notify(notifiable.to_msg().as_ref(), LogLevel::Warn, &dict! {}) {
53 nvim_oxi::dbg!(format!("cannot notify warning | msg={notifiable:?} error={err:#?}"));
54 }
55}