ai_dataloader/collate/default_collate/
string.rs

1use super::super::Collate;
2use super::DefaultCollate;
3use std::ffi::{CStr, CString, OsString};
4
5impl Collate<String> for DefaultCollate {
6    type Output = Vec<String>;
7    fn collate(&self, batch: Vec<String>) -> Self::Output {
8        batch
9    }
10}
11
12impl<'a> Collate<&'a str> for DefaultCollate {
13    type Output = Vec<&'a str>;
14    fn collate(&self, batch: Vec<&'a str>) -> Self::Output {
15        batch
16    }
17}
18
19impl Collate<CString> for DefaultCollate {
20    type Output = Vec<CString>;
21    fn collate(&self, batch: Vec<CString>) -> Self::Output {
22        batch
23    }
24}
25
26impl<'a> Collate<&'a CStr> for DefaultCollate {
27    type Output = Vec<&'a CStr>;
28    fn collate(&self, batch: Vec<&'a CStr>) -> Self::Output {
29        batch
30    }
31}
32
33impl Collate<OsString> for DefaultCollate {
34    type Output = Vec<OsString>;
35    fn collate(&self, batch: Vec<OsString>) -> Self::Output {
36        batch
37    }
38}
39
40#[cfg(test)]
41mod tests {
42    use super::*;
43
44    #[test]
45    fn no_op() {
46        assert_eq!(
47            DefaultCollate.collate(vec![String::from("a"), String::from("b")]),
48            vec![String::from("a"), String::from("b")]
49        );
50
51        assert_eq!(DefaultCollate.collate(vec!["a", "b"]), vec!["a", "b"]);
52    }
53}