From accdd9037c23c7f25c9cdc565794023ff5f79659 Mon Sep 17 00:00:00 2001
From: Christoph Girstenbrei <Christoph.Girstenbrei@gmail.com>
Date: Fri, 10 Jan 2025 18:12:40 +0100
Subject: [PATCH 1/5] Expose the stored subsystem name via the subsystem handle

---
 src/subsystem/subsystem_handle.rs | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/subsystem/subsystem_handle.rs b/src/subsystem/subsystem_handle.rs
index 1547029..509eb96 100644
--- a/src/subsystem/subsystem_handle.rs
+++ b/src/subsystem/subsystem_handle.rs
@@ -328,6 +328,13 @@ impl<ErrType: ErrTypeTraits> SubsystemHandle<ErrType> {
     pub fn create_cancellation_token(&self) -> CancellationToken {
         self.inner.cancellation_token.child_token()
     }
+
+    /// Get the name associated with this subsystem.
+    ///
+    /// See [`SubsystemBuilder::new()`] how to set this name.
+    pub fn name(&self) -> Arc<str> {
+        self.inner.name.clone()
+    }
 }
 
 impl<ErrType: ErrTypeTraits> Drop for SubsystemHandle<ErrType> {

From 49195cdf7f5951190c62fbe73d02fbcc26771106 Mon Sep 17 00:00:00 2001
From: Christoph Girstenbrei <Christoph.Girstenbrei@gmail.com>
Date: Fri, 10 Jan 2025 18:16:07 +0100
Subject: [PATCH 2/5] Switch to directly returning borrowed str

---
 src/subsystem/subsystem_handle.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/subsystem/subsystem_handle.rs b/src/subsystem/subsystem_handle.rs
index 509eb96..5263430 100644
--- a/src/subsystem/subsystem_handle.rs
+++ b/src/subsystem/subsystem_handle.rs
@@ -332,8 +332,8 @@ impl<ErrType: ErrTypeTraits> SubsystemHandle<ErrType> {
     /// Get the name associated with this subsystem.
     ///
     /// See [`SubsystemBuilder::new()`] how to set this name.
-    pub fn name(&self) -> Arc<str> {
-        self.inner.name.clone()
+    pub fn name(&self) -> &str {
+        &self.inner.name
     }
 }
 

From fcfacb1b7938b326e83bb56e1f53b7419c1867e5 Mon Sep 17 00:00:00 2001
From: Christoph Girstenbrei <Christoph.Girstenbrei@gmail.com>
Date: Fri, 10 Jan 2025 19:14:57 +0100
Subject: [PATCH 3/5] Add test for name access in subsystem

---
 tests/integration_test.rs | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/tests/integration_test.rs b/tests/integration_test.rs
index 463d463..e9ecfc9 100644
--- a/tests/integration_test.rs
+++ b/tests/integration_test.rs
@@ -920,3 +920,19 @@ async fn shutdown_through_signal() {
         },
     );
 }
+
+#[tokio::test]
+#[traced_test]
+async fn access_name_from_within_subsystem() {
+    let subsys1 = move |subsys: SubsystemHandle| async move {
+        assert_eq!("/subsys", subsys.name());
+        BoxedResult::Ok(())
+    };
+
+    Toplevel::new(move |s| async move {
+        s.start(SubsystemBuilder::new("subsys", subsys1));
+    })
+    .handle_shutdown_requests(Duration::from_millis(100))
+    .await
+    .unwrap();
+}

From 4602be106bd452d1f4dca6407530a254005fc079 Mon Sep 17 00:00:00 2001
From: Christoph Girstenbrei <Christoph.Girstenbrei@gmail.com>
Date: Fri, 10 Jan 2025 19:19:08 +0100
Subject: [PATCH 4/5] Document subsystem name structure

---
 src/subsystem/subsystem_handle.rs | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/subsystem/subsystem_handle.rs b/src/subsystem/subsystem_handle.rs
index 5263430..02fa2d5 100644
--- a/src/subsystem/subsystem_handle.rs
+++ b/src/subsystem/subsystem_handle.rs
@@ -331,6 +331,9 @@ impl<ErrType: ErrTypeTraits> SubsystemHandle<ErrType> {
 
     /// Get the name associated with this subsystem.
     ///
+    /// Note that the names of nested subsystems are built unix-path alike,
+    /// starting and delimited by slashes (e.g. `/a/b/c`).
+    /// 
     /// See [`SubsystemBuilder::new()`] how to set this name.
     pub fn name(&self) -> &str {
         &self.inner.name

From 8f3eff5a04aca1dc629b0d998286a5ab010fd280 Mon Sep 17 00:00:00 2001
From: Christoph Girstenbrei <Christoph.Girstenbrei@gmail.com>
Date: Fri, 10 Jan 2025 19:23:18 +0100
Subject: [PATCH 5/5] Test nested subsystem naming

---
 src/subsystem/subsystem_handle.rs |  2 +-
 tests/integration_test.rs         | 12 +++++++++---
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/subsystem/subsystem_handle.rs b/src/subsystem/subsystem_handle.rs
index 02fa2d5..5539417 100644
--- a/src/subsystem/subsystem_handle.rs
+++ b/src/subsystem/subsystem_handle.rs
@@ -333,7 +333,7 @@ impl<ErrType: ErrTypeTraits> SubsystemHandle<ErrType> {
     ///
     /// Note that the names of nested subsystems are built unix-path alike,
     /// starting and delimited by slashes (e.g. `/a/b/c`).
-    /// 
+    ///
     /// See [`SubsystemBuilder::new()`] how to set this name.
     pub fn name(&self) -> &str {
         &self.inner.name
diff --git a/tests/integration_test.rs b/tests/integration_test.rs
index e9ecfc9..3b8b7b2 100644
--- a/tests/integration_test.rs
+++ b/tests/integration_test.rs
@@ -924,13 +924,19 @@ async fn shutdown_through_signal() {
 #[tokio::test]
 #[traced_test]
 async fn access_name_from_within_subsystem() {
-    let subsys1 = move |subsys: SubsystemHandle| async move {
-        assert_eq!("/subsys", subsys.name());
+    let subsys_nested = move |subsys: SubsystemHandle| async move {
+        assert_eq!("/subsys_top/subsys_nested", subsys.name());
+        BoxedResult::Ok(())
+    };
+
+    let subsys_top = move |subsys: SubsystemHandle| async move {
+        assert_eq!("/subsys_top", subsys.name());
+        subsys.start(SubsystemBuilder::new("subsys_nested", subsys_nested));
         BoxedResult::Ok(())
     };
 
     Toplevel::new(move |s| async move {
-        s.start(SubsystemBuilder::new("subsys", subsys1));
+        s.start(SubsystemBuilder::new("subsys_top", subsys_top));
     })
     .handle_shutdown_requests(Duration::from_millis(100))
     .await