Skip to content

Commit

Permalink
Seal naming trait
Browse files Browse the repository at this point in the history
  • Loading branch information
leftmostcat committed Apr 15, 2024
1 parent b5d79c0 commit 4635133
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
9 changes: 7 additions & 2 deletions src/types/get_folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use serde::Deserialize;
use xml_struct::XmlSerialize;

use crate::{
BaseFolderId, Folder, FolderShape, Operation, OperationResponse, ResponseClass, MESSAGES_NS_URI,
types::sealed::NamedStructure, BaseFolderId, Folder, FolderShape, Operation, OperationResponse,
ResponseClass, MESSAGES_NS_URI,
};

/// A request to get information on one or more folders.
Expand All @@ -21,7 +22,9 @@ pub struct GetFolder {

impl Operation for GetFolder {
type Response = GetFolderResponse;
}

impl NamedStructure for GetFolder {
fn name() -> &'static str {
"GetFolder"
}
Expand All @@ -36,7 +39,9 @@ pub struct GetFolderResponse {
pub response_messages: ResponseMessages,
}

impl OperationResponse for GetFolderResponse {
impl OperationResponse for GetFolderResponse {}

impl NamedStructure for GetFolderResponse {
fn name() -> &'static str {
"GetFolderResponse"
}
Expand Down
12 changes: 7 additions & 5 deletions src/types/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
use serde::Deserialize;
use xml_struct::XmlSerialize;

pub trait Operation: XmlSerialize {
pub trait Operation: XmlSerialize + sealed::NamedStructure {
type Response: OperationResponse;

fn name() -> &'static str;
}

pub trait OperationResponse: for<'de> Deserialize<'de> {
fn name() -> &'static str;
pub trait OperationResponse: for<'de> Deserialize<'de> + sealed::NamedStructure {}

pub(super) mod sealed {
pub trait NamedStructure {
fn name() -> &'static str;
}
}
14 changes: 10 additions & 4 deletions src/types/soap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ pub struct FaultDetail {
mod tests {
use serde::Deserialize;

use crate::{Error, OperationResponse};
use crate::{types::sealed::NamedStructure, Error, OperationResponse};

use super::Envelope;

Expand All @@ -467,7 +467,9 @@ mod tests {
_other_field: (),
}

impl OperationResponse for SomeStruct {
impl OperationResponse for SomeStruct {}

impl NamedStructure for SomeStruct {
fn name() -> &'static str {
"Foo"
}
Expand All @@ -492,7 +494,9 @@ mod tests {
#[derive(Debug, Deserialize)]
struct Foo;

impl OperationResponse for Foo {
impl OperationResponse for Foo {}

impl NamedStructure for Foo {
fn name() -> &'static str {
"Foo"
}
Expand Down Expand Up @@ -543,7 +547,9 @@ mod tests {
#[derive(Debug, Deserialize)]
struct Foo;

impl OperationResponse for Foo {
impl OperationResponse for Foo {}

impl NamedStructure for Foo {
fn name() -> &'static str {
"Foo"
}
Expand Down
10 changes: 7 additions & 3 deletions src/types/sync_folder_hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use serde::Deserialize;
use xml_struct::XmlSerialize;

use crate::{
BaseFolderId, Folder, FolderId, FolderShape, Operation, OperationResponse, ResponseClass,
MESSAGES_NS_URI,
types::sealed::NamedStructure, BaseFolderId, Folder, FolderId, FolderShape, Operation,
OperationResponse, ResponseClass, MESSAGES_NS_URI,
};

/// The request for update regarding the folder hierarchy in a mailbox.
Expand All @@ -23,7 +23,9 @@ pub struct SyncFolderHierarchy {

impl Operation for SyncFolderHierarchy {
type Response = SyncFolderHierarchyResponse;
}

impl NamedStructure for SyncFolderHierarchy {
fn name() -> &'static str {
"SyncFolderHierarchy"
}
Expand All @@ -38,7 +40,9 @@ pub struct SyncFolderHierarchyResponse {
pub response_messages: ResponseMessages,
}

impl OperationResponse for SyncFolderHierarchyResponse {
impl OperationResponse for SyncFolderHierarchyResponse {}

impl NamedStructure for SyncFolderHierarchyResponse {
fn name() -> &'static str {
"SyncFolderHierarchyResponse"
}
Expand Down

0 comments on commit 4635133

Please sign in to comment.