-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathmisc.rs
More file actions
46 lines (39 loc) · 1.04 KB
/
Copy pathmisc.rs
File metadata and controls
46 lines (39 loc) · 1.04 KB
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
use core::fmt;
use std::io;
use arcstr::ArcStr;
pub fn write_comma_io<T>(mut file: T, comma: &mut bool) -> io::Result<()>
where T: io::Write {
if *comma {
file.write_all(b",")?;
}
*comma = true;
Ok(())
}
pub fn write_comma_fmt<T>(mut file: T, comma: &mut bool) -> fmt::Result
where T: fmt::Write {
if *comma {
file.write_str(",")?;
}
*comma = true;
Ok(())
}
pub type SmolStr = ArcStr;
pub mod base64 {
use base64::Engine;
use serde::{
Deserialize,
Deserializer,
Serialize,
Serializer,
};
pub fn serialize<S: Serializer>(v: &Vec<u8>, s: S) -> Result<S::Ok, S::Error> {
let base64 = base64::engine::general_purpose::STANDARD.encode(v);
String::serialize(&base64, s)
}
pub fn deserialize<'de, D: Deserializer<'de>>(d: D) -> Result<Vec<u8>, D::Error> {
let base64 = String::deserialize(d)?;
base64::engine::general_purpose::STANDARD
.decode(base64.as_bytes())
.map_err(serde::de::Error::custom)
}
}