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
#[derive(Debug)]
pub struct DecoderError(String);
#[derive(Debug)]
pub struct EncoderError(String);
pub fn decode(s: &str) -> Result<Playlist, DecoderError> {
Ok(Playlist::new(s))
}
pub fn encode(playlist: &Playlist) -> Result<String, EncoderError> {
Ok(playlist.name.clone())
}
pub struct Playlist {
name: String
}
impl Playlist {
pub fn new(name: &str) -> Playlist {
Playlist {
name: name.to_string()
}
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_decode() {
let playlist = decode("ololo").unwrap();
assert_eq!(&playlist.name[..], "ololo");
}
#[test]
fn test_encode() {
let playlist = encode(&Playlist::new("test")).unwrap();
assert_eq!(&playlist[..], "test");
}
}