#[non_exhaustive]pub struct Contingency {
pub contingency_type: Option<ContingencyType>,
pub reason: Option<String>,
pub activated_at: Option<String>,
pub timestamp: u64,
}Expand description
Contingency manager for NF-e emission.
Manages activation and deactivation of contingency mode, used when the primary SEFAZ authorizer is unavailable. Supports SVC-AN, SVC-RS, and offline contingency types.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.contingency_type: Option<ContingencyType>The active contingency type, or None when in normal mode.
reason: Option<String>Justification reason for entering contingency (15-256 chars).
activated_at: Option<String>ISO-8601 timestamp when contingency was activated.
timestamp: u64Unix timestamp (seconds since epoch) of activation.
Implementations§
Source§impl Contingency
impl Contingency
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new contingency manager with no active contingency (normal mode).
Sourcepub fn activate(
&mut self,
contingency_type: ContingencyType,
reason: &str,
) -> Result<(), FiscalError>
pub fn activate( &mut self, contingency_type: ContingencyType, reason: &str, ) -> Result<(), FiscalError>
Activate contingency mode with the given type and justification reason.
The reason is trimmed and must be between 15 and 256 UTF-8 characters (inclusive). On success, the contingency is activated with the current UTC timestamp.
§Errors
Returns FiscalError::Contingency if the trimmed reason is shorter
than 15 characters or longer than 256 characters.
Sourcepub fn deactivate(&mut self)
pub fn deactivate(&mut self)
Deactivate contingency mode, resetting to normal emission.
Sourcepub fn load(json: &str) -> Result<Self, FiscalError>
pub fn load(json: &str) -> Result<Self, FiscalError>
Load contingency state from a JSON string.
Expected JSON format:
{"motive":"reason","timestamp":1480700623,"type":"SVCAN","tpEmis":6}§Errors
Returns FiscalError::Contingency if the JSON cannot be parsed or
contains an unrecognized contingency type.
Sourcepub fn emission_type(&self) -> u8
pub fn emission_type(&self) -> u8
Get the emission type code for the current contingency state.
Returns 1 (normal) if no contingency is active, or 6 (SVC-AN),
7 (SVC-RS), or 9 (offline) when contingency is active.
Sourcepub fn emission_type_enum(&self) -> EmissionType
pub fn emission_type_enum(&self) -> EmissionType
Get the EmissionType enum for the current contingency state.
Trait Implementations§
Source§impl Clone for Contingency
impl Clone for Contingency
Source§fn clone(&self) -> Contingency
fn clone(&self) -> Contingency
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more