[
  {
    "path": ".github/workflows/ci.yml",
    "content": "name: CI\n\non:\n  pull_request:\n  workflow_dispatch:\n  push:\n    branches:\n      - main\n\njobs:\n  build:\n    strategy:\n      matrix:\n        os: [windows-latest, ubuntu-latest, macos-latest]\n    runs-on: ${{ matrix.os }}\n    steps:\n      - uses: actions/checkout@v3\n      - uses: actions/cache@v3\n        with:\n          path: |\n            ~/.cargo/bin/\n            ~/.cargo/registry/index/\n            ~/.cargo/registry/cache/\n            ~/.cargo/git/db/\n            target/\n          key: ${{ runner.os }}-cargo-build-${{ matrix.toolchain }}-${{ hashFiles('**/Cargo.toml') }}\n      - uses: dtolnay/rust-toolchain@stable\n      - name: Install Bevy dependencies\n        run: sudo apt-get update; sudo apt-get install --no-install-recommends g++ pkg-config libx11-dev libasound2-dev libudev-dev libxkbcommon-x11-0 libwayland-dev libxkbcommon-dev\n        if: runner.os == 'linux'\n      - name: Build & run tests\n        run: cargo test --all-features\n  lint:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v3\n      - uses: actions/cache@v3\n        with:\n          path: |\n            ~/.cargo/bin/\n            ~/.cargo/registry/index/\n            ~/.cargo/registry/cache/\n            ~/.cargo/git/db/\n            target/\n          key: ubuntu-latest-cargo-build-stable-${{ hashFiles('**/Cargo.toml') }}\n      - uses: dtolnay/rust-toolchain@stable\n        with:\n          components: rustfmt, clippy\n      - name: Install Bevy dependencies\n        run: sudo apt-get update; sudo apt-get install --no-install-recommends g++ pkg-config libx11-dev libasound2-dev libudev-dev libxkbcommon-x11-0 libwayland-dev libxkbcommon-dev\n      - name: Run clippy\n        run: cargo clippy --all-targets --all-features -- -W clippy::doc_markdown -Dwarnings\n      - name: Check format\n        run: cargo fmt -- --check\n"
  },
  {
    "path": ".gitignore",
    "content": "target/\nCargo.lock\n.idea/\n\nimported_assets/\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "# Changelog\n\n## v0.16.0 - 22.03.2026\n- Add asset savers to all supported formats\n\n## v0.15.0 - 14.01.2026\n- Update to Bevy 0.18\n- depend on Bevy subcrates\n- remove default feature (accidentally was `csv`)\n\n## v0.14.0 - 01.10.2025\n- Support for CBOR files (@Kamduis in [#49](https://github.com/NiklasEi/bevy_common_assets/pull/49))\n- Update to Bevy 0.17\n\n## v0.13.0 - 26.04.2025\n- Update to Bevy 0.16\n- new example `asset_savers`\n\n## v0.12.0 - 29.11.2024\n- Update to Bevy 0.15\n\n## v0.11.0 - 04.07.2024\n- Update to Bevy 0.14\n- Update `quick-xml` to `0.34`\n- Support for [postcard](https://github.com/jamesmunns/postcard)\n\n## v0.10.0 - 17.02.2024\n- Update to Bevy 0.13\n\n## v0.9.1 - 17.01.2024\n- CsvAssetPlugin supports configuring the delimiter with `with_delimiter`\n\n## v0.9.0 - 07.01.2024\n- Add support for CSV files\n\n## v0.8.0 - 04.11.2023\n- Update to Bevy 0.12\n\n## v0.7.0 - 10.07.2023\n- Update to Bevy 0.11\n\n## v0.6.0 - 18.03.2023\n- Support for xml assets\n\n## v0.5.0 - 06.03.2023\n- Update to Bevy 0.10\n- Update `ron` to 0.8 and `toml` to 0.7\n\n## v0.4.0 - 13.11.2022\n- Update to Bevy 0.9\n\n## v0.3.0 - 30.7.2022\n- Update to Bevy 0.8\n\n## v0.2.0 - 8.5.2022\n- Support MessagePack assets\n"
  },
  {
    "path": "Cargo.toml",
    "content": "[package]\nname = \"bevy_common_assets\"\nversion = \"0.16.0\"\nauthors = [\"Niklas Eicker <git@nikl.me>\"]\nedition = \"2024\"\nlicense = \"MIT OR Apache-2.0\"\ndescription = \"Bevy plugin adding support for loading your own asset types from common file formats such as json and yaml\"\nrepository = \"https://github.com/NiklasEi/bevy_common_assets\"\nhomepage = \"https://github.com/NiklasEi/bevy_common_assets\"\ndocumentation = \"https://docs.rs/bevy_common_assets\"\nkeywords = [\"bevy\", \"gamedev\", \"asset\", \"assets\"]\ncategories = [\"game-development\"]\nreadme = \"./README.md\"\n\n[features]\nron = [\"dep:serde_ron\"]\ntoml = [\"dep:serde_toml\"]\nyaml = [\"dep:serde_yaml\"]\njson = [\"dep:serde_json\"]\nmsgpack = [\"dep:rmp-serde\"]\nxml = [\"dep:quick-xml\"]\ncsv = [\"dep:csv\"]\npostcard = [\"dep:postcard\"]\ncbor = [\"dep:ciborium\"]\n\n[dependencies]\nbevy_app = { version = \"0.18.0\", default-features = false }\nbevy_asset = { version = \"0.18.0\", default-features = false }\nbevy_reflect = { version = \"0.18.0\", default-features = false }\nserde_toml = { version = \"0.9\", package = \"toml\", optional = true }\nserde_ron = { version = \"0.11\", package = \"ron\", optional = true }\nserde_yaml = { version = \"0.9\", optional = true }\nserde_json = { version = \"1\", optional = true }\nrmp-serde = { version = \"1\", optional = true }\ncsv = { version = \"1\", optional = true }\nthiserror = \"2.0\"\nquick-xml = { version = \"0.38.3\", features = [\"serialize\"], optional = true }\nserde = { version = \"1\" }\nanyhow = { version = \"1\" }\npostcard = { version = \"1.0\", features = [\"use-std\"], optional = true }\nciborium = { version = \"0.2.2\", optional = true }\n\n[dev-dependencies]\nbevy = { version = \"0.18.0\", features = [\n    \"file_watcher\",\n    \"asset_processor\",\n] }\nserde = { version = \"1\" }\n\n[package.metadata.docs.rs]\nall-features = true\nrustdoc-args = [\"--cfg\", \"docsrs\"]\n\n[[example]]\nname = \"msgpack\"\npath = \"examples/msgpack.rs\"\nrequired-features = [\"msgpack\"]\n\n[[example]]\nname = \"postcard\"\npath = \"examples/postcard.rs\"\nrequired-features = [\"postcard\"]\n\n[[example]]\nname = \"ron\"\npath = \"examples/ron.rs\"\nrequired-features = [\"ron\"]\n\n[[example]]\nname = \"toml\"\npath = \"examples/toml.rs\"\nrequired-features = [\"toml\"]\n\n[[example]]\nname = \"yaml\"\npath = \"examples/yaml.rs\"\nrequired-features = [\"yaml\"]\n\n[[example]]\nname = \"json\"\npath = \"examples/json.rs\"\nrequired-features = [\"json\"]\n\n[[example]]\nname = \"xml\"\npath = \"examples/xml.rs\"\nrequired-features = [\"xml\"]\n\n[[example]]\nname = \"csv\"\npath = \"examples/csv.rs\"\nrequired-features = [\"csv\"]\n\n[[example]]\nname = \"cbor\"\npath = \"examples/cbor.rs\"\nrequired-features = [\"cbor\"]\n\n[[example]]\nname = \"multiple_formats\"\npath = \"examples/multiple_formats.rs\"\nrequired-features = [\"ron\", \"json\"]\n\n[[example]]\nname = \"asset_savers\"\npath = \"examples/asset_savers/asset_savers.rs\"\nrequired-features = [\"ron\", \"json\", \"postcard\", \"cbor\", \"msgpack\", \"toml\", \"yaml\"]\n"
  },
  {
    "path": "LICENSE-APACHE",
    "content": "                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\nTERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n1. Definitions.\n\n   \"License\" shall mean the terms and conditions for use, reproduction,\n   and distribution as defined by Sections 1 through 9 of this document.\n\n   \"Licensor\" shall mean the copyright owner or entity authorized by\n   the copyright owner that is granting the License.\n\n   \"Legal Entity\" shall mean the union of the acting entity and all\n   other entities that control, are controlled by, or are under common\n   control with that entity. For the purposes of this definition,\n   \"control\" means (i) the power, direct or indirect, to cause the\n   direction or management of such entity, whether by contract or\n   otherwise, or (ii) ownership of fifty percent (50%) or more of the\n   outstanding shares, or (iii) beneficial ownership of such entity.\n\n   \"You\" (or \"Your\") shall mean an individual or Legal Entity\n   exercising permissions granted by this License.\n\n   \"Source\" form shall mean the preferred form for making modifications,\n   including but not limited to software source code, documentation\n   source, and configuration files.\n\n   \"Object\" form shall mean any form resulting from mechanical\n   transformation or translation of a Source form, including but\n   not limited to compiled object code, generated documentation,\n   and conversions to other media types.\n\n   \"Work\" shall mean the work of authorship, whether in Source or\n   Object form, made available under the License, as indicated by a\n   copyright notice that is included in or attached to the work\n   (an example is provided in the Appendix below).\n\n   \"Derivative Works\" shall mean any work, whether in Source or Object\n   form, that is based on (or derived from) the Work and for which the\n   editorial revisions, annotations, elaborations, or other modifications\n   represent, as a whole, an original work of authorship. For the purposes\n   of this License, Derivative Works shall not include works that remain\n   separable from, or merely link (or bind by name) to the interfaces of,\n   the Work and Derivative Works thereof.\n\n   \"Contribution\" shall mean any work of authorship, including\n   the original version of the Work and any modifications or additions\n   to that Work or Derivative Works thereof, that is intentionally\n   submitted to Licensor for inclusion in the Work by the copyright owner\n   or by an individual or Legal Entity authorized to submit on behalf of\n   the copyright owner. For the purposes of this definition, \"submitted\"\n   means any form of electronic, verbal, or written communication sent\n   to the Licensor or its representatives, including but not limited to\n   communication on electronic mailing lists, source code control systems,\n   and issue tracking systems that are managed by, or on behalf of, the\n   Licensor for the purpose of discussing and improving the Work, but\n   excluding communication that is conspicuously marked or otherwise\n   designated in writing by the copyright owner as \"Not a Contribution.\"\n\n   \"Contributor\" shall mean Licensor and any individual or Legal Entity\n   on behalf of whom a Contribution has been received by Licensor and\n   subsequently incorporated within the Work.\n\n2. Grant of Copyright License. Subject to the terms and conditions of\n   this License, each Contributor hereby grants to You a perpetual,\n   worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n   copyright license to reproduce, prepare Derivative Works of,\n   publicly display, publicly perform, sublicense, and distribute the\n   Work and such Derivative Works in Source or Object form.\n\n3. Grant of Patent License. Subject to the terms and conditions of\n   this License, each Contributor hereby grants to You a perpetual,\n   worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n   (except as stated in this section) patent license to make, have made,\n   use, offer to sell, sell, import, and otherwise transfer the Work,\n   where such license applies only to those patent claims licensable\n   by such Contributor that are necessarily infringed by their\n   Contribution(s) alone or by combination of their Contribution(s)\n   with the Work to which such Contribution(s) was submitted. If You\n   institute patent litigation against any entity (including a\n   cross-claim or counterclaim in a lawsuit) alleging that the Work\n   or a Contribution incorporated within the Work constitutes direct\n   or contributory patent infringement, then any patent licenses\n   granted to You under this License for that Work shall terminate\n   as of the date such litigation is filed.\n\n4. Redistribution. You may reproduce and distribute copies of the\n   Work or Derivative Works thereof in any medium, with or without\n   modifications, and in Source or Object form, provided that You\n   meet the following conditions:\n\n   (a) You must give any other recipients of the Work or\n   Derivative Works a copy of this License; and\n\n   (b) You must cause any modified files to carry prominent notices\n   stating that You changed the files; and\n\n   (c) You must retain, in the Source form of any Derivative Works\n   that You distribute, all copyright, patent, trademark, and\n   attribution notices from the Source form of the Work,\n   excluding those notices that do not pertain to any part of\n   the Derivative Works; and\n\n   (d) If the Work includes a \"NOTICE\" text file as part of its\n   distribution, then any Derivative Works that You distribute must\n   include a readable copy of the attribution notices contained\n   within such NOTICE file, excluding those notices that do not\n   pertain to any part of the Derivative Works, in at least one\n   of the following places: within a NOTICE text file distributed\n   as part of the Derivative Works; within the Source form or\n   documentation, if provided along with the Derivative Works; or,\n   within a display generated by the Derivative Works, if and\n   wherever such third-party notices normally appear. The contents\n   of the NOTICE file are for informational purposes only and\n   do not modify the License. You may add Your own attribution\n   notices within Derivative Works that You distribute, alongside\n   or as an addendum to the NOTICE text from the Work, provided\n   that such additional attribution notices cannot be construed\n   as modifying the License.\n\n   You may add Your own copyright statement to Your modifications and\n   may provide additional or different license terms and conditions\n   for use, reproduction, or distribution of Your modifications, or\n   for any such Derivative Works as a whole, provided Your use,\n   reproduction, and distribution of the Work otherwise complies with\n   the conditions stated in this License.\n\n5. Submission of Contributions. Unless You explicitly state otherwise,\n   any Contribution intentionally submitted for inclusion in the Work\n   by You to the Licensor shall be under the terms and conditions of\n   this License, without any additional terms or conditions.\n   Notwithstanding the above, nothing herein shall supersede or modify\n   the terms of any separate license agreement you may have executed\n   with Licensor regarding such Contributions.\n\n6. Trademarks. This License does not grant permission to use the trade\n   names, trademarks, service marks, or product names of the Licensor,\n   except as required for reasonable and customary use in describing the\n   origin of the Work and reproducing the content of the NOTICE file.\n\n7. Disclaimer of Warranty. Unless required by applicable law or\n   agreed to in writing, Licensor provides the Work (and each\n   Contributor provides its Contributions) on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n   implied, including, without limitation, any warranties or conditions\n   of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n   PARTICULAR PURPOSE. You are solely responsible for determining the\n   appropriateness of using or redistributing the Work and assume any\n   risks associated with Your exercise of permissions under this License.\n\n8. Limitation of Liability. In no event and under no legal theory,\n   whether in tort (including negligence), contract, or otherwise,\n   unless required by applicable law (such as deliberate and grossly\n   negligent acts) or agreed to in writing, shall any Contributor be\n   liable to You for damages, including any direct, indirect, special,\n   incidental, or consequential damages of any character arising as a\n   result of this License or out of the use or inability to use the\n   Work (including but not limited to damages for loss of goodwill,\n   work stoppage, computer failure or malfunction, or any and all\n   other commercial damages or losses), even if such Contributor\n   has been advised of the possibility of such damages.\n\n9. Accepting Warranty or Additional Liability. While redistributing\n   the Work or Derivative Works thereof, You may choose to offer,\n   and charge a fee for, acceptance of support, warranty, indemnity,\n   or other liability obligations and/or rights consistent with this\n   License. However, in accepting such obligations, You may act only\n   on Your own behalf and on Your sole responsibility, not on behalf\n   of any other Contributor, and only if You agree to indemnify,\n   defend, and hold each Contributor harmless for any liability\n   incurred by, or claims asserted against, such Contributor by reason\n   of your accepting any such warranty or additional liability.\n\nEND OF TERMS AND CONDITIONS"
  },
  {
    "path": "LICENSE-MIT",
    "content": "MIT License\n\nCopyright 2021 Niklas Eicker\n\nPermission 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:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE 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.\n"
  },
  {
    "path": "README.md",
    "content": "# Bevy common assets\n\n[![crates.io](https://img.shields.io/crates/v/bevy_common_assets.svg)](https://crates.io/crates/bevy_common_assets)\n[![docs](https://docs.rs/bevy_common_assets/badge.svg)](https://docs.rs/bevy_common_assets)\n[![license](https://img.shields.io/crates/l/bevy_common_assets)](https://github.com/NiklasEi/bevy_common_assets#license)\n[![crates.io](https://img.shields.io/crates/d/bevy_common_assets.svg)](https://crates.io/crates/bevy_common_assets)\n\nCollection of [Bevy][bevy] plugins offering generic asset loaders and writers for common file formats.\n\nSupported formats:\n\n| format     | feature    | example                                 |\n| :--------- | :--------- | :-------------------------------------- |\n| `json`     | `json`     | [`json.rs`](./examples/json.rs)         |\n| `msgpack`  | `msgpack`  | [`msgpack.rs`](./examples/msgpack.rs)   |\n| `postcard` | `postcard` | [`postcard.rs`](./examples/postcard.rs) |\n| `ron`      | `ron`      | [`ron.rs`](./examples/ron.rs)           |\n| `toml`     | `toml`     | [`toml.rs`](./examples/toml.rs)         |\n| `xml`      | `xml`      | [`xml.rs`](./examples/xml.rs)           |\n| `yaml`     | `yaml`     | [`yaml.rs`](./examples/yaml.rs)         |\n| `csv`      | `csv`      | [`csv.rs`](./examples/csv.rs)           |\n| `cbor`     | `cbor`     | [`cbor.rs`](./examples/cbor.rs)         |\n\n## Usage\n\nEnable the feature(s) for the format(s) that you want to use.\n\nDefine the types that you would like to load from files and derive `serde::Deserialize`, `bevy::reflect::TypePath`, and `bevy::asset::Asset` for them.\n\n```rust\n#[derive(serde::Deserialize, bevy::asset::Asset, bevy::reflect::TypePath)]\nstruct Level {\n    positions: Vec<[f32;3]>,\n}\n```\n\nWith the types ready, you can start adding asset plugins. Every plugin gets the asset type that it is supposed to load\nas a generic parameter. You can also configure custom file endings for each plugin:\n\n```rust no_run\nuse bevy::prelude::*;\nuse bevy_common_assets::cbor::CborAssetPlugin;\nuse bevy_common_assets::json::JsonAssetPlugin;\nuse bevy_common_assets::msgpack::MsgPackAssetPlugin;\nuse bevy_common_assets::postcard::PostcardAssetPlugin;\nuse bevy_common_assets::ron::RonAssetPlugin;\nuse bevy_common_assets::toml::TomlAssetPlugin;\nuse bevy_common_assets::xml::XmlAssetPlugin;\nuse bevy_common_assets::yaml::YamlAssetPlugin;\n\nfn main() {\n    App::new()\n        .add_plugins((\n            DefaultPlugins,\n            JsonAssetPlugin::<Level>::new(&[\"level.json\", \"custom.json\"]),\n            RonAssetPlugin::<Level>::new(&[\"level.ron\"]),\n            MsgPackAssetPlugin::<Level>::new(&[\"level.msgpack\"]),\n            PostcardAssetPlugin::<Level>::new(&[\"level.postcard\"]),\n            TomlAssetPlugin::<Level>::new(&[\"level.toml\"]),\n            XmlAssetPlugin::<Level>::new(&[\"level.xml\"]),\n            YamlAssetPlugin::<Level>::new(&[\"level.yaml\"]),\n            CborAssetPlugin::<Level>::new(&[\"level.cbor\"])\n        ))\n        // ...\n        .run();\n}\n\n#[derive(serde::Deserialize, bevy::asset::Asset, bevy::reflect::TypePath)]\nstruct Level {\n    positions: Vec<[f32; 3]>,\n}\n```\n\nThe example above will load `Level` structs from json files ending on `.level.json` or `.custom.json`, from\nron files ending on `.level.ron` and so on...\n\nSee the [examples](./examples) for working Bevy apps using the different formats.\n\n## Asset savers / using the loaders in .meta files\n\nThe more involved [example `asset_savers`](./examples/asset_savers) demonstrates how you can convert a json\nasset into a processed postcard asset using the `JsonAssetLoader` and `PostcardAssetSaver`.\n\n## Compatible Bevy versions\n\nThe main branch is compatible with the latest Bevy release.\n\nCompatibility of `bevy_common_assets` versions:\n\n| `bevy_common_assets` | `bevy` |\n| :------------------- | :----- |\n| `0.15`               | `0.18` |\n| `0.14`               | `0.17` |\n| `0.13`               | `0.16` |\n| `0.12`               | `0.15` |\n| `0.11`               | `0.14` |\n| `0.10`               | `0.13` |\n| `0.8` - `0.9`        | `0.12` |\n| `0.7`                | `0.11` |\n| `0.5` - `0.6`        | `0.10` |\n| `0.4`                | `0.9`  |\n| `0.3`                | `0.8`  |\n| `0.1` - `0.2`        | `0.7`  |\n\n## License\n\nDual-licensed under either of\n\n- Apache License, Version 2.0, ([LICENSE-APACHE](/LICENSE-APACHE) or https://www.apache.org/licenses/LICENSE-2.0)\n- MIT license ([LICENSE-MIT](/LICENSE-MIT) or https://opensource.org/licenses/MIT)\n\nat your option.\n\n## Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any\nadditional terms or conditions.\n\n[bevy]: https://bevyengine.org/\n"
  },
  {
    "path": "assets/trees.level.csv",
    "content": "x,y,z\n42.0,42.0,0.0\n4.0,32.0,0.0\n54.0,7.0,0.0\n-61.0,4.0,0.0\n-6.0,-72.0,0.0\n6.0,-89.0,0.0\n"
  },
  {
    "path": "assets/trees.level.json",
    "content": "{\n  \"positions\": [\n    [\n      42.0,\n      42.0,\n      0.0\n    ],\n    [\n      4.0,\n      32.0,\n      0.0\n    ],\n    [\n      54.0,\n      7.0,\n      0.0\n    ],\n    [\n      -61.0,\n      4.0,\n      0.0\n    ],\n    [\n      -6.0,\n      -72.0,\n      0.0\n    ],\n    [\n      6.0,\n      -89.0,\n      0.0\n    ]\n  ]\n}\n"
  },
  {
    "path": "assets/trees.level.ron",
    "content": "(\n    positions: [\n        (142., 56., 0.),\n        (25., 132., 0.),\n        (123., 7., 0.),\n        (-61., 149., 0.),\n        (-96., -52., 0.),\n        (69., -189., 0.),\n    ]\n)\n"
  },
  {
    "path": "assets/trees.level.toml",
    "content": "positions = [\n    [42.0, 42.0, 0.0],\n    [4.0, 32.0, 0.0],\n    [54.0, 7.0, 0.0],\n    [-61.0, 4.0, 0.0],\n    [-6.0, -72.0, 0.0],\n    [6.0, -89.0, 0.0],\n]\n"
  },
  {
    "path": "assets/trees.level.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Level>\n  <Position x=\"42.0\" y=\"42.0\" z=\"0.0\" />\n  <Position x=\"4.0\" y=\"32.0\" z=\"0.0\" />\n  <Position x=\"54.0\" y=\"7.0\" z=\"0.0\" />\n  <Position x=\"-61.0\" y=\"4.0\" z=\"0.0\" />\n  <Position x=\"-6.0\" y=\"-72.0\" z=\"0.0\" />\n  <Position x=\"6.0\" y=\"-89.0\" z=\"0.0\" />\n</Level>\n"
  },
  {
    "path": "assets/trees.level.yaml",
    "content": "positions:\n  - [42.0, 42.0, 0.0]\n  - [4.0, 32.0, 0.0]\n  - [54.0, 7.0, 0.0]\n  - [-61.0, 4.0, 0.0]\n  - [-6.0, -72.0, 0.0]\n  - [6.0, -89.0, 0.0]\n"
  },
  {
    "path": "examples/asset_savers/asset_savers.rs",
    "content": "use bevy::asset::processor::LoadTransformAndSave;\nuse bevy::asset::transformer::IdentityAssetTransformer;\nuse bevy::prelude::*;\nuse bevy_common_assets::cbor::{CborAssetPlugin, CborAssetSaver};\nuse bevy_common_assets::json::{JsonAssetLoader, JsonAssetPlugin, JsonAssetSaver};\nuse bevy_common_assets::msgpack::{MsgPackAssetPlugin, MsgPackAssetSaver};\nuse bevy_common_assets::postcard::{PostcardAssetPlugin, PostcardAssetSaver};\nuse bevy_common_assets::ron::{RonAssetLoader, RonAssetPlugin, RonAssetSaver};\nuse bevy_common_assets::toml::{TomlAssetPlugin, TomlAssetSaver};\nuse bevy_common_assets::yaml::{YamlAssetPlugin, YamlAssetSaver};\nuse serde::{Deserialize, Serialize};\n\n/// This example processes source asset files into various binary and text formats using asset\n/// savers, then loads and renders the processed assets.\n///\n/// When you run the example, `examples/asset_savers/imported_assets` is created and populated\n/// with the processed files. Edit any source file in `examples/asset_savers/assets/` and\n/// re-run to see the processor rebuild it.\n///\n/// Source files and their processing pipelines:\n///\n/// | Source file      | Source format | Processed format    |\n/// |------------------|---------------|---------------------|\n/// | trees.postlevel  | JSON          | Postcard (binary)   |\n/// | trees.cborlevel  | JSON          | CBOR (binary)       |\n/// | trees.msglevel   | JSON          | MessagePack (binary)|\n/// | trees.ronlevel   | JSON          | RON                 |\n/// | trees.jsonlevel  | RON           | JSON                |\n/// | trees.tomllevel  | JSON          | TOML                |\n/// | trees.yamllevel  | JSON          | YAML                |\nfn main() {\n    App::new()\n        .add_plugins((\n            DefaultPlugins.set(AssetPlugin {\n                mode: AssetMode::Processed,\n                file_path: \"examples/asset_savers/assets\".to_string(),\n                processed_file_path: \"examples/asset_savers/imported_assets/Default\".to_string(),\n                ..default()\n            }),\n            // Each plugin registers the loader for the processed output extension\n            PostcardAssetPlugin::<Level>::new(&[\"postlevel\"]),\n            CborAssetPlugin::<Level>::new(&[\"cborlevel\"]),\n            MsgPackAssetPlugin::<Level>::new(&[\"msglevel\"]),\n            RonAssetPlugin::<Level>::new(&[\"ronlevel\"]),\n            JsonAssetPlugin::<Level>::new(&[\"jsonlevel\"]),\n            TomlAssetPlugin::<Level>::new(&[\"tomllevel\"]),\n            YamlAssetPlugin::<Level>::new(&[\"yamllevel\"]),\n        ))\n        // JSON source → Postcard binary\n        .register_asset_processor::<LoadTransformAndSave<\n            JsonAssetLoader<Level>,\n            IdentityAssetTransformer<Level>,\n            PostcardAssetSaver<Level>,\n        >>(LoadTransformAndSave::new(\n            IdentityAssetTransformer::default(),\n            PostcardAssetSaver::default(),\n        ))\n        // JSON source → CBOR binary\n        .register_asset_processor::<LoadTransformAndSave<\n            JsonAssetLoader<Level>,\n            IdentityAssetTransformer<Level>,\n            CborAssetSaver<Level>,\n        >>(LoadTransformAndSave::new(\n            IdentityAssetTransformer::default(),\n            CborAssetSaver::default(),\n        ))\n        // JSON source → MessagePack binary\n        .register_asset_processor::<LoadTransformAndSave<\n            JsonAssetLoader<Level>,\n            IdentityAssetTransformer<Level>,\n            MsgPackAssetSaver<Level>,\n        >>(LoadTransformAndSave::new(\n            IdentityAssetTransformer::default(),\n            MsgPackAssetSaver::default(),\n        ))\n        // JSON source → RON text\n        .register_asset_processor::<LoadTransformAndSave<\n            JsonAssetLoader<Level>,\n            IdentityAssetTransformer<Level>,\n            RonAssetSaver<Level>,\n        >>(LoadTransformAndSave::new(\n            IdentityAssetTransformer::default(),\n            RonAssetSaver::default(),\n        ))\n        // RON source → JSON text  (avoids a trivial JSON→JSON round-trip)\n        .register_asset_processor::<LoadTransformAndSave<\n            RonAssetLoader<Level>,\n            IdentityAssetTransformer<Level>,\n            JsonAssetSaver<Level>,\n        >>(LoadTransformAndSave::new(\n            IdentityAssetTransformer::default(),\n            JsonAssetSaver::default(),\n        ))\n        // JSON source → TOML text\n        .register_asset_processor::<LoadTransformAndSave<\n            JsonAssetLoader<Level>,\n            IdentityAssetTransformer<Level>,\n            TomlAssetSaver<Level>,\n        >>(LoadTransformAndSave::new(\n            IdentityAssetTransformer::default(),\n            TomlAssetSaver::default(),\n        ))\n        // JSON source → YAML text\n        .register_asset_processor::<LoadTransformAndSave<\n            JsonAssetLoader<Level>,\n            IdentityAssetTransformer<Level>,\n            YamlAssetSaver<Level>,\n        >>(LoadTransformAndSave::new(\n            IdentityAssetTransformer::default(),\n            YamlAssetSaver::default(),\n        ))\n        .init_state::<AppState>()\n        .add_systems(Startup, setup)\n        .add_systems(Update, spawn_trees.run_if(in_state(AppState::Loading)))\n        .run();\n}\n\nfn setup(mut commands: Commands, asset_server: Res<AssetServer>) {\n    commands.insert_resource(LevelHandles {\n        postcard: asset_server.load(\"trees.postlevel\"),\n        cbor: asset_server.load(\"trees.cborlevel\"),\n        msgpack: asset_server.load(\"trees.msglevel\"),\n        ron: asset_server.load(\"trees.ronlevel\"),\n        json: asset_server.load(\"trees.jsonlevel\"),\n        toml: asset_server.load(\"trees.tomllevel\"),\n        yaml: asset_server.load(\"trees.yamllevel\"),\n    });\n    commands.insert_resource(ImageHandle(asset_server.load(\"tree.png\")));\n    commands.spawn((Camera2d, Msaa::Off));\n}\n\nfn spawn_trees(\n    mut commands: Commands,\n    handles: Res<LevelHandles>,\n    tree: Res<ImageHandle>,\n    levels: Res<Assets<Level>>,\n    mut state: ResMut<NextState<AppState>>,\n) {\n    let format_offsets: [(&Handle<Level>, Vec2); 7] = [\n        (&handles.postcard, Vec2::new(-525., 75.)),\n        (&handles.cbor, Vec2::new(-175., 75.)),\n        (&handles.msgpack, Vec2::new(175., 75.)),\n        (&handles.ron, Vec2::new(525., 75.)),\n        (&handles.json, Vec2::new(-350., -75.)),\n        (&handles.toml, Vec2::new(0., -75.)),\n        (&handles.yaml, Vec2::new(350., -75.)),\n    ];\n\n    for (handle, _) in &format_offsets {\n        if levels.get(handle.id()).is_none() {\n            return;\n        }\n    }\n\n    for (handle, offset) in &format_offsets {\n        let level = levels.get(handle.id()).unwrap();\n        for position in &level.positions {\n            commands.spawn((\n                Sprite::from_image(tree.0.clone()),\n                Transform::from_translation(Vec3::new(\n                    position[0] + offset.x,\n                    position[1] + offset.y,\n                    position[2],\n                )),\n            ));\n        }\n    }\n\n    state.set(AppState::Level);\n}\n\n#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]\nenum AppState {\n    #[default]\n    Loading,\n    Level,\n}\n\n#[derive(Resource)]\nstruct ImageHandle(Handle<Image>);\n\n#[derive(Resource)]\nstruct LevelHandles {\n    postcard: Handle<Level>,\n    cbor: Handle<Level>,\n    msgpack: Handle<Level>,\n    ron: Handle<Level>,\n    json: Handle<Level>,\n    toml: Handle<Level>,\n    yaml: Handle<Level>,\n}\n\n#[derive(Deserialize, Serialize, Asset, TypePath)]\nstruct Level {\n    positions: Vec<[f32; 3]>,\n}\n"
  },
  {
    "path": "examples/asset_savers/assets/tree.png.meta",
    "content": "(\n    meta_format_version: \"1.0\",\n    asset: Load(\n        loader: \"bevy_image::image_loader::ImageLoader\",\n        settings: (\n            format: FromExtension,\n            is_srgb: true,\n            sampler: Default,\n            asset_usage: (\"MAIN_WORLD | RENDER_WORLD\"),\n        ),\n    ),\n)"
  },
  {
    "path": "examples/asset_savers/assets/trees.cborlevel",
    "content": "{\n  \"positions\": [\n    [0.0, 10.0, 0.0],\n    [10.0, 0.0, 0.0],\n    [-10.0, 0.0, 0.0],\n    [0.0, -10.0, 0.0]\n  ]\n}\n"
  },
  {
    "path": "examples/asset_savers/assets/trees.cborlevel.meta",
    "content": "(\n    meta_format_version: \"1.0\",\n    asset: Process(\n        processor: \"bevy_asset::processor::process::LoadTransformAndSave<bevy_common_assets::json::JsonAssetLoader<asset_savers::Level>, bevy_asset::transformer::IdentityAssetTransformer<asset_savers::Level>, bevy_common_assets::cbor::CborAssetSaver<asset_savers::Level>>\",\n        settings: (\n            loader_settings: (),\n            transformer_settings: (),\n            saver_settings: (),\n        ),\n    ),\n)\n"
  },
  {
    "path": "examples/asset_savers/assets/trees.jsonlevel",
    "content": "(\n    positions: [\n        (0.0, 10.0, 0.0),\n        (10.0, 0.0, 0.0),\n        (-10.0, 0.0, 0.0),\n        (0.0, -10.0, 0.0),\n    ],\n)\n"
  },
  {
    "path": "examples/asset_savers/assets/trees.jsonlevel.meta",
    "content": "(\n    meta_format_version: \"1.0\",\n    asset: Process(\n        processor: \"bevy_asset::processor::process::LoadTransformAndSave<bevy_common_assets::ron::RonAssetLoader<asset_savers::Level>, bevy_asset::transformer::IdentityAssetTransformer<asset_savers::Level>, bevy_common_assets::json::JsonAssetSaver<asset_savers::Level>>\",\n        settings: (\n            loader_settings: (),\n            transformer_settings: (),\n            saver_settings: (),\n        ),\n    ),\n)\n"
  },
  {
    "path": "examples/asset_savers/assets/trees.msglevel",
    "content": "{\n  \"positions\": [\n    [0.0, 10.0, 0.0],\n    [10.0, 0.0, 0.0],\n    [-10.0, 0.0, 0.0],\n    [0.0, -10.0, 0.0]\n  ]\n}\n"
  },
  {
    "path": "examples/asset_savers/assets/trees.msglevel.meta",
    "content": "(\n    meta_format_version: \"1.0\",\n    asset: Process(\n        processor: \"bevy_asset::processor::process::LoadTransformAndSave<bevy_common_assets::json::JsonAssetLoader<asset_savers::Level>, bevy_asset::transformer::IdentityAssetTransformer<asset_savers::Level>, bevy_common_assets::msgpack::MsgPackAssetSaver<asset_savers::Level>>\",\n        settings: (\n            loader_settings: (),\n            transformer_settings: (),\n            saver_settings: (),\n        ),\n    ),\n)\n"
  },
  {
    "path": "examples/asset_savers/assets/trees.postlevel",
    "content": "{\n  \"positions\": [\n    [0.0, 10.0, 0.0],\n    [10.0, 0.0, 0.0],\n    [-10.0, 0.0, 0.0],\n    [0.0, -10.0, 0.0]\n  ]\n}\n"
  },
  {
    "path": "examples/asset_savers/assets/trees.postlevel.meta",
    "content": "(\n    meta_format_version: \"1.0\",\n    asset: Process(\n        processor: \"bevy_asset::processor::process::LoadTransformAndSave<bevy_common_assets::json::JsonAssetLoader<asset_savers::Level>, bevy_asset::transformer::IdentityAssetTransformer<asset_savers::Level>, bevy_common_assets::postcard::PostcardAssetSaver<asset_savers::Level>>\",\n        settings: (\n            loader_settings: (),\n            transformer_settings: (),\n            saver_settings: (),\n        ),\n    ),\n)\n"
  },
  {
    "path": "examples/asset_savers/assets/trees.ronlevel",
    "content": "{\n  \"positions\": [\n    [0.0, 10.0, 0.0],\n    [10.0, 0.0, 0.0],\n    [-10.0, 0.0, 0.0],\n    [0.0, -10.0, 0.0]\n  ]\n}\n"
  },
  {
    "path": "examples/asset_savers/assets/trees.ronlevel.meta",
    "content": "(\n    meta_format_version: \"1.0\",\n    asset: Process(\n        processor: \"bevy_asset::processor::process::LoadTransformAndSave<bevy_common_assets::json::JsonAssetLoader<asset_savers::Level>, bevy_asset::transformer::IdentityAssetTransformer<asset_savers::Level>, bevy_common_assets::ron::RonAssetSaver<asset_savers::Level>>\",\n        settings: (\n            loader_settings: (),\n            transformer_settings: (),\n            saver_settings: (),\n        ),\n    ),\n)\n"
  },
  {
    "path": "examples/asset_savers/assets/trees.tomllevel",
    "content": "{\n  \"positions\": [\n    [0.0, 10.0, 0.0],\n    [10.0, 0.0, 0.0],\n    [-10.0, 0.0, 0.0],\n    [0.0, -10.0, 0.0]\n  ]\n}\n"
  },
  {
    "path": "examples/asset_savers/assets/trees.tomllevel.meta",
    "content": "(\n    meta_format_version: \"1.0\",\n    asset: Process(\n        processor: \"bevy_asset::processor::process::LoadTransformAndSave<bevy_common_assets::json::JsonAssetLoader<asset_savers::Level>, bevy_asset::transformer::IdentityAssetTransformer<asset_savers::Level>, bevy_common_assets::toml::TomlAssetSaver<asset_savers::Level>>\",\n        settings: (\n            loader_settings: (),\n            transformer_settings: (),\n            saver_settings: (),\n        ),\n    ),\n)\n"
  },
  {
    "path": "examples/asset_savers/assets/trees.yamllevel",
    "content": "{\n  \"positions\": [\n    [0.0, 10.0, 0.0],\n    [10.0, 0.0, 0.0],\n    [-10.0, 0.0, 0.0],\n    [0.0, -10.0, 0.0]\n  ]\n}\n"
  },
  {
    "path": "examples/asset_savers/assets/trees.yamllevel.meta",
    "content": "(\n    meta_format_version: \"1.0\",\n    asset: Process(\n        processor: \"bevy_asset::processor::process::LoadTransformAndSave<bevy_common_assets::json::JsonAssetLoader<asset_savers::Level>, bevy_asset::transformer::IdentityAssetTransformer<asset_savers::Level>, bevy_common_assets::yaml::YamlAssetSaver<asset_savers::Level>>\",\n        settings: (\n            loader_settings: (),\n            transformer_settings: (),\n            saver_settings: (),\n        ),\n    ),\n)\n"
  },
  {
    "path": "examples/cbor.rs",
    "content": "use bevy::prelude::*;\nuse bevy::reflect::TypePath;\nuse bevy_common_assets::cbor::CborAssetPlugin;\n\nfn main() {\n    App::new()\n        .add_plugins((\n            DefaultPlugins,\n            CborAssetPlugin::<Level>::new(&[\"level.cbor\"]),\n        ))\n        .init_state::<AppState>()\n        .add_systems(Startup, setup)\n        .add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))\n        .run();\n}\n\nfn setup(mut commands: Commands, asset_server: Res<AssetServer>) {\n    let level = LevelHandle(asset_server.load(\"trees.level.cbor\"));\n    commands.insert_resource(level);\n    let tree = ImageHandle(asset_server.load(\"tree.png\"));\n    commands.insert_resource(tree);\n    commands.spawn((Camera2d, Msaa::Off));\n}\n\nfn spawn_level(\n    mut commands: Commands,\n    level: Res<LevelHandle>,\n    tree: Res<ImageHandle>,\n    mut levels: ResMut<Assets<Level>>,\n    mut state: ResMut<NextState<AppState>>,\n) {\n    if let Some(level) = levels.remove(level.0.id()) {\n        for position in level.positions {\n            commands.spawn((\n                Sprite::from_image(tree.0.clone()),\n                Transform::from_translation(position.into()),\n            ));\n        }\n        state.set(AppState::Level);\n    }\n}\n\n#[derive(serde::Deserialize, Asset, TypePath)]\nstruct Level {\n    positions: Vec<[f32; 3]>,\n}\n\n#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]\nenum AppState {\n    #[default]\n    Loading,\n    Level,\n}\n\n#[derive(Resource)]\nstruct ImageHandle(Handle<Image>);\n\n#[derive(Resource)]\nstruct LevelHandle(Handle<Level>);\n"
  },
  {
    "path": "examples/csv.rs",
    "content": "use bevy::prelude::*;\nuse bevy::reflect::TypePath;\nuse bevy_common_assets::csv::{CsvAssetPlugin, LoadedCsv};\n\nfn main() {\n    App::new()\n        .add_plugins((\n            DefaultPlugins,\n            CsvAssetPlugin::<TreePosition>::new(&[\"level.csv\"]),\n        ))\n        .init_state::<AppState>()\n        .add_systems(Startup, setup)\n        .add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))\n        .run();\n}\n\nfn setup(mut commands: Commands, asset_server: Res<AssetServer>) {\n    let level = LevelHandle(asset_server.load(\"trees.level.csv\"));\n    commands.insert_resource(level);\n    let tree = ImageHandle(asset_server.load(\"tree.png\"));\n    commands.insert_resource(tree);\n\n    commands.spawn((Camera2d, Msaa::Off));\n}\n\nfn spawn_level(\n    mut commands: Commands,\n    level: Res<LevelHandle>,\n    tree: Res<ImageHandle>,\n    positions: Res<Assets<LoadedCsv<TreePosition>>>,\n    mut state: ResMut<NextState<AppState>>,\n) {\n    if let Some(level) = positions.get(&level.0) {\n        for position in level.rows.iter() {\n            commands.spawn((\n                Sprite::from_image(tree.0.clone()),\n                Transform::from_translation(Vec3::new(position.x, position.y, position.z)),\n            ));\n        }\n\n        state.set(AppState::Level);\n    }\n}\n\n#[derive(serde::Deserialize, Asset, TypePath, Debug)]\nstruct TreePosition {\n    x: f32,\n    y: f32,\n    z: f32,\n}\n\n#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]\nenum AppState {\n    #[default]\n    Loading,\n    Level,\n}\n\n#[derive(Resource)]\nstruct ImageHandle(Handle<Image>);\n\n#[derive(Resource)]\nstruct LevelHandle(Handle<LoadedCsv<TreePosition>>);\n"
  },
  {
    "path": "examples/json.rs",
    "content": "use bevy::prelude::*;\nuse bevy::reflect::TypePath;\nuse bevy_common_assets::json::JsonAssetPlugin;\n\nfn main() {\n    App::new()\n        .add_plugins((\n            DefaultPlugins,\n            JsonAssetPlugin::<Level>::new(&[\"level.json\"]),\n        ))\n        .init_state::<AppState>()\n        .add_systems(Startup, setup)\n        .add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))\n        .run();\n}\n\nfn setup(mut commands: Commands, asset_server: Res<AssetServer>) {\n    let level = LevelHandle(asset_server.load(\"trees.level.json\"));\n    commands.insert_resource(level);\n    let tree = ImageHandle(asset_server.load(\"tree.png\"));\n    commands.insert_resource(tree);\n\n    commands.spawn((Camera2d, Msaa::Off));\n}\n\nfn spawn_level(\n    mut commands: Commands,\n    level: Res<LevelHandle>,\n    tree: Res<ImageHandle>,\n    mut levels: ResMut<Assets<Level>>,\n    mut state: ResMut<NextState<AppState>>,\n) {\n    if let Some(level) = levels.remove(level.0.id()) {\n        for position in level.positions {\n            commands.spawn((\n                Sprite::from_image(tree.0.clone()),\n                Transform::from_translation(position.into()),\n            ));\n        }\n\n        state.set(AppState::Level);\n    }\n}\n\n#[derive(serde::Deserialize, Asset, TypePath)]\nstruct Level {\n    positions: Vec<[f32; 3]>,\n}\n\n#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]\nenum AppState {\n    #[default]\n    Loading,\n    Level,\n}\n\n#[derive(Resource)]\nstruct ImageHandle(Handle<Image>);\n\n#[derive(Resource)]\nstruct LevelHandle(Handle<Level>);\n"
  },
  {
    "path": "examples/msgpack.rs",
    "content": "use bevy::prelude::*;\nuse bevy::reflect::TypePath;\nuse bevy_common_assets::msgpack::MsgPackAssetPlugin;\n\nfn main() {\n    App::new()\n        .add_plugins((\n            DefaultPlugins,\n            MsgPackAssetPlugin::<Level>::new(&[\"level.msgpack\"]),\n        ))\n        .init_state::<AppState>()\n        .add_systems(Startup, setup)\n        .add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))\n        .run();\n}\n\nfn setup(mut commands: Commands, asset_server: Res<AssetServer>) {\n    let level = LevelHandle(asset_server.load(\"trees.level.msgpack\"));\n    commands.insert_resource(level);\n    let tree = ImageHandle(asset_server.load(\"tree.png\"));\n    commands.insert_resource(tree);\n\n    commands.spawn((Camera2d, Msaa::Off));\n}\n\nfn spawn_level(\n    mut commands: Commands,\n    level: Res<LevelHandle>,\n    tree: Res<ImageHandle>,\n    mut levels: ResMut<Assets<Level>>,\n    mut state: ResMut<NextState<AppState>>,\n) {\n    if let Some(level) = levels.remove(level.0.id()) {\n        for position in level.positions {\n            commands.spawn((\n                Sprite::from_image(tree.0.clone()),\n                Transform::from_translation(position.into()),\n            ));\n        }\n\n        state.set(AppState::Level);\n    }\n}\n\n#[derive(serde::Deserialize, Asset, TypePath)]\nstruct Level {\n    positions: Vec<[f32; 3]>,\n}\n\n#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]\nenum AppState {\n    #[default]\n    Loading,\n    Level,\n}\n\n#[derive(Resource)]\nstruct ImageHandle(Handle<Image>);\n\n#[derive(Resource)]\nstruct LevelHandle(Handle<Level>);\n"
  },
  {
    "path": "examples/multiple_formats.rs",
    "content": "use bevy::prelude::*;\nuse bevy::reflect::TypePath;\nuse bevy_common_assets::json::JsonAssetPlugin;\nuse bevy_common_assets::ron::RonAssetPlugin;\n\nfn main() {\n    App::new()\n        // You can add loaders for different asset types, but also multiple loaders for the same asset type\n        // The important thing is: they all need distinct extensions!\n        .add_plugins((\n            DefaultPlugins,\n            RonAssetPlugin::<Level>::new(&[\"level.ron\"]),\n            JsonAssetPlugin::<Level>::new(&[\"level.json\"]),\n        ))\n        .init_state::<AppState>()\n        .add_systems(Startup, setup)\n        .add_systems(Update, check_loading.run_if(in_state(AppState::Loading)))\n        .add_systems(OnEnter(AppState::Level), spawn_level)\n        .run();\n}\n\n#[derive(serde::Deserialize, Asset, TypePath)]\nstruct Level {\n    positions: Vec<[f32; 3]>,\n}\n\nfn setup(mut commands: Commands, asset_server: Res<AssetServer>) {\n    let json_trees: Handle<Level> = asset_server.load(\"trees.level.json\");\n    let ron_trees: Handle<Level> = asset_server.load(\"trees.level.ron\");\n    commands.insert_resource(Levels(vec![json_trees, ron_trees]));\n    let tree = ImageHandle(asset_server.load(\"tree.png\"));\n    commands.insert_resource(tree);\n\n    commands.spawn((Camera2d, Msaa::Off));\n}\n\nfn spawn_level(\n    mut commands: Commands,\n    levels: Res<Levels>,\n    tree: Res<ImageHandle>,\n    mut level_assets: ResMut<Assets<Level>>,\n) {\n    for handle in levels.0.iter() {\n        let level = level_assets.remove(handle).unwrap();\n        for position in level.positions {\n            commands.spawn((\n                Sprite::from_image(tree.0.clone()),\n                Transform::from_translation(position.into()),\n            ));\n        }\n    }\n}\n\nfn check_loading(\n    asset_server: Res<AssetServer>,\n    handles: Res<Levels>,\n    mut state: ResMut<NextState<AppState>>,\n) {\n    for handle in &handles.0 {\n        if asset_server\n            .get_load_state(handle)\n            .map(|state| !state.is_loaded())\n            .unwrap_or(true)\n        {\n            return;\n        }\n    }\n    state.set(AppState::Level);\n}\n\n#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]\nenum AppState {\n    #[default]\n    Loading,\n    Level,\n}\n\n#[derive(Resource)]\nstruct ImageHandle(Handle<Image>);\n\n#[derive(Resource)]\nstruct Levels(Vec<Handle<Level>>);\n"
  },
  {
    "path": "examples/postcard.rs",
    "content": "use bevy::prelude::*;\nuse bevy::reflect::TypePath;\nuse bevy_common_assets::postcard::PostcardAssetPlugin;\n\nfn main() {\n    App::new()\n        .add_plugins((\n            DefaultPlugins,\n            PostcardAssetPlugin::<Level>::new(&[\"level.postcard\"]),\n        ))\n        .init_state::<AppState>()\n        .add_systems(Startup, setup)\n        .add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))\n        .run();\n}\n\nfn setup(mut commands: Commands, asset_server: Res<AssetServer>) {\n    let level = LevelHandle(asset_server.load(\"trees.level.postcard\"));\n    commands.insert_resource(level);\n    let tree = ImageHandle(asset_server.load(\"tree.png\"));\n    commands.insert_resource(tree);\n    commands.spawn((Camera2d, Msaa::Off));\n}\n\nfn spawn_level(\n    mut commands: Commands,\n    level: Res<LevelHandle>,\n    tree: Res<ImageHandle>,\n    mut levels: ResMut<Assets<Level>>,\n    mut state: ResMut<NextState<AppState>>,\n) {\n    if let Some(level) = levels.remove(level.0.id()) {\n        for position in level.positions {\n            commands.spawn((\n                Sprite::from_image(tree.0.clone()),\n                Transform::from_translation(position.into()),\n            ));\n        }\n        state.set(AppState::Level);\n    }\n}\n\n#[derive(serde::Deserialize, Asset, TypePath)]\nstruct Level {\n    positions: Vec<[f32; 3]>,\n}\n\n#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]\nenum AppState {\n    #[default]\n    Loading,\n    Level,\n}\n\n#[derive(Resource)]\nstruct ImageHandle(Handle<Image>);\n\n#[derive(Resource)]\nstruct LevelHandle(Handle<Level>);\n"
  },
  {
    "path": "examples/ron.rs",
    "content": "use bevy::prelude::*;\nuse bevy::reflect::TypePath;\nuse bevy_common_assets::ron::RonAssetPlugin;\n\nfn main() {\n    App::new()\n        .add_plugins((DefaultPlugins, RonAssetPlugin::<Level>::new(&[\"level.ron\"])))\n        .init_state::<AppState>()\n        .add_systems(Startup, setup)\n        .add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))\n        .run();\n}\n\nfn setup(mut commands: Commands, asset_server: Res<AssetServer>) {\n    let level = LevelHandle(asset_server.load(\"trees.level.ron\"));\n    commands.insert_resource(level);\n    let tree = ImageHandle(asset_server.load(\"tree.png\"));\n    commands.insert_resource(tree);\n\n    commands.spawn((Camera2d, Msaa::Off));\n}\n\nfn spawn_level(\n    mut commands: Commands,\n    level: Res<LevelHandle>,\n    tree: Res<ImageHandle>,\n    mut levels: ResMut<Assets<Level>>,\n    mut state: ResMut<NextState<AppState>>,\n) {\n    if let Some(level) = levels.remove(level.0.id()) {\n        for position in level.positions {\n            commands.spawn((\n                Sprite::from_image(tree.0.clone()),\n                Transform::from_translation(position.into()),\n            ));\n        }\n\n        state.set(AppState::Level);\n    }\n}\n\n#[derive(serde::Deserialize, Asset, TypePath)]\nstruct Level {\n    positions: Vec<[f32; 3]>,\n}\n\n#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]\nenum AppState {\n    #[default]\n    Loading,\n    Level,\n}\n\n#[derive(Resource)]\nstruct ImageHandle(Handle<Image>);\n\n#[derive(Resource)]\nstruct LevelHandle(Handle<Level>);\n"
  },
  {
    "path": "examples/toml.rs",
    "content": "use bevy::prelude::*;\nuse bevy::reflect::TypePath;\nuse bevy_common_assets::toml::TomlAssetPlugin;\n\nfn main() {\n    App::new()\n        .add_plugins((\n            DefaultPlugins,\n            TomlAssetPlugin::<Level>::new(&[\"level.toml\"]),\n        ))\n        .init_state::<AppState>()\n        .add_systems(Startup, setup)\n        .add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))\n        .run();\n}\n\nfn setup(mut commands: Commands, asset_server: Res<AssetServer>) {\n    let level = LevelHandle(asset_server.load(\"trees.level.toml\"));\n    commands.insert_resource(level);\n    let tree = ImageHandle(asset_server.load(\"tree.png\"));\n    commands.insert_resource(tree);\n\n    commands.spawn((Camera2d, Msaa::Off));\n}\n\nfn spawn_level(\n    mut commands: Commands,\n    level: Res<LevelHandle>,\n    tree: Res<ImageHandle>,\n    mut levels: ResMut<Assets<Level>>,\n    mut state: ResMut<NextState<AppState>>,\n) {\n    if let Some(level) = levels.remove(level.0.id()) {\n        for position in level.positions {\n            commands.spawn((\n                Sprite::from_image(tree.0.clone()),\n                Transform::from_translation(position.into()),\n            ));\n        }\n\n        state.set(AppState::Level);\n    }\n}\n\n#[derive(serde::Deserialize, Asset, TypePath)]\nstruct Level {\n    positions: Vec<[f32; 3]>,\n}\n\n#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]\nenum AppState {\n    #[default]\n    Loading,\n    Level,\n}\n\n#[derive(Resource)]\nstruct ImageHandle(Handle<Image>);\n\n#[derive(Resource)]\nstruct LevelHandle(Handle<Level>);\n"
  },
  {
    "path": "examples/xml.rs",
    "content": "use bevy::math::f32::Vec3;\nuse bevy::prelude::*;\nuse bevy::reflect::TypePath;\nuse bevy_common_assets::xml::XmlAssetPlugin;\n\nfn main() {\n    App::new()\n        .add_plugins((DefaultPlugins, XmlAssetPlugin::<Level>::new(&[\"level.xml\"])))\n        .init_state::<AppState>()\n        .add_systems(Startup, setup)\n        .add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))\n        .run();\n}\n\nfn setup(mut commands: Commands, asset_server: Res<AssetServer>) {\n    let level = LevelHandle(asset_server.load(\"trees.level.xml\"));\n    commands.insert_resource(level);\n    let tree = ImageHandle(asset_server.load(\"tree.png\"));\n    commands.insert_resource(tree);\n\n    commands.spawn((Camera2d, Msaa::Off));\n}\n\nfn spawn_level(\n    mut commands: Commands,\n    level: Res<LevelHandle>,\n    tree: Res<ImageHandle>,\n    mut levels: ResMut<Assets<Level>>,\n    mut state: ResMut<NextState<AppState>>,\n) {\n    if let Some(level) = levels.remove(level.0.id()) {\n        for position in level.positions {\n            commands.spawn((\n                Sprite::from_image(tree.0.clone()),\n                Transform::from_translation(Vec3::new(position.x, position.y, position.z)),\n            ));\n        }\n\n        state.set(AppState::Level);\n    }\n}\n\n#[derive(serde::Deserialize, Asset, TypePath)]\nstruct Level {\n    #[serde(rename = \"Position\")]\n    positions: Vec<Position>,\n}\n\n#[derive(serde::Deserialize)]\nstruct Position {\n    #[serde(rename = \"@x\")]\n    x: f32,\n    #[serde(rename = \"@y\")]\n    y: f32,\n    #[serde(rename = \"@z\")]\n    z: f32,\n}\n\n#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]\nenum AppState {\n    #[default]\n    Loading,\n    Level,\n}\n\n#[derive(Resource)]\nstruct ImageHandle(Handle<Image>);\n\n#[derive(Resource)]\nstruct LevelHandle(Handle<Level>);\n"
  },
  {
    "path": "examples/yaml.rs",
    "content": "use bevy::prelude::*;\nuse bevy::reflect::TypePath;\nuse bevy_common_assets::yaml::YamlAssetPlugin;\n\nfn main() {\n    App::new()\n        .add_plugins((\n            DefaultPlugins,\n            YamlAssetPlugin::<Level>::new(&[\"level.yaml\"]),\n        ))\n        .init_state::<AppState>()\n        .add_systems(Startup, setup)\n        .add_systems(Update, spawn_level.run_if(in_state(AppState::Loading)))\n        .run();\n}\n\nfn setup(mut commands: Commands, asset_server: Res<AssetServer>) {\n    let level = LevelHandle(asset_server.load(\"trees.level.yaml\"));\n    commands.insert_resource(level);\n    let tree = ImageHandle(asset_server.load(\"tree.png\"));\n    commands.insert_resource(tree);\n\n    commands.spawn((Camera2d, Msaa::Off));\n}\n\nfn spawn_level(\n    mut commands: Commands,\n    level: Res<LevelHandle>,\n    tree: Res<ImageHandle>,\n    mut levels: ResMut<Assets<Level>>,\n    mut state: ResMut<NextState<AppState>>,\n) {\n    if let Some(level) = levels.remove(level.0.id()) {\n        for position in level.positions {\n            commands.spawn((\n                Sprite::from_image(tree.0.clone()),\n                Transform::from_translation(position.into()),\n            ));\n        }\n\n        state.set(AppState::Level);\n    }\n}\n\n#[derive(serde::Deserialize, Asset, TypePath)]\nstruct Level {\n    positions: Vec<[f32; 3]>,\n}\n\n#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]\nenum AppState {\n    #[default]\n    Loading,\n    Level,\n}\n\n#[derive(Resource)]\nstruct ImageHandle(Handle<Image>);\n\n#[derive(Resource)]\nstruct LevelHandle(Handle<Level>);\n"
  },
  {
    "path": "src/cbor.rs",
    "content": "use bevy_app::{App, Plugin};\nuse bevy_asset::{\n    Asset, AssetApp, AssetLoader, AsyncWriteExt, LoadContext, io::Reader, saver::AssetSaver,\n};\nuse bevy_reflect::TypePath;\nuse ciborium::from_reader;\nuse serde::{Deserialize, Serialize};\nuse std::marker::PhantomData;\nuse thiserror::Error;\n\n/// Plugin to load your asset type `A` from \"Concise Binary Object Representation\" (CBOR) files.\npub struct CborAssetPlugin<A> {\n    extensions: Vec<&'static str>,\n    _marker: PhantomData<A>,\n}\n\nimpl<A> Plugin for CborAssetPlugin<A>\nwhere\n    for<'de> A: Deserialize<'de> + Asset,\n{\n    fn build(&self, app: &mut App) {\n        app.init_asset::<A>()\n            .register_asset_loader(CborAssetLoader::<A> {\n                extensions: self.extensions.clone(),\n                _marker: PhantomData,\n            });\n    }\n}\n\nimpl<A> CborAssetPlugin<A>\nwhere\n    for<'de> A: Deserialize<'de> + Asset,\n{\n    /// Create a new plugin that will load assets from files with the given extensions.\n    pub fn new(extensions: &[&'static str]) -> Self {\n        Self {\n            extensions: extensions.to_owned(),\n            _marker: PhantomData,\n        }\n    }\n}\n\n/// Loads your asset type `A` from CBOR files\n#[derive(TypePath)]\npub struct CborAssetLoader<A> {\n    extensions: Vec<&'static str>,\n    _marker: PhantomData<A>,\n}\n\n/// Possible errors that can be produced by [`CborAssetLoader`] or [`CborAssetSaver`]\n#[non_exhaustive]\n#[derive(Debug, Error)]\npub enum CborAssetError {\n    /// An [IO Error](std::io::Error)\n    #[error(\"Could not read the file: {0}\")]\n    Io(#[from] std::io::Error),\n\n    /// A [ciborium serializing Error](ciborium::ser::Error)\n    #[error(\"Could not serialize into CBOR: {0}\")]\n    CborSerError(#[from] ciborium::ser::Error<std::io::Error>),\n\n    /// A [ciborium deserializing Error](ciborium::de::Error)\n    #[error(\"Could not parse CBOR: {0}\")]\n    CborDeError(#[from] ciborium::de::Error<std::io::Error>),\n}\n\nimpl<A> AssetLoader for CborAssetLoader<A>\nwhere\n    for<'de> A: Deserialize<'de> + Asset,\n{\n    type Asset = A;\n    type Settings = ();\n    type Error = CborAssetError;\n\n    async fn load(\n        &self,\n        reader: &mut dyn Reader,\n        _settings: &(),\n        _load_context: &mut LoadContext<'_>,\n    ) -> Result<Self::Asset, Self::Error> {\n        let mut bytes = Vec::new();\n        reader.read_to_end(&mut bytes).await?;\n        let asset: A = from_reader(&bytes[..])?;\n        Ok(asset)\n    }\n\n    fn extensions(&self) -> &[&str] {\n        &self.extensions\n    }\n}\n\n/// Saves your asset type `A` to `Cbor` files\n#[derive(TypePath)]\npub struct CborAssetSaver<A> {\n    _marker: PhantomData<A>,\n}\n\nimpl<A> Default for CborAssetSaver<A> {\n    fn default() -> Self {\n        Self {\n            _marker: PhantomData,\n        }\n    }\n}\n\nimpl<A: Asset + for<'de> Deserialize<'de> + Serialize> AssetSaver for CborAssetSaver<A> {\n    type Asset = A;\n    type Settings = ();\n    type OutputLoader = CborAssetLoader<A>;\n    type Error = CborAssetError;\n\n    async fn save(\n        &self,\n        writer: &mut bevy_asset::io::Writer,\n        asset: bevy_asset::saver::SavedAsset<'_, Self::Asset>,\n        _settings: &Self::Settings,\n    ) -> Result<<Self::OutputLoader as AssetLoader>::Settings, Self::Error> {\n        let mut bytes = Vec::new();\n        ciborium::into_writer(&asset.get(), &mut bytes)?;\n        writer.write_all(&bytes).await?;\n        Ok(())\n    }\n}\n"
  },
  {
    "path": "src/csv.rs",
    "content": "use bevy_app::{App, Plugin};\nuse bevy_asset::io::Reader;\nuse bevy_asset::{Asset, AssetApp, AssetLoader, LoadContext};\nuse bevy_reflect::TypePath;\nuse std::marker::PhantomData;\nuse thiserror::Error;\n\n/// Plugin to load your asset type `A` from csv files.\npub struct CsvAssetPlugin<A> {\n    extensions: Vec<&'static str>,\n    _marker: PhantomData<A>,\n    delimiter: u8,\n}\n\nimpl<A> Plugin for CsvAssetPlugin<A>\nwhere\n    for<'de> A: serde::Deserialize<'de> + Asset,\n{\n    fn build(&self, app: &mut App) {\n        app.init_asset::<LoadedCsv<A>>()\n            .register_asset_loader(CsvAssetLoader::<A> {\n                extensions: self.extensions.clone(),\n                _marker: PhantomData,\n                delimiter: self.delimiter,\n            });\n    }\n}\n\nimpl<A> CsvAssetPlugin<A>\nwhere\n    for<'de> A: serde::Deserialize<'de> + Asset,\n{\n    /// Create a new plugin that will load assets from files with the given extensions.\n    pub fn new(extensions: &[&'static str]) -> Self {\n        Self {\n            extensions: extensions.to_owned(),\n            _marker: PhantomData,\n            delimiter: b',',\n        }\n    }\n\n    /// Change the delimiter used to parse the CSV file.\n    ///\n    /// The default is \",\"\n    ///\n    /// ```no_run\n    /// # use bevy::prelude::*;\n    /// # use bevy_common_assets::csv::CsvAssetPlugin;\n    /// App::new()\n    ///     .add_plugins(CsvAssetPlugin::<TreePosition>::new(&[\"some_file.csv\"]).with_delimiter(b';'));\n    /// # #[derive(serde::Deserialize, Asset, TypePath, Debug)]\n    /// # struct TreePosition {\n    /// #     x: f32,\n    /// #     y: f32,\n    /// #     z: f32,\n    /// # }\n    /// ```\n    pub fn with_delimiter(mut self, delimiter: u8) -> Self {\n        self.delimiter = delimiter;\n        self\n    }\n}\n\n/// Loads your asset type `A` from csv files\n#[derive(TypePath)]\npub struct CsvAssetLoader<A> {\n    extensions: Vec<&'static str>,\n    _marker: PhantomData<A>,\n    delimiter: u8,\n}\n\n/// Possible errors that can be produced by [`CsvAssetLoader`]\n#[non_exhaustive]\n#[derive(Debug, Error)]\npub enum CsvLoaderError {\n    /// An [IO Error](std::io::Error)\n    #[error(\"Could not read the file: {0}\")]\n    Io(#[from] std::io::Error),\n    /// A [CSV Error](serde_csv::Error)\n    #[error(\"Could not parse CSV: {0}\")]\n    CsvError(#[from] csv::Error),\n}\n\n/// Asset representing a loaded CSV file with rows deserialized to Assets of type `A`\n#[derive(TypePath, Asset)]\npub struct LoadedCsv<A>\nwhere\n    for<'de> A: serde::Deserialize<'de> + Asset,\n{\n    /// Handles to the Assets the were loaded from the rows of this CSV file\n    pub rows: Vec<A>,\n}\n\nimpl<A> AssetLoader for CsvAssetLoader<A>\nwhere\n    for<'de> A: serde::Deserialize<'de> + Asset,\n{\n    type Asset = LoadedCsv<A>;\n    type Settings = ();\n    type Error = CsvLoaderError;\n\n    async fn load(\n        &self,\n        reader: &mut dyn Reader,\n        _settings: &(),\n        _: &mut LoadContext<'_>,\n    ) -> Result<Self::Asset, Self::Error> {\n        let mut bytes = Vec::new();\n        reader.read_to_end(&mut bytes).await?;\n        let mut reader = csv::ReaderBuilder::new()\n            .delimiter(self.delimiter)\n            .from_reader(bytes.as_slice());\n        let mut rows = vec![];\n        for row in reader.deserialize() {\n            rows.push(row?);\n        }\n        Ok(LoadedCsv { rows })\n    }\n\n    fn extensions(&self) -> &[&str] {\n        &self.extensions\n    }\n}\n"
  },
  {
    "path": "src/json.rs",
    "content": "use bevy_app::{App, Plugin};\nuse bevy_asset::io::Reader;\nuse bevy_asset::{Asset, AssetApp, AssetLoader, AsyncWriteExt, LoadContext, saver::AssetSaver};\nuse bevy_reflect::TypePath;\nuse serde::{Deserialize, Serialize};\nuse serde_json::from_slice;\nuse std::marker::PhantomData;\nuse thiserror::Error;\n\n/// Plugin to load your asset type `A` from json files.\npub struct JsonAssetPlugin<A> {\n    extensions: Vec<&'static str>,\n    _marker: PhantomData<A>,\n}\n\nimpl<A> Plugin for JsonAssetPlugin<A>\nwhere\n    for<'de> A: serde::Deserialize<'de> + Asset,\n{\n    fn build(&self, app: &mut App) {\n        app.init_asset::<A>()\n            .register_asset_loader(JsonAssetLoader::<A> {\n                extensions: self.extensions.clone(),\n                _marker: PhantomData,\n            });\n    }\n}\n\nimpl<A> JsonAssetPlugin<A>\nwhere\n    for<'de> A: serde::Deserialize<'de> + Asset,\n{\n    /// Create a new plugin that will load assets from files with the given extensions.\n    pub fn new(extensions: &[&'static str]) -> Self {\n        Self {\n            extensions: extensions.to_owned(),\n            _marker: PhantomData,\n        }\n    }\n}\n\n/// Loads your asset type `A` from json files\n#[derive(TypePath)]\npub struct JsonAssetLoader<A> {\n    extensions: Vec<&'static str>,\n    _marker: PhantomData<A>,\n}\n\n/// Possible errors that can be produced by [`JsonAssetLoader`] or [`JsonAssetSaver`]\n#[non_exhaustive]\n#[derive(Debug, Error)]\npub enum JsonAssetError {\n    /// An [IO Error](std::io::Error)\n    #[error(\"Could not read the file: {0}\")]\n    Io(#[from] std::io::Error),\n    /// A [JSON Error](serde_json::error::Error)\n    #[error(\"Could not parse/serialize JSON: {0}\")]\n    JsonError(#[from] serde_json::error::Error),\n}\n\n/// Deprecated alias for [`JsonAssetError`]\n#[deprecated(since = \"0.15.0\", note = \"Use JsonAssetError instead\")]\npub type JsonLoaderError = JsonAssetError;\n\nimpl<A> AssetLoader for JsonAssetLoader<A>\nwhere\n    for<'de> A: serde::Deserialize<'de> + Asset,\n{\n    type Asset = A;\n    type Settings = ();\n    type Error = JsonAssetError;\n\n    async fn load(\n        &self,\n        reader: &mut dyn Reader,\n        _settings: &(),\n        _load_context: &mut LoadContext<'_>,\n    ) -> Result<Self::Asset, Self::Error> {\n        let mut bytes = Vec::new();\n        reader.read_to_end(&mut bytes).await?;\n        let asset = from_slice::<A>(&bytes)?;\n        Ok(asset)\n    }\n\n    fn extensions(&self) -> &[&str] {\n        &self.extensions\n    }\n}\n\n/// Saves your asset type `A` to JSON files\n#[derive(TypePath)]\npub struct JsonAssetSaver<A> {\n    _marker: PhantomData<A>,\n}\n\nimpl<A> Default for JsonAssetSaver<A> {\n    fn default() -> Self {\n        Self {\n            _marker: PhantomData,\n        }\n    }\n}\n\nimpl<A: Asset + for<'de> Deserialize<'de> + Serialize> AssetSaver for JsonAssetSaver<A> {\n    type Asset = A;\n    type Settings = ();\n    type OutputLoader = JsonAssetLoader<A>;\n    type Error = JsonAssetError;\n\n    async fn save(\n        &self,\n        writer: &mut bevy_asset::io::Writer,\n        asset: bevy_asset::saver::SavedAsset<'_, Self::Asset>,\n        _settings: &Self::Settings,\n    ) -> Result<<Self::OutputLoader as AssetLoader>::Settings, Self::Error> {\n        let bytes = serde_json::to_vec(asset.get())?;\n        writer.write_all(&bytes).await?;\n        Ok(())\n    }\n}\n"
  },
  {
    "path": "src/lib.rs",
    "content": "//! Bevy plugin offering generic asset loaders for common file formats\n//!\n//! This library includes a collection of thin wrapper plugins around serde implementations for the\n//! common file formats `json`, `ron`, `toml`, `yaml`, `MessagePack` and `xml`. Each plugin adds\n//! an asset loader for a user type. Assets of that type will then be loaded from all files with\n//! configurable extensions.\n//!\n//! The following example requires the `json` feature and loads a custom asset from a json file.\n//! ```\n//! use bevy::prelude::*;\n//! use bevy::reflect::TypePath;\n//! # /*\n//! use bevy_common_assets::json::JsonAssetPlugin;\n//! # */\n//! # use bevy::app::AppExit;\n//!\n//! fn main() {\n//!     App::new()\n//! # /*\n//!         .add_plugins((DefaultPlugins, JsonAssetPlugin::<Level>::new(&[\"level.json\"])))\n//! # */\n//! #       .add_plugins((MinimalPlugins, AssetPlugin::default()))\n//! #       .init_asset::<Level>()\n//!         .add_systems(Startup, load_level)\n//! #       .add_systems(Update, stop)\n//!         .run();\n//! }\n//!\n//! fn load_level(mut commands: Commands, asset_server: Res<AssetServer>) {\n//!     let handle = LevelAsset(asset_server.load(\"trees.level.json\"));\n//!     commands.insert_resource(handle);\n//! }\n//!\n//! #[derive(serde::Deserialize, Asset, TypePath)]\n//! struct Level {\n//!     positions: Vec<[f32; 3]>,\n//! }\n//!\n//! #[derive(Resource)]\n//! struct LevelAsset(Handle<Level>);\n//!\n//! # fn stop(mut events: MessageWriter<AppExit>) {\n//! #     events.write(AppExit::Success);\n//! # }\n//! ```\n\n#![forbid(unsafe_code)]\n#![warn(unused_imports, missing_docs)]\n#![cfg_attr(docsrs, feature(doc_cfg))]\n\n/// Module containing a Bevy plugin to load assets from `cbor` files with custom file extensions.\n#[cfg_attr(docsrs, doc(cfg(feature = \"cbor\")))]\n#[cfg(feature = \"cbor\")]\npub mod cbor;\n/// Module containing a Bevy plugin to load assets from `csv` files with custom file extensions.\n#[cfg_attr(docsrs, doc(cfg(feature = \"csv\")))]\n#[cfg(feature = \"csv\")]\npub mod csv;\n/// Module containing a Bevy plugin to load assets from `json` files with custom file extensions.\n#[cfg_attr(docsrs, doc(cfg(feature = \"json\")))]\n#[cfg(feature = \"json\")]\npub mod json;\n/// Module containing a Bevy plugin to load assets from `MessagePack` files with custom file extensions.\n#[cfg_attr(docsrs, doc(cfg(feature = \"msgpack\")))]\n#[cfg(feature = \"msgpack\")]\npub mod msgpack;\n/// Module containing a Bevy plugin to load assets from `postcard` files with custom file extensions.\n#[cfg_attr(docsrs, doc(cfg(feature = \"postcard\")))]\n#[cfg(feature = \"postcard\")]\npub mod postcard;\n/// Module containing a Bevy plugin to load assets from `ron` files with custom file extensions.\n#[cfg_attr(docsrs, doc(cfg(feature = \"ron\")))]\n#[cfg(feature = \"ron\")]\npub mod ron;\n/// Module containing a Bevy plugin to load assets from `toml` files with custom file extensions.\n#[cfg_attr(docsrs, doc(cfg(feature = \"toml\")))]\n#[cfg(feature = \"toml\")]\npub mod toml;\n/// Module containing a Bevy plugin to load assets from `xml` files with custom file extensions.\n#[cfg_attr(docsrs, doc(cfg(feature = \"xml\")))]\n#[cfg(feature = \"xml\")]\npub mod xml;\n/// Module containing a Bevy plugin to load assets from `yaml` files with custom file extensions.\n#[cfg_attr(docsrs, doc(cfg(feature = \"yaml\")))]\n#[cfg(feature = \"yaml\")]\npub mod yaml;\n\n#[cfg(all(\n    feature = \"json\",\n    feature = \"msgpack\",\n    feature = \"ron\",\n    feature = \"toml\",\n    feature = \"xml\",\n    feature = \"yaml\",\n    feature = \"csv\",\n    feature = \"postcard\",\n    feature = \"cbor\",\n))]\n#[doc = include_str!(\"../README.md\")]\n#[cfg(doctest)]\npub struct ReadmeDoctests;\n"
  },
  {
    "path": "src/msgpack.rs",
    "content": "use bevy_app::{App, Plugin};\nuse bevy_asset::io::Reader;\nuse bevy_asset::{Asset, AssetApp, AssetLoader, AsyncWriteExt, LoadContext, saver::AssetSaver};\nuse bevy_reflect::TypePath;\nuse rmp_serde::from_slice;\nuse serde::{Deserialize, Serialize};\nuse std::marker::PhantomData;\nuse thiserror::Error;\n\n/// Plugin to load your asset type `A` from `MessagePack` files.\npub struct MsgPackAssetPlugin<A> {\n    extensions: Vec<&'static str>,\n    _marker: PhantomData<A>,\n}\n\nimpl<A> Plugin for MsgPackAssetPlugin<A>\nwhere\n    for<'de> A: serde::Deserialize<'de> + Asset,\n{\n    fn build(&self, app: &mut App) {\n        app.init_asset::<A>()\n            .register_asset_loader(MsgPackAssetLoader::<A> {\n                extensions: self.extensions.clone(),\n                _marker: PhantomData,\n            });\n    }\n}\n\nimpl<A> MsgPackAssetPlugin<A>\nwhere\n    for<'de> A: serde::Deserialize<'de> + Asset,\n{\n    /// Create a new plugin that will load assets from files with the given extensions.\n    pub fn new(extensions: &[&'static str]) -> Self {\n        Self {\n            extensions: extensions.to_owned(),\n            _marker: PhantomData,\n        }\n    }\n}\n\n/// Loads your asset type `A` from `MessagePack` files\n#[derive(TypePath)]\npub struct MsgPackAssetLoader<A> {\n    extensions: Vec<&'static str>,\n    _marker: PhantomData<A>,\n}\n\n/// Possible errors that can be produced by [`MsgPackAssetLoader`] or [`MsgPackAssetSaver`]\n#[non_exhaustive]\n#[derive(Debug, Error)]\npub enum MsgPackAssetError {\n    /// An [IO Error](std::io::Error)\n    #[error(\"Could not read the file: {0}\")]\n    Io(#[from] std::io::Error),\n    /// A [`MessagePack` decoding Error](rmp_serde::decode::Error)\n    #[error(\"Could not parse MessagePack: {0}\")]\n    MsgPackDecodeError(#[from] rmp_serde::decode::Error),\n    /// A [`MessagePack` encoding Error](rmp_serde::encode::Error)\n    #[error(\"Could not serialize MessagePack: {0}\")]\n    MsgPackEncodeError(#[from] rmp_serde::encode::Error),\n}\n\n/// Deprecated alias for [`MsgPackAssetError`]\n#[deprecated(since = \"0.15.0\", note = \"Use MsgPackAssetError instead\")]\npub type MsgPackLoaderError = MsgPackAssetError;\n\nimpl<A> AssetLoader for MsgPackAssetLoader<A>\nwhere\n    for<'de> A: serde::Deserialize<'de> + Asset,\n{\n    type Asset = A;\n    type Settings = ();\n    type Error = MsgPackAssetError;\n\n    async fn load(\n        &self,\n        reader: &mut dyn Reader,\n        _settings: &(),\n        _load_context: &mut LoadContext<'_>,\n    ) -> Result<Self::Asset, Self::Error> {\n        let mut bytes = Vec::new();\n        reader.read_to_end(&mut bytes).await?;\n        let asset = from_slice::<A>(&bytes)?;\n        Ok(asset)\n    }\n\n    fn extensions(&self) -> &[&str] {\n        &self.extensions\n    }\n}\n\n/// Saves your asset type `A` to `MessagePack` files\n#[derive(TypePath)]\npub struct MsgPackAssetSaver<A> {\n    _marker: PhantomData<A>,\n}\n\nimpl<A> Default for MsgPackAssetSaver<A> {\n    fn default() -> Self {\n        Self {\n            _marker: PhantomData,\n        }\n    }\n}\n\nimpl<A: Asset + for<'de> Deserialize<'de> + Serialize> AssetSaver for MsgPackAssetSaver<A> {\n    type Asset = A;\n    type Settings = ();\n    type OutputLoader = MsgPackAssetLoader<A>;\n    type Error = MsgPackAssetError;\n\n    async fn save(\n        &self,\n        writer: &mut bevy_asset::io::Writer,\n        asset: bevy_asset::saver::SavedAsset<'_, Self::Asset>,\n        _settings: &Self::Settings,\n    ) -> Result<<Self::OutputLoader as AssetLoader>::Settings, Self::Error> {\n        let bytes = rmp_serde::to_vec(asset.get())?;\n        writer.write_all(&bytes).await?;\n        Ok(())\n    }\n}\n"
  },
  {
    "path": "src/postcard.rs",
    "content": "use bevy_app::{App, Plugin};\nuse bevy_asset::{\n    Asset, AssetApp, AssetLoader, AsyncWriteExt, LoadContext, io::Reader, saver::AssetSaver,\n};\nuse bevy_reflect::TypePath;\nuse postcard::{from_bytes, to_stdvec};\nuse serde::{Deserialize, Serialize};\nuse std::marker::PhantomData;\nuse thiserror::Error;\n\n/// Plugin to load your asset type `A` from `Postcard` files.\npub struct PostcardAssetPlugin<A> {\n    extensions: Vec<&'static str>,\n    _marker: PhantomData<A>,\n}\n\nimpl<A> Plugin for PostcardAssetPlugin<A>\nwhere\n    for<'de> A: Deserialize<'de> + Asset,\n{\n    fn build(&self, app: &mut App) {\n        app.init_asset::<A>()\n            .register_asset_loader(PostcardAssetLoader::<A> {\n                extensions: self.extensions.clone(),\n                _marker: PhantomData,\n            });\n    }\n}\n\nimpl<A> PostcardAssetPlugin<A>\nwhere\n    for<'de> A: Deserialize<'de> + Asset,\n{\n    /// Create a new plugin that will load assets from files with the given extensions.\n    pub fn new(extensions: &[&'static str]) -> Self {\n        Self {\n            extensions: extensions.to_owned(),\n            _marker: PhantomData,\n        }\n    }\n}\n\n/// Loads your asset type `A` from `Postcard` files\n#[derive(TypePath)]\npub struct PostcardAssetLoader<A> {\n    extensions: Vec<&'static str>,\n    _marker: PhantomData<A>,\n}\n\n/// Possible errors that can be produced by [`PostcardAssetLoader`] or [`PostcardAssetSaver`]\n#[non_exhaustive]\n#[derive(Debug, Error)]\npub enum PostcardAssetError {\n    /// An [IO Error](std::io::Error)\n    #[error(\"Could not read the file: {0}\")]\n    Io(#[from] std::io::Error),\n    /// A [Postcard Error](postcard::Error)\n    #[error(\"Could not parse Postcard: {0}\")]\n    PostcardError(#[from] postcard::Error),\n}\n\nimpl<A> AssetLoader for PostcardAssetLoader<A>\nwhere\n    for<'de> A: Deserialize<'de> + Asset,\n{\n    type Asset = A;\n    type Settings = ();\n    type Error = PostcardAssetError;\n\n    async fn load(\n        &self,\n        reader: &mut dyn Reader,\n        _settings: &(),\n        _load_context: &mut LoadContext<'_>,\n    ) -> Result<Self::Asset, Self::Error> {\n        let mut bytes = Vec::new();\n        reader.read_to_end(&mut bytes).await?;\n        let asset = from_bytes::<A>(&bytes)?;\n        Ok(asset)\n    }\n\n    fn extensions(&self) -> &[&str] {\n        &self.extensions\n    }\n}\n\n/// Saves your asset type `A` to `Postcard` files\n#[derive(TypePath)]\npub struct PostcardAssetSaver<A> {\n    _marker: PhantomData<A>,\n}\n\nimpl<A> Default for PostcardAssetSaver<A> {\n    fn default() -> Self {\n        Self {\n            _marker: PhantomData,\n        }\n    }\n}\n\nimpl<A: Asset + for<'de> Deserialize<'de> + Serialize> AssetSaver for PostcardAssetSaver<A> {\n    type Asset = A;\n    type Settings = ();\n    type OutputLoader = PostcardAssetLoader<A>;\n    type Error = PostcardAssetError;\n\n    async fn save(\n        &self,\n        writer: &mut bevy_asset::io::Writer,\n        asset: bevy_asset::saver::SavedAsset<'_, Self::Asset>,\n        _settings: &Self::Settings,\n    ) -> Result<<Self::OutputLoader as AssetLoader>::Settings, Self::Error> {\n        let bytes = to_stdvec(&asset.get())?;\n        writer.write_all(&bytes).await?;\n        Ok(())\n    }\n}\n"
  },
  {
    "path": "src/ron.rs",
    "content": "use bevy_app::{App, Plugin};\nuse bevy_asset::io::Reader;\nuse bevy_asset::{Asset, AssetApp, AssetLoader, AsyncWriteExt, LoadContext, saver::AssetSaver};\nuse bevy_reflect::TypePath;\nuse serde::{Deserialize, Serialize};\nuse serde_ron::de::from_bytes;\nuse std::marker::PhantomData;\nuse thiserror::Error;\n\n/// Plugin to load your asset type `A` from ron files.\npub struct RonAssetPlugin<A> {\n    extensions: Vec<&'static str>,\n    _marker: PhantomData<A>,\n}\n\nimpl<A> Plugin for RonAssetPlugin<A>\nwhere\n    for<'de> A: serde::Deserialize<'de> + Asset,\n{\n    fn build(&self, app: &mut App) {\n        app.init_asset::<A>()\n            .register_asset_loader(RonAssetLoader::<A> {\n                extensions: self.extensions.clone(),\n                _marker: PhantomData,\n            });\n    }\n}\n\nimpl<A> RonAssetPlugin<A>\nwhere\n    for<'de> A: serde::Deserialize<'de> + Asset,\n{\n    /// Create a new plugin that will load assets from files with the given extensions.\n    pub fn new(extensions: &[&'static str]) -> Self {\n        Self {\n            extensions: extensions.to_owned(),\n            _marker: PhantomData,\n        }\n    }\n}\n\n/// Loads your asset type `A` from ron files\n#[derive(TypePath)]\npub struct RonAssetLoader<A> {\n    extensions: Vec<&'static str>,\n    _marker: PhantomData<A>,\n}\n\n/// Possible errors that can be produced by [`RonAssetLoader`] or [`RonAssetSaver`]\n#[non_exhaustive]\n#[derive(Debug, Error)]\npub enum RonAssetError {\n    /// An [IO Error](std::io::Error)\n    #[error(\"Could not read the file: {0}\")]\n    Io(#[from] std::io::Error),\n    /// A [RON deserialization Error](serde_ron::error::SpannedError)\n    #[error(\"Could not parse RON: {0}\")]\n    RonDeError(#[from] serde_ron::error::SpannedError),\n    /// A [RON serialization Error](serde_ron::Error)\n    #[error(\"Could not serialize RON: {0}\")]\n    RonSerError(#[from] serde_ron::Error),\n}\n\n/// Deprecated alias for [`RonAssetError`]\n#[deprecated(since = \"0.15.0\", note = \"Use RonAssetError instead\")]\npub type RonLoaderError = RonAssetError;\n\nimpl<A> AssetLoader for RonAssetLoader<A>\nwhere\n    for<'de> A: serde::Deserialize<'de> + Asset,\n{\n    type Asset = A;\n    type Settings = ();\n    type Error = RonAssetError;\n\n    async fn load(\n        &self,\n        reader: &mut dyn Reader,\n        _settings: &(),\n        _load_context: &mut LoadContext<'_>,\n    ) -> Result<Self::Asset, Self::Error> {\n        let mut bytes = Vec::new();\n        reader.read_to_end(&mut bytes).await?;\n        let asset = from_bytes::<A>(&bytes)?;\n        Ok(asset)\n    }\n\n    fn extensions(&self) -> &[&str] {\n        &self.extensions\n    }\n}\n\n/// Saves your asset type `A` to RON files\n#[derive(TypePath)]\npub struct RonAssetSaver<A> {\n    _marker: PhantomData<A>,\n}\n\nimpl<A> Default for RonAssetSaver<A> {\n    fn default() -> Self {\n        Self {\n            _marker: PhantomData,\n        }\n    }\n}\n\nimpl<A: Asset + for<'de> Deserialize<'de> + Serialize> AssetSaver for RonAssetSaver<A> {\n    type Asset = A;\n    type Settings = ();\n    type OutputLoader = RonAssetLoader<A>;\n    type Error = RonAssetError;\n\n    async fn save(\n        &self,\n        writer: &mut bevy_asset::io::Writer,\n        asset: bevy_asset::saver::SavedAsset<'_, Self::Asset>,\n        _settings: &Self::Settings,\n    ) -> Result<<Self::OutputLoader as AssetLoader>::Settings, Self::Error> {\n        let ron = serde_ron::ser::to_string(asset.get())?;\n        writer.write_all(ron.as_bytes()).await?;\n        Ok(())\n    }\n}\n"
  },
  {
    "path": "src/toml.rs",
    "content": "use bevy_app::{App, Plugin};\nuse bevy_asset::io::Reader;\nuse bevy_asset::{Asset, AssetApp, AssetLoader, AsyncWriteExt, LoadContext, saver::AssetSaver};\nuse bevy_reflect::TypePath;\nuse serde::{Deserialize, Serialize};\nuse std::marker::PhantomData;\nuse std::str::from_utf8;\nuse thiserror::Error;\n\n/// Plugin to load your asset type `A` from toml files.\npub struct TomlAssetPlugin<A> {\n    extensions: Vec<&'static str>,\n    _marker: PhantomData<A>,\n}\n\nimpl<A> Plugin for TomlAssetPlugin<A>\nwhere\n    for<'de> A: serde::Deserialize<'de> + Asset,\n{\n    fn build(&self, app: &mut App) {\n        app.init_asset::<A>()\n            .register_asset_loader(TomlAssetLoader::<A> {\n                extensions: self.extensions.clone(),\n                _marker: PhantomData,\n            });\n    }\n}\n\nimpl<A> TomlAssetPlugin<A>\nwhere\n    for<'de> A: serde::Deserialize<'de> + Asset,\n{\n    /// Create a new plugin that will load assets from files with the given extensions.\n    pub fn new(extensions: &[&'static str]) -> Self {\n        Self {\n            extensions: extensions.to_owned(),\n            _marker: PhantomData,\n        }\n    }\n}\n\n/// Loads your asset type `A` from toml files\n#[derive(TypePath)]\npub struct TomlAssetLoader<A> {\n    extensions: Vec<&'static str>,\n    _marker: PhantomData<A>,\n}\n\n/// Possible errors that can be produced by [`TomlAssetLoader`] or [`TomlAssetSaver`]\n#[non_exhaustive]\n#[derive(Debug, Error)]\npub enum TomlAssetError {\n    /// An [IO Error](std::io::Error)\n    #[error(\"Could not read the file: {0}\")]\n    Io(#[from] std::io::Error),\n    /// A [conversion Error](std::str::Utf8Error)\n    #[error(\"Could not interpret as UTF-8: {0}\")]\n    FormatError(#[from] std::str::Utf8Error),\n    /// A [TOML deserialization Error](serde_toml::de::Error)\n    #[error(\"Could not parse TOML: {0}\")]\n    TomlDeError(#[from] serde_toml::de::Error),\n    /// A [TOML serialization Error](serde_toml::ser::Error)\n    #[error(\"Could not serialize TOML: {0}\")]\n    TomlSerError(#[from] serde_toml::ser::Error),\n}\n\n/// Deprecated alias for [`TomlAssetError`]\n#[deprecated(since = \"0.15.0\", note = \"Use TomlAssetError instead\")]\npub type TomlLoaderError = TomlAssetError;\n\nimpl<A> AssetLoader for TomlAssetLoader<A>\nwhere\n    for<'de> A: serde::Deserialize<'de> + Asset,\n{\n    type Asset = A;\n    type Settings = ();\n    type Error = TomlAssetError;\n\n    async fn load(\n        &self,\n        reader: &mut dyn Reader,\n        _settings: &(),\n        _load_context: &mut LoadContext<'_>,\n    ) -> Result<Self::Asset, Self::Error> {\n        let mut bytes = Vec::new();\n        reader.read_to_end(&mut bytes).await?;\n        let asset = serde_toml::from_str::<A>(from_utf8(&bytes)?)?;\n        Ok(asset)\n    }\n\n    fn extensions(&self) -> &[&str] {\n        &self.extensions\n    }\n}\n\n/// Saves your asset type `A` to TOML files\n#[derive(TypePath)]\npub struct TomlAssetSaver<A> {\n    _marker: PhantomData<A>,\n}\n\nimpl<A> Default for TomlAssetSaver<A> {\n    fn default() -> Self {\n        Self {\n            _marker: PhantomData,\n        }\n    }\n}\n\nimpl<A: Asset + for<'de> Deserialize<'de> + Serialize> AssetSaver for TomlAssetSaver<A> {\n    type Asset = A;\n    type Settings = ();\n    type OutputLoader = TomlAssetLoader<A>;\n    type Error = TomlAssetError;\n\n    async fn save(\n        &self,\n        writer: &mut bevy_asset::io::Writer,\n        asset: bevy_asset::saver::SavedAsset<'_, Self::Asset>,\n        _settings: &Self::Settings,\n    ) -> Result<<Self::OutputLoader as AssetLoader>::Settings, Self::Error> {\n        let toml = serde_toml::to_string(asset.get())?;\n        writer.write_all(toml.as_bytes()).await?;\n        Ok(())\n    }\n}\n"
  },
  {
    "path": "src/xml.rs",
    "content": "use bevy_app::{App, Plugin};\nuse bevy_asset::io::Reader;\nuse bevy_asset::{Asset, AssetApp, AssetLoader, AsyncWriteExt, LoadContext, saver::AssetSaver};\nuse bevy_reflect::TypePath;\nuse quick_xml::de::from_str;\nuse serde::{Deserialize, Serialize};\nuse std::marker::PhantomData;\nuse std::str::from_utf8;\nuse thiserror::Error;\n\n/// Plugin to load your asset type `A` from xml files.\n/// Read the [`quick_xml` docs](https://docs.rs/quick-xml/latest/quick_xml/de/) for tips on deserialization.\npub struct XmlAssetPlugin<A> {\n    extensions: Vec<&'static str>,\n    _marker: PhantomData<A>,\n}\n\nimpl<A> Plugin for XmlAssetPlugin<A>\nwhere\n    for<'de> A: serde::Deserialize<'de> + Asset,\n{\n    fn build(&self, app: &mut App) {\n        app.init_asset::<A>()\n            .register_asset_loader(XmlAssetLoader::<A> {\n                extensions: self.extensions.clone(),\n                _marker: PhantomData,\n            });\n    }\n}\n\nimpl<A> XmlAssetPlugin<A>\nwhere\n    for<'de> A: serde::Deserialize<'de> + Asset,\n{\n    /// Create a new plugin that will load assets from files with the given extensions.\n    pub fn new(extensions: &[&'static str]) -> Self {\n        Self {\n            extensions: extensions.to_owned(),\n            _marker: PhantomData,\n        }\n    }\n}\n\n/// Loads your asset type `A` from xml files\n#[derive(TypePath)]\npub struct XmlAssetLoader<A> {\n    extensions: Vec<&'static str>,\n    _marker: PhantomData<A>,\n}\n\n/// Possible errors that can be produced by [`XmlAssetLoader`] or [`XmlAssetSaver`]\n#[non_exhaustive]\n#[derive(Debug, Error)]\npub enum XmlAssetError {\n    /// An [IO Error](std::io::Error)\n    #[error(\"Could not read the file: {0}\")]\n    Io(#[from] std::io::Error),\n    /// A [conversion Error](std::str::Utf8Error)\n    #[error(\"Could not interpret as UTF-8: {0}\")]\n    FormatError(#[from] std::str::Utf8Error),\n    /// A [XML deserialization Error](quick_xml::DeError)\n    #[error(\"Could not parse XML: {0}\")]\n    XmlDeError(#[from] quick_xml::DeError),\n    /// A XML serialization error\n    #[error(\"Could not serialize XML: {0}\")]\n    XmlSerError(String),\n}\n\n/// Deprecated alias for [`XmlAssetError`]\n#[deprecated(since = \"0.15.0\", note = \"Use XmlAssetError instead\")]\npub type XmlLoaderError = XmlAssetError;\n\nimpl<A> AssetLoader for XmlAssetLoader<A>\nwhere\n    for<'de> A: serde::Deserialize<'de> + Asset,\n{\n    type Asset = A;\n    type Settings = ();\n    type Error = XmlAssetError;\n\n    async fn load(\n        &self,\n        reader: &mut dyn Reader,\n        _settings: &(),\n        _load_context: &mut LoadContext<'_>,\n    ) -> Result<Self::Asset, Self::Error> {\n        let mut bytes = Vec::new();\n        reader.read_to_end(&mut bytes).await?;\n        let asset = from_str::<A>(from_utf8(&bytes)?)?;\n        Ok(asset)\n    }\n\n    fn extensions(&self) -> &[&str] {\n        &self.extensions\n    }\n}\n\n/// Saves your asset type `A` to XML files\n#[derive(TypePath)]\npub struct XmlAssetSaver<A> {\n    _marker: PhantomData<A>,\n}\n\nimpl<A> Default for XmlAssetSaver<A> {\n    fn default() -> Self {\n        Self {\n            _marker: PhantomData,\n        }\n    }\n}\n\nimpl<A: Asset + for<'de> Deserialize<'de> + Serialize> AssetSaver for XmlAssetSaver<A> {\n    type Asset = A;\n    type Settings = ();\n    type OutputLoader = XmlAssetLoader<A>;\n    type Error = XmlAssetError;\n\n    async fn save(\n        &self,\n        writer: &mut bevy_asset::io::Writer,\n        asset: bevy_asset::saver::SavedAsset<'_, Self::Asset>,\n        _settings: &Self::Settings,\n    ) -> Result<<Self::OutputLoader as AssetLoader>::Settings, Self::Error> {\n        let xml = quick_xml::se::to_string(asset.get())\n            .map_err(|e| XmlAssetError::XmlSerError(e.to_string()))?;\n        writer.write_all(xml.as_bytes()).await?;\n        Ok(())\n    }\n}\n"
  },
  {
    "path": "src/yaml.rs",
    "content": "use bevy_app::{App, Plugin};\nuse bevy_asset::io::Reader;\nuse bevy_asset::{Asset, AssetApp, AssetLoader, AsyncWriteExt, LoadContext, saver::AssetSaver};\nuse bevy_reflect::TypePath;\nuse serde::{Deserialize, Serialize};\nuse serde_yaml::from_slice;\nuse std::marker::PhantomData;\nuse thiserror::Error;\n\n/// Plugin to load your asset type `A` from yaml files.\npub struct YamlAssetPlugin<A> {\n    extensions: Vec<&'static str>,\n    _marker: PhantomData<A>,\n}\n\nimpl<A> Plugin for YamlAssetPlugin<A>\nwhere\n    for<'de> A: serde::Deserialize<'de> + Asset,\n{\n    fn build(&self, app: &mut App) {\n        app.init_asset::<A>()\n            .register_asset_loader(YamlAssetLoader::<A> {\n                extensions: self.extensions.clone(),\n                _marker: PhantomData,\n            });\n    }\n}\n\nimpl<A> YamlAssetPlugin<A>\nwhere\n    for<'de> A: serde::Deserialize<'de> + Asset,\n{\n    /// Create a new plugin that will load assets from files with the given extensions.\n    pub fn new(extensions: &[&'static str]) -> Self {\n        Self {\n            extensions: extensions.to_owned(),\n            _marker: PhantomData,\n        }\n    }\n}\n\n/// Loads your asset type `A` from yaml files\n#[derive(TypePath)]\npub struct YamlAssetLoader<A> {\n    extensions: Vec<&'static str>,\n    _marker: PhantomData<A>,\n}\n\n/// Possible errors that can be produced by [`YamlAssetLoader`] or [`YamlAssetSaver`]\n#[non_exhaustive]\n#[derive(Debug, Error)]\npub enum YamlAssetError {\n    /// An [IO Error](std::io::Error)\n    #[error(\"Could not read the file: {0}\")]\n    Io(#[from] std::io::Error),\n    /// A [YAML Error](serde_yaml::Error)\n    #[error(\"Could not parse/serialize YAML: {0}\")]\n    YamlError(#[from] serde_yaml::Error),\n}\n\n/// Deprecated alias for [`YamlAssetError`]\n#[deprecated(since = \"0.15.0\", note = \"Use YamlAssetError instead\")]\npub type YamlLoaderError = YamlAssetError;\n\nimpl<A> AssetLoader for YamlAssetLoader<A>\nwhere\n    for<'de> A: serde::Deserialize<'de> + Asset,\n{\n    type Asset = A;\n    type Settings = ();\n    type Error = YamlAssetError;\n\n    async fn load(\n        &self,\n        reader: &mut dyn Reader,\n        _settings: &(),\n        _load_context: &mut LoadContext<'_>,\n    ) -> Result<Self::Asset, Self::Error> {\n        let mut bytes = Vec::new();\n        reader.read_to_end(&mut bytes).await?;\n        let asset = from_slice::<A>(&bytes)?;\n        Ok(asset)\n    }\n\n    fn extensions(&self) -> &[&str] {\n        &self.extensions\n    }\n}\n\n/// Saves your asset type `A` to YAML files\n#[derive(TypePath)]\npub struct YamlAssetSaver<A> {\n    _marker: PhantomData<A>,\n}\n\nimpl<A> Default for YamlAssetSaver<A> {\n    fn default() -> Self {\n        Self {\n            _marker: PhantomData,\n        }\n    }\n}\n\nimpl<A: Asset + for<'de> Deserialize<'de> + Serialize> AssetSaver for YamlAssetSaver<A> {\n    type Asset = A;\n    type Settings = ();\n    type OutputLoader = YamlAssetLoader<A>;\n    type Error = YamlAssetError;\n\n    async fn save(\n        &self,\n        writer: &mut bevy_asset::io::Writer,\n        asset: bevy_asset::saver::SavedAsset<'_, Self::Asset>,\n        _settings: &Self::Settings,\n    ) -> Result<<Self::OutputLoader as AssetLoader>::Settings, Self::Error> {\n        let yaml = serde_yaml::to_string(asset.get())?;\n        writer.write_all(yaml.as_bytes()).await?;\n        Ok(())\n    }\n}\n"
  }
]