tokio-serde-0.8.0/.cargo_vcs_info.json0000644000000001121377102504600133230ustar { "git": { "sha1": "cbd4a0e4a5ee4b0090c493954af496b6201e4c85" } } tokio-serde-0.8.0/.github/workflows/main.yml010060000007650000024000000027351357306172000171720ustar 00000000000000on: [push, pull_request] name: Continuous integration jobs: check: name: Check runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable override: true - uses: actions-rs/cargo@v1 with: command: check args: --all-features test: name: Test Suite runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable override: true - uses: actions-rs/cargo@v1 with: command: test args: --all-features fmt: name: Rustfmt runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable override: true - run: rustup component add rustfmt - uses: actions-rs/cargo@v1 with: command: fmt args: --all -- --check clippy: name: Clippy runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable override: true - run: rustup component add clippy - uses: actions-rs/cargo@v1 with: command: clippy args: --all-features -- -D warnings tokio-serde-0.8.0/.gitignore010060000007650000024000000000221356066125300141040ustar 00000000000000target Cargo.lock tokio-serde-0.8.0/Cargo.lock0000644000000373511377102504600113150ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] name = "async-stream" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3670df70cbc01729f901f94c887814b3c68db038aad1329a418bae178bc5295c" dependencies = [ "async-stream-impl", "futures-core", ] [[package]] name = "async-stream-impl" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3548b8efc9f8e8a5a0a2808c5bd8451a9031b9e5b879a79590304ae928b0a70" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "autocfg" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "bincode" version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f30d3a39baa26f9651f17b375061f3233dde33424a8b72b0dbe93a68a0bc896d" dependencies = [ "byteorder", "serde", ] [[package]] name = "byteorder" version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" [[package]] name = "bytes" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad1f8e949d755f9d79112b5bb46938e0ef9d3804a0b16dfab13aafcaa5f0fa72" [[package]] name = "cfg-if" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "educe" version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7260c7e6e656fc7702a1aa8d5b498a1a69aa84ac4ffcd5501b7d26939f368a93" dependencies = [ "enum-ordinalize", "proc-macro2", "quote", "syn", ] [[package]] name = "enum-ordinalize" version = "3.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1676e1daadfd216bda88d3a6fedd1bf53b829a085f5cc4d81c6f3054f50ef983" dependencies = [ "num-bigint", "num-traits", "proc-macro2", "quote", "syn", ] [[package]] name = "futures" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b3b0c040a1fe6529d30b3c5944b280c7f0dcb2930d2c3062bca967b602583d0" dependencies = [ "futures-channel", "futures-core", "futures-executor", "futures-io", "futures-sink", "futures-task", "futures-util", ] [[package]] name = "futures-channel" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b7109687aa4e177ef6fe84553af6280ef2778bdb7783ba44c9dc3399110fe64" dependencies = [ "futures-core", "futures-sink", ] [[package]] name = "futures-core" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "847ce131b72ffb13b6109a221da9ad97a64cbe48feb1028356b836b47b8f1748" [[package]] name = "futures-executor" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4caa2b2b68b880003057c1dd49f1ed937e38f22fcf6c212188a121f08cf40a65" dependencies = [ "futures-core", "futures-task", "futures-util", ] [[package]] name = "futures-io" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "611834ce18aaa1bd13c4b374f5d653e1027cf99b6b502584ff8c9a64413b30bb" [[package]] name = "futures-macro" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77408a692f1f97bcc61dc001d752e00643408fbc922e4d634c655df50d595556" dependencies = [ "proc-macro-hack", "proc-macro2", "quote", "syn", ] [[package]] name = "futures-sink" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f878195a49cee50e006b02b93cf7e0a95a38ac7b776b4c4d9cc1207cd20fcb3d" [[package]] name = "futures-task" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c554eb5bf48b2426c4771ab68c6b14468b6e76cc90996f528c3338d761a4d0d" dependencies = [ "once_cell", ] [[package]] name = "futures-util" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d304cff4a7b99cfb7986f7d43fbe93d175e72e704a8860787cc95e9ffd85cbd2" dependencies = [ "futures-channel", "futures-core", "futures-io", "futures-macro", "futures-sink", "futures-task", "memchr", "pin-project", "pin-utils", "proc-macro-hack", "proc-macro-nested", "slab", ] [[package]] name = "half" version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d36fab90f82edc3c747f9d438e06cf0a491055896f2a279638bb5beed6c40177" [[package]] name = "hermit-abi" version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" dependencies = [ "libc", ] [[package]] name = "impls" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a46645bbd70538861a90d0f26c31537cdf1e44aae99a794fb75a664b70951bc" [[package]] name = "instant" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" dependencies = [ "cfg-if 1.0.0", ] [[package]] name = "itoa" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" [[package]] name = "libc" version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" [[package]] name = "lock_api" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd96ffd135b2fd7b973ac026d28085defbe8983df057ced3eb4f2130b0831312" dependencies = [ "scopeguard", ] [[package]] name = "log" version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" dependencies = [ "cfg-if 0.1.10", ] [[package]] name = "memchr" version = "2.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" [[package]] name = "mio" version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f33bc887064ef1fd66020c9adfc45bb9f33d75a42096c81e7c56c65b75dd1a8b" dependencies = [ "libc", "log", "miow", "ntapi", "winapi", ] [[package]] name = "miow" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a33c1b55807fbed163481b5ba66db4b2fa6cde694a5027be10fb724206c5897" dependencies = [ "socket2", "winapi", ] [[package]] name = "ntapi" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" dependencies = [ "winapi", ] [[package]] name = "num-bigint" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e9a41747ae4633fce5adffb4d2e81ffc5e89593cb19917f8fb2cc5ff76507bf" dependencies = [ "autocfg", "num-integer", "num-traits", ] [[package]] name = "num-integer" version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" dependencies = [ "autocfg", "num-traits", ] [[package]] name = "num-traits" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" dependencies = [ "autocfg", ] [[package]] name = "num_cpus" version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" dependencies = [ "hermit-abi", "libc", ] [[package]] name = "once_cell" version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" [[package]] name = "parking_lot" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" dependencies = [ "instant", "lock_api", "parking_lot_core", ] [[package]] name = "parking_lot_core" version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ccb628cad4f84851442432c60ad8e1f607e29752d0bf072cbd0baf28aa34272" dependencies = [ "cfg-if 1.0.0", "instant", "libc", "redox_syscall", "smallvec", "winapi", ] [[package]] name = "pin-project" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ccc2237c2c489783abd8c4c80e5450fc0e98644555b1364da68cc29aa151ca7" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8e8d2bf0b23038a4424865103a4df472855692821aab4e4f5c3312d461d9e5f" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "pin-project-lite" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b063f57ec186e6140e2b8b6921e5f1bd89c7356dda5b33acc5401203ca6131c" [[package]] name = "pin-utils" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "proc-macro-hack" version = "0.5.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" [[package]] name = "proc-macro-nested" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a" [[package]] name = "proc-macro2" version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" dependencies = [ "unicode-xid", ] [[package]] name = "quote" version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df" dependencies = [ "proc-macro2", ] [[package]] name = "redox_syscall" version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" [[package]] name = "rmp" version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f10b46df14cf1ee1ac7baa4d2fbc2c52c0622a4b82fa8740e37bc452ac0184f" dependencies = [ "byteorder", "num-traits", ] [[package]] name = "rmp-serde" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2657c5ae22d7d73f8cebfa8bf69c851fb3aa4ba3fb09e59b87de88bd18ecbe01" dependencies = [ "byteorder", "rmp", "serde", ] [[package]] name = "ryu" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" [[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" version = "1.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800" [[package]] name = "serde_cbor" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e18acfa2f90e8b735b2836ab8d538de304cbb6729a7360729ea5a895d15a622" dependencies = [ "half", "serde", ] [[package]] name = "serde_json" version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1500e84d27fe482ed1dc791a56eddc2f230046a040fa908c08bda1d9fb615779" dependencies = [ "itoa", "ryu", "serde", ] [[package]] name = "signal-hook-registry" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16f1d0fef1604ba8f7a073c7e701f213e056707210e9020af4528e0101ce11a6" dependencies = [ "libc", ] [[package]] name = "slab" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" [[package]] name = "smallvec" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae524f056d7d770e174287294f562e95044c68e88dec909a00d2094805db9d75" [[package]] name = "socket2" version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" dependencies = [ "cfg-if 1.0.0", "libc", "winapi", ] [[package]] name = "static_assertions" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "syn" version = "1.0.55" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a571a711dddd09019ccc628e1b17fe87c59b09d513c06c026877aa708334f37a" dependencies = [ "proc-macro2", "quote", "unicode-xid", ] [[package]] name = "tokio" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f4bfdcbd00fa893ac0549b38aa27080636a0104b0d0c38475a99439405e1df8" dependencies = [ "autocfg", "bytes", "libc", "memchr", "mio", "num_cpus", "once_cell", "parking_lot", "pin-project-lite", "signal-hook-registry", "tokio-macros", "winapi", ] [[package]] name = "tokio-macros" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42517d2975ca3114b22a16192634e8241dc5cc1f130be194645970cc1c371494" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "tokio-serde" version = "0.8.0" dependencies = [ "bincode", "bytes", "educe", "futures", "futures-core", "futures-sink", "impls", "pin-project", "rmp-serde", "serde", "serde_cbor", "serde_json", "static_assertions", "tokio", "tokio-util", ] [[package]] name = "tokio-stream" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f3be913b74b13210c8fe04b17ab833f5a124f45b93d0f99f59fff621f64392a" dependencies = [ "async-stream", "futures-core", "pin-project-lite", "tokio", ] [[package]] name = "tokio-util" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "36135b7e7da911f5f8b9331209f7fab4cc13498f3fff52f72a710c78187e3148" dependencies = [ "bytes", "futures-core", "futures-sink", "log", "pin-project-lite", "tokio", "tokio-stream", ] [[package]] name = "unicode-xid" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" [[package]] name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ "winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu", ] [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" tokio-serde-0.8.0/Cargo.toml0000644000000047511377102504600113360ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] edition = "2018" name = "tokio-serde" version = "0.8.0" authors = ["Carl Lerche ", "Artem Vorotnikov ", "Bastian Köcher "] description = "Send and receive Serde encodable types over the network using Tokio.\n\nThis library is used as a building block for serialization format specific\nlibraries.\n" homepage = "https://github.com/carllerche/tokio-serde" documentation = "https://docs.rs/tokio-serde" readme = "README.md" keywords = ["async", "serde", "serialization"] categories = ["asynchronous", "encoding"] license = "MIT OR Apache-2.0" repository = "https://github.com/carllerche/tokio-serde" [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] [[example]] name = "client" required-features = ["bincode", "cbor", "json", "messagepack"] [[example]] name = "server" required-features = ["bincode", "cbor", "json", "messagepack"] [dependencies.bincode-crate] version = "1" optional = true package = "bincode" [dependencies.bytes] version = "1.0" [dependencies.educe] version = "0.4" optional = true default-features = false [dependencies.futures-core] version = "0.3" [dependencies.futures-sink] version = "0.3" [dependencies.pin-project] version = "1" [dependencies.rmp-serde] version = "0.15" optional = true [dependencies.serde] version = "1" optional = true [dependencies.serde_cbor] version = "0.11" optional = true [dependencies.serde_json] version = "1" optional = true [dev-dependencies.futures] version = "0.3" [dev-dependencies.impls] version = "1" [dev-dependencies.static_assertions] version = "1.1.0" [dev-dependencies.tokio] version = "1.0" features = ["full"] [dev-dependencies.tokio-util] version = "0.6" features = ["codec"] [features] bincode = ["educe/Debug", "serde", "bincode-crate"] cbor = ["educe/Debug", "educe/Default", "serde", "serde_cbor"] json = ["educe/Debug", "educe/Default", "serde", "serde_json"] messagepack = ["educe/Debug", "educe/Default", "serde", "rmp-serde"] tokio-serde-0.8.0/Cargo.toml.orig010064400007650000024000000034211377102473700150250ustar 00000000000000[package] name = "tokio-serde" version = "0.8.0" edition = "2018" authors = [ "Carl Lerche ", "Artem Vorotnikov ", "Bastian Köcher ", ] license = "MIT OR Apache-2.0" readme = "README.md" categories = ["asynchronous", "encoding"] keywords = ["async", "serde", "serialization"] repository = "https://github.com/carllerche/tokio-serde" homepage = "https://github.com/carllerche/tokio-serde" documentation = "https://docs.rs/tokio-serde" description = """ Send and receive Serde encodable types over the network using Tokio. This library is used as a building block for serialization format specific libraries. """ [dependencies] bytes = "1.0" educe = { version = "0.4", optional = true, default-features = false } futures-core = "0.3" futures-sink = "0.3" pin-project = "1" serde = { version = "1", optional = true } bincode-crate = { package = "bincode", version = "1", optional = true } serde_json = { version = "1", optional = true } rmp-serde = { version = "0.15", optional = true } serde_cbor = { version = "0.11", optional = true } [dev-dependencies] futures = "0.3" impls = "1" tokio = { version = "1.0", features = ["full"] } tokio-util = { version = "0.6", features = ["codec"] } static_assertions = "1.1.0" [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] [features] bincode = ["educe/Debug", "serde", "bincode-crate"] json = ["educe/Debug", "educe/Default", "serde", "serde_json"] messagepack = ["educe/Debug", "educe/Default", "serde", "rmp-serde"] cbor = ["educe/Debug", "educe/Default", "serde", "serde_cbor"] [[example]] name = "client" required-features = ["bincode", "cbor", "json", "messagepack"] [[example]] name = "server" required-features = ["bincode", "cbor", "json", "messagepack"] tokio-serde-0.8.0/LICENSE-APACHE010064400007650000024000000227731374722250000140640ustar 00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS tokio-serde-0.8.0/LICENSE-MIT010060000007650000024000000021531363604647400135650ustar 00000000000000Copyright (c) 2017 Carl Lerche Copyright (c) 2018 Bastian Köcher Copyright (c) 2019-2020 Artem Vorotnikov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. tokio-serde-0.8.0/README.md010064400007650000024000000017021377102473600134140ustar 00000000000000# Tokio Serialize / Deserialize Utilities needed to easily implement a Tokio transport using [serde] for serialization and deserialization of frame values. [Documentation](https://docs.rs/tokio-serde) ## Usage To use `tokio-serde`, first add this to your `Cargo.toml`: ```toml [dependencies] tokio-serde = "0.8" ``` Next, add this to your crate: ```rust use tokio_serde::{Serializer, Deserializer, Framed}; ``` [serde]: https://serde.rs # License This project is licensed under either of * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) at your option. ### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in iovec by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. tokio-serde-0.8.0/examples/client.rs010060000007650000024000000015111363226742000155600ustar 00000000000000use futures::prelude::*; use serde_json::json; use tokio::net::TcpStream; use tokio_serde::formats::*; use tokio_util::codec::{FramedWrite, LengthDelimitedCodec}; #[tokio::main] pub async fn main() { // Bind a server socket let socket = TcpStream::connect("127.0.0.1:17653").await.unwrap(); // Delimit frames using a length header let length_delimited = FramedWrite::new(socket, LengthDelimitedCodec::new()); // Serialize frames with JSON let mut serialized = tokio_serde::SymmetricallyFramed::new(length_delimited, SymmetricalJson::default()); // Send the value serialized .send(json!({ "name": "John Doe", "age": 43, "phones": [ "+44 1234567", "+44 2345678" ] })) .await .unwrap() } tokio-serde-0.8.0/examples/server.rs010064400007650000024000000017671377102443000156310ustar 00000000000000use futures::prelude::*; use serde_json::Value; use tokio::net::TcpListener; use tokio_serde::formats::*; use tokio_util::codec::{FramedRead, LengthDelimitedCodec}; #[tokio::main] pub async fn main() { // Bind a server socket let listener = TcpListener::bind("127.0.0.1:17653").await.unwrap(); println!("listening on {:?}", listener.local_addr()); loop { let (socket, _) = listener.accept().await.unwrap(); // Delimit frames using a length header let length_delimited = FramedRead::new(socket, LengthDelimitedCodec::new()); // Deserialize frames let mut deserialized = tokio_serde::SymmetricallyFramed::new( length_delimited, SymmetricalJson::::default(), ); // Spawn a task that prints all received messages to STDOUT tokio::spawn(async move { while let Some(msg) = deserialized.try_next().await.unwrap() { println!("GOT: {:?}", msg); } }); } } tokio-serde-0.8.0/src/lib.rs010064400007650000024000000463671374723401300140520ustar 00000000000000//! This crate provides the utilities needed to easily implement a Tokio //! transport using [serde] for serialization and deserialization of frame //! values. //! //! # Introduction //! //! This crate provides [transport] combinators that transform a stream of //! frames encoded as bytes into a stream of frame values. It is expected that //! the framing happens at another layer. One option is to use a [length //! delimited] framing transport. //! //! The crate provides two traits that must be implemented: [`Serializer`] and //! [`Deserializer`]. Implementations of these traits are then passed to //! [`Framed`] along with the upstream [`Stream`] or //! [`Sink`] that handles the byte encoded frames. //! //! By doing this, a transformation pipeline is built. For reading, it looks //! something like this: //! //! * `tokio_serde::Framed` //! * `tokio_util::codec::FramedRead` //! * `tokio::net::TcpStream` //! //! The write half looks like: //! //! * `tokio_serde::Framed` //! * `tokio_util::codec::FramedWrite` //! * `tokio::net::TcpStream` //! //! # Examples //! //! For an example, see how JSON support is implemented: //! //! * [server](https://github.com/carllerche/tokio-serde/blob/master/examples/server.rs) //! * [client](https://github.com/carllerche/tokio-serde/blob/master/examples/client.rs) //! //! [serde]: https://serde.rs //! [serde-json]: https://github.com/serde-rs/json //! [transport]: https://tokio.rs/docs/going-deeper/transports/ //! [length delimited]: https://docs.rs/tokio-util/0.2/tokio_util/codec/length_delimited/index.html //! [`Serializer`]: trait.Serializer.html //! [`Deserializer`]: trait.Deserializer.html //! [`Framed`]: struct.Framed.html //! [`Stream`]: https://docs.rs/futures/0.3/futures/stream/trait.Stream.html //! [`Sink`]: https://docs.rs/futures/0.3/futures/sink/trait.Sink.html #![cfg_attr(docsrs, feature(doc_cfg))] use bytes::{Bytes, BytesMut}; use futures_core::{ready, Stream, TryStream}; use futures_sink::Sink; use pin_project::pin_project; use std::{ marker::PhantomData, pin::Pin, task::{Context, Poll}, }; /// Serializes a value into a destination buffer /// /// Implementations of `Serializer` are able to take values of type `T` and /// convert them to a byte representation. The specific byte format, i.e. JSON, /// protobuf, binpack, ... is an implementation detail. /// /// The `serialize` function takes `&mut self`, allowing for `Serializer` /// instances to be created with runtime configuration settings. /// /// # Examples /// /// An integer serializer that allows the width to be configured. /// /// ``` /// use tokio_serde::Serializer; /// use bytes::{Buf, Bytes, BytesMut, BufMut}; /// use std::pin::Pin; /// /// struct IntSerializer { /// width: usize, /// } /// /// #[derive(Debug)] /// enum Error { /// Overflow, /// } /// /// impl Serializer for IntSerializer { /// type Error = Error; /// /// fn serialize(self: Pin<&mut Self>, item: &u64) -> Result { /// assert!(self.width <= 8); /// /// let max = (1 << (self.width * 8)) - 1; /// /// if *item > max { /// return Err(Error::Overflow); /// } /// /// let mut ret = BytesMut::with_capacity(self.width); /// ret.put_uint(*item, self.width); /// Ok(ret.into()) /// } /// } /// /// let mut serializer = IntSerializer { width: 3 }; /// /// let buf = Pin::new(&mut serializer).serialize(&5).unwrap(); /// assert_eq!(buf, &b"\x00\x00\x05"[..]); /// ``` pub trait Serializer { type Error; /// Serializes `item` into a new buffer /// /// The serialization format is specific to the various implementations of /// `Serializer`. If the serialization is successful, a buffer containing /// the serialized item is returned. If the serialization is unsuccessful, /// an error is returned. /// /// Implementations of this function should not mutate `item` via any sort /// of internal mutability strategy. /// /// See the trait level docs for more detail. fn serialize(self: Pin<&mut Self>, item: &T) -> Result; } /// Deserializes a value from a source buffer /// /// Implementatinos of `Deserializer` take a byte buffer and return a value by /// parsing the contents of the buffer according to the implementation's format. /// The specific byte format, i.e. JSON, protobuf, binpack, is an implementation /// detail /// /// The `deserialize` function takes `&mut self`, allowing for `Deserializer` /// instances to be created with runtime configuration settings. /// /// It is expected that the supplied buffer represents a full value and only /// that value. If after deserializing a value there are remaining bytes the /// buffer, the deserializer will return an error. /// /// # Examples /// /// An integer deserializer that allows the width to be configured. /// /// ``` /// use tokio_serde::Deserializer; /// use bytes::{BytesMut, Buf}; /// use std::pin::Pin; /// /// struct IntDeserializer { /// width: usize, /// } /// /// #[derive(Debug)] /// enum Error { /// Underflow, /// Overflow /// } /// /// impl Deserializer for IntDeserializer { /// type Error = Error; /// /// fn deserialize(self: Pin<&mut Self>, buf: &BytesMut) -> Result { /// assert!(self.width <= 8); /// /// if buf.len() > self.width { /// return Err(Error::Overflow); /// } /// /// if buf.len() < self.width { /// return Err(Error::Underflow); /// } /// /// let ret = std::io::Cursor::new(buf).get_uint(self.width); /// Ok(ret) /// } /// } /// /// let mut deserializer = IntDeserializer { width: 3 }; /// /// let i = Pin::new(&mut deserializer).deserialize(&b"\x00\x00\x05"[..].into()).unwrap(); /// assert_eq!(i, 5); /// ``` pub trait Deserializer { type Error; /// Deserializes a value from `buf` /// /// The serialization format is specific to the various implementations of /// `Deserializer`. If the deserialization is successful, the value is /// returned. If the deserialization is unsuccessful, an error is returned. /// /// See the trait level docs for more detail. fn deserialize(self: Pin<&mut Self>, src: &BytesMut) -> Result; } /// Adapts a transport to a value sink by serializing the values and to a stream of values by deserializing them. /// /// It is expected that the buffers yielded by the supplied transport be framed. In /// other words, each yielded buffer must represent exactly one serialized /// value. /// /// The provided transport will receive buffer values containing the /// serialized value. Each buffer contains exactly one value. This sink will be /// responsible for writing these buffers to an `AsyncWrite` using some sort of /// framing strategy. /// /// The specific framing strategy is left up to the /// implementor. One option would be to use [length_delimited] provided by /// [tokio-util]. /// /// [length_delimited]: http://docs.rs/tokio-util/0.2/tokio_util/codec/length_delimited/index.html /// [tokio-util]: http://crates.io/crates/tokio-util #[pin_project] #[derive(Debug)] pub struct Framed { #[pin] inner: Transport, #[pin] codec: Codec, item: PhantomData<(Item, SinkItem)>, } impl Framed { /// Creates a new `Framed` with the given transport and codec. pub fn new(inner: Transport, codec: Codec) -> Self { Self { inner, codec, item: PhantomData, } } /// Returns a reference to the underlying transport wrapped by `Framed`. /// /// Note that care should be taken to not tamper with the underlying transport as /// it may corrupt the sequence of frames otherwise being worked with. pub fn get_ref(&self) -> &Transport { &self.inner } /// Returns a mutable reference to the underlying transport wrapped by /// `Framed`. /// /// Note that care should be taken to not tamper with the underlying transport as /// it may corrupt the sequence of frames otherwise being worked with. pub fn get_mut(&mut self) -> &mut Transport { &mut self.inner } /// Consumes the `Framed`, returning its underlying transport. /// /// Note that care should be taken to not tamper with the underlying transport as /// it may corrupt the sequence of frames otherwise being worked with. pub fn into_inner(self) -> Transport { self.inner } } impl Stream for Framed where Transport: TryStream, Transport::Error: From, BytesMut: From, Codec: Deserializer, { type Item = Result; fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { match ready!(self.as_mut().project().inner.try_poll_next(cx)) { Some(bytes) => Poll::Ready(Some(Ok(self .as_mut() .project() .codec .deserialize(&bytes?)?))), None => Poll::Ready(None), } } } impl Sink for Framed where Transport: Sink, Codec: Serializer, Codec::Error: Into, { type Error = Transport::Error; fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { self.project().inner.poll_ready(cx) } fn start_send(mut self: Pin<&mut Self>, item: SinkItem) -> Result<(), Self::Error> { let res = self.as_mut().project().codec.serialize(&item); let bytes = res.map_err(Into::into)?; self.as_mut().project().inner.start_send(bytes)?; Ok(()) } fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { self.project().inner.poll_flush(cx) } fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { ready!(self.as_mut().poll_flush(cx))?; self.project().inner.poll_close(cx) } } pub type SymmetricallyFramed = Framed; #[cfg(any( feature = "json", feature = "bincode", feature = "messagepack", feature = "cbor" ))] pub mod formats { #[cfg(feature = "bincode")] pub use self::bincode::*; #[cfg(feature = "cbor")] pub use self::cbor::*; #[cfg(feature = "json")] pub use self::json::*; #[cfg(feature = "messagepack")] pub use self::messagepack::*; use super::{Deserializer, Serializer}; use bytes::{Bytes, BytesMut}; use educe::Educe; use serde::{Deserialize, Serialize}; use std::{marker::PhantomData, pin::Pin}; #[cfg(feature = "bincode")] mod bincode { use super::*; use bincode_crate::config::Options; use std::io; /// Bincode codec using [bincode](https://docs.rs/bincode) crate. #[cfg_attr(docsrs, doc(cfg(feature = "bincode")))] #[derive(Educe)] #[educe(Debug)] pub struct Bincode { #[educe(Debug(ignore))] options: O, #[educe(Debug(ignore))] ghost: PhantomData<(Item, SinkItem)>, } impl Default for Bincode { fn default() -> Self { Bincode { options: Default::default(), ghost: PhantomData, } } } impl From for Bincode where O: Options, { fn from(options: O) -> Self { Self { options, ghost: PhantomData, } } } #[cfg_attr(docsrs, doc(cfg(feature = "bincode")))] pub type SymmetricalBincode = Bincode; impl Deserializer for Bincode where for<'a> Item: Deserialize<'a>, O: Options + Clone, { type Error = io::Error; fn deserialize(self: Pin<&mut Self>, src: &BytesMut) -> Result { Ok(self .options .clone() .deserialize(src) .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?) } } impl Serializer for Bincode where SinkItem: Serialize, O: Options + Clone, { type Error = io::Error; fn serialize(self: Pin<&mut Self>, item: &SinkItem) -> Result { Ok(self .options .clone() .serialize(item) .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))? .into()) } } } #[cfg(feature = "json")] mod json { use super::*; use bytes::Buf; /// JSON codec using [serde_json](https://docs.rs/serde_json) crate. #[cfg_attr(docsrs, doc(cfg(feature = "json")))] #[derive(Educe)] #[educe(Debug, Default)] pub struct Json { #[educe(Debug(ignore), Default(expression = "PhantomData"))] ghost: PhantomData<(Item, SinkItem)>, } #[cfg_attr(docsrs, doc(cfg(feature = "json")))] pub type SymmetricalJson = Json; impl Deserializer for Json where for<'a> Item: Deserialize<'a>, { type Error = serde_json::Error; fn deserialize(self: Pin<&mut Self>, src: &BytesMut) -> Result { serde_json::from_reader(std::io::Cursor::new(src).reader()) } } impl Serializer for Json where SinkItem: Serialize, { type Error = serde_json::Error; fn serialize(self: Pin<&mut Self>, item: &SinkItem) -> Result { serde_json::to_vec(item).map(Into::into) } } } #[cfg(feature = "messagepack")] mod messagepack { use super::*; use bytes::Buf; use std::io; /// MessagePack codec using [rmp-serde](https://docs.rs/rmp-serde) crate. #[cfg_attr(docsrs, doc(cfg(feature = "messagepack")))] #[derive(Educe)] #[educe(Debug, Default)] pub struct MessagePack { #[educe(Debug(ignore), Default(expression = "PhantomData"))] ghost: PhantomData<(Item, SinkItem)>, } #[cfg_attr(docsrs, doc(cfg(feature = "messagepack")))] pub type SymmetricalMessagePack = MessagePack; impl Deserializer for MessagePack where for<'a> Item: Deserialize<'a>, { type Error = io::Error; fn deserialize(self: Pin<&mut Self>, src: &BytesMut) -> Result { Ok(rmp_serde::from_read(std::io::Cursor::new(src).reader()) .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?) } } impl Serializer for MessagePack where SinkItem: Serialize, { type Error = io::Error; fn serialize(self: Pin<&mut Self>, item: &SinkItem) -> Result { Ok(rmp_serde::to_vec(item) .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))? .into()) } } } #[cfg(feature = "cbor")] mod cbor { use super::*; use std::io; /// CBOR codec using [serde_cbor](https://docs.rs/serde_cbor) crate. #[cfg_attr(docsrs, doc(cfg(feature = "cbor")))] #[derive(Educe)] #[educe(Debug, Default)] pub struct Cbor { #[educe(Debug(ignore), Default(expression = "PhantomData"))] _mkr: PhantomData<(Item, SinkItem)>, } #[cfg_attr(docsrs, doc(cfg(feature = "cbor")))] pub type SymmetricalCbor = Cbor; impl Deserializer for Cbor where for<'a> Item: Deserialize<'a>, { type Error = io::Error; fn deserialize(self: Pin<&mut Self>, src: &BytesMut) -> Result { serde_cbor::from_slice(src.as_ref()).map_err(into_io_error) } } impl Serializer for Cbor where SinkItem: Serialize, { type Error = io::Error; fn serialize(self: Pin<&mut Self>, item: &SinkItem) -> Result { serde_cbor::to_vec(item) .map_err(into_io_error) .map(Into::into) } } fn into_io_error(cbor_err: serde_cbor::Error) -> io::Error { use io::ErrorKind; use serde_cbor::error::Category; use std::error::Error; match cbor_err.classify() { Category::Eof => io::Error::new(ErrorKind::UnexpectedEof, cbor_err), Category::Syntax => io::Error::new(ErrorKind::InvalidInput, cbor_err), Category::Data => io::Error::new(ErrorKind::InvalidData, cbor_err), Category::Io => { // Extract the underlying io error's type let kind = cbor_err .source() .and_then(|err| err.downcast_ref::()) .map(|io_err| io_err.kind()) .unwrap_or(ErrorKind::Other); io::Error::new(kind, cbor_err) } } } } } #[cfg(test)] mod tests { #[cfg(feature = "bincode")] #[test] fn bincode_impls() { use impls::impls; use std::fmt::Debug; struct Nothing; type T = crate::formats::Bincode; assert!(impls!(T: Debug)); assert!(impls!(T: Default)); } #[cfg(feature = "json")] #[test] fn json_impls() { use impls::impls; use std::fmt::Debug; struct Nothing; type T = crate::formats::Json; assert!(impls!(T: Debug)); assert!(impls!(T: Default)); } #[cfg(feature = "messagepack")] #[test] fn messagepack_impls() { use impls::impls; use std::fmt::Debug; struct Nothing; type T = crate::formats::MessagePack; assert!(impls!(T: Debug)); assert!(impls!(T: Default)); } #[cfg(feature = "cbor")] #[test] fn cbor_impls() { use impls::impls; use std::fmt::Debug; struct Nothing; type T = crate::formats::Cbor; assert!(impls!(T: Debug)); assert!(impls!(T: Default)); } }