move BuilderDelegate to prelude
Signed-off-by: Walker Crouse <walker.crouse@coop.co.uk>
This commit is contained in:
parent
df3fe9db74
commit
8b308b349f
|
@ -63,7 +63,7 @@ fn impl_builder_delegate(ast: &DeriveInput) -> TokenStream {
|
||||||
let generics = &ast.generics;
|
let generics = &ast.generics;
|
||||||
|
|
||||||
let gen = quote! {
|
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()
|
gen.into()
|
||||||
|
|
|
@ -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()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -137,7 +137,6 @@ mod tests;
|
||||||
mod txt_record;
|
mod txt_record;
|
||||||
|
|
||||||
pub mod browser;
|
pub mod browser;
|
||||||
pub mod builder;
|
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod event_loop;
|
pub mod event_loop;
|
||||||
pub mod ffi;
|
pub mod ffi;
|
||||||
|
|
|
@ -8,9 +8,8 @@ use super::raw_browser::{ManagedAvahiServiceBrowser, ManagedAvahiServiceBrowserP
|
||||||
use super::resolver::{
|
use super::resolver::{
|
||||||
ManagedAvahiServiceResolver, ManagedAvahiServiceResolverParams, ServiceResolverSet,
|
ManagedAvahiServiceResolver, ManagedAvahiServiceResolverParams, ServiceResolverSet,
|
||||||
};
|
};
|
||||||
use crate::browser::TMdnsBrowser;
|
|
||||||
use crate::builder::BuilderDelegate;
|
|
||||||
use crate::ffi::{c_str, AsRaw, FromRaw};
|
use crate::ffi::{c_str, AsRaw, FromRaw};
|
||||||
|
use crate::prelude::*;
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
use crate::{EventLoop, NetworkInterface, ServiceDiscoveredCallback, ServiceDiscovery};
|
use crate::{EventLoop, NetworkInterface, ServiceDiscoveredCallback, ServiceDiscovery};
|
||||||
use avahi_sys::{
|
use avahi_sys::{
|
||||||
|
|
|
@ -5,8 +5,8 @@ use super::client::{self, ManagedAvahiClient, ManagedAvahiClientParams};
|
||||||
use super::constants;
|
use super::constants;
|
||||||
use super::entry_group::{AddServiceParams, ManagedAvahiEntryGroup, ManagedAvahiEntryGroupParams};
|
use super::entry_group::{AddServiceParams, ManagedAvahiEntryGroup, ManagedAvahiEntryGroupParams};
|
||||||
use super::poll::ManagedAvahiSimplePoll;
|
use super::poll::ManagedAvahiSimplePoll;
|
||||||
use crate::builder::BuilderDelegate;
|
|
||||||
use crate::ffi::{c_str, AsRaw, FromRaw};
|
use crate::ffi::{c_str, AsRaw, FromRaw};
|
||||||
|
use crate::prelude::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
EventLoop, NetworkInterface, Result, ServiceRegisteredCallback, ServiceRegistration, TxtRecord,
|
EventLoop, NetworkInterface, Result, ServiceRegisteredCallback, ServiceRegistration, TxtRecord,
|
||||||
};
|
};
|
||||||
|
@ -29,8 +29,8 @@ pub struct AvahiMdnsService {
|
||||||
context: *mut AvahiServiceContext,
|
context: *mut AvahiServiceContext,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AvahiMdnsService {
|
impl TMdnsService for AvahiMdnsService {
|
||||||
pub fn new(kind: &str, port: u16) -> Self {
|
fn new(kind: &str, port: u16) -> Self {
|
||||||
Self {
|
Self {
|
||||||
client: None,
|
client: None,
|
||||||
poll: None,
|
poll: None,
|
||||||
|
@ -45,35 +45,35 @@ impl AvahiMdnsService {
|
||||||
/// See: [`AvahiClient::host_name()`]
|
/// See: [`AvahiClient::host_name()`]
|
||||||
///
|
///
|
||||||
/// [`AvahiClient::host_name()`]: client/struct.ManagedAvahiClient.html#method.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)) };
|
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) };
|
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!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_host(&mut self, _host: &str) {
|
fn set_host(&mut self, _host: &str) {
|
||||||
todo!()
|
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);
|
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) };
|
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)) };
|
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);
|
debug!("Registering service: {:?}", self);
|
||||||
|
|
||||||
self.poll = Some(Arc::new(ManagedAvahiSimplePoll::new()?));
|
self.poll = Some(Arc::new(ManagedAvahiSimplePoll::new()?));
|
||||||
|
|
|
@ -4,3 +4,11 @@ pub use crate::browser::TMdnsBrowser;
|
||||||
pub use crate::event_loop::TEventLoop;
|
pub use crate::event_loop::TEventLoop;
|
||||||
pub use crate::service::TMdnsService;
|
pub use crate::service::TMdnsService;
|
||||||
pub use crate::txt_record::TTxtRecord;
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue