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
#[derive(Debug)]
pub struct Text {
    _bytes: Vec<u8>,
    _length: i32,
}

impl Text {
    /// Converts the provided String to bytes using the
    /// UTF-8 encoding. If `replace` is true, then
    /// malformed input is replaced with the
    /// substitution character, which is U+FFFD. Otherwise the
    /// method throws a MalformedInputException.
    fn encode(s: &str, _replace: bool) -> &[u8] {
        // TODO: handle malformed input

        s.as_bytes()
    }
}

impl From<String> for Text {
    fn from(s: String) -> Self {
        let bb = Self::encode(&s, true);
        Self {
            _bytes: bb.into(),
            _length: bb.len() as i32,
        }
    }
}