Skip to content

Commit

Permalink
Derive Clone for types and force Debug for operations/responses (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobypilling authored Oct 28, 2024
1 parent 9a54b74 commit 8918191
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 64 deletions.
52 changes: 26 additions & 26 deletions src/types/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub(crate) const TYPES_NS_URI: &str = "http://schemas.microsoft.com/exchange/ser
/// The folder properties which should be included in the response.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/foldershape>.
#[derive(Debug, Default, XmlSerialize)]
#[derive(Clone, Debug, Default, XmlSerialize)]
pub struct FolderShape {
#[xml_struct(ns_prefix = "t")]
pub base_shape: BaseShape,
Expand All @@ -25,7 +25,7 @@ pub struct FolderShape {
/// The item properties which should be included in the response.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/itemshape>.
#[derive(Debug, Default, XmlSerialize)]
#[derive(Clone, Debug, Default, XmlSerialize)]
pub struct ItemShape {
/// The base set of properties to include, which may be extended by other
/// fields.
Expand All @@ -49,7 +49,7 @@ pub struct ItemShape {
}

/// An identifier for a property on an Exchange entity.
#[derive(Debug, XmlSerialize)]
#[derive(Clone, Debug, XmlSerialize)]
#[xml_struct(variant_ns_prefix = "t")]
pub enum PathToElement {
/// An identifier for an extended MAPI property.
Expand Down Expand Up @@ -131,7 +131,7 @@ pub enum PathToElement {
// which follows the same structure. However, xml-struct doesn't currently
// support using a nested structure to define an element's attributes, see
// https://github.com/thunderbird/xml-struct-rs/issues/9
#[derive(Debug, XmlSerialize)]
#[derive(Clone, Debug, XmlSerialize)]
pub struct ExtendedFieldURI {
/// A well-known identifier for a property set.
#[xml_struct(attribute)]
Expand Down Expand Up @@ -241,7 +241,7 @@ pub enum ResponseClass {
/// any.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/responsecode>
#[derive(Debug, Deserialize, PartialEq)]
#[derive(Clone, Debug, Deserialize, PartialEq)]
pub struct ResponseCode(pub String);

impl<T> From<T> for ResponseCode
Expand All @@ -254,7 +254,7 @@ where
}

/// An identifier for an Exchange folder.
#[derive(Debug, XmlSerialize)]
#[derive(Clone, Debug, XmlSerialize)]
#[xml_struct(variant_ns_prefix = "t")]
pub enum BaseFolderId {
/// An identifier for an arbitrary folder.
Expand Down Expand Up @@ -284,7 +284,7 @@ pub enum BaseFolderId {
/// The unique identifier of a folder.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/folderid>
#[derive(Debug, Deserialize, PartialEq, XmlSerialize)]
#[derive(Clone, Debug, Deserialize, PartialEq, XmlSerialize)]
pub struct FolderId {
#[serde(rename = "@Id")]
pub id: String,
Expand All @@ -297,7 +297,7 @@ pub struct FolderId {
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/itemids>
// N.B.: Commented-out variants are not yet implemented.
#[derive(Debug, XmlSerialize)]
#[derive(Clone, Debug, XmlSerialize)]
#[xml_struct(variant_ns_prefix = "t")]
pub enum BaseItemId {
/// An identifier for a standard Exchange item.
Expand Down Expand Up @@ -327,7 +327,7 @@ pub struct ItemId {
}

/// The representation of a folder in an EWS operation.
#[derive(Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
pub enum Folder {
/// A calendar folder in a mailbox.
///
Expand Down Expand Up @@ -397,7 +397,7 @@ pub enum Folder {
}

/// An array of items.
#[derive(Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
pub struct Items {
#[serde(rename = "$value", default)]
pub inner: Vec<RealItem>,
Expand All @@ -407,7 +407,7 @@ pub struct Items {
/// Exchange item.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/items>
#[derive(Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
pub enum RealItem {
Message(Message),
}
Expand All @@ -417,7 +417,7 @@ pub enum RealItem {
/// See [`Attachment::ItemAttachment`] for details.
// N.B.: Commented-out variants are not yet implemented.
#[non_exhaustive]
#[derive(Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
pub enum AttachmentItem {
// Item(Item),
Message(Message),
Expand All @@ -433,7 +433,7 @@ pub enum AttachmentItem {
/// A date and time with second precision.
// `time` provides an `Option<OffsetDateTime>` deserializer, but it does not
// work with map fields which may be omitted, as in our case.
#[derive(Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
pub struct DateTime(#[serde(with = "time::serde::iso8601")] pub time::OffsetDateTime);

impl XmlSerialize for DateTime {
Expand All @@ -458,7 +458,7 @@ impl XmlSerialize for DateTime {
/// An email message.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/message-ex15websvcsotherref>
#[derive(Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct Message {
/// The MIME content of the item.
Expand Down Expand Up @@ -531,7 +531,7 @@ pub struct Message {
/// A list of attachments.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/attachments-ex15websvcsotherref>
#[derive(Debug, Deserialize, XmlSerialize)]
#[derive(Clone, Debug, Deserialize, XmlSerialize)]
pub struct Attachments {
#[serde(rename = "$value")]
#[xml_struct(flatten)]
Expand All @@ -540,7 +540,7 @@ pub struct Attachments {

/// A newtype around a vector of `Recipient`s, that is deserialized using
/// `deserialize_recipients`.
#[derive(Debug, Default, Deserialize, XmlSerialize)]
#[derive(Clone, Debug, Default, Deserialize, XmlSerialize)]
pub struct ArrayOfRecipients(
#[serde(deserialize_with = "deserialize_recipients")] pub Vec<Recipient>,
);
Expand All @@ -560,7 +560,7 @@ impl DerefMut for ArrayOfRecipients {
}

/// A single mailbox.
#[derive(Debug, Deserialize, XmlSerialize, PartialEq)]
#[derive(Clone, Debug, Deserialize, XmlSerialize, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct Recipient {
#[xml_struct(ns_prefix = "t")]
Expand All @@ -580,7 +580,7 @@ fn deserialize_recipients<'de, D>(deserializer: D) -> Result<Vec<Recipient>, D::
where
D: Deserializer<'de>,
{
#[derive(Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
struct MailboxSequence {
mailbox: Vec<Mailbox>,
Expand All @@ -596,7 +596,7 @@ where
}

/// A list of Internet Message Format headers.
#[derive(Debug, Deserialize, XmlSerialize)]
#[derive(Clone, Debug, Deserialize, XmlSerialize)]
#[serde(rename_all = "PascalCase")]
pub struct InternetMessageHeaders {
pub internet_message_header: Vec<InternetMessageHeader>,
Expand Down Expand Up @@ -672,7 +672,7 @@ pub enum Importance {
/// A string value.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/string>
#[derive(Debug, Deserialize, XmlSerialize)]
#[derive(Clone, Debug, Deserialize, XmlSerialize)]
#[serde(rename_all = "PascalCase")]
pub struct StringElement {
/// The string content.
Expand All @@ -694,7 +694,7 @@ pub enum Sensitivity {
/// The body of an item.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/body>
#[derive(Debug, Deserialize, XmlSerialize)]
#[derive(Clone, Debug, Deserialize, XmlSerialize)]
pub struct Body {
/// The content type of the body.
#[serde(rename = "@BodyType")]
Expand Down Expand Up @@ -727,7 +727,7 @@ pub enum BodyType {
/// An attachment to an Exchange item.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/attachments-ex15websvcsotherref>
#[derive(Debug, Deserialize, XmlSerialize)]
#[derive(Clone, Debug, Deserialize, XmlSerialize)]
pub enum Attachment {
/// An attachment containing an Exchange item.
///
Expand Down Expand Up @@ -843,7 +843,7 @@ pub enum Attachment {
/// An identifier for an attachment.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/attachmentid>
#[derive(Debug, Deserialize, XmlSerialize)]
#[derive(Clone, Debug, Deserialize, XmlSerialize)]
pub struct AttachmentId {
/// A unique identifier for the attachment.
#[serde(rename = "@Id")]
Expand All @@ -865,7 +865,7 @@ pub struct AttachmentId {
/// Mail Extensions).
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/mimecontent>
#[derive(Debug, Deserialize, XmlSerialize)]
#[derive(Clone, Debug, Deserialize, XmlSerialize)]
pub struct MimeContent {
/// The character set of the MIME content if it contains [RFC 2045]-encoded
/// text.
Expand All @@ -884,7 +884,7 @@ pub struct MimeContent {
/// The headers of an Exchange item's MIME content.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/internetmessageheader>
#[derive(Debug, Deserialize, XmlSerialize)]
#[derive(Clone, Debug, Deserialize, XmlSerialize)]
#[serde(rename_all = "PascalCase")]
pub struct InternetMessageHeader {
/// The name of the header.
Expand All @@ -906,7 +906,7 @@ pub struct InternetMessageHeader {
/// provided as additional fields of this structure.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/messagexml>
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct MessageXml {
/// A text representation of the contents of the field.
Expand Down
16 changes: 8 additions & 8 deletions src/types/create_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
/// The action an Exchange server will take upon creating a `Message` item.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/createitem#messagedisposition-attribute>
#[derive(Debug, XmlSerialize)]
#[derive(Clone, Debug, XmlSerialize)]
#[xml_struct(text)]
pub enum MessageDisposition {
SaveOnly,
Expand All @@ -24,7 +24,7 @@ pub enum MessageDisposition {
/// A request to create (and optionally send) one or more Exchange item(s).
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/createitem>
#[derive(Debug, XmlSerialize)]
#[derive(Clone, Debug, XmlSerialize)]
#[xml_struct(default_ns = MESSAGES_NS_URI)]
pub struct CreateItem {
/// The action the Exchange server will take upon creating this item.
Expand Down Expand Up @@ -55,7 +55,7 @@ pub struct CreateItem {
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/items>
// N.B.: Commented-out variants are not yet implemented.
#[non_exhaustive]
#[derive(Debug, XmlSerialize)]
#[derive(Clone, Debug, XmlSerialize)]
#[xml_struct(variant_ns_prefix = "t")]
pub enum Item {
// Item(Item),
Expand All @@ -79,7 +79,7 @@ pub enum Item {
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/message-ex15websvcsotherref>
///
/// [`common::message`]: crate::Message
#[derive(Debug, Default, XmlSerialize)]
#[derive(Clone, Debug, Default, XmlSerialize)]
pub struct Message {
/// The MIME content of the item.
#[xml_struct(ns_prefix = "t")]
Expand Down Expand Up @@ -107,7 +107,7 @@ pub struct Message {
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/extendedproperty>
#[allow(non_snake_case)]
#[derive(Debug, XmlSerialize)]
#[derive(Clone, Debug, XmlSerialize)]
pub struct ExtendedProperty {
#[xml_struct(ns_prefix = "t")]
pub extended_field_URI: ExtendedFieldURI,
Expand All @@ -129,7 +129,7 @@ impl EnvelopeBodyContents for CreateItem {
/// A response to a [`CreateItem`] request.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/createitemresponse>
#[derive(Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct CreateItemResponse {
pub response_messages: ResponseMessages,
Expand All @@ -143,13 +143,13 @@ impl EnvelopeBodyContents for CreateItemResponse {
}
}

#[derive(Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct ResponseMessages {
pub create_item_response_message: Vec<CreateItemResponseMessage>,
}

#[derive(Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct CreateItemResponseMessage {
/// The status of the corresponding request, i.e. whether it succeeded or
Expand Down
10 changes: 5 additions & 5 deletions src/types/get_folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
/// A request to get information on one or more folders.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/getfolder>
#[derive(Debug, XmlSerialize)]
#[derive(Clone, Debug, XmlSerialize)]
#[xml_struct(default_ns = MESSAGES_NS_URI)]
pub struct GetFolder {
/// A description of the information to be included in the response for each
Expand All @@ -37,7 +37,7 @@ impl EnvelopeBodyContents for GetFolder {
/// A response to a [`GetFolder`] request.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/getfolderresponse>
#[derive(Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct GetFolderResponse {
pub response_messages: ResponseMessages,
Expand All @@ -54,7 +54,7 @@ impl EnvelopeBodyContents for GetFolderResponse {
/// A collection of responses for individual entities within a request.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/responsemessages>
#[derive(Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct ResponseMessages {
pub get_folder_response_message: Vec<GetFolderResponseMessage>,
Expand All @@ -63,7 +63,7 @@ pub struct ResponseMessages {
/// A response to a request for an individual folder within a [`GetFolder`] operation.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/getfolderresponsemessage>
#[derive(Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct GetFolderResponseMessage {
/// The status of the corresponding request, i.e. whether it succeeded or
Expand All @@ -78,7 +78,7 @@ pub struct GetFolderResponseMessage {
/// A collection of information on Exchange folders.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/folders-ex15websvcsotherref>
#[derive(Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
pub struct Folders {
#[serde(rename = "$value")]
pub inner: Vec<Folder>,
Expand Down
8 changes: 4 additions & 4 deletions src/types/get_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
/// calendar events, or contacts.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/getitem>
#[derive(Debug, XmlSerialize)]
#[derive(Clone, Debug, XmlSerialize)]
#[xml_struct(default_ns = MESSAGES_NS_URI)]
pub struct GetItem {
/// A description of the information to be included in the response for each
Expand Down Expand Up @@ -42,7 +42,7 @@ impl EnvelopeBodyContents for GetItem {
/// A response to a [`GetItem`] request.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/getitemresponse>
#[derive(Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct GetItemResponse {
pub response_messages: ResponseMessages,
Expand All @@ -56,13 +56,13 @@ impl EnvelopeBodyContents for GetItemResponse {
}
}

#[derive(Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct ResponseMessages {
pub get_item_response_message: Vec<GetItemResponseMessage>,
}

#[derive(Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct GetItemResponseMessage {
/// The status of the corresponding request, i.e. whether it succeeded or
Expand Down
Loading

0 comments on commit 8918191

Please sign in to comment.