@@ -497,11 +497,20 @@ pub enum Container {
497497 Vector ,
498498}
499499
500+ // Typed container names. They must match the strum `Display` (kebab-case) of the variants above,
501+ // which is pinned by a unit test.
502+ constant ! ( DRUID_CONTAINER_NAME : ContainerName = "druid" ) ;
503+ constant ! ( PREPARE_CONTAINER_NAME : ContainerName = "prepare" ) ;
504+ constant ! ( VECTOR_CONTAINER_NAME : ContainerName = "vector" ) ;
505+
500506impl Container {
501- /// Returns the typed container name for this container.
502- pub fn to_container_name ( & self ) -> ContainerName {
503- ContainerName :: from_str ( & self . to_string ( ) )
504- . expect ( "a Container always serializes to a valid container name" )
507+ /// The typed container name of this variant.
508+ pub fn name ( & self ) -> & ' static ContainerName {
509+ match self {
510+ Container :: Druid => & DRUID_CONTAINER_NAME ,
511+ Container :: Prepare => & PREPARE_CONTAINER_NAME ,
512+ Container :: Vector => & VECTOR_CONTAINER_NAME ,
513+ }
505514 }
506515}
507516
@@ -901,10 +910,20 @@ pub fn build_string_list(strings: &[String]) -> String {
901910#[ cfg( test) ]
902911mod tests {
903912 use stackable_operator:: versioned:: test_utils:: RoundtripTestData ;
913+ use strum:: IntoEnumIterator ;
904914
905915 use super :: * ;
906916 use crate :: crd:: v1alpha1;
907917
918+ /// The typed container names returned by `name` must agree with the strum `Display`
919+ /// of `Container`, which the logging configuration still uses as the per-container key.
920+ #[ test]
921+ fn container_names_match_display ( ) {
922+ for container in Container :: iter ( ) {
923+ assert_eq ! ( container. name( ) . to_string( ) , container. to_string( ) ) ;
924+ }
925+ }
926+
908927 #[ test]
909928 fn test_constants ( ) {
910929 // Test that dereferencing the constants does not panic.
@@ -916,6 +935,9 @@ mod tests {
916935 let _ = * COOKIE_PASSPHRASE_ENV ;
917936 let _ = * COOKIE_PASSPHRASE_SECRET_KEY ;
918937 let _ = * DRUID_DEFAULT_LISTENER_CLASS ;
938+ let _ = * DRUID_CONTAINER_NAME ;
939+ let _ = * PREPARE_CONTAINER_NAME ;
940+ let _ = * VECTOR_CONTAINER_NAME ;
919941 }
920942
921943 impl RoundtripTestData for v1alpha1:: DruidClusterSpec {
0 commit comments