dimas_core/utils/
mod.rs

1// Copyright © 2024 Stephan Kunz
2
3//! Helper functions and structs
4//!
5
6#[doc(hidden)]
7extern crate alloc;
8
9// region:		--- modules
10use alloc::string::{String, ToString};
11// endregion:	--- modules
12
13// region:    --- tracing
14/// Initialize tracing
15pub fn init_tracing() {
16	let subscriber = tracing_subscriber::fmt()
17		//.with_env_filter(env_filter)
18		.with_thread_ids(true)
19		.with_thread_names(true)
20		.with_level(true)
21		.with_target(true);
22
23	let subscriber = subscriber.finish();
24	let _ = tracing::subscriber::set_global_default(subscriber);
25}
26// endregion: --- tracing
27
28// region:    --- helper
29/// create selector
30#[must_use]
31pub fn selector_from(topic: &str, mut prefix: Option<&String>) -> String {
32	prefix.take().map_or(topic.to_string(), |prefix| {
33		let mut result = String::from(prefix);
34		result.push('/');
35		result.push_str(topic);
36		result
37	})
38}
39
40/// create request selector
41#[must_use]
42pub fn request_selector_from(selector: &str) -> String {
43	let mut result = String::from(selector);
44	result.push_str("?request");
45	result
46}
47
48/// create cancel selector
49#[must_use]
50pub fn cancel_selector_from(selector: &str) -> String {
51	let mut result = String::from(selector);
52	result.push_str("?cancel");
53	result
54}
55
56/// create feedback selector
57#[must_use]
58pub fn feedback_selector_from(selector: &str, id: &str) -> String {
59	let mut result = String::from(selector);
60	result.push_str("/feedback/");
61	result.push_str(id);
62	result
63}
64// endregion: --- helper