Skip to content

Commit

Permalink
feat: optionally derive serde traits
Browse files Browse the repository at this point in the history
  • Loading branch information
lus committed Apr 4, 2024
1 parent 323387a commit cd50ea3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ serde = { version = "1.0.197", optional = true, features = ["derive"] }
[features]
default = ["default-tls"]

hetzner = ["dep:serde", "dep:reqwest"]
hetzner = ["serde", "dep:reqwest"]

default-tls = ["reqwest?/default-tls"]
rustls-tls = ["reqwest?/rustls-tls"]
Expand Down
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ use std::{
str::FromStr,
};

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

use thiserror::Error;

#[cfg(feature = "hetzner")]
Expand Down Expand Up @@ -67,6 +70,7 @@ pub trait Provider {
/// Providers can provide a custom error type ([`Provider::CustomRetrieveError`]) and return it using [`RetrieveZoneError::Custom`] to extend the pool of well-defined errors.
/// Refer to the provider's documentation for more information.
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Error)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum RetrieveZoneError<T> {
/// Indicates that the DNS provider is not authorized to execute this action.
#[error("the DNS provider is unauthorized")]
Expand Down Expand Up @@ -99,6 +103,7 @@ pub trait CreateZone: Provider {
/// Providers can provide a custom error type ([`CreateZone::CustomCreateError`]) and return it using [`CreateZoneError::Custom`] to extend the pool of well-defined errors.
/// Refer to the provider's documentation for more information.
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Error)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum CreateZoneError<T> {
/// Indicates that the DNS provider is not authorized to execute this action.
#[error("the DNS provider is unauthorized")]
Expand Down Expand Up @@ -132,6 +137,7 @@ pub trait DeleteZone: Provider {
/// Providers can provide a custom error type ([`DeleteZone::CustomDeleteError`]) and return it using [`DeleteZoneError::Custom`] to extend the pool of well-defined errors.
/// Refer to the provider's documentation for more information.
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Error)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum DeleteZoneError<T> {
/// Indicates that the DNS provider is not authorized to execute this action.
#[error("the DNS provider is unauthorized")]
Expand All @@ -148,6 +154,7 @@ pub enum DeleteZoneError<T> {

/// Represents a DNS record value.
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum RecordData {
A(Ipv4Addr),
AAAA(Ipv6Addr),
Expand Down Expand Up @@ -261,6 +268,7 @@ impl RecordData {

/// Represents a DNS record.
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Record {
pub id: String,
pub host: String,
Expand Down Expand Up @@ -305,6 +313,7 @@ pub trait Zone {
/// Providers can provide a custom error type ([`Zone::CustomRetrieveError`]) and return it using [`RetrieveRecordError::Custom`] to extend the pool of well-defined errors.
/// Refer to the provider's documentation for more information.
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Error)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum RetrieveRecordError<T> {
/// Indicates that the DNS provider is not authorized to execute this action.
#[error("the DNS provider is unauthorized")]
Expand Down Expand Up @@ -339,6 +348,7 @@ pub trait CreateRecord: Zone {
/// Providers can provide a custom error type ([`CreateRecord::CustomCreateError`]) and return it using [`CreateRecordError::Custom`] to extend the pool of well-defined errors.
/// Refer to the provider's documentation for more information.
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Error)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum CreateRecordError<T> {
/// Indicates that the DNS provider is not authorized to execute this action.
#[error("the DNS provider is unauthorized")]
Expand Down Expand Up @@ -375,6 +385,7 @@ pub trait DeleteRecord: Zone {
/// Providers can provide a custom error type ([`DeleteRecord::CustomDeleteError`]) and return it using [`DeleteRecordError::Custom`] to extend the pool of well-defined errors.
/// Refer to the provider's documentation for more information.
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Error)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum DeleteRecordError<T> {
/// Indicates that the DNS provider is not authorized to execute this action.
#[error("the DNS provider is unauthorized")]
Expand Down

0 comments on commit cd50ea3

Please sign in to comment.