diff --git a/zeroconf-macros/src/lib.rs b/zeroconf-macros/src/lib.rs index 4000720..9c50bff 100644 --- a/zeroconf-macros/src/lib.rs +++ b/zeroconf-macros/src/lib.rs @@ -63,7 +63,7 @@ fn impl_builder_delegate(ast: &DeriveInput) -> TokenStream { let generics = &ast.generics; let gen = quote! { - impl #generics crate::builder::BuilderDelegate<#builder #generics> for #name #generics {} + impl #generics crate::prelude::BuilderDelegate<#builder #generics> for #name #generics {} }; gen.into() diff --git a/zeroconf/src/builder.rs b/zeroconf/src/builder.rs deleted file mode 100644 index 64d3153..0000000 --- a/zeroconf/src/builder.rs +++ /dev/null @@ -1,9 +0,0 @@ -//! Provides builder related helpers - -/// Implements a `builder()` function for the specified type -pub trait BuilderDelegate { - /// Initializes a new default builder of type `T` - fn builder() -> T { - T::default() - } -} diff --git a/zeroconf/src/lib.rs b/zeroconf/src/lib.rs index e620beb..1c7bf60 100644 --- a/zeroconf/src/lib.rs +++ b/zeroconf/src/lib.rs @@ -137,7 +137,6 @@ mod tests; mod txt_record; pub mod browser; -pub mod builder; pub mod error; pub mod event_loop; pub mod ffi; diff --git a/zeroconf/src/linux/browser.rs b/zeroconf/src/linux/browser.rs index 08ad78b..ebcb14c 100644 --- a/zeroconf/src/linux/browser.rs +++ b/zeroconf/src/linux/browser.rs @@ -8,9 +8,8 @@ use super::raw_browser::{ManagedAvahiServiceBrowser, ManagedAvahiServiceBrowserP use super::resolver::{ ManagedAvahiServiceResolver, ManagedAvahiServiceResolverParams, ServiceResolverSet, }; -use crate::browser::TMdnsBrowser; -use crate::builder::BuilderDelegate; use crate::ffi::{c_str, AsRaw, FromRaw}; +use crate::prelude::*; use crate::Result; use crate::{EventLoop, NetworkInterface, ServiceDiscoveredCallback, ServiceDiscovery}; use avahi_sys::{ diff --git a/zeroconf/src/linux/service.rs b/zeroconf/src/linux/service.rs index d704b1f..5194f77 100644 --- a/zeroconf/src/linux/service.rs +++ b/zeroconf/src/linux/service.rs @@ -5,8 +5,8 @@ use super::client::{self, ManagedAvahiClient, ManagedAvahiClientParams}; use super::constants; use super::entry_group::{AddServiceParams, ManagedAvahiEntryGroup, ManagedAvahiEntryGroupParams}; use super::poll::ManagedAvahiSimplePoll; -use crate::builder::BuilderDelegate; use crate::ffi::{c_str, AsRaw, FromRaw}; +use crate::prelude::*; use crate::{ EventLoop, NetworkInterface, Result, ServiceRegisteredCallback, ServiceRegistration, TxtRecord, }; @@ -29,8 +29,8 @@ pub struct AvahiMdnsService { context: *mut AvahiServiceContext, } -impl AvahiMdnsService { - pub fn new(kind: &str, port: u16) -> Self { +impl TMdnsService for AvahiMdnsService { + fn new(kind: &str, port: u16) -> Self { Self { client: None, poll: None, @@ -45,35 +45,35 @@ impl AvahiMdnsService { /// See: [`AvahiClient::host_name()`] /// /// [`AvahiClient::host_name()`]: client/struct.ManagedAvahiClient.html#method.host_name - pub fn set_name(&mut self, name: &str) { + fn set_name(&mut self, name: &str) { unsafe { (*self.context).name = Some(c_string!(name)) }; } - pub fn set_network_interface(&mut self, interface: NetworkInterface) { + fn set_network_interface(&mut self, interface: NetworkInterface) { unsafe { (*self.context).interface_index = avahi_util::interface_index(interface) }; } - pub fn set_domain(&mut self, _domain: &str) { + fn set_domain(&mut self, _domain: &str) { todo!() } - pub fn set_host(&mut self, _host: &str) { + fn set_host(&mut self, _host: &str) { todo!() } - pub fn set_txt_record(&mut self, txt_record: TxtRecord) { + fn set_txt_record(&mut self, txt_record: TxtRecord) { self.txt_record = Some(txt_record); } - pub fn set_registered_callback(&mut self, registered_callback: Box) { + fn set_registered_callback(&mut self, registered_callback: Box) { unsafe { (*self.context).registered_callback = Some(registered_callback) }; } - pub fn set_context(&mut self, context: Box) { + fn set_context(&mut self, context: Box) { unsafe { (*self.context).user_context = Some(Arc::from(context)) }; } - pub fn register(&mut self) -> Result { + fn register(&mut self) -> Result { debug!("Registering service: {:?}", self); self.poll = Some(Arc::new(ManagedAvahiSimplePoll::new()?)); diff --git a/zeroconf/src/prelude.rs b/zeroconf/src/prelude.rs index c43d891..89c8063 100644 --- a/zeroconf/src/prelude.rs +++ b/zeroconf/src/prelude.rs @@ -4,3 +4,11 @@ pub use crate::browser::TMdnsBrowser; pub use crate::event_loop::TEventLoop; pub use crate::service::TMdnsService; pub use crate::txt_record::TTxtRecord; + +/// Implements a `builder()` function for the specified type +pub trait BuilderDelegate { + /// Initializes a new default builder of type `T` + fn builder() -> T { + T::default() + } +}