├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE.md ├── README.md ├── src └── main.rs └── tests └── conversion.rs /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "anyhow" 7 | version = "1.0.66" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" 10 | 11 | [[package]] 12 | name = "autocfg" 13 | version = "1.1.0" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" 16 | 17 | [[package]] 18 | name = "base64" 19 | version = "0.13.1" 20 | source = "registry+https://github.com/rust-lang/crates.io-index" 21 | checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" 22 | 23 | [[package]] 24 | name = "bitflags" 25 | version = "1.3.2" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 28 | 29 | [[package]] 30 | name = "byteorder" 31 | version = "1.4.3" 32 | source = "registry+https://github.com/rust-lang/crates.io-index" 33 | checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" 34 | 35 | [[package]] 36 | name = "form_urlencoded" 37 | version = "1.1.0" 38 | source = "registry+https://github.com/rust-lang/crates.io-index" 39 | checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" 40 | dependencies = [ 41 | "percent-encoding", 42 | ] 43 | 44 | [[package]] 45 | name = "half" 46 | version = "1.8.2" 47 | source = "registry+https://github.com/rust-lang/crates.io-index" 48 | checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" 49 | 50 | [[package]] 51 | name = "hashbrown" 52 | version = "0.12.3" 53 | source = "registry+https://github.com/rust-lang/crates.io-index" 54 | checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" 55 | 56 | [[package]] 57 | name = "indexmap" 58 | version = "1.9.2" 59 | source = "registry+https://github.com/rust-lang/crates.io-index" 60 | checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" 61 | dependencies = [ 62 | "autocfg", 63 | "hashbrown", 64 | ] 65 | 66 | [[package]] 67 | name = "iter-read" 68 | version = "0.3.1" 69 | source = "registry+https://github.com/rust-lang/crates.io-index" 70 | checksum = "c397ca3ea05ad509c4ec451fea28b4771236a376ca1c69fd5143aae0cf8f93c4" 71 | 72 | [[package]] 73 | name = "itoa" 74 | version = "1.0.4" 75 | source = "registry+https://github.com/rust-lang/crates.io-index" 76 | checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" 77 | 78 | [[package]] 79 | name = "num-bigint" 80 | version = "0.4.3" 81 | source = "registry+https://github.com/rust-lang/crates.io-index" 82 | checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" 83 | dependencies = [ 84 | "autocfg", 85 | "num-integer", 86 | "num-traits", 87 | ] 88 | 89 | [[package]] 90 | name = "num-integer" 91 | version = "0.1.45" 92 | source = "registry+https://github.com/rust-lang/crates.io-index" 93 | checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" 94 | dependencies = [ 95 | "autocfg", 96 | "num-traits", 97 | ] 98 | 99 | [[package]] 100 | name = "num-traits" 101 | version = "0.2.15" 102 | source = "registry+https://github.com/rust-lang/crates.io-index" 103 | checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" 104 | dependencies = [ 105 | "autocfg", 106 | ] 107 | 108 | [[package]] 109 | name = "paste" 110 | version = "1.0.9" 111 | source = "registry+https://github.com/rust-lang/crates.io-index" 112 | checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1" 113 | 114 | [[package]] 115 | name = "percent-encoding" 116 | version = "2.2.0" 117 | source = "registry+https://github.com/rust-lang/crates.io-index" 118 | checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" 119 | 120 | [[package]] 121 | name = "proc-macro2" 122 | version = "1.0.47" 123 | source = "registry+https://github.com/rust-lang/crates.io-index" 124 | checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" 125 | dependencies = [ 126 | "unicode-ident", 127 | ] 128 | 129 | [[package]] 130 | name = "quote" 131 | version = "1.0.21" 132 | source = "registry+https://github.com/rust-lang/crates.io-index" 133 | checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" 134 | dependencies = [ 135 | "proc-macro2", 136 | ] 137 | 138 | [[package]] 139 | name = "rmp" 140 | version = "0.8.11" 141 | source = "registry+https://github.com/rust-lang/crates.io-index" 142 | checksum = "44519172358fd6d58656c86ab8e7fbc9e1490c3e8f14d35ed78ca0dd07403c9f" 143 | dependencies = [ 144 | "byteorder", 145 | "num-traits", 146 | "paste", 147 | ] 148 | 149 | [[package]] 150 | name = "rmp-serde" 151 | version = "1.1.1" 152 | source = "registry+https://github.com/rust-lang/crates.io-index" 153 | checksum = "c5b13be192e0220b8afb7222aa5813cb62cc269ebb5cac346ca6487681d2913e" 154 | dependencies = [ 155 | "byteorder", 156 | "rmp", 157 | "serde", 158 | ] 159 | 160 | [[package]] 161 | name = "ron" 162 | version = "0.8.0" 163 | source = "registry+https://github.com/rust-lang/crates.io-index" 164 | checksum = "300a51053b1cb55c80b7a9fde4120726ddf25ca241a1cbb926626f62fb136bff" 165 | dependencies = [ 166 | "base64", 167 | "bitflags", 168 | "serde", 169 | ] 170 | 171 | [[package]] 172 | name = "ryu" 173 | version = "1.0.11" 174 | source = "registry+https://github.com/rust-lang/crates.io-index" 175 | checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" 176 | 177 | [[package]] 178 | name = "serde" 179 | version = "1.0.147" 180 | source = "registry+https://github.com/rust-lang/crates.io-index" 181 | checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" 182 | dependencies = [ 183 | "serde_derive", 184 | ] 185 | 186 | [[package]] 187 | name = "serde-pickle" 188 | version = "1.1.1" 189 | source = "registry+https://github.com/rust-lang/crates.io-index" 190 | checksum = "c762ad136a26407c6a80825813600ceeab5e613660d93d79a41f0ec877171e71" 191 | dependencies = [ 192 | "byteorder", 193 | "iter-read", 194 | "num-bigint", 195 | "num-traits", 196 | "serde", 197 | ] 198 | 199 | [[package]] 200 | name = "serde-transcode" 201 | version = "1.1.1" 202 | source = "registry+https://github.com/rust-lang/crates.io-index" 203 | checksum = "590c0e25c2a5bb6e85bf5c1bce768ceb86b316e7a01bdf07d2cb4ec2271990e2" 204 | dependencies = [ 205 | "serde", 206 | ] 207 | 208 | [[package]] 209 | name = "serde_cbor" 210 | version = "0.11.2" 211 | source = "registry+https://github.com/rust-lang/crates.io-index" 212 | checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5" 213 | dependencies = [ 214 | "half", 215 | "serde", 216 | ] 217 | 218 | [[package]] 219 | name = "serde_derive" 220 | version = "1.0.147" 221 | source = "registry+https://github.com/rust-lang/crates.io-index" 222 | checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" 223 | dependencies = [ 224 | "proc-macro2", 225 | "quote", 226 | "syn", 227 | ] 228 | 229 | [[package]] 230 | name = "serde_json" 231 | version = "1.0.88" 232 | source = "registry+https://github.com/rust-lang/crates.io-index" 233 | checksum = "8e8b3801309262e8184d9687fb697586833e939767aea0dda89f5a8e650e8bd7" 234 | dependencies = [ 235 | "itoa", 236 | "ryu", 237 | "serde", 238 | ] 239 | 240 | [[package]] 241 | name = "serde_urlencoded" 242 | version = "0.7.1" 243 | source = "registry+https://github.com/rust-lang/crates.io-index" 244 | checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" 245 | dependencies = [ 246 | "form_urlencoded", 247 | "itoa", 248 | "ryu", 249 | "serde", 250 | ] 251 | 252 | [[package]] 253 | name = "serde_yaml" 254 | version = "0.9.14" 255 | source = "registry+https://github.com/rust-lang/crates.io-index" 256 | checksum = "6d232d893b10de3eb7258ff01974d6ee20663d8e833263c99409d4b13a0209da" 257 | dependencies = [ 258 | "indexmap", 259 | "itoa", 260 | "ryu", 261 | "serde", 262 | "unsafe-libyaml", 263 | ] 264 | 265 | [[package]] 266 | name = "syn" 267 | version = "1.0.103" 268 | source = "registry+https://github.com/rust-lang/crates.io-index" 269 | checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" 270 | dependencies = [ 271 | "proc-macro2", 272 | "quote", 273 | "unicode-ident", 274 | ] 275 | 276 | [[package]] 277 | name = "thisthat" 278 | version = "0.1.3" 279 | dependencies = [ 280 | "anyhow", 281 | "form_urlencoded", 282 | "rmp", 283 | "rmp-serde", 284 | "ron", 285 | "serde", 286 | "serde-pickle", 287 | "serde-transcode", 288 | "serde_cbor", 289 | "serde_json", 290 | "serde_urlencoded", 291 | "serde_yaml", 292 | "toml", 293 | ] 294 | 295 | [[package]] 296 | name = "toml" 297 | version = "0.5.9" 298 | source = "registry+https://github.com/rust-lang/crates.io-index" 299 | checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" 300 | dependencies = [ 301 | "serde", 302 | ] 303 | 304 | [[package]] 305 | name = "unicode-ident" 306 | version = "1.0.5" 307 | source = "registry+https://github.com/rust-lang/crates.io-index" 308 | checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" 309 | 310 | [[package]] 311 | name = "unsafe-libyaml" 312 | version = "0.2.4" 313 | source = "registry+https://github.com/rust-lang/crates.io-index" 314 | checksum = "c1e5fa573d8ac5f1a856f8d7be41d390ee973daf97c806b2c1a465e4e1406e68" 315 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "thisthat" 3 | authors = ["Tim McNamara "] 4 | description = "Data conversion utility" 5 | version = "0.1.3" 6 | edition = "2021" 7 | license = "BlueOak-1.0.0" 8 | categories = ["command-line-utilities"] 9 | repository = "https://github.com/timClicks/thisthat/" 10 | 11 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 12 | 13 | [dependencies] 14 | anyhow = "1" 15 | form_urlencoded = "1" 16 | rmp = "0.8" 17 | rmp-serde = "1.1" 18 | ron = "0.8" 19 | serde = { version = "1", features = ["derive"] } 20 | serde_cbor = "0.11" 21 | serde_json = "1" 22 | serde_urlencoded = "0.7" 23 | serde_yaml = "0.9" 24 | serde-pickle = "1.0" 25 | serde-transcode = "1" 26 | toml = "0.5" 27 | 28 | # TODO: a proper CLI 29 | # clap = "3" 30 | 31 | # TODO: these crates doesn't expose Serializer as easily as they could 32 | # bson = "2" 33 | # postcard = { version = "1", features = ["alloc"] } 34 | # quick-xml = "0.27" # needs CLI 35 | 36 | [[bin]] 37 | name = "tt" 38 | path = "src/main.rs" -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # Blue Oak Model License 2 | 3 | Version 1.0.0 4 | 5 | ## Purpose 6 | 7 | This license gives everyone as much permission to work with 8 | this software as possible, while protecting contributors 9 | from liability. 10 | 11 | ## Acceptance 12 | 13 | In order to receive this license, you must agree to its 14 | rules. The rules of this license are both obligations 15 | under that agreement and conditions to your license. 16 | You must not do anything with this software that triggers 17 | a rule that you cannot or will not follow. 18 | 19 | ## Copyright 20 | 21 | Each contributor licenses you to do everything with this 22 | software that would otherwise infringe that contributor's 23 | copyright in it. 24 | 25 | ## Notices 26 | 27 | You must ensure that everyone who gets a copy of 28 | any part of this software from you, with or without 29 | changes, also gets the text of this license or a link to 30 | . 31 | 32 | ## Excuse 33 | 34 | If anyone notifies you in writing that you have not 35 | complied with [Notices](#notices), you can keep your 36 | license by taking all practical steps to comply within 30 37 | days after the notice. If you do not do so, your license 38 | ends immediately. 39 | 40 | ## Patent 41 | 42 | Each contributor licenses you to do everything with this 43 | software that would otherwise infringe any patent claims 44 | they can license or become able to license. 45 | 46 | ## Reliability 47 | 48 | No contributor can revoke this license. 49 | 50 | ## No Liability 51 | 52 | ***As far as the law allows, this software comes as is, 53 | without any warranty or condition, and no contributor 54 | will be liable to anyone for any damages related to this 55 | software or this license, under any kind of legal claim.*** 56 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # thisthat 2 | 3 | Data format conversion utility. 4 | 5 | ## About 6 | 7 | **thisthat** provides a command-line tool `tt` for converting between data formats. 8 | It can to and from convert between these formats: 9 | 10 | - CBOR 11 | - JSON 12 | - MsgPack 13 | - YAML 14 | - Pickle 15 | - RON 16 | - TOML 17 | - x-www-form-urlencoded ("url" or "www-form") 18 | 19 | ## Usage 20 | 21 | `tt` reads from stdin and writes to stdout. Specify the formats using positional 22 | parameters, e.g. `tt THIS THAT`. For example, to convert from JSON to TOML, use 23 | `tt json toml`. 24 | 25 | ```console 26 | $ echo '{"abc": 123 }' | tt json toml 27 | abc = 123 28 | ``` 29 | 30 | To convert data from a file, use `cat` (or an equivalent tool) to do the reading. 31 | 32 | ```console 33 | $ echo '{"abc": 123 }' > /tmp/example.json 34 | $ cat /tmp/example.json | tt json toml 35 | abc = 123 36 | ``` 37 | 38 | Some formats produce non-printable characters. Send the output to anther tool to 39 | generate readable output. 40 | 41 | ```console 42 | $ echo '{"abc": 123 }' | tt json msgpack | base64 43 | gaNhYmN7 44 | ``` 45 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | #![deny(warnings)] 2 | 3 | use std::{io, str::FromStr}; 4 | use anyhow::{Ok, Error, Result}; 5 | 6 | /// Supported output formats 7 | #[non_exhaustive] 8 | #[derive(Debug, Default, PartialEq, Eq)] 9 | enum Source { 10 | #[default] 11 | StdIn, 12 | } 13 | 14 | #[derive(Debug, PartialEq, Eq)] 15 | enum Format { 16 | Cbor, 17 | Json { pretty: bool }, 18 | MsgPack, 19 | Toml { pretty: bool }, 20 | Yaml, 21 | Pickle, 22 | Ron, 23 | UrlEncoded, 24 | } 25 | 26 | impl FromStr for Format { 27 | type Err = anyhow::Error; 28 | 29 | fn from_str(s: &str) -> Result { 30 | let fmt = match s { 31 | "cbor" | "CBOR" => Format::Cbor, 32 | "json" | "JSON" => Format::Json { pretty: true }, 33 | "yaml" | "YAML" => Format::Yaml, 34 | "toml" | "TOML "=> Format::Toml { pretty: true }, 35 | "msgpack" | "MSGPACK" => Format::MsgPack, 36 | "pickle" | "PICKLE" => Format::Pickle, 37 | "ron" | "RON" => Format::Ron, 38 | "url" | "www-form" => Format::UrlEncoded, 39 | _ => anyhow::bail!("unsupported format ({})." , s), 40 | }; 41 | Ok(fmt) 42 | } 43 | } 44 | 45 | 46 | #[non_exhaustive] 47 | #[derive(Debug,Default)] 48 | enum Destination { 49 | #[default] 50 | StdOut, 51 | } 52 | 53 | struct Args { 54 | input: Format, 55 | output: Format, 56 | dest: Destination, 57 | source: Source, 58 | } 59 | 60 | macro_rules! transcode { 61 | ($output_format:expr, $destination:expr, $deserializer:expr) => { 62 | match $output_format { 63 | Format::Cbor => { 64 | let mut dest = serde_cbor::ser::IoWrite::new(&mut $destination); 65 | let mut serializer = serde_cbor::Serializer::new(&mut dest) 66 | .packed_format(); 67 | serde_transcode::transcode($deserializer, &mut serializer)?; 68 | } 69 | Format::Json { pretty: true } => { 70 | let mut serializer = serde_json::Serializer::pretty($destination); 71 | serde_transcode::transcode($deserializer, &mut serializer)?; 72 | } 73 | Format::Json { pretty: false } => { 74 | let mut serializer = serde_json::Serializer::new($destination); 75 | serde_transcode::transcode($deserializer, &mut serializer)?; 76 | } 77 | Format::MsgPack => { 78 | let mut serializer = rmp_serde::Serializer::new($destination); 79 | serde_transcode::transcode($deserializer, &mut serializer)?; 80 | } 81 | Format::Pickle => { 82 | let mut serializer = serde_pickle::Serializer::new($destination, serde_pickle::ser::SerOptions::new()); 83 | serde_transcode::transcode($deserializer, &mut serializer)?; 84 | } 85 | Format::Ron => { 86 | let mut serializer = ron::Serializer::new($destination, None)?; 87 | serde_transcode::transcode($deserializer, &mut serializer)?; 88 | } 89 | Format::UrlEncoded => { 90 | use form_urlencoded::Serializer as UrlEncoder; 91 | let mut data = String::new(); 92 | let mut encoder = UrlEncoder::new(&mut data); 93 | let serializer = serde_urlencoded::Serializer::new(&mut encoder); 94 | serde_transcode::transcode($deserializer, serializer)?; 95 | $destination.write_all(data.as_bytes())?; 96 | } 97 | Format::Toml { pretty: true } => { 98 | let mut data = String::new(); 99 | let mut serializer = toml::Serializer::pretty(&mut data); 100 | serde_transcode::transcode($deserializer, &mut serializer)?; 101 | $destination.write_all(data.as_bytes())?; 102 | } 103 | Format::Toml { pretty: false } => { 104 | let mut data = String::new(); 105 | let mut serializer = toml::Serializer::new(&mut data); 106 | serde_transcode::transcode($deserializer, &mut serializer)?; 107 | $destination.write_all(data.as_bytes())?; 108 | } 109 | Format::Yaml => { 110 | let mut serializer = serde_yaml::Serializer::new($destination); 111 | serde_transcode::transcode($deserializer, &mut serializer)?; 112 | } 113 | } 114 | }; 115 | } 116 | 117 | fn help() -> ! { 118 | eprintln!("\ 119 | tt (\"this that\") data format converter 120 | 121 | Usage: 122 | tt THIS THAT Convert THIS to THAT 123 | tt -h Prints help 124 | 125 | tt reads from stdin and writes to stdout. Supported 126 | formats for THIS and THAT are: cbor, json, msgpack, 127 | pickle, ron, toml, url (for x-www-form-urlencoded), 128 | and yaml. 129 | "); 130 | std::process::exit(1) 131 | } 132 | 133 | fn main() -> Result<(), Error> { 134 | let mut input_format = None; 135 | let mut output_format = None; 136 | 137 | for arg in std::env::args() { 138 | match (arg.as_str(), &input_format, &output_format) { 139 | ("-h", _, _) => help(), 140 | (fmt, None, None) => { 141 | input_format = fmt.parse::().ok(); 142 | } 143 | (fmt, Some(_), None) => { 144 | output_format = fmt.parse::().ok(); 145 | } 146 | (_, _, _) => help() 147 | } 148 | } 149 | 150 | if input_format.is_none() || output_format.is_none() { 151 | help() 152 | } 153 | 154 | let args = Args { 155 | output: output_format.unwrap(), 156 | input: input_format.unwrap(), 157 | dest: Destination::StdOut, 158 | source: Source::StdIn, 159 | }; 160 | 161 | let mut source: Box = match args.source { 162 | Source::StdIn => Box::new(io::stdin()), 163 | // Source::Test => Box::new(StringReader::new(test_input)), 164 | }; 165 | 166 | let mut destination: Box = match args.dest { 167 | Destination::StdOut => Box::new(io::stdout()), 168 | // Destination::StdErr => Box::new(io::stderr()), 169 | }; 170 | 171 | 172 | // Yes, repetition here is horrific, but `serde::Deserializer` and 173 | // `serde::Serializer` cannot be made trait objects .. patch welcome 174 | match args.input { 175 | Format::Cbor => { 176 | let reader = serde_cbor::de::IoRead::new(source); 177 | 178 | let mut deserializer = serde_cbor::Deserializer::new(reader); 179 | 180 | transcode!(args.output, destination, &mut deserializer) 181 | } 182 | Format::Json { pretty: _ } => { 183 | let mut deserializer = serde_json::Deserializer::from_reader(source); 184 | 185 | transcode!(args.output, destination, &mut deserializer) 186 | }, 187 | Format::Yaml => { 188 | let deserializer = serde_yaml::Deserializer::from_reader(source); 189 | 190 | transcode!(args.output, destination, deserializer) 191 | } 192 | Format::MsgPack => { 193 | let mut deserializer = rmp_serde::Deserializer::new(source); 194 | 195 | transcode!(args.output, destination, &mut deserializer) 196 | }, 197 | Format::UrlEncoded => { 198 | let mut data = Vec::::with_capacity(0x100); 199 | let _bytes_read = source.read_to_end(&mut data)?; 200 | 201 | let parser = form_urlencoded::parse(&data); 202 | let deserializer = serde_urlencoded::Deserializer::new(parser); 203 | 204 | transcode!(args.output, destination, deserializer) 205 | } 206 | Format::Toml { pretty: _ } => { 207 | let mut data = String::with_capacity(0x100); 208 | let _bytes_read = source.read_to_string(&mut data)?; 209 | 210 | let mut deserializer = toml::Deserializer::new(&data); 211 | 212 | transcode!(args.output, destination, &mut deserializer) 213 | }, 214 | Format::Ron => { 215 | let mut data = Vec::::with_capacity(0x100); 216 | let _bytes_read = source.read_to_end(&mut data)?; 217 | 218 | let mut deserializer = ron::Deserializer::from_bytes(&data)?; 219 | 220 | transcode!(args.output, destination, &mut deserializer) 221 | 222 | }, 223 | Format::Pickle => { 224 | let mut deserializer = serde_pickle::Deserializer::new(source, serde_pickle::de::DeOptions::new()); 225 | transcode!(args.output, destination, &mut deserializer) 226 | }, 227 | } 228 | 229 | Ok(()) 230 | } 231 | -------------------------------------------------------------------------------- /tests/conversion.rs: -------------------------------------------------------------------------------- 1 | use std::vec; 2 | 3 | use serde::{self, Deserialize, Serialize}; 4 | use serde_json; 5 | 6 | #[derive(Debug, Serialize, Deserialize)] 7 | struct Fixture { 8 | a: String, 9 | b: f32, 10 | c: i32, 11 | d: Vec, 12 | e: Option>, 13 | } 14 | 15 | impl Fixture { 16 | fn new() -> Self { 17 | let garbage: Vec<&'static str> = vec!["a", "b", "c", "", "e"]; 18 | 19 | Fixture { 20 | a: "hello there".to_string(), 21 | b: -10.0, 22 | c: 12312, 23 | d: garbage.iter().map(|x| x.to_string()).collect(), 24 | e: Some(Box::new(Fixture { 25 | a: "hello there".to_string(), 26 | b: -10.0, 27 | c: 12312, 28 | d: garbage.iter().map(|x| x.to_string()).collect(), 29 | e: None, 30 | })), 31 | } 32 | } 33 | } 34 | 35 | #[test] 36 | fn todo() { 37 | // whelp 38 | } 39 | --------------------------------------------------------------------------------