dimas_core/utils/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright © 2024 Stephan Kunz

//! Helper functions and structs
//!

#[doc(hidden)]
extern crate alloc;

// region:		--- modules
use alloc::string::{String, ToString};
// endregion:	--- modules

// region:    --- tracing
/// Initialize tracing
pub fn init_tracing() {
	let subscriber = tracing_subscriber::fmt()
		//.with_env_filter(env_filter)
		.with_thread_ids(true)
		.with_thread_names(true)
		.with_level(true)
		.with_target(true);

	let subscriber = subscriber.finish();
	let _ = tracing::subscriber::set_global_default(subscriber);
}
// endregion: --- tracing

// region:    --- helper
/// create selector
#[must_use]
pub fn selector_from(topic: &str, mut prefix: Option<&String>) -> String {
	prefix.take().map_or(topic.to_string(), |prefix| {
		let mut result = String::from(prefix);
		result.push('/');
		result.push_str(topic);
		result
	})
}

/// create request selector
#[must_use]
pub fn request_selector_from(selector: &str) -> String {
	let mut result = String::from(selector);
	result.push_str("?request");
	result
}

/// create cancel selector
#[must_use]
pub fn cancel_selector_from(selector: &str) -> String {
	let mut result = String::from(selector);
	result.push_str("?cancel");
	result
}

/// create feedback selector
#[must_use]
pub fn feedback_selector_from(selector: &str, id: &str) -> String {
	let mut result = String::from(selector);
	result.push_str("/feedback/");
	result.push_str(id);
	result
}
// endregion: --- helper