LocatedError: For a given error enum {Name} generate a struct called Located{Name} that
carries the Span
(the error location in the input stream) info along the
error. Additionally, generates [From
] for nom
library errors, external,
and another located errors.
```rust use netgauzeserdemacros::LocatedError;
pub enum ExtendedCommunityParsingError { NomError(#[fromnom] nom::error::ErrorKind), CommunityError(#[fromlocated(module = "self")] CommunityParsingError), UndefinedCapabilityCode(#[from_external] UndefinedBgpCapabilityCode), }
pub enum CommunityParsingError { NomError(#[from_nom] nom::error::ErrorKind), }
pub struct UndefinedBgpCapabilityCode(pub u8);
fn test() { let span = Span::new(&[1, 2, 3]); // LocatedExtendedCommunityParsingError is generated by LocatedError let _located = LocatedExtendedCommunityParsingError::new( span, ExtendedCommunityParsingError::UndefinedCapabilityCode(UndefinedBgpCapabilityCode(1))); } ```
WritingError: Decorate an enum
as an error for serializing binary protocol
provides the following decorations for any members of the enum.
#[from_std_io_error]
automatically generate [From
] implementation
from [std::io::Error
] to a [String
].#[from]
, automatically generates a [From
] implementation for a given
type.Example:
```rust use netgauzeserdemacros::WritingError;
pub enum BgpMessageWritingError { /// std::io::Error will be converted to this value StdIOError(#[fromstdio_error] String),
/// BgpOpenMessageWritingError will be converted to this value
OpenError(#[from] BgpOpenMessageWritingError),
} ```