diff --git a/commons/zenoh-protocol/src/scouting/hello.rs b/commons/zenoh-protocol/src/scouting/hello.rs index 62ea915e5a..6639792976 100644 --- a/commons/zenoh-protocol/src/scouting/hello.rs +++ b/commons/zenoh-protocol/src/scouting/hello.rs @@ -12,7 +12,6 @@ // ZettaScale Zenoh Team, // use alloc::vec::Vec; -use core::fmt; use crate::core::{Locator, WhatAmI, ZenohId}; @@ -107,16 +106,6 @@ pub struct Hello { pub locators: Vec, } -impl fmt::Display for Hello { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_struct("Hello") - .field("zid", &self.zid) - .field("whatami", &self.whatami) - .field("locators", &self.locators) - .finish() - } -} - impl Hello { #[cfg(feature = "test")] pub fn rand() -> Self { diff --git a/zenoh/src/api/scouting.rs b/zenoh/src/api/scouting.rs index 566f18f061..e16f31da2e 100644 --- a/zenoh/src/api/scouting.rs +++ b/zenoh/src/api/scouting.rs @@ -21,7 +21,7 @@ use std::{ use tokio::net::UdpSocket; use zenoh_core::{Resolvable, Wait}; -use zenoh_protocol::{core::WhatAmIMatcher, scouting::Hello}; +use zenoh_protocol::core::WhatAmIMatcher; use zenoh_result::ZResult; use zenoh_task::TerminatableTask; @@ -30,6 +30,36 @@ use crate::{ net::runtime::{orchestrator::Loop, Runtime}, }; +/// A zenoh Hello message. +pub struct Hello(zenoh_protocol::scouting::Hello); + +impl Hello { + /// Get the locators of this Hello message. + pub fn locators(&self) -> &[zenoh_protocol::core::Locator] { + &self.0.locators + } + + /// Get the zenoh id of this Hello message. + pub fn zid(&self) -> zenoh_protocol::core::ZenohId { + self.0.zid + } + + /// Get the whatami of this Hello message. + pub fn whatami(&self) -> zenoh_protocol::core::WhatAmI { + self.0.whatami + } +} + +impl fmt::Display for Hello { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Hello") + .field("zid", &self.zid()) + .field("whatami", &self.whatami()) + .field("locators", &self.locators()) + .finish() + } +} + /// A builder for initializing a [`Scout`]. /// /// # Examples @@ -324,7 +354,7 @@ fn _scout( let scout = Runtime::scout(&sockets, what, &addr, move |hello| { let callback = callback.clone(); async move { - callback(hello); + callback(Hello(hello)); Loop::Continue } }); diff --git a/zenoh/src/lib.rs b/zenoh/src/lib.rs index 0c47070609..a5ea8b5518 100644 --- a/zenoh/src/lib.rs +++ b/zenoh/src/lib.rs @@ -324,10 +324,7 @@ pub mod handlers { /// Scouting primitives pub mod scouting { - /// A zenoh Hello message. - pub use zenoh_protocol::scouting::Hello; - - pub use crate::api::scouting::{scout, Scout, ScoutBuilder}; + pub use crate::api::scouting::{scout, Hello, Scout, ScoutBuilder}; } /// Liveliness primitives