Skip to main content

qubit_config/
config_name.rs

1/*******************************************************************************
2 *
3 *    Copyright (c) 2025 - 2026 Haixing Hu.
4 *
5 *    SPDX-License-Identifier: Apache-2.0
6 *
7 *    Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10
11//! Ergonomic configuration key argument adapters.
12
13/// Provides borrowed access to a configuration key argument.
14pub trait ConfigName {
15    /// Invokes `operation` with this argument as a string slice.
16    fn with_config_name<R>(self, operation: impl FnOnce(&str) -> R) -> R;
17}
18
19impl ConfigName for &str {
20    #[inline]
21    fn with_config_name<R>(self, operation: impl FnOnce(&str) -> R) -> R {
22        operation(self)
23    }
24}
25
26impl ConfigName for String {
27    #[inline]
28    fn with_config_name<R>(self, operation: impl FnOnce(&str) -> R) -> R {
29        operation(self.as_str())
30    }
31}
32
33impl ConfigName for &String {
34    #[inline]
35    fn with_config_name<R>(self, operation: impl FnOnce(&str) -> R) -> R {
36        operation(self.as_str())
37    }
38}