kx_utils/experimental/to_string.rs
1//
2#![allow(unused)]
3
4/// Converts the parameter into a [String] using the [Into] trait.
5///
6/// Requires parameter to implement a [From] or [Into] trait to allow it be transformed.
7pub fn s(v: impl Into<String>) -> String {
8 v.into()
9}
10
11/// Converts the parameter into a [String] by calling `.to_string()`.
12///
13/// Unlike the [s] function, the value only need to have a [to_string] method. Preusmably it will
14/// return a [String], but this macro doesn't make that gaurantee.
15#[macro_export]
16macro_rules! s {
17 ($value:expr) => {
18 $value.to_string()
19 };
20}
21
22#[cfg(test)]
23mod tests {
24 use super::*;
25
26 #[test]
27 fn s_converts_to_string() {
28 let v = 123.to_string();
29 let result = s("123");
30 assert_eq!(result, v);
31 }
32}