| 1 | use super::{decoder, encoder}; |
| 2 | use codec::{Audio, Id, Video}; |
| 3 | use Codec; |
| 4 | |
| 5 | pub trait Decoder { |
| 6 | fn decoder(self) -> Option<Codec>; |
| 7 | } |
| 8 | |
| 9 | impl<'a> Decoder for &'a str { |
| 10 | fn decoder(self) -> Option<Codec> { |
| 11 | decoder::find_by_name(self) |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | impl Decoder for Id { |
| 16 | fn decoder(self) -> Option<Codec> { |
| 17 | decoder::find(self) |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | impl Decoder for Codec { |
| 22 | fn decoder(self) -> Option<Codec> { |
| 23 | if self.is_decoder() { |
| 24 | Some(self) |
| 25 | } else { |
| 26 | None |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | impl Decoder for Option<Codec> { |
| 32 | fn decoder(self) -> Option<Codec> { |
| 33 | self.and_then(|c: Codec| c.decoder()) |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | impl Decoder for Audio { |
| 38 | fn decoder(self) -> Option<Codec> { |
| 39 | if self.is_decoder() { |
| 40 | Some(*self) |
| 41 | } else { |
| 42 | None |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | impl Decoder for Video { |
| 48 | fn decoder(self) -> Option<Codec> { |
| 49 | if self.is_decoder() { |
| 50 | Some(*self) |
| 51 | } else { |
| 52 | None |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | pub trait Encoder { |
| 58 | fn encoder(self) -> Option<Codec>; |
| 59 | } |
| 60 | |
| 61 | impl<'a> Encoder for &'a str { |
| 62 | fn encoder(self) -> Option<Codec> { |
| 63 | encoder::find_by_name(self) |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | impl Encoder for Id { |
| 68 | fn encoder(self) -> Option<Codec> { |
| 69 | encoder::find(self) |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | impl Encoder for Codec { |
| 74 | fn encoder(self) -> Option<Codec> { |
| 75 | if self.is_encoder() { |
| 76 | Some(self) |
| 77 | } else { |
| 78 | None |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | impl Encoder for Option<Codec> { |
| 84 | fn encoder(self) -> Option<Codec> { |
| 85 | self.and_then(|c: Codec| c.encoder()) |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | impl Encoder for Audio { |
| 90 | fn encoder(self) -> Option<Codec> { |
| 91 | if self.is_encoder() { |
| 92 | Some(*self) |
| 93 | } else { |
| 94 | None |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | impl Encoder for Video { |
| 100 | fn encoder(self) -> Option<Codec> { |
| 101 | if self.is_encoder() { |
| 102 | Some(*self) |
| 103 | } else { |
| 104 | None |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |