Skip to content

Commit

Permalink
🔥 zb: message::Field* API now private
Browse files Browse the repository at this point in the history
This exposes way too much internal details about the protocol that users
do not need. The specific field getters we provide are sufficient for
any low-level code.

I wrote most of this when I was still very new to Rust and I started
with a very bottoms-up approach. Hence we these API had been public
until now.

I doubt anyone uses these anyway so chances of people's code breaking
are low but even if they do, it's a API breaking release.
  • Loading branch information
zeenix committed Aug 15, 2023
1 parent 8b1376b commit 8db83bd
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 26 deletions.
10 changes: 0 additions & 10 deletions zbus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,6 @@ pub use message::Builder as MessageBuilder;
#[deprecated(note = "Use `message::EndianSig` instead")]
#[doc(hidden)]
pub use message::EndianSig;
#[deprecated(note = "Use `message::Field` instead")]
#[doc(hidden)]
pub use message::Field as MessageField;
#[deprecated(note = "Use `message::FieldCode` instead")]
#[doc(hidden)]
pub use message::FieldCode as MessageFieldCode;
#[deprecated(note = "Use `message::Fields` instead")]
#[doc(hidden)]
pub use message::Fields as MessageFields;
#[deprecated(note = "Use `message::Flags` instead")]
#[doc(hidden)]
pub use message::Flags as MessageFlags;
#[deprecated(note = "Use `message::Header` instead")]
Expand Down
4 changes: 2 additions & 2 deletions zbus/src/message/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use zvariant::{ObjectPath, Signature, Type, Value};
/// [`Fields`]: struct.Fields.html
#[repr(u8)]
#[derive(Copy, Clone, Debug, Deserialize_repr, PartialEq, Eq, Serialize_repr, Type)]
pub enum FieldCode {
pub(super) enum FieldCode {
/// Code for [`Field::Path`](enum.Field.html#variant.Path)
Path = 1,
/// Code for [`Field::Interface`](enum.Field.html#variant.Interface)
Expand Down Expand Up @@ -73,7 +73,7 @@ impl<'f> Field<'f> {
/// [are fixed]: struct.PrimaryHeader.html
/// [Message Format]: https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-messages
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Field<'f> {
pub(super) enum Field<'f> {
/// The object to send a call to, or the object a signal is emitted from.
Path(ObjectPath<'f>),
/// The interface to invoke a method call on, or that a signal is emitted from.
Expand Down
2 changes: 1 addition & 1 deletion zbus/src/message/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const MAX_FIELDS_IN_MESSAGE: usize = 16;
///
/// [`Field`]: enum.Field.html
#[derive(Debug, Clone, Serialize, Deserialize, Type)]
pub struct Fields<'m>(#[serde(borrow)] Vec<Field<'m>>);
pub(super) struct Fields<'m>(#[serde(borrow)] Vec<Field<'m>>);

assert_impl_all!(Fields<'_>: Send, Sync, Unpin);

Expand Down
4 changes: 2 additions & 2 deletions zbus/src/message/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,12 @@ impl<'m> Header<'m> {
}

/// Get a reference to the message fields.
pub fn fields(&self) -> &Fields<'m> {
fn fields(&self) -> &Fields<'m> {
&self.fields
}

/// Get a mutable reference to the message fields.
pub fn fields_mut(&mut self) -> &mut Fields<'m> {
pub(super) fn fields_mut(&mut self) -> &mut Fields<'m> {
&mut self.fields
}

Expand Down
14 changes: 3 additions & 11 deletions zbus/src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ mod builder;
pub use builder::Builder;

mod field;
pub use field::{Field, FieldCode};
use field::{Field, FieldCode};

mod fields;
pub use fields::Fields;
use fields::QuickFields;
use fields::{Fields, QuickFields};

pub(crate) mod header;
use header::MIN_MESSAGE_SIZE;
Expand Down Expand Up @@ -313,13 +312,6 @@ impl Message {
/// zero-cost. While the allocation is small and will hopefully be removed in the future, it's
/// best to keep the header around if you need to access it a lot.
pub fn header(&self) -> Header<'_> {
Header::new(self.primary_header.clone(), self.fields())
}

/// The message header fields.
///
/// The note on [`Message::header`] applies here too.
pub fn fields(&self) -> Fields<'_> {
let mut fields = Fields::new();
let quick_fields = &self.quick_fields;
if let Some(p) = quick_fields.path(self) {
Expand Down Expand Up @@ -350,7 +342,7 @@ impl Message {
fields.add(Field::UnixFDs(u));
}

fields
Header::new(self.primary_header.clone(), fields)
}

/// The message type.
Expand Down

0 comments on commit 8db83bd

Please sign in to comment.