nardol/bytes/
into_bytes.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
use chrono::{DateTime, Utc};

use crate::bytes::Bytes;

impl From<Vec<u8>> for Bytes {
    fn from(value: Vec<u8>) -> Self {
        Bytes(value)
    }
}

impl<const L: usize> From<[u8; L]> for Bytes {
    fn from(value: [u8; L]) -> Self {
        let bytes: Bytes = value.iter().copied().collect();

        bytes
    }
}

impl From<usize> for Bytes {
    fn from(value: usize) -> Self {
        Bytes::from(value.to_be_bytes())
    }
}

impl From<u8> for Bytes {
    fn from(value: u8) -> Self {
        Bytes::from(value.to_be_bytes())
    }
}

impl From<u16> for Bytes {
    fn from(value: u16) -> Self {
        Bytes::from(value.to_be_bytes())
    }
}

impl From<u32> for Bytes {
    fn from(value: u32) -> Self {
        Bytes::from(value.to_be_bytes())
    }
}

impl From<String> for Bytes {
    fn from(value: String) -> Self {
        Bytes::from(value.into_bytes())
    }
}

impl From<DateTime<Utc>> for Bytes {
    fn from(value: DateTime<Utc>) -> Self {
        Bytes::from(value.timestamp() as usize)
    }
}