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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use IntoFragment;
use crate::;
/// Converts a [`Value`] reference into a [`Cow<'a, str>`].
///
/// This conversion is used to represent different `Value` variants as string data.
///
/// The possible variants and their conversions:
/// - `Value::String(s)` returns the cloned string.
/// - `Value::Number(n)` is formatted as a string.
/// - `Value::Boolean(b)` is formatted as a string.
/// - `Value::Null` is formatted as `"null"`.
/// - `Value::DataSource`:
/// - If the `DataProvider` is a `File` and its data is `Text`, returns the text data.
/// - Otherwise, it returns `"Unsupported DataProvider"` or `"Unknown DataType"`.
///
/// # Examples
///
/// ```rust
/// use snowcap::Value;
/// let value = Value::Number(42.0);
/// let cow: std::borrow::Cow<'_, str> = (&value).into();
/// assert_eq!(cow, "42");
/// ```
/// Converts a reference to a [`MarkupTree<AppMessage>`] into a text fragment.
///
/// This implementation extracts and converts the `MarkupTree::Value` variant into
/// an `iced::widget::text::Fragment`. If the `MarkupTree` is not a `Value` variant,
/// it returns a fragment indicating that `MarkupType::Value` was expected.
///
/// # Examples
///
/// ```rust
/// enum AppMessage {
/// None
/// };
/// use snowcap::{MarkupTree,Value};
/// use iced::advanced::text::IntoFragment;
/// let markup_tree = MarkupTree::<AppMessage>::Value(Value::String("Hello".to_string()));
/// let fragment: iced::widget::text::Fragment = (&markup_tree).into_fragment();
/// ```
/// Converts a reference to an [`Attribute`] into a text fragment.
///
/// This implementation extracts the value of the `Attribute` and converts it into
/// an `iced::widget::text::Fragment`.
///
/// # Examples
///
/// ```rust
/// use snowcap::{Attribute,Value};
/// use iced::advanced::text::IntoFragment;
/// let attr = Attribute { name: "test".into(), value: Value::String("Hello".to_string()) };
/// let fragment: iced::widget::text::Fragment = (&attr).into_fragment();
/// ```