Skip to content

Commit 2ebc146

Browse files
committed
export InterfaceId and rebase to main
1 parent 007e32a commit 2ebc146

File tree

4 files changed

+9
-17
lines changed

4 files changed

+9
-17
lines changed

examples/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn main() {
5050
println!(
5151
" Address: {} ({:?})",
5252
addr,
53-
interfaces.iter().map(|i| i.name()).collect::<Vec<_>>()
53+
interfaces.iter().map(|i| &i.name).collect::<Vec<_>>()
5454
);
5555
}
5656
for prop in info.txt_properties.iter() {

src/dns_parser.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,19 @@ use std::{
2222
time::SystemTime,
2323
};
2424

25-
/// InterfaceId is used to represent the interface identifier
25+
/// Represents a network interface identifier defined by the OS.
2626
#[derive(Clone, Debug, Eq, Hash, PartialEq, Default)]
2727
pub struct InterfaceId {
28-
name: String,
29-
index: u32,
30-
}
31-
32-
impl InterfaceId {
33-
pub fn index(&self) -> u32 {
34-
self.index
35-
}
28+
/// Interface name, e.g. "en0", "wlan0", etc.
29+
pub name: String,
3630

37-
pub fn name(&self) -> &str {
38-
&self.name
39-
}
31+
/// Interface index assigned by the OS, e.g. 1, 2, etc.
32+
pub index: u32,
4033
}
4134

4235
impl fmt::Display for InterfaceId {
4336
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44-
write!(f, "{}: {}", self.index, self.name)
37+
write!(f, "{}(idx {})", self.name, self.index)
4538
}
4639
}
4740

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ mod error;
162162
mod service_daemon;
163163
mod service_info;
164164

165-
pub use dns_parser::RRType;
165+
pub use dns_parser::{InterfaceId, RRType};
166166
pub use error::{Error, Result};
167167
pub use service_daemon::{
168168
DaemonEvent, DaemonStatus, DnsNameChange, HostnameResolutionEvent, IfKind, Metrics,

tests/mdns_test.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,8 +2641,7 @@ fn test_use_service_detailed_v6() {
26412641
println!("Resolved address: {:?}", first_addr);
26422642
println!(
26432643
"Interface ID of the first addr: {} index: {}",
2644-
interface_id.name(),
2645-
interface_id.index()
2644+
interface_id.name, interface_id.index
26462645
);
26472646
break;
26482647
}

0 commit comments

Comments
 (0)