Skip to content

Commit

Permalink
with removed, into<opttion<>> added
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Mar 28, 2024
1 parent 3620c3a commit aafd2a4
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 139 deletions.
2 changes: 1 addition & 1 deletion examples/examples/z_pub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async fn main() {
println!("Putting Data ('{}': '{}')...", &key_expr, buf);
let mut put = publisher.put(buf);
if let Some(attachment) = &attachment {
put = put.with_attachment(
put = put.attachment(
attachment
.split('&')
.map(|pair| split_once(pair, '='))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl AlignQueryable {
query
.reply(k, v.payload)
.with_encoding(v.encoding)
.with_timestamp(ts)
.timestamp(ts)
.res()
.await
.unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Aligner {
} = value;
let sample = PutSampleBuilder::new(key, payload)
.with_encoding(encoding)
.with_timestamp(ts)
.timestamp(ts)
.res_sync();
log::debug!("[ALIGNER] Adding {:?} to storage", sample);
self.tx_sample.send_async(sample).await.unwrap_or_else(|e| {
Expand Down
10 changes: 5 additions & 5 deletions plugins/zenoh-plugin-storage-manager/src/replica/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl StorageService {
}
};
let timestamp = sample.timestamp().cloned().unwrap_or(new_reception_timestamp());
let sample = SampleBuilder::from(sample).with_timestamp(timestamp).res_sync();
let sample = SampleBuilder::from(sample).timestamp(timestamp).res_sync();
self.process_sample(sample).await;
},
// on query on key_expr
Expand Down Expand Up @@ -316,14 +316,14 @@ impl StorageService {
} = data.value;
PutSampleBuilder::new(KeyExpr::from(k.clone()), payload)
.with_encoding(encoding)
.with_timestamp(data.timestamp)
.timestamp(data.timestamp)
.res_sync()
}
Some(Update {
kind: SampleKind::Delete,
data,
}) => DeleteSampleBuilder::new(KeyExpr::from(k.clone()))
.with_timestamp(data.timestamp)
.timestamp(data.timestamp)
.res_sync(),
None => SampleBuilder::from(sample.clone())
.keyexpr(k.clone())
Expand Down Expand Up @@ -533,7 +533,7 @@ impl StorageService {
if let Err(e) = q
.reply(key.clone(), payload)
.with_encoding(encoding)
.with_timestamp(entry.timestamp)
.timestamp(entry.timestamp)
.res_async()
.await
{
Expand Down Expand Up @@ -568,7 +568,7 @@ impl StorageService {
if let Err(e) = q
.reply(q.key_expr().clone(), payload)
.with_encoding(encoding)
.with_timestamp(entry.timestamp)
.timestamp(entry.timestamp)
.res_async()
.await
{
Expand Down
2 changes: 1 addition & 1 deletion zenoh-ext/src/querying_subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ impl<'a, Receiver> FetchingSubscriber<'a, Receiver> {
// ensure the sample has a timestamp, thus it will always be sorted into the MergeQueue
// after any timestamped Sample possibly coming from a fetch reply.
let timestamp = s.timestamp().cloned().unwrap_or(new_reception_timestamp());
let s = SampleBuilder::from(s).with_timestamp(timestamp).res_sync();
let s = SampleBuilder::from(s).timestamp(timestamp).res_sync();
state.merge_queue.push(s);
}
}
Expand Down
70 changes: 32 additions & 38 deletions zenoh/src/publication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,54 +147,52 @@ impl QoSBuilderTrait for DeleteBuilder<'_, '_> {
}

impl TimestampBuilderTrait for PutBuilder<'_, '_> {
fn with_timestamp(self, timestamp: Option<uhlc::Timestamp>) -> Self {
Self { timestamp, ..self }
fn timestamp<T: Into<Option<uhlc::Timestamp>>>(self, timestamp: T) -> Self {
Self {
timestamp: timestamp.into(),
..self
}
}
}

impl SampleBuilderTrait for PutBuilder<'_, '_> {
#[cfg(feature = "unstable")]
fn with_source_info(self, source_info: SourceInfo) -> Self {
fn source_info(self, source_info: SourceInfo) -> Self {
Self {
source_info,
..self
}
}
#[cfg(feature = "unstable")]
fn with_attachment_opt(self, attachment: Option<Attachment>) -> Self {
Self { attachment, ..self }
}
#[cfg(feature = "unstable")]
fn with_attachment(self, attachment: Attachment) -> Self {
fn attachment<T: Into<Option<Attachment>>>(self, attachment: T) -> Self {
Self {
attachment: Some(attachment),
attachment: attachment.into(),
..self
}
}
}

impl TimestampBuilderTrait for DeleteBuilder<'_, '_> {
fn with_timestamp(self, timestamp: Option<uhlc::Timestamp>) -> Self {
Self { timestamp, ..self }
fn timestamp<T: Into<Option<uhlc::Timestamp>>>(self, timestamp: T) -> Self {
Self {
timestamp: timestamp.into(),
..self
}
}
}

impl SampleBuilderTrait for DeleteBuilder<'_, '_> {
#[cfg(feature = "unstable")]
fn with_source_info(self, source_info: SourceInfo) -> Self {
fn source_info(self, source_info: SourceInfo) -> Self {
Self {
source_info,
..self
}
}
#[cfg(feature = "unstable")]
fn with_attachment_opt(self, attachment: Option<Attachment>) -> Self {
Self { attachment, ..self }
}
#[cfg(feature = "unstable")]
fn with_attachment(self, attachment: Attachment) -> Self {
fn attachment<T: Into<Option<Attachment>>>(self, attachment: T) -> Self {
Self {
attachment: Some(attachment),
attachment: attachment.into(),
..self
}
}
Expand Down Expand Up @@ -754,29 +752,27 @@ pub struct DeletePublication<'a> {
}

impl TimestampBuilderTrait for PutPublication<'_> {
fn with_timestamp(self, timestamp: Option<uhlc::Timestamp>) -> Self {
Self { timestamp, ..self }
fn timestamp<T: Into<Option<uhlc::Timestamp>>>(self, timestamp: T) -> Self {
Self {
timestamp: timestamp.into(),
..self
}
}
}

impl SampleBuilderTrait for PutPublication<'_> {
#[cfg(feature = "unstable")]
fn with_source_info(self, source_info: SourceInfo) -> Self {
fn source_info(self, source_info: SourceInfo) -> Self {
Self {
source_info,
..self
}
}

#[cfg(feature = "unstable")]
fn with_attachment_opt(self, attachment: Option<Attachment>) -> Self {
Self { attachment, ..self }
}

#[cfg(feature = "unstable")]
fn with_attachment(self, attachment: Attachment) -> Self {
fn attachment<T: Into<Option<Attachment>>>(self, attachment: T) -> Self {
Self {
attachment: Some(attachment),
attachment: attachment.into(),
..self
}
}
Expand All @@ -799,29 +795,27 @@ impl ValueBuilderTrait for PutPublication<'_> {
}

impl TimestampBuilderTrait for DeletePublication<'_> {
fn with_timestamp(self, timestamp: Option<uhlc::Timestamp>) -> Self {
Self { timestamp, ..self }
fn timestamp<T: Into<Option<uhlc::Timestamp>>>(self, timestamp: T) -> Self {
Self {
timestamp: timestamp.into(),
..self
}
}
}

impl SampleBuilderTrait for DeletePublication<'_> {
#[cfg(feature = "unstable")]
fn with_source_info(self, source_info: SourceInfo) -> Self {
fn source_info(self, source_info: SourceInfo) -> Self {
Self {
source_info,
..self
}
}

#[cfg(feature = "unstable")]
fn with_attachment_opt(self, attachment: Option<Attachment>) -> Self {
Self { attachment, ..self }
}

#[cfg(feature = "unstable")]
fn with_attachment(self, attachment: Attachment) -> Self {
fn attachment<T: Into<Option<Attachment>>>(self, attachment: T) -> Self {
Self {
attachment: Some(attachment),
attachment: attachment.into(),
..self
}
}
Expand Down
11 changes: 3 additions & 8 deletions zenoh/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,17 @@ pub struct GetBuilder<'a, 'b, Handler> {

impl<Handler> SampleBuilderTrait for GetBuilder<'_, '_, Handler> {
#[cfg(feature = "unstable")]
fn with_source_info(self, source_info: SourceInfo) -> Self {
fn source_info(self, source_info: SourceInfo) -> Self {
Self {
source_info,
..self
}
}

#[cfg(feature = "unstable")]
fn with_attachment_opt(self, attachment: Option<Attachment>) -> Self {
Self { attachment, ..self }
}

#[cfg(feature = "unstable")]
fn with_attachment(self, attachment: Attachment) -> Self {
fn attachment<T: Into<Option<Attachment>>>(self, attachment: T) -> Self {
Self {
attachment: Some(attachment),
attachment: attachment.into(),
..self
}
}
Expand Down
60 changes: 18 additions & 42 deletions zenoh/src/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,35 +239,27 @@ impl<'a> ReplySampleBuilder<'a> {
}

impl TimestampBuilderTrait for ReplySampleBuilder<'_> {
fn with_timestamp(self, timestamp: Option<Timestamp>) -> Self {
fn timestamp<T: Into<Option<Timestamp>>>(self, timestamp: T) -> Self {
Self {
sample_builder: self.sample_builder.with_timestamp(timestamp),
sample_builder: self.sample_builder.timestamp(timestamp),
..self
}
}
}

impl SampleBuilderTrait for ReplySampleBuilder<'_> {
#[cfg(feature = "unstable")]
fn with_source_info(self, source_info: SourceInfo) -> Self {
fn source_info(self, source_info: SourceInfo) -> Self {
Self {
sample_builder: self.sample_builder.with_source_info(source_info),
sample_builder: self.sample_builder.source_info(source_info),
..self
}
}

#[cfg(feature = "unstable")]
fn with_attachment_opt(self, attachment: Option<Attachment>) -> Self {
fn attachment<T: Into<Option<Attachment>>>(self, attachment: T) -> Self {
Self {
sample_builder: self.sample_builder.with_attachment_opt(attachment),
..self
}
}

#[cfg(feature = "unstable")]
fn with_attachment(self, attachment: Attachment) -> Self {
Self {
sample_builder: self.sample_builder.with_attachment(attachment),
sample_builder: self.sample_builder.attachment(attachment),
..self
}
}
Expand Down Expand Up @@ -324,35 +316,27 @@ pub struct ReplyBuilder<'a> {
}

impl TimestampBuilderTrait for ReplyBuilder<'_> {
fn with_timestamp(self, timestamp: Option<Timestamp>) -> Self {
fn timestamp<T: Into<Option<Timestamp>>>(self, timestamp: T) -> Self {
Self {
sample_builder: self.sample_builder.with_timestamp(timestamp),
sample_builder: self.sample_builder.timestamp(timestamp),
..self
}
}
}

impl SampleBuilderTrait for ReplyBuilder<'_> {
#[cfg(feature = "unstable")]
fn with_source_info(self, source_info: SourceInfo) -> Self {
Self {
sample_builder: self.sample_builder.with_source_info(source_info),
..self
}
}

#[cfg(feature = "unstable")]
fn with_attachment_opt(self, attachment: Option<Attachment>) -> Self {
fn source_info(self, source_info: SourceInfo) -> Self {
Self {
sample_builder: self.sample_builder.with_attachment_opt(attachment),
sample_builder: self.sample_builder.source_info(source_info),
..self
}
}

#[cfg(feature = "unstable")]
fn with_attachment(self, attachment: Attachment) -> Self {
fn attachment<T: Into<Option<Attachment>>>(self, attachment: T) -> Self {
Self {
sample_builder: self.sample_builder.with_attachment(attachment),
sample_builder: self.sample_builder.attachment(attachment),
..self
}
}
Expand Down Expand Up @@ -409,35 +393,27 @@ pub struct ReplyDelBuilder<'a> {
}

impl TimestampBuilderTrait for ReplyDelBuilder<'_> {
fn with_timestamp(self, timestamp: Option<Timestamp>) -> Self {
fn timestamp<T: Into<Option<Timestamp>>>(self, timestamp: T) -> Self {
Self {
sample_builder: self.sample_builder.with_timestamp(timestamp),
sample_builder: self.sample_builder.timestamp(timestamp),
..self
}
}
}

impl SampleBuilderTrait for ReplyDelBuilder<'_> {
#[cfg(feature = "unstable")]
fn with_source_info(self, source_info: SourceInfo) -> Self {
Self {
sample_builder: self.sample_builder.with_source_info(source_info),
..self
}
}

#[cfg(feature = "unstable")]
fn with_attachment_opt(self, attachment: Option<Attachment>) -> Self {
fn source_info(self, source_info: SourceInfo) -> Self {
Self {
sample_builder: self.sample_builder.with_attachment_opt(attachment),
sample_builder: self.sample_builder.source_info(source_info),
..self
}
}

#[cfg(feature = "unstable")]
fn with_attachment(self, attachment: Attachment) -> Self {
fn attachment<T: Into<Option<Attachment>>>(self, attachment: T) -> Self {
Self {
sample_builder: self.sample_builder.with_attachment(attachment),
sample_builder: self.sample_builder.attachment(attachment),
..self
}
}
Expand Down
11 changes: 11 additions & 0 deletions zenoh/src/sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,17 @@ mod attachment {
}
}
}
#[zenoh_macros::unstable]
impl From<AttachmentBuilder> for Option<Attachment> {
fn from(value: AttachmentBuilder) -> Self {
if value.inner.is_empty() {
None
} else {
Some(value.into())
}
}
}

#[zenoh_macros::unstable]
#[derive(Clone)]
pub struct Attachment {
Expand Down
Loading

0 comments on commit aafd2a4

Please sign in to comment.