move BuilderDelegate to prelude

Signed-off-by: Walker Crouse <walker.crouse@coop.co.uk>
This commit is contained in:
Walker Crouse 2020-09-29 10:44:52 -04:00
parent df3fe9db74
commit 8b308b349f
6 changed files with 21 additions and 24 deletions

View File

@ -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()

View File

@ -1,9 +0,0 @@
//! Provides builder related helpers
/// Implements a `builder()` function for the specified type
pub trait BuilderDelegate<T: Default> {
/// Initializes a new default builder of type `T`
fn builder() -> T {
T::default()
}
}

View File

@ -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;

View File

@ -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::{

View File

@ -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<ServiceRegisteredCallback>) {
fn set_registered_callback(&mut self, registered_callback: Box<ServiceRegisteredCallback>) {
unsafe { (*self.context).registered_callback = Some(registered_callback) };
}
pub fn set_context(&mut self, context: Box<dyn Any>) {
fn set_context(&mut self, context: Box<dyn Any>) {
unsafe { (*self.context).user_context = Some(Arc::from(context)) };
}
pub fn register(&mut self) -> Result<EventLoop> {
fn register(&mut self) -> Result<EventLoop> {
debug!("Registering service: {:?}", self);
self.poll = Some(Arc::new(ManagedAvahiSimplePoll::new()?));

View File

@ -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<T: Default> {
/// Initializes a new default builder of type `T`
fn builder() -> T {
T::default()
}
}