diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c023788..67f5813 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,9 +8,10 @@ on: jobs: mix_test: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 env: MIX_ENV: test + HTML5EVER_BUILD: "true" name: Elixir ${{ matrix.pair.elixir }} / OTP ${{ matrix.pair.otp }} @@ -19,25 +20,22 @@ jobs: matrix: include: - pair: - elixir: 1.11.2 - otp: 23.1.4 + elixir: 1.11.4 + otp: 23.3.4 - pair: - elixir: 1.12.3 - otp: 24.1.1 + elixir: 1.14.3 + otp: 25.2.1 lint: lint steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - uses: erlef/setup-beam@v1 + - uses: erlef/setup-beam@v1.15 with: - otp-version: ${{matrix.pair.otp}} - elixir-version: ${{matrix.pair.elixir}} + otp-version: ${{ matrix.pair.otp }} + elixir-version: ${{ matrix.pair.elixir }} - name: Install minimal stable Rust toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable + uses: dtolnay/rust-toolchain@stable - name: Install Dependencies run: mix deps.get @@ -48,9 +46,9 @@ jobs: - run: mix deps.unlock --check-unused if: ${{ matrix.lint }} - - run: HTML5EVER_BUILD=1 mix deps.compile + - run: mix deps.compile - - run: HTML5EVER_BUILD=1 mix compile --warnings-as-errors + - run: mix compile --warnings-as-errors if: ${{ matrix.lint }} - - run: HTML5EVER_BUILD=1 mix test + - run: mix test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 146d472..c83ad3f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,8 +1,5 @@ name: Build precompiled NIFs -env: - NIF_DIRECTORY: "native/html5ever_nif" - on: push: branches: @@ -11,12 +8,6 @@ on: tags: - '*' -defaults: - run: - # Sets the working dir for "run" scripts. - # Note that this won't change the directory for actions (tasks with "uses"). - working-directory: "./native/html5ever_nif" - jobs: build_release: name: NIF ${{ matrix.job.nif }} - ${{ matrix.job.target }} (${{ matrix.job.os }}) @@ -24,153 +15,53 @@ jobs: strategy: fail-fast: false matrix: + nif: ["2.16", "2.15", "2.14"] job: - # NIF version 2.16 - - { target: arm-unknown-linux-gnueabihf , os: ubuntu-20.04 , nif: "2.16", use-cross: true } - - { target: aarch64-unknown-linux-gnu , os: ubuntu-20.04 , nif: "2.16", use-cross: true } - - { target: aarch64-apple-darwin , os: macos-11 , nif: "2.16" } - - { target: x86_64-apple-darwin , os: macos-11 , nif: "2.16" } - - { target: x86_64-unknown-linux-gnu , os: ubuntu-20.04 , nif: "2.16" } - - { target: x86_64-unknown-linux-musl , os: ubuntu-20.04 , nif: "2.16", use-cross: true } - - { target: x86_64-pc-windows-gnu , os: windows-2019 , nif: "2.16" } - - { target: x86_64-pc-windows-msvc , os: windows-2019 , nif: "2.16" } - # NIF version 2.15 - - { target: arm-unknown-linux-gnueabihf , os: ubuntu-20.04 , nif: "2.15", use-cross: true } - - { target: aarch64-unknown-linux-gnu , os: ubuntu-20.04 , nif: "2.15", use-cross: true } - - { target: aarch64-apple-darwin , os: macos-11 , nif: "2.15" } - - { target: x86_64-apple-darwin , os: macos-11 , nif: "2.15" } - - { target: x86_64-unknown-linux-gnu , os: ubuntu-20.04 , nif: "2.15" } - - { target: x86_64-unknown-linux-musl , os: ubuntu-20.04 , nif: "2.15", use-cross: true } - - { target: x86_64-pc-windows-gnu , os: windows-2019 , nif: "2.15" } - - { target: x86_64-pc-windows-msvc , os: windows-2019 , nif: "2.15" } - # NIF version 2.14 - - { target: arm-unknown-linux-gnueabihf , os: ubuntu-20.04 , nif: "2.14", use-cross: true } - - { target: aarch64-unknown-linux-gnu , os: ubuntu-20.04 , nif: "2.14", use-cross: true } - - { target: aarch64-apple-darwin , os: macos-11 , nif: "2.14" } - - { target: x86_64-apple-darwin , os: macos-11 , nif: "2.14" } - - { target: x86_64-unknown-linux-gnu , os: ubuntu-20.04 , nif: "2.14" } - - { target: x86_64-unknown-linux-musl , os: ubuntu-20.04 , nif: "2.14", use-cross: true } - - { target: x86_64-pc-windows-gnu , os: windows-2019 , nif: "2.14" } - - { target: x86_64-pc-windows-msvc , os: windows-2019 , nif: "2.14" } + - { target: arm-unknown-linux-gnueabihf , os: ubuntu-20.04 , use-cross: true } + - { target: aarch64-unknown-linux-gnu , os: ubuntu-20.04 , use-cross: true } + - { target: aarch64-apple-darwin , os: macos-11 } + - { target: x86_64-apple-darwin , os: macos-11 } + - { target: x86_64-unknown-linux-gnu , os: ubuntu-20.04 } + - { target: x86_64-unknown-linux-musl , os: ubuntu-20.04 , use-cross: true } + - { target: x86_64-pc-windows-gnu , os: windows-2019 } + - { target: x86_64-pc-windows-msvc , os: windows-2019 } - env: - RUSTLER_NIF_VERSION: ${{ matrix.job.nif }} steps: - name: Checkout source code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - - name: Install prerequisites + - name: Extract project version shell: bash run: | - case ${{ matrix.job.target }} in - arm-unknown-linux-*) sudo apt-get -y update ; sudo apt-get -y install gcc-arm-linux-gnueabihf ;; - aarch64-unknown-linux-gnu) sudo apt-get -y update ; sudo apt-get -y install gcc-aarch64-linux-gnu ;; - esac - - - name: Extract crate information - shell: bash - run: | - echo "PROJECT_NAME=$(sed -n 's/^name = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV # Get the project version from mix.exs - echo "PROJECT_VERSION=$(sed -n 's/^ @version "\(.*\)"/\1/p' ../../mix.exs | head -n1)" >> $GITHUB_ENV + echo "PROJECT_VERSION=$(sed -n 's/^ @version "\(.*\)"/\1/p' mix.exs | head -n1)" >> $GITHUB_ENV - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable with: toolchain: stable target: ${{ matrix.job.target }} - override: true - profile: minimal - - name: Show version information (Rust, cargo, GCC) - shell: bash - run: | - gcc --version || true - rustup -V - rustup toolchain list - rustup default - cargo -V - rustc -V - rustc --print=cfg - - - name: Download cross from GitHub releases - uses: giantswarm/install-binary-action@v1.0.0 - if: ${{ matrix.job.use-cross }} + - name: Build the project + id: build-crate + uses: philss/rustler-precompiled-action@v1.0.1 with: - binary: "cross" - version: "v0.2.2" - download_url: "https://github.com/cross-rs/cross/releases/download/${version}/cross-x86_64-unknown-linux-gnu.tar.gz" - tarball_binary_path: "${binary}" - smoke_test: "${binary} --version" - - - name: Build - shell: bash - run: | - if [ "${{ matrix.job.use-cross }}" == "true" ]; then - cross build --release --target=${{ matrix.job.target }} - else - cargo build --release --target=${{ matrix.job.target }} - fi - - - name: Rename lib to the final name - id: rename - shell: bash - run: | - LIB_PREFIX="lib" - case ${{ matrix.job.target }} in - *-pc-windows-*) LIB_PREFIX="" ;; - esac; - - # Figure out suffix of lib - # See: https://doc.rust-lang.org/reference/linkage.html - LIB_SUFFIX=".so" - case ${{ matrix.job.target }} in - *-apple-darwin) LIB_SUFFIX=".dylib" ;; - *-pc-windows-*) LIB_SUFFIX=".dll" ;; - esac; - - CICD_INTERMEDIATES_DIR=$(mktemp -d) - - # Setup paths - LIB_DIR="${CICD_INTERMEDIATES_DIR}/released-lib" - mkdir -p "${LIB_DIR}" - LIB_NAME="${LIB_PREFIX}${{ env.PROJECT_NAME }}${LIB_SUFFIX}" - LIB_PATH="${LIB_DIR}/${LIB_NAME}" - - # Copy the release build lib to the result location - cp "target/${{ matrix.job.target }}/release/${LIB_NAME}" "${LIB_DIR}" - - # Final paths - # In the end we use ".so" for MacOS in the final build - # See: https://www.erlang.org/doc/man/erlang.html#load_nif-2 - LIB_FINAL_SUFFIX="${LIB_SUFFIX}" - case ${{ matrix.job.target }} in - *-apple-darwin) LIB_FINAL_SUFFIX=".so" ;; - esac; - - LIB_FINAL_NAME="${LIB_PREFIX}${PROJECT_NAME}-v${PROJECT_VERSION}-nif-${RUSTLER_NIF_VERSION}-${{ matrix.job.target }}${LIB_FINAL_SUFFIX}" - - # Copy lib to final name on this directory - cp "${LIB_PATH}" "${LIB_FINAL_NAME}" - - tar -cvzf "${LIB_FINAL_NAME}.tar.gz" "${LIB_FINAL_NAME}" - - # Passes the path relative to the root of the project. - LIB_FINAL_PATH="${NIF_DIRECTORY}/${LIB_FINAL_NAME}.tar.gz" - - # Let subsequent steps know where to find the lib - echo ::set-output name=LIB_FINAL_PATH::${LIB_FINAL_PATH} - echo ::set-output name=LIB_FINAL_NAME::${LIB_FINAL_NAME}.tar.gz + project-name: html5ever_nif + project-version: ${{ env.PROJECT_VERSION }} + target: ${{ matrix.job.target }} + nif-version: ${{ matrix.nif }} + use-cross: ${{ matrix.job.use-cross }} + project-dir: "native/html5ever_nif" - - name: "Artifact upload" - uses: actions/upload-artifact@v2 + - name: Artifact upload + uses: actions/upload-artifact@v3 with: - name: ${{ steps.rename.outputs.LIB_FINAL_NAME }} - path: ${{ steps.rename.outputs.LIB_FINAL_PATH }} + name: ${{ steps.build-crate.outputs.file-name }} + path: ${{ steps.build-crate.outputs.file-path }} - name: Publish archives and packages uses: softprops/action-gh-release@v1 with: files: | - ${{ steps.rename.outputs.LIB_FINAL_PATH }} + ${{ steps.build-crate.outputs.file-path }} if: startsWith(github.ref, 'refs/tags/') diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cec8af..9d9c689 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.14.1] - 2023-05-20 + +### Added + +- Add support for `rustler_precompiled` v0.6. + +### Changed + +- Update Rustler version in the crate from `v0.26` to `v0.28`. + This shouldn't break anything, but would require the installation of rustler `v0.28` + if needed in the Elixir side. + +- Change the Rust edition to 2021 (it was 2018). This shouldn't change any behaviour. + ## [0.14.0] - 2022-11-04 ### Changed @@ -98,7 +112,8 @@ is not needed for most of people using this project. - Add support for OTP 24. This was achieved by updating Rustler to v0.22. -[Unreleased]: https://github.com/rusterlium/html5ever_elixir/compare/v0.14.0...HEAD +[Unreleased]: https://github.com/rusterlium/html5ever_elixir/compare/v0.14.1...HEAD +[0.14.1]: https://github.com/rusterlium/html5ever_elixir/compare/v0.14.0...v0.14.1 [0.14.0]: https://github.com/rusterlium/html5ever_elixir/compare/v0.13.1...v0.14.0 [0.13.1]: https://github.com/rusterlium/html5ever_elixir/compare/v0.13.0...v0.13.1 [0.13.0]: https://github.com/rusterlium/html5ever_elixir/compare/v0.12.0...v0.13.0 diff --git a/mix.exs b/mix.exs index 6352d1d..36f6203 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule Html5ever.Mixfile do use Mix.Project - @version "0.14.0" + @version "0.14.1" @repo_url "https://github.com/rusterlium/html5ever_elixir" def project do @@ -24,7 +24,7 @@ defmodule Html5ever.Mixfile do defp deps do [ - {:rustler_precompiled, "~> 0.5.2"}, + {:rustler_precompiled, "~> 0.5.2 or ~> 0.6.0"}, {:rustler, ">= 0.0.0", optional: true}, {:ex_doc, ">= 0.0.0", only: :dev} ] diff --git a/mix.lock b/mix.lock index 3a01914..c4e7499 100644 --- a/mix.lock +++ b/mix.lock @@ -1,13 +1,13 @@ %{ - "castore": {:hex, :castore, "0.1.18", "deb5b9ab02400561b6f5708f3e7660fc35ca2d51bfc6a940d2f513f89c2975fc", [:mix], [], "hexpm", "61bbaf6452b782ef80b33cdb45701afbcf0a918a45ebe7e73f1130d661e66a06"}, - "earmark_parser": {:hex, :earmark_parser, "1.4.26", "f4291134583f373c7d8755566122908eb9662df4c4b63caa66a0eabe06569b0a", [:mix], [], "hexpm", "48d460899f8a0c52c5470676611c01f64f3337bad0b26ddab43648428d94aabc"}, - "ex_doc": {:hex, :ex_doc, "0.28.5", "3e52a6d2130ce74d096859e477b97080c156d0926701c13870a4e1f752363279", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "d2c4b07133113e9aa3e9ba27efb9088ba900e9e51caa383919676afdf09ab181"}, + "castore": {:hex, :castore, "1.0.0", "c25cd0794c054ebe6908a86820c8b92b5695814479ec95eeff35192720b71eec", [:mix], [], "hexpm", "577d0e855983a97ca1dfa33cbb8a3b6ece6767397ffb4861514343b078fc284b"}, + "earmark_parser": {:hex, :earmark_parser, "1.4.31", "a93921cdc6b9b869f519213d5bc79d9e218ba768d7270d46fdcf1c01bacff9e2", [:mix], [], "hexpm", "317d367ee0335ef037a87e46c91a2269fef6306413f731e8ec11fc45a7efd059"}, + "ex_doc": {:hex, :ex_doc, "0.29.4", "6257ecbb20c7396b1fe5accd55b7b0d23f44b6aa18017b415cb4c2b91d997729", [:mix], [{:earmark_parser, "~> 1.4.31", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "2c6699a737ae46cb61e4ed012af931b57b699643b24dabe2400a8168414bc4f5"}, "jason": {:hex, :jason, "1.4.0", "e855647bc964a44e2f67df589ccf49105ae039d4179db7f6271dfd3843dc27e6", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "79a3791085b2a0f743ca04cec0f7be26443738779d09302e01318f97bdb82121"}, "makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"}, "makeup_elixir": {:hex, :makeup_elixir, "0.16.0", "f8c570a0d33f8039513fbccaf7108c5d750f47d8defd44088371191b76492b0b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "28b2cbdc13960a46ae9a8858c4bebdec3c9a6d7b4b9e7f4ed1502f8159f338e7"}, "makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"}, "nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"}, - "rustler": {:hex, :rustler, "0.26.0", "06a2773d453ee3e9109efda643cf2ae633dedea709e2455ac42b83637c9249bf", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:toml, "~> 0.6", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm", "42961e9d2083d004d5a53e111ad1f0c347efd9a05cb2eb2ffa1d037cdc74db91"}, - "rustler_precompiled": {:hex, :rustler_precompiled, "0.5.2", "7619fff0309a012eac7441993da4f6e257022bd456449a366756696a9a18fb19", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: false]}, {:rustler, "~> 0.23", [hex: :rustler, repo: "hexpm", optional: true]}], "hexpm", "4e3716fd7cf6fbb806a9ed2b1449c987cfe578b24e3deb3ca4b8645638cc644c"}, - "toml": {:hex, :toml, "0.6.2", "38f445df384a17e5d382befe30e3489112a48d3ba4c459e543f748c2f25dd4d1", [:mix], [], "hexpm", "d013e45126d74c0c26a38d31f5e8e9b83ea19fc752470feb9a86071ca5a672fa"}, + "rustler": {:hex, :rustler, "0.28.0", "b8e2c43013e12dd06f61dcf87033d2e2c8245feddb121b82179c923be31ad319", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:toml, "~> 0.6", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm", "99f811f58c993f0343851adb0af589a99cfd3dc20f2efb8ef08d1a8447980b98"}, + "rustler_precompiled": {:hex, :rustler_precompiled, "0.6.1", "160b545bce8bf9a3f1b436b2c10f53574036a0db628e40f393328cbbe593602f", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:rustler, "~> 0.23", [hex: :rustler, repo: "hexpm", optional: true]}], "hexpm", "0dd269fa261c4e3df290b12031c575fff07a542749f7b0e8b744d72d66c43600"}, + "toml": {:hex, :toml, "0.7.0", "fbcd773caa937d0c7a02c301a1feea25612720ac3fa1ccb8bfd9d30d822911de", [:mix], [], "hexpm", "0690246a2478c1defd100b0c9b89b4ea280a22be9a7b313a8a058a2408a2fa70"}, } diff --git a/native/html5ever_nif/Cargo.lock b/native/html5ever_nif/Cargo.lock index 96030f7..0499d90 100644 --- a/native/html5ever_nif/Cargo.lock +++ b/native/html5ever_nif/Cargo.lock @@ -4,24 +4,30 @@ version = 3 [[package]] name = "aho-corasick" -version = "0.7.18" +version = "0.7.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" dependencies = [ "memchr", ] [[package]] -name = "cfg-if" -version = "1.0.0" +name = "autocfg" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] -name = "crossbeam" -version = "0.2.12" +name = "cfg-if" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd66663db5a988098a89599d4857919b3acf7f61402e61365acfd3919857b9be" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "futf" @@ -35,31 +41,20 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" -dependencies = [ - "cfg-if", - "libc", - "wasi 0.9.0+wasi-snapshot-preview1", -] - -[[package]] -name = "getrandom" -version = "0.2.6" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ "cfg-if", "libc", - "wasi 0.10.2+wasi-snapshot-preview1", + "wasi", ] [[package]] name = "heck" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "html5ever" @@ -72,7 +67,7 @@ dependencies = [ "markup5ever", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -83,7 +78,6 @@ dependencies = [ "lazy_static", "markup5ever", "rustler", - "scoped-pool", "tendril", ] @@ -95,15 +89,25 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.122" +version = "0.2.140" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" + +[[package]] +name = "lock_api" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec647867e2bf0772e28c8bcde4f0d19a9216916e890543b5a03ed8ef27b8f259" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +dependencies = [ + "autocfg", + "scopeguard", +] [[package]] name = "log" -version = "0.4.14" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", ] @@ -130,9 +134,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "new_debug_unreachable" @@ -141,51 +145,61 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" [[package]] -name = "phf" -version = "0.10.1" +name = "once_cell" +version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ - "phf_shared 0.10.0", + "lock_api", + "parking_lot_core", ] [[package]] -name = "phf_codegen" -version = "0.10.0" +name = "parking_lot_core" +version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" dependencies = [ - "phf_generator 0.10.0", - "phf_shared 0.10.0", + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-sys", ] [[package]] -name = "phf_generator" -version = "0.8.0" +name = "phf" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17367f0cc86f2d25802b2c26ee58a7b23faeccf78a396094c13dced0d0182526" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" dependencies = [ - "phf_shared 0.8.0", - "rand 0.7.3", + "phf_shared", ] [[package]] -name = "phf_generator" +name = "phf_codegen" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" dependencies = [ - "phf_shared 0.10.0", - "rand 0.8.5", + "phf_generator", + "phf_shared", ] [[package]] -name = "phf_shared" -version = "0.8.0" +name = "phf_generator" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c00cf8b9eafe68dde5e9eaa2cef8ee84a9336a47d566ec55ca16589633b65af7" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" dependencies = [ - "siphasher", + "phf_shared", + "rand", ] [[package]] @@ -199,9 +213,9 @@ dependencies = [ [[package]] name = "ppv-lite86" -version = "0.2.10" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "precomputed-hash" @@ -211,36 +225,22 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" [[package]] name = "proc-macro2" -version = "1.0.29" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d" +checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.9" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" -dependencies = [ - "getrandom 0.1.16", - "libc", - "rand_chacha 0.2.2", - "rand_core 0.5.1", - "rand_hc", - "rand_pcg", -] - [[package]] name = "rand" version = "0.8.5" @@ -248,18 +248,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha 0.3.1", - "rand_core 0.6.3", -] - -[[package]] -name = "rand_chacha" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" -dependencies = [ - "ppv-lite86", - "rand_core 0.5.1", + "rand_chacha", + "rand_core", ] [[package]] @@ -269,50 +259,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.3", + "rand_core", ] [[package]] name = "rand_core" -version = "0.5.1" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.1.16", + "getrandom", ] [[package]] -name = "rand_core" -version = "0.6.3" +name = "redox_syscall" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ - "getrandom 0.2.6", -] - -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core 0.5.1", -] - -[[package]] -name = "rand_pcg" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429" -dependencies = [ - "rand_core 0.5.1", + "bitflags", ] [[package]] name = "regex" -version = "1.5.4" +version = "1.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" dependencies = [ "aho-corasick", "memchr", @@ -321,15 +293,15 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.25" +version = "0.6.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "rustler" -version = "0.26.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d61e8ddf75de20513455d7b6f17241a595abbb01b53a6340cecc798a1b13422d" +checksum = "7d7a2f98cb272ae0548e434bb3afde626012084cbebef84542bc7afed868bd6f" dependencies = [ "lazy_static", "rustler_codegen", @@ -338,14 +310,14 @@ dependencies = [ [[package]] name = "rustler_codegen" -version = "0.26.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baa2e45c0165272070f80ce93bcd7dd5407a3c84a1ef73ab9900e00f00ef3d36" +checksum = "2ae37fb154683a1ff13e95dfd16c15043d6aee9853ea650ca34a45bd94e319a5" dependencies = [ "heck", "proc-macro2", "quote", - "syn", + "syn 2.0.15", ] [[package]] @@ -358,69 +330,76 @@ dependencies = [ "unreachable", ] -[[package]] -name = "scoped-pool" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "817a3a15e704545ce59ed2b5c60a5d32bda4d7869befb8b36667b658a6c00b43" -dependencies = [ - "crossbeam", - "scopeguard", - "variance", -] - [[package]] name = "scopeguard" -version = "0.1.2" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a076157c1e2dc561d8de585151ee6965d910dd4dcb5dabb7ae3e83981a6c57" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.130" +version = "1.0.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" +checksum = "3c04e8343c3daeec41f58990b9d77068df31209f2af111e059e9fe9646693065" [[package]] name = "siphasher" -version = "0.3.7" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" + +[[package]] +name = "smallvec" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "533494a8f9b724d33625ab53c6c4800f7cc445895924a8ef649222dcb76e938b" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "string_cache" -version = "0.8.1" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ddb1139b5353f96e429e1a5e19fbaf663bddedaa06d1dbd49f82e352601209a" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" dependencies = [ - "lazy_static", "new_debug_unreachable", - "phf_shared 0.8.0", + "once_cell", + "parking_lot", + "phf_shared", "precomputed-hash", "serde", ] [[package]] name = "string_cache_codegen" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f24c8e5e19d22a726626f1a5e16fe15b132dcf21d10177fa5a45ce7962996b97" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" dependencies = [ - "phf_generator 0.8.0", - "phf_shared 0.8.0", + "phf_generator", + "phf_shared", "proc-macro2", "quote", ] [[package]] name = "syn" -version = "1.0.77" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5239bc68e0fef57495900cfea4e8dc75596d9a319d7e16b1e0a440d24e6fe0a0" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", ] [[package]] @@ -435,10 +414,10 @@ dependencies = [ ] [[package]] -name = "unicode-xid" -version = "0.2.2" +name = "unicode-ident" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" [[package]] name = "unreachable" @@ -455,12 +434,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "variance" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3abfc2be1fb59663871379ea884fd81de80c496f2274e021c01d6fe56cd77b05" - [[package]] name = "void" version = "1.0.2" @@ -469,12 +442,72 @@ checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" [[package]] name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] -name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" diff --git a/native/html5ever_nif/Cargo.toml b/native/html5ever_nif/Cargo.toml index 430d12b..daa988b 100644 --- a/native/html5ever_nif/Cargo.toml +++ b/native/html5ever_nif/Cargo.toml @@ -2,7 +2,7 @@ name = "html5ever_nif" version = "0.1.0" authors = ["HansiHE "] -edition = "2018" +edition = "2021" [lib] name = "html5ever_nif" @@ -10,12 +10,10 @@ path = "src/lib.rs" crate-type = ["cdylib"] [dependencies] -rustler = "0.26.0" +rustler = "0.28.0" html5ever = "0.26" markup5ever = "0.11" tendril = "0.4" lazy_static = "1.4" -scoped-pool = "1.0" - diff --git a/native/html5ever_nif/src/flat_dom.rs b/native/html5ever_nif/src/flat_dom.rs index b1bf031..80d011e 100644 --- a/native/html5ever_nif/src/flat_dom.rs +++ b/native/html5ever_nif/src/flat_dom.rs @@ -1,30 +1,27 @@ -use html5ever::{ QualName, Attribute }; -use html5ever::tree_builder::{ TreeSink, QuirksMode, NodeOrText, ElementFlags }; +use html5ever::tree_builder::{ElementFlags, NodeOrText, QuirksMode, TreeSink}; +use html5ever::{Attribute, QualName}; use markup5ever::ExpandedName; use tendril::StrTendril; use std::borrow::Cow; -use rustler::{ Env, Encoder, Term }; +use rustler::{Encoder, Env, Term}; -use crate::common::{ STW, QNW }; +use crate::common::{QNW, STW}; #[derive(Copy, Clone, PartialEq, Debug)] pub struct NodeHandle(pub usize); pub enum PoolOrVec { - Pool { - head: usize, - len: usize, - }, - Vec { - vec: Vec, - } + Pool { head: usize, len: usize }, + Vec { vec: Vec }, } -impl PoolOrVec where T: Clone { - +impl PoolOrVec +where + T: Clone, +{ pub fn new(pool: &Vec) -> Self { PoolOrVec::Pool { head: pool.len(), @@ -34,24 +31,16 @@ impl PoolOrVec where T: Clone { pub fn get<'a>(&'a self, idx: usize, pool: &'a Vec) -> Option<&'a T> { match self { - PoolOrVec::Pool { head, len } if idx < *len => { - Some(&pool[*head + idx]) - }, - PoolOrVec::Vec { vec } => { - vec.get(idx) - }, + PoolOrVec::Pool { head, len } if idx < *len => Some(&pool[*head + idx]), + PoolOrVec::Vec { vec } => vec.get(idx), _ => None, } } pub fn as_slice<'a>(&'a self, pool: &'a Vec) -> &'a [T] { match self { - PoolOrVec::Pool { head, len } => { - &pool[*head..(*head + *len)] - }, - PoolOrVec::Vec { vec } => { - &*vec - }, + PoolOrVec::Pool { head, len } => &pool[*head..(*head + *len)], + PoolOrVec::Vec { vec } => &*vec, } } @@ -60,21 +49,19 @@ impl PoolOrVec where T: Clone { PoolOrVec::Pool { head, len } if pool.len() == *head + *len => { pool.push(item); *len += 1; - }, + } val @ PoolOrVec::Pool { .. } => { if let PoolOrVec::Pool { head, len } = val { let mut vec = pool[*head..(*head + *len)].to_owned(); vec.push(item); - *val = PoolOrVec::Vec { - vec: vec, - }; + *val = PoolOrVec::Vec { vec }; } else { unreachable!() } - }, + } PoolOrVec::Vec { vec } => { vec.push(item); - }, + } } } @@ -96,10 +83,10 @@ impl PoolOrVec where T: Clone { vec }, }; - }, + } PoolOrVec::Vec { vec } => { vec.insert(index, item); - }, + } } } @@ -113,13 +100,12 @@ impl PoolOrVec where T: Clone { vec }, }; - }, + } PoolOrVec::Vec { vec } => { vec.remove(index); - }, + } } } - } pub struct Node { @@ -134,13 +120,13 @@ impl Node { id: NodeHandle(id), parent: None, children: PoolOrVec::new(pool), - data: data, + data, } } } #[derive(Debug, PartialEq)] -pub enum NodeData{ +pub enum NodeData { Document, DocType { name: StrTendril, @@ -172,7 +158,6 @@ pub struct FlatSink { } impl FlatSink { - pub fn new() -> FlatSink { let mut sink = FlatSink { root: NodeHandle(0), @@ -181,7 +166,8 @@ impl FlatSink { }; // Element 0 is always root - sink.nodes.push(Node::new(0, NodeData::Document, &sink.pool)); + sink.nodes + .push(Node::new(0, NodeData::Document, &sink.pool)); sink } @@ -203,17 +189,12 @@ impl FlatSink { self.nodes.push(node); id } - } fn node_or_text_to_node(sink: &mut FlatSink, not: NodeOrText) -> NodeHandle { match not { NodeOrText::AppendNode(handle) => handle, - NodeOrText::AppendText(text) => { - sink.make_node(NodeData::Text { - contents: text, - }) - }, + NodeOrText::AppendText(text) => sink.make_node(NodeData::Text { contents: text }), } } @@ -229,12 +210,16 @@ impl TreeSink for FlatSink { fn parse_error(&mut self, _msg: Cow<'static, str>) {} fn set_quirks_mode(&mut self, _mode: QuirksMode) {} - fn get_document(&mut self) -> Self::Handle { NodeHandle(0) } + fn get_document(&mut self) -> Self::Handle { + NodeHandle(0) + } fn get_template_contents(&mut self, _target: &Self::Handle) -> Self::Handle { panic!("Templates not supported"); } - fn same_node(&self, x: &Self::Handle, y: &Self::Handle) -> bool { x == y } + fn same_node(&self, x: &Self::Handle, y: &Self::Handle) -> bool { + x == y + } fn elem_name(&self, target: &Self::Handle) -> ExpandedName { let node = self.node(*target); match node.data { @@ -243,7 +228,12 @@ impl TreeSink for FlatSink { } } - fn create_element(&mut self, name: QualName, attrs: Vec, flags: ElementFlags) -> Self::Handle { + fn create_element( + &mut self, + name: QualName, + attrs: Vec, + flags: ElementFlags, + ) -> Self::Handle { let template_contents = if flags.template { Some(self.make_node(NodeData::Document)) } else { @@ -251,30 +241,32 @@ impl TreeSink for FlatSink { }; self.make_node(NodeData::Element { - name: name, - attrs: attrs, + name, + attrs, mathml_annotation_xml_integration_point: flags.mathml_annotation_xml_integration_point, - template_contents: template_contents, + template_contents, }) } fn create_comment(&mut self, text: StrTendril) -> Self::Handle { - self.make_node(NodeData::Comment { - contents: text, - }) + self.make_node(NodeData::Comment { contents: text }) } fn append(&mut self, parent_id: &Self::Handle, child: NodeOrText) { let handle = node_or_text_to_node(self, child); - self.nodes[parent_id.0].children.push(handle, &mut self.pool); + self.nodes[parent_id.0] + .children + .push(handle, &mut self.pool); self.node_mut(handle).parent = Some(*parent_id); } - fn append_based_on_parent_node(&mut self, - element: &Self::Handle, - prev_element: &Self::Handle, - child: NodeOrText) { + fn append_based_on_parent_node( + &mut self, + element: &Self::Handle, + prev_element: &Self::Handle, + child: NodeOrText, + ) { let has_parent = self.node(*element).parent.is_some(); if has_parent { self.append_before_sibling(element, child); @@ -283,28 +275,48 @@ impl TreeSink for FlatSink { } } - fn append_before_sibling(&mut self, sibling: &Self::Handle, new_node: NodeOrText) { + fn append_before_sibling( + &mut self, + sibling: &Self::Handle, + new_node: NodeOrText, + ) { let new_node_handle = node_or_text_to_node(self, new_node); let parent = self.node(*sibling).parent.unwrap(); let parent_node = &mut self.nodes[parent.0]; - let sibling_index = parent_node.children.iter(&self.pool).enumerate() - .find(|&(_, node)| node == sibling).unwrap().0; - parent_node.children.insert(sibling_index, new_node_handle, &mut self.pool); - } - - fn append_doctype_to_document(&mut self, name: StrTendril, public_id: StrTendril, system_id: StrTendril) { + let sibling_index = parent_node + .children + .iter(&self.pool) + .enumerate() + .find(|&(_, node)| node == sibling) + .unwrap() + .0; + parent_node + .children + .insert(sibling_index, new_node_handle, &mut self.pool); + } + + fn append_doctype_to_document( + &mut self, + name: StrTendril, + public_id: StrTendril, + system_id: StrTendril, + ) { let doctype = self.make_node(NodeData::DocType { - name: name, - public_id: public_id, - system_id: system_id, + name, + public_id, + system_id, }); let root = self.root; self.nodes[root.0].children.push(doctype, &mut self.pool); self.node_mut(doctype).parent = Some(self.root); } - fn add_attrs_if_missing(&mut self, target_handle: &Self::Handle, mut add_attrs: Vec) { + fn add_attrs_if_missing( + &mut self, + target_handle: &Self::Handle, + mut add_attrs: Vec, + ) { let target = self.node_mut(*target_handle); match target.data { NodeData::Element { ref mut attrs, .. } => { @@ -321,8 +333,13 @@ impl TreeSink for FlatSink { fn remove_from_parent(&mut self, target: &Self::Handle) { let parent = self.node(*target).parent.unwrap(); let parent_node = &mut self.nodes[parent.0]; - let sibling_index = parent_node.children.iter(&self.pool).enumerate() - .find(|&(_, node)| node == target).unwrap().0; + let sibling_index = parent_node + .children + .iter(&self.pool) + .enumerate() + .find(|&(_, node)| node == target) + .unwrap() + .0; parent_node.children.remove(sibling_index, &mut self.pool); } @@ -347,11 +364,10 @@ impl TreeSink for FlatSink { fn create_pi(&mut self, target: StrTendril, data: StrTendril) -> Self::Handle { self.make_node(NodeData::ProcessingInstruction { - target: target, + target, contents: data, }) } - } impl Encoder for NodeHandle { @@ -362,40 +378,90 @@ impl Encoder for NodeHandle { fn encode_node<'a>(node: &Node, env: Env<'a>, pool: &Vec) -> Term<'a> { let map = ::rustler::types::map::map_new(env) - .map_put(self::atoms::id().encode(env), node.id.encode(env)).ok().unwrap() - .map_put(self::atoms::parent().encode(env), match node.parent { - Some(handle) => handle.encode(env), - None => self::atoms::nil().encode(env), - }).ok().unwrap(); + .map_put(self::atoms::id().encode(env), node.id.encode(env)) + .ok() + .unwrap() + .map_put( + self::atoms::parent().encode(env), + match node.parent { + Some(handle) => handle.encode(env), + None => self::atoms::nil().encode(env), + }, + ) + .ok() + .unwrap(); match node.data { - NodeData::Document => { - map - .map_put(self::atoms::type_().encode(env), self::atoms::document().encode(env)).ok().unwrap() - } - NodeData::Element { ref attrs, ref name, .. } => { - map - .map_put(self::atoms::type_().encode(env), self::atoms::element().encode(env)).ok().unwrap() - .map_put(self::atoms::children().encode(env), node.children.as_slice(pool).encode(env)).ok().unwrap() - .map_put(self::atoms::name().encode(env), QNW(name).encode(env)).ok().unwrap() - .map_put(self::atoms::attrs().encode(env), attrs.iter().map(|attr| { - (QNW(&attr.name), STW(&attr.value)) - }).collect::>().encode(env)).ok().unwrap() - } - NodeData::Text { ref contents } => { - map - .map_put(self::atoms::type_().encode(env), self::atoms::text().encode(env)).ok().unwrap() - .map_put(self::atoms::contents().encode(env), STW(contents).encode(env)).ok().unwrap() - } - NodeData::DocType { .. } => { - map - .map_put(self::atoms::type_().encode(env), self::atoms::doctype().encode(env)).ok().unwrap() - } - NodeData::Comment { ref contents } => { - map - .map_put(self::atoms::type_().encode(env), self::atoms::comment().encode(env)).ok().unwrap() - .map_put(self::atoms::contents().encode(env), STW(contents).encode(env)).ok().unwrap() - } + NodeData::Document => map + .map_put( + self::atoms::type_().encode(env), + self::atoms::document().encode(env), + ) + .ok() + .unwrap(), + NodeData::Element { + ref attrs, + ref name, + .. + } => map + .map_put( + self::atoms::type_().encode(env), + self::atoms::element().encode(env), + ) + .ok() + .unwrap() + .map_put( + self::atoms::children().encode(env), + node.children.as_slice(pool).encode(env), + ) + .ok() + .unwrap() + .map_put(self::atoms::name().encode(env), QNW(name).encode(env)) + .ok() + .unwrap() + .map_put( + self::atoms::attrs().encode(env), + attrs + .iter() + .map(|attr| (QNW(&attr.name), STW(&attr.value))) + .collect::>() + .encode(env), + ) + .ok() + .unwrap(), + NodeData::Text { ref contents } => map + .map_put( + self::atoms::type_().encode(env), + self::atoms::text().encode(env), + ) + .ok() + .unwrap() + .map_put( + self::atoms::contents().encode(env), + STW(contents).encode(env), + ) + .ok() + .unwrap(), + NodeData::DocType { .. } => map + .map_put( + self::atoms::type_().encode(env), + self::atoms::doctype().encode(env), + ) + .ok() + .unwrap(), + NodeData::Comment { ref contents } => map + .map_put( + self::atoms::type_().encode(env), + self::atoms::comment().encode(env), + ) + .ok() + .unwrap() + .map_put( + self::atoms::contents().encode(env), + STW(contents).encode(env), + ) + .ok() + .unwrap(), _ => unimplemented!(), } } @@ -423,14 +489,22 @@ mod atoms { } pub fn flat_sink_to_flat_term<'a>(env: Env<'a>, sink: &FlatSink) -> Term<'a> { - let nodes = sink.nodes.iter() + let nodes = sink + .nodes + .iter() .fold(rustler::types::map::map_new(env), |acc, node| { - acc.map_put(node.id.encode(env), encode_node(node, env, &sink.pool)).ok().unwrap() + acc.map_put(node.id.encode(env), encode_node(node, env, &sink.pool)) + .ok() + .unwrap() }); ::rustler::types::map::map_new(env) - .map_put(self::atoms::nodes().encode(env), nodes).ok().unwrap() - .map_put(self::atoms::root().encode(env), sink.root.encode(env)).ok().unwrap() + .map_put(self::atoms::nodes().encode(env), nodes) + .ok() + .unwrap() + .map_put(self::atoms::root().encode(env), sink.root.encode(env)) + .ok() + .unwrap() } struct RecState { @@ -442,13 +516,11 @@ struct RecState { pub fn flat_sink_to_rec_term<'a>(env: Env<'a>, sink: &FlatSink) -> Term<'a> { let mut child_stack = vec![]; - let mut stack: Vec = vec![ - RecState { - node: sink.root(), - child_base: 0, - child_n: 0, - }, - ]; + let mut stack: Vec = vec![RecState { + node: sink.root(), + child_base: 0, + child_n: 0, + }]; loop { let mut top = stack.pop().unwrap(); @@ -483,8 +555,12 @@ pub fn flat_sink_to_rec_term<'a>(env: Env<'a>, sink: &FlatSink) -> Term<'a> { assert_eq!(stack.len(), 0); return term; - }, - NodeData::DocType { name, public_id, system_id } => { + } + NodeData::DocType { + name, + public_id, + system_id, + } => { assert!(stack.len() > 0); assert!(child_stack.len() == 0); @@ -493,22 +569,24 @@ pub fn flat_sink_to_rec_term<'a>(env: Env<'a>, sink: &FlatSink) -> Term<'a> { STW(name), STW(public_id), STW(system_id), - ).encode(env); - }, + ) + .encode(env); + } NodeData::Element { attrs, name, .. } => { assert!(stack.len() > 0); - let attribute_terms: Vec> = attrs.iter() + let attribute_terms: Vec> = attrs + .iter() .map(|a| (QNW(&a.name), STW(&a.value)).encode(env)) .collect(); term = (QNW(name), attribute_terms, &child_stack[top.child_base..]).encode(env); for _ in 0..(child_stack.len() - top.child_base) { child_stack.pop(); } - }, + } NodeData::Text { contents } => { term = STW(contents).encode(env); - }, + } NodeData::Comment { .. } => continue, _ => unimplemented!(""), } @@ -517,12 +595,3 @@ pub fn flat_sink_to_rec_term<'a>(env: Env<'a>, sink: &FlatSink) -> Term<'a> { } } } - - - - - - - - -