Skip to content

Commit

Permalink
tags
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Feb 17, 2024
1 parent 35a3bcb commit 52490a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions commons/zenoh-buffers/src/zslice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ impl<const N: usize> ZSliceBuffer for [u8; N] {
#[cfg(feature = "shared-memory")]
#[derive(Copy, Clone, PartialEq, Eq)]
#[repr(u8)]
// tags{rust.z_slice_kind}
pub enum ZSliceKind {
Raw = 0,
ShmPtr = 1,
}

/// A clonable wrapper to a contiguous slice of bytes.
// tags{rust.z_slice}
#[derive(Clone)]
pub struct ZSlice {
pub(crate) buf: Arc<dyn ZSliceBuffer>,
Expand All @@ -92,6 +94,7 @@ pub struct ZSlice {
}

impl ZSlice {
// tags{rust.z_slice.make, api.buffer.create}
pub fn make(
buf: Arc<dyn ZSliceBuffer>,
start: usize,
Expand Down
7 changes: 7 additions & 0 deletions commons/zenoh-protocol/src/core/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ mod consts {

#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
// tags{rust.encoding, api.options.encoding}
pub enum KnownEncoding {
Empty = 0,
AppOctetStream = 1,
Expand Down Expand Up @@ -106,13 +107,15 @@ impl AsRef<str> for KnownEncoding {
///
/// A zenoh encoding is a HTTP Mime type represented, for wire efficiency,
/// as an integer prefix (that maps to a string) and a string suffix.
// tags{rust.encoding, api.encoding}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Encoding {
Exact(KnownEncoding),
WithSuffix(KnownEncoding, CowStr<'static>),
}

impl Encoding {
// tags{rust.encoding.new, api.encoding.create}
pub fn new<IntoCowStr>(prefix: u8, suffix: IntoCowStr) -> ZResult<Self>
where
IntoCowStr: Into<Cow<'static, str>> + AsRef<str>,
Expand All @@ -130,6 +133,7 @@ impl Encoding {
}

/// Sets the suffix of this encoding.
// tags{rust.encoding.with_suffix, api.encoding.suffix.set}
pub fn with_suffix<IntoCowStr>(self, suffix: IntoCowStr) -> ZResult<Self>
where
IntoCowStr: Into<Cow<'static, str>> + AsRef<str>,
Expand All @@ -149,6 +153,7 @@ impl Encoding {

/// Returns `true`if the string representation of this encoding starts with
/// the string representation of ther given encoding.
// tags{rust.encoding.starts_with, api.encoding.starts_with}
pub fn starts_with<T>(&self, with: T) -> bool
where
T: Into<Encoding>,
Expand All @@ -157,12 +162,14 @@ impl Encoding {
self.prefix() == with.prefix() && self.suffix().starts_with(with.suffix())
}

// tags{rust.encoding.prefix, api.encoding.prefix.get}
pub const fn prefix(&self) -> &KnownEncoding {
match self {
Encoding::Exact(e) | Encoding::WithSuffix(e, _) => e,
}
}

// tags{rust.encoding.suffix, api.encoding.suffix.get}
pub fn suffix(&self) -> &str {
match self {
Encoding::Exact(_) => "",
Expand Down

0 comments on commit 52490a1

Please sign in to comment.