1
0
mirror of https://github.com/Sebekerga/native_api_1c.git synced 2025-06-16 23:47:43 +02:00

change all errors to darling::Error

This commit is contained in:
Kozlov Maxim
2023-11-06 00:49:19 +06:00
parent faea246425
commit 1af4d759c2
8 changed files with 89 additions and 89 deletions

View File

@ -1,14 +1,10 @@
use proc_macro2::Span;
use proc_macro2::{LexError, TokenStream};
use proc_macro2::LexError;
use syn::Ident;
use self::macros::tkn_err_inner;
pub mod macros {
macro_rules! tkn_err_inner {
($str:expr, $span:expr) => {{
let err_inner: proc_macro2::TokenStream =
syn::Error::new($span, $str).to_compile_error().into();
let err_inner: darling::Error = darling::Error::custom($str).with_span($span);
err_inner
}};
}
@ -25,10 +21,6 @@ pub mod macros {
const IDENT_OPTION_ERR: &str = "Unable to get ident from option";
pub fn ident_option_to_token_err(ident: Option<&Ident>) -> Result<&Ident, TokenStream> {
ident.ok_or(tkn_err_inner!(IDENT_OPTION_ERR, Span::call_site()))
}
pub fn ident_option_to_darling_err(ident: Option<&Ident>) -> Result<&Ident, darling::Error> {
ident.ok_or_else(|| darling::Error::custom(IDENT_OPTION_ERR))
}
@ -36,16 +28,11 @@ pub fn ident_option_to_darling_err(ident: Option<&Ident>) -> Result<&Ident, darl
pub fn str_literal_token(
str_literal: &str,
err_ident: &Ident,
) -> Result<proc_macro2::TokenStream, TokenStream> {
let token: Result<TokenStream, TokenStream> =
format!(r#""{}""#, str_literal)
.parse()
.map_err(|e: LexError| {
let token2: TokenStream =
Err(syn::Error::new(err_ident.span(), format!("LexErr: {}", e))
.to_compile_error())
.unwrap();
token2
});
token
) -> Result<proc_macro2::TokenStream, darling::Error> {
format!(r#""{}""#, str_literal)
.parse()
.map_err(|e: LexError| {
darling::Error::custom(format!("Unable to parse string literal: {}", e))
.with_span(err_ident)
})
}