1#![warn(missing_docs)]
47#![no_std]
48#![forbid(unsafe_code)]
49
50macro_rules! code_name { () => { "cld" }}
55macro_rules! version { () => { "0.5.1" }}
56
57pub const NAME: &str = "CLD";
59
60pub const CODE_NAME: &str = code_name!();
62
63pub const ID: &str = concat!(
65 "2cf37bc5-bfd0f66b-7cbf8382-4eb3e3cb-d2a9e255-ef4858eb-07c2ffe7-0e0b66a7-",
66 "b29673a3-386a6335-9bf7dc3b-faad33d9-76db4b61-57f6a606-da001cbb-8ba95a71",
67);
68
69pub const VERSION: &str = version!();
71
72pub const RELEASE_DATE: (u16, u8, u8) = (2023, 2, 22);
74
75pub const TAG: &str = concat!(code_name!(), "::2cf37bc5::", version!());
77
78#[macro_use]
83extern crate alloc;
84
85#[cfg(feature="std")]
86extern crate std;
87
88macro_rules! err {
90 () => {
91 $crate::Error::new(line!(), module_path!(), None)
92 };
93 ($s: literal) => {
94 $crate::Error::new(line!(), module_path!(), Some(alloc::borrow::Cow::Borrowed($s)))
95 };
96 ($s: literal, $($arg: tt)+) => {
97 $crate::Error::new(line!(), module_path!(), Some(alloc::borrow::Cow::Owned(alloc::format!($s, $($arg)+))))
98 };
99 ($expr: expr, $err: expr) => {
100 $expr.ok_or_else(|| $err)
101 };
102}
103
104#[allow(unused_macros)]
106macro_rules! err_from {
107 ($($s: tt)+) => {
108 $crate::Error::new(line!(), module_path!(), Some(alloc::borrow::Cow::Borrowed(concat!($($s)+))))
109 };
110}
111
112macro_rules! map_err {
114 ($e: expr) => {
115 $e.map_err(|e| err!("{}", e))
116 };
117 ($expr: expr, $err: expr) => {
118 $expr.map_err(|_| $err)
119 };
120}
121
122#[test]
123fn test_macro_err() {
124 use alloc::borrow::Cow;
125
126 macro_rules! s_test { () => { "test" }}
127
128 fn eq(first: Error, second: Error) -> bool {
129 first.line() == second.line() && first.module_path() == second.module_path() && first.msg() == second.msg()
130 }
131
132 assert!(eq(err!(), Error::new(line!(), module_path!(), None)));
133 assert!(eq(err!("test"), Error::new(line!(), module_path!(), Some(Cow::Borrowed(s_test!())))));
134 assert!(eq(err!("{s:?}", s=s_test!()), Error::new(line!(), module_path!(), Some(Cow::Owned(alloc::format!("{:?}", s_test!()))))));
135
136 assert!(eq(err_from!(s_test!(), s_test!()), Error::new(line!(), module_path!(), Some(Cow::Borrowed(concat!(s_test!(), s_test!()))))));
137 assert!(eq(err_from!("test"), map_err!(core::result::Result::<(), _>::Err(s_test!())).unwrap_err()));
138 assert!(eq(err_from!("test", "test"), Error::new(line!(), module_path!(), Some(Cow::Owned(s_test!().repeat(2))))));
139}
140
141pub mod version_info;
142
143mod cld;
144mod error;
145
146pub use self::{
147 cld::*,
148 error::*,
149};
150
151pub type Result<T> = core::result::Result<T, Error>;
153
154#[test]
155fn test_crate_version() {
156 assert_eq!(VERSION, env!("CARGO_PKG_VERSION"));
157}