Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SubscriptionInformation struct to usubscription #179

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/core/usubscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,41 @@ pub use crate::up_core_api::usubscription::{

use crate::{UStatus, UUri};

// Tracks information for the SubscriptionCache
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use triple forward slashes for doc comments

Suggested change
// Tracks information for the SubscriptionCache
/// Tracks information for the SubscriptionCache

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to expand this a bit with a code usage example a in triple tick block, e.g.

/// ```
/// // put the usage here
/// ```

that way it'll be compiled and tested.

pub struct SubscriptionInformation {
pub topic: UUri,
pub subscriber: SubscriberInfo,
pub status: SubscriptionStatus,
pub attributes: SubscribeAttributes,
pub config: EventDeliveryConfig,
}

impl Eq for SubscriptionInformation {}

impl PartialEq for SubscriptionInformation {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some comment explaining the choice to use subscriber as the only member to check equality on would be good.

fn eq(&self, other: &Self) -> bool {
self.subscriber == other.subscriber
}
}

impl Hash for SubscriptionInformation {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest adding similar level of doc comment and doc example as below

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same sort of comment as above -- good to explain here why only the subscriber is being used in the Hash.

fn hash<H: Hasher>(&self, state: &mut H) {
self.subscriber.hash(state);
}
}

impl Clone for SubscriptionInformation {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to explicitly impl Clone in this case, since all the members are just having .clone() in turn called on them?

Reference this Rust Playground snippet.

Would it suffice to derive Clone for SubscriptionInformation as shown in the snippet?

fn clone(&self) -> Self {
Self {
topic: self.topic.clone(),
subscriber: self.subscriber.clone(),
status: self.status.clone(),
attributes: self.attributes.clone(),
config: self.config.clone(),
}
}
}

impl Hash for SubscriberInfo {
/// Creates a hash value based on the URI property.
///
Expand Down