Skip to content

Commit

Permalink
separate qosbuilder trait
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Mar 25, 2024
1 parent 1945492 commit 48d8d77
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
8 changes: 7 additions & 1 deletion zenoh/src/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::prelude::*;
use crate::sample::SourceInfo;
use crate::sample_builder::{
DeleteSampleBuilder, DeleteSampleBuilderTrait, PutSampleBuilder, PutSampleBuilderTrait,
SampleBuilder, SampleBuilderTrait,
QoSBuilderTrait, SampleBuilder, SampleBuilderTrait,
};
use crate::Id;
use crate::SessionRef;
Expand Down Expand Up @@ -287,7 +287,9 @@ impl SampleBuilderTrait for ReplySampleBuilder<'_> {
..self
}
}
}

impl QoSBuilderTrait for ReplySampleBuilder<'_> {
fn congestion_control(self, congestion_control: CongestionControl) -> Self {
Self {
sample_builder: self.sample_builder.congestion_control(congestion_control),
Expand Down Expand Up @@ -366,7 +368,9 @@ impl SampleBuilderTrait for ReplyBuilder<'_> {
..self
}
}
}

impl QoSBuilderTrait for ReplyBuilder<'_> {
fn congestion_control(self, congestion_control: CongestionControl) -> Self {
Self {
sample_builder: self.sample_builder.congestion_control(congestion_control),
Expand Down Expand Up @@ -464,7 +468,9 @@ impl SampleBuilderTrait for ReplyDelBuilder<'_> {
..self
}
}
}

impl QoSBuilderTrait for ReplyDelBuilder<'_> {
fn congestion_control(self, congestion_control: CongestionControl) -> Self {
Self {
sample_builder: self.sample_builder.congestion_control(congestion_control),
Expand Down
18 changes: 15 additions & 3 deletions zenoh/src/sample_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ use zenoh_core::Resolvable;
use zenoh_core::SyncResolve;
use zenoh_protocol::core::CongestionControl;

pub trait QoSBuilderTrait {
fn congestion_control(self, congestion_control: CongestionControl) -> Self;
fn priority(self, priority: Priority) -> Self;
fn express(self, is_express: bool) -> Self;
}

pub trait SampleBuilderTrait {
fn with_keyexpr<IntoKeyExpr>(self, key_expr: IntoKeyExpr) -> Self
where
Expand All @@ -40,9 +46,6 @@ pub trait SampleBuilderTrait {
fn with_attachment_opt(self, attachment: Option<Attachment>) -> Self;
#[zenoh_macros::unstable]
fn with_attachment(self, attachment: Attachment) -> Self;
fn congestion_control(self, congestion_control: CongestionControl) -> Self;
fn priority(self, priority: Priority) -> Self;
fn express(self, is_express: bool) -> Self;
}

pub trait PutSampleBuilderTrait: SampleBuilderTrait {
Expand Down Expand Up @@ -119,6 +122,9 @@ impl SampleBuilderTrait for SampleBuilder {
fn with_attachment(self, attachment: Attachment) -> Self {
self.with_attachment_opt(Some(attachment))
}
}

impl QoSBuilderTrait for SampleBuilder {
fn congestion_control(self, congestion_control: CongestionControl) -> Self {
Self(Sample {
qos: self.0.qos.with_congestion_control(congestion_control),
Expand Down Expand Up @@ -201,6 +207,9 @@ impl SampleBuilderTrait for PutSampleBuilder {
fn with_attachment_opt(self, attachment: Option<Attachment>) -> Self {
Self(self.0.with_attachment_opt(attachment))
}
}

impl QoSBuilderTrait for PutSampleBuilder {
fn congestion_control(self, congestion_control: CongestionControl) -> Self {
Self(self.0.congestion_control(congestion_control))
}
Expand Down Expand Up @@ -291,6 +300,9 @@ impl SampleBuilderTrait for DeleteSampleBuilder {
fn with_attachment_opt(self, attachment: Option<Attachment>) -> Self {
Self(self.0.with_attachment_opt(attachment))
}
}

impl QoSBuilderTrait for DeleteSampleBuilder {
fn congestion_control(self, congestion_control: CongestionControl) -> Self {
Self(self.0.congestion_control(congestion_control))
}
Expand Down

0 comments on commit 48d8d77

Please sign in to comment.