yellowstone_vixen_parser/
lib.rs1#![deny(
2 clippy::disallowed_methods,
3 clippy::suspicious,
4 clippy::style,
5 clippy::clone_on_ref_ptr,
6 missing_debug_implementations,
7 missing_copy_implementations
8)]
9#![warn(clippy::pedantic, missing_docs)]
10#![allow(clippy::module_name_repetitions)]
11#![allow(missing_docs, clippy::missing_errors_doc, clippy::missing_panics_doc)]
13
14pub use error::*;
15
16mod helpers;
17
18#[cfg(feature = "block-meta")]
19pub mod block_meta;
20
21#[cfg(feature = "slot")]
22pub mod slot;
23
24#[cfg(feature = "token-extensions")]
25pub mod token_extension_program;
26#[cfg(feature = "token-program")]
27pub mod token_program;
28
29mod error {
30 use std::{borrow::Cow, error::Error as StdError};
31
32 pub type Result<T, E = Error> = std::result::Result<T, E>;
33
34 #[derive(Debug, thiserror::Error)]
35 #[error("{message}")]
36 pub struct Error {
37 message: Cow<'static, str>,
38 #[source]
39 inner: Option<Box<dyn StdError + Send + Sync + 'static>>,
40 }
41
42 impl Error {
43 pub(crate) fn new<M: Into<Cow<'static, str>>>(message: M) -> Self {
44 Self {
45 message: message.into(),
46 inner: None,
47 }
48 }
49
50 pub(crate) fn from_inner<
51 M: Into<Cow<'static, str>>,
52 T: Into<Box<dyn StdError + Send + Sync + 'static>>,
53 >(
54 message: M,
55 inner: T,
56 ) -> Self {
57 Self {
58 message: message.into(),
59 inner: Some(inner.into()),
60 }
61 }
62 }
63
64 pub(crate) trait ResultExt<T, E: StdError + Sized + Send + Sync + 'static>:
65 Sized
66 {
67 fn parse_err(self, message: &'static str) -> Result<T, Error>;
68 }
69
70 impl<T, E: StdError + Sized + Send + Sync + 'static> ResultExt<T, E> for Result<T, E> {
71 fn parse_err(self, message: &'static str) -> Result<T, Error> {
72 self.map_err(|e| Error::from_inner(message, e))
73 }
74 }
75}