Skip to main content

Contingency

Struct Contingency 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional 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: u64

Unix timestamp (seconds since epoch) of activation.

Implementations§

Source§

impl Contingency

Source

pub fn new() -> Self

Create a new contingency manager with no active contingency (normal mode).

Source

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.

Source

pub fn deactivate(&mut self)

Deactivate contingency mode, resetting to normal emission.

Source

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.

Source

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.

Source

pub fn emission_type_enum(&self) -> EmissionType

Get the EmissionType enum for the current contingency state.

Trait Implementations§

Source§

impl Clone for Contingency

Source§

fn clone(&self) -> Contingency

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Contingency

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Contingency

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.