kstring-1.0.0/.clog.toml010064400007650000024000000001661370113146400133120ustar0000000000000000[clog] repository = "https://github.com/cobalt-org/liquid-rust" changelog = "CHANGELOG.md" from-latest-tag = true kstring-1.0.0/.gitattributes010064400007650000024000000000451370113150700143000ustar0000000000000000*.txt text eol=lf *.rs text eol=lf kstring-1.0.0/.github/ISSUE_TEMPLATE.md010064400007650000024000000000521370113150700154500ustar0000000000000000liquid-rust version: rust version: OS: kstring-1.0.0/.github/PULL_REQUEST_TEMPLATE.md010064400007650000024000000001131370113150700165420ustar0000000000000000- [ ] Tests created for any new feature or regression tests for bugfixes. kstring-1.0.0/.gitignore010064400007650000024000000001661370113150700134010ustar0000000000000000# Compiled files *.o *.so *.rlib *.dll # Executables *.exe # Generated by Cargo /target/ Cargo.lock liquid *.rs.bk kstring-1.0.0/.rustfmt.toml010064400007650000024000000000011370113150700140540ustar0000000000000000 kstring-1.0.0/azure-pipelines.yml010064400007650000024000000075201370113517700152600ustar0000000000000000schedules: - cron: "12 12 12 * *" displayName: Monthly Build branches: include: - master variables: minrust: 1.37.0 codecov_token: $(CODECOV_TOKEN_SECRET) windows_vm: vs2017-win2016 mac_vm: macos-10.14 linux_vm: ubuntu-16.04 stages: - stage: check displayName: Compilation Check jobs: - job: cargo_check displayName: cargo check pool: vmImage: ${{ variables.linux_vm }} steps: - template: install-rust.yml@templates parameters: rust: stable - script: cargo check --all --bins --examples --tests displayName: Default features - stage: test displayName: Test jobs: - job: test displayName: Test strategy: matrix: windows: imageName: ${{ variables.windows_vm }} target: 'x86_64-pc-windows-msvc' channel: stable mac: imageName: ${{ variables.mac_vm }} target: 'x86_64-apple-darwin' channel: stable linux: imageName: ${{ variables.linux_vm }} target: 'x86_64-unknown-linux-gnu' channel: stable linux_beta: imageName: ${{ variables.linux_vm }} target: 'x86_64-unknown-linux-gnu' channel: beta linux_nightly: imageName: ${{ variables.linux_vm }} target: 'x86_64-unknown-linux-gnu' channel: nightly continueOnError: ${{ eq(variables.channel, 'nightly') }} pool: vmImage: $(imageName) steps: - template: install-rust.yml@templates parameters: rust: $(channel) targets: ["$(TARGET)"] - script: cargo test --target $(TARGET) --all displayName: cargo test - script: cargo doc --target $(TARGET) --no-deps --all displayName: cargo doc - job: msrv displayName: "${{ format('Minimum supported Rust version: {0}', variables.minrust) }}" dependsOn: [] pool: vmImage: ${{ variables.linux_vm }} steps: - template: install-rust.yml@templates parameters: rust: ${{ variables.minrust }} - script: cargo check --all displayName: cargo check - stage: style displayName: Style checks dependsOn: [] jobs: - job: "Committed" pool: vmImage: ${{ variables.linux_vm }} steps: - checkout: self - template: v1/azdo-step.yml@gh-install parameters: git: crate-ci/committed target: 'x86_64-unknown-linux-gnu' to: $(Build.StagingDirectory)/tools - script: | echo "This project uses Conventional style, see https://www.conventionalcommits.org" $(Build.StagingDirectory)/tools/committed HEAD~..HEAD^2 --no-merge-commit -vv displayName: Committed condition: and(succeeded(), eq(variables['Build.Reason'], 'PullRequest')) - job: style displayName: Style linting strategy: matrix: current: channel: stable next: channel: beta continueOnError: ${{ eq(variables.channel, 'beta') }} pool: vmImage: ${{ variables.linux_vm }} steps: - template: install-rust.yml@templates parameters: rust: $(channel) components: - rustfmt - clippy - script: cargo fmt --all -- --check displayName: rustfmt - script: cargo check --all displayName: Warnings env: RUSTFLAGS: "-D warnings" - script: cargo clippy --all -- -D warnings displayName: clippy - ${{ if ne('', variables.codecov_token) }}: - stage: coverage displayName: Code coverage dependsOn: test jobs: - template: coverage.yml@templates parameters: token: ${{ variables.codecov_token }} resources: repositories: - repository: templates type: github name: crate-ci/azure-pipelines endpoint: crate-ci - repository: gh-install type: github name: crate-ci/gh-install endpoint: crate-ci kstring-1.0.0/benches/cow.rs010064400007650000024000000156111370113146300141600ustar0000000000000000#![feature(test)] extern crate test; mod macros; type StringCow<'s> = std::borrow::Cow<'s, str>; mod cow { use super::*; bench_clone_static!(bench_clone_static_00, 0, |fixture| StringCow::from(fixture)); bench_clone_static!(bench_clone_static_01, 1, |fixture| StringCow::from(fixture)); bench_clone_static!(bench_clone_static_02, 2, |fixture| StringCow::from(fixture)); bench_clone_static!(bench_clone_static_03, 3, |fixture| StringCow::from(fixture)); bench_clone_static!(bench_clone_static_04, 4, |fixture| StringCow::from(fixture)); bench_clone_static!(bench_clone_static_05, 5, |fixture| StringCow::from(fixture)); bench_clone_static!(bench_clone_static_06, 6, |fixture| StringCow::from(fixture)); bench_clone_static!(bench_clone_static_07, 7, |fixture| StringCow::from(fixture)); bench_clone_static!(bench_clone_static_08, 8, |fixture| StringCow::from(fixture)); bench_clone_static!(bench_clone_static_09, 9, |fixture| StringCow::from(fixture)); bench_clone_static!(bench_clone_static_10, 10, |fixture| StringCow::from( fixture )); bench_clone_static!(bench_clone_static_11, 11, |fixture| StringCow::from( fixture )); bench_clone_static!(bench_clone_static_12, 12, |fixture| StringCow::from( fixture )); bench_clone_static!(bench_clone_static_13, 13, |fixture| StringCow::from( fixture )); bench_clone_ref!(bench_clone_ref_00, 0, |fixture| StringCow::from(fixture)); bench_clone_ref!(bench_clone_ref_01, 1, |fixture| StringCow::from(fixture)); bench_clone_ref!(bench_clone_ref_02, 2, |fixture| StringCow::from(fixture)); bench_clone_ref!(bench_clone_ref_03, 3, |fixture| StringCow::from(fixture)); bench_clone_ref!(bench_clone_ref_04, 4, |fixture| StringCow::from(fixture)); bench_clone_ref!(bench_clone_ref_05, 5, |fixture| StringCow::from(fixture)); bench_clone_ref!(bench_clone_ref_06, 6, |fixture| StringCow::from(fixture)); bench_clone_ref!(bench_clone_ref_07, 7, |fixture| StringCow::from(fixture)); bench_clone_ref!(bench_clone_ref_08, 8, |fixture| StringCow::from(fixture)); bench_clone_ref!(bench_clone_ref_09, 9, |fixture| StringCow::from(fixture)); bench_clone_ref!(bench_clone_ref_10, 10, |fixture| StringCow::from(fixture)); bench_clone_ref!(bench_clone_ref_11, 11, |fixture| StringCow::from(fixture)); bench_clone_ref!(bench_clone_ref_12, 12, |fixture| StringCow::from(fixture)); bench_clone_ref!(bench_clone_ref_13, 13, |fixture| StringCow::from(fixture)); bench_clone_owned!(bench_clone_owned_00, 0, |fixture| StringCow::from(fixture)); bench_clone_owned!(bench_clone_owned_01, 1, |fixture| StringCow::from(fixture)); bench_clone_owned!(bench_clone_owned_02, 2, |fixture| StringCow::from(fixture)); bench_clone_owned!(bench_clone_owned_03, 3, |fixture| StringCow::from(fixture)); bench_clone_owned!(bench_clone_owned_04, 4, |fixture| StringCow::from(fixture)); bench_clone_owned!(bench_clone_owned_05, 5, |fixture| StringCow::from(fixture)); bench_clone_owned!(bench_clone_owned_06, 6, |fixture| StringCow::from(fixture)); bench_clone_owned!(bench_clone_owned_07, 7, |fixture| StringCow::from(fixture)); bench_clone_owned!(bench_clone_owned_08, 8, |fixture| StringCow::from(fixture)); bench_clone_owned!(bench_clone_owned_09, 9, |fixture| StringCow::from(fixture)); bench_clone_owned!(bench_clone_owned_10, 10, |fixture| StringCow::from(fixture)); bench_clone_owned!(bench_clone_owned_11, 11, |fixture| StringCow::from(fixture)); bench_clone_owned!(bench_clone_owned_12, 12, |fixture| StringCow::from(fixture)); bench_clone_owned!(bench_clone_owned_13, 13, |fixture| StringCow::from(fixture)); bench_eq_static!(bench_eq_static_00, 0, |fixture| StringCow::from(fixture)); bench_eq_static!(bench_eq_static_01, 1, |fixture| StringCow::from(fixture)); bench_eq_static!(bench_eq_static_02, 2, |fixture| StringCow::from(fixture)); bench_eq_static!(bench_eq_static_03, 3, |fixture| StringCow::from(fixture)); bench_eq_static!(bench_eq_static_04, 4, |fixture| StringCow::from(fixture)); bench_eq_static!(bench_eq_static_05, 5, |fixture| StringCow::from(fixture)); bench_eq_static!(bench_eq_static_06, 6, |fixture| StringCow::from(fixture)); bench_eq_static!(bench_eq_static_07, 7, |fixture| StringCow::from(fixture)); bench_eq_static!(bench_eq_static_08, 8, |fixture| StringCow::from(fixture)); bench_eq_static!(bench_eq_static_09, 9, |fixture| StringCow::from(fixture)); bench_eq_static!(bench_eq_static_10, 10, |fixture| StringCow::from(fixture)); bench_eq_static!(bench_eq_static_11, 11, |fixture| StringCow::from(fixture)); bench_eq_static!(bench_eq_static_12, 12, |fixture| StringCow::from(fixture)); bench_eq_static!(bench_eq_static_13, 13, |fixture| StringCow::from(fixture)); bench_eq_ref!(bench_eq_ref_00, 0, |fixture| StringCow::from(fixture)); bench_eq_ref!(bench_eq_ref_01, 1, |fixture| StringCow::from(fixture)); bench_eq_ref!(bench_eq_ref_02, 2, |fixture| StringCow::from(fixture)); bench_eq_ref!(bench_eq_ref_03, 3, |fixture| StringCow::from(fixture)); bench_eq_ref!(bench_eq_ref_04, 4, |fixture| StringCow::from(fixture)); bench_eq_ref!(bench_eq_ref_05, 5, |fixture| StringCow::from(fixture)); bench_eq_ref!(bench_eq_ref_06, 6, |fixture| StringCow::from(fixture)); bench_eq_ref!(bench_eq_ref_07, 7, |fixture| StringCow::from(fixture)); bench_eq_ref!(bench_eq_ref_08, 8, |fixture| StringCow::from(fixture)); bench_eq_ref!(bench_eq_ref_09, 9, |fixture| StringCow::from(fixture)); bench_eq_ref!(bench_eq_ref_10, 10, |fixture| StringCow::from(fixture)); bench_eq_ref!(bench_eq_ref_11, 11, |fixture| StringCow::from(fixture)); bench_eq_ref!(bench_eq_ref_12, 12, |fixture| StringCow::from(fixture)); bench_eq_ref!(bench_eq_ref_13, 13, |fixture| StringCow::from(fixture)); bench_eq_owned!(bench_eq_owned_00, 0, |fixture| StringCow::from(fixture)); bench_eq_owned!(bench_eq_owned_01, 1, |fixture| StringCow::from(fixture)); bench_eq_owned!(bench_eq_owned_02, 2, |fixture| StringCow::from(fixture)); bench_eq_owned!(bench_eq_owned_03, 3, |fixture| StringCow::from(fixture)); bench_eq_owned!(bench_eq_owned_04, 4, |fixture| StringCow::from(fixture)); bench_eq_owned!(bench_eq_owned_05, 5, |fixture| StringCow::from(fixture)); bench_eq_owned!(bench_eq_owned_06, 6, |fixture| StringCow::from(fixture)); bench_eq_owned!(bench_eq_owned_07, 7, |fixture| StringCow::from(fixture)); bench_eq_owned!(bench_eq_owned_08, 8, |fixture| StringCow::from(fixture)); bench_eq_owned!(bench_eq_owned_09, 9, |fixture| StringCow::from(fixture)); bench_eq_owned!(bench_eq_owned_10, 10, |fixture| StringCow::from(fixture)); bench_eq_owned!(bench_eq_owned_11, 11, |fixture| StringCow::from(fixture)); bench_eq_owned!(bench_eq_owned_12, 12, |fixture| StringCow::from(fixture)); bench_eq_owned!(bench_eq_owned_13, 13, |fixture| StringCow::from(fixture)); } kstring-1.0.0/benches/kstring.rs010064400007650000024000000176341370113146300150600ustar0000000000000000#![feature(test)] extern crate test; use kstring::KString; mod macros; mod kstring_ { use super::*; bench_clone_static!(bench_clone_static_00, 0, |fixture| KString::from_static( fixture )); bench_clone_static!(bench_clone_static_01, 1, |fixture| KString::from_static( fixture )); bench_clone_static!(bench_clone_static_02, 2, |fixture| KString::from_static( fixture )); bench_clone_static!(bench_clone_static_03, 3, |fixture| KString::from_static( fixture )); bench_clone_static!(bench_clone_static_04, 4, |fixture| KString::from_static( fixture )); bench_clone_static!(bench_clone_static_05, 5, |fixture| KString::from_static( fixture )); bench_clone_static!(bench_clone_static_06, 6, |fixture| KString::from_static( fixture )); bench_clone_static!(bench_clone_static_07, 7, |fixture| KString::from_static( fixture )); bench_clone_static!(bench_clone_static_08, 8, |fixture| KString::from_static( fixture )); bench_clone_static!(bench_clone_static_09, 9, |fixture| KString::from_static( fixture )); bench_clone_static!(bench_clone_static_10, 10, |fixture| KString::from_static( fixture )); bench_clone_static!(bench_clone_static_11, 11, |fixture| KString::from_static( fixture )); bench_clone_static!(bench_clone_static_12, 12, |fixture| KString::from_static( fixture )); bench_clone_static!(bench_clone_static_13, 13, |fixture| KString::from_static( fixture )); bench_clone_ref!(bench_clone_ref_00, 0, |fixture| KString::from_ref(fixture)); bench_clone_ref!(bench_clone_ref_01, 1, |fixture| KString::from_ref(fixture)); bench_clone_ref!(bench_clone_ref_02, 2, |fixture| KString::from_ref(fixture)); bench_clone_ref!(bench_clone_ref_03, 3, |fixture| KString::from_ref(fixture)); bench_clone_ref!(bench_clone_ref_04, 4, |fixture| KString::from_ref(fixture)); bench_clone_ref!(bench_clone_ref_05, 5, |fixture| KString::from_ref(fixture)); bench_clone_ref!(bench_clone_ref_06, 6, |fixture| KString::from_ref(fixture)); bench_clone_ref!(bench_clone_ref_07, 7, |fixture| KString::from_ref(fixture)); bench_clone_ref!(bench_clone_ref_08, 8, |fixture| KString::from_ref(fixture)); bench_clone_ref!(bench_clone_ref_09, 9, |fixture| KString::from_ref(fixture)); bench_clone_ref!(bench_clone_ref_10, 10, |fixture| KString::from_ref(fixture)); bench_clone_ref!(bench_clone_ref_11, 11, |fixture| KString::from_ref(fixture)); bench_clone_ref!(bench_clone_ref_12, 12, |fixture| KString::from_ref(fixture)); bench_clone_ref!(bench_clone_ref_13, 13, |fixture| KString::from_ref(fixture)); bench_clone_owned!(bench_clone_owned_00, 0, |fixture| KString::from_string( fixture )); bench_clone_owned!(bench_clone_owned_01, 1, |fixture| KString::from_string( fixture )); bench_clone_owned!(bench_clone_owned_02, 2, |fixture| KString::from_string( fixture )); bench_clone_owned!(bench_clone_owned_03, 3, |fixture| KString::from_string( fixture )); bench_clone_owned!(bench_clone_owned_04, 4, |fixture| KString::from_string( fixture )); bench_clone_owned!(bench_clone_owned_05, 5, |fixture| KString::from_string( fixture )); bench_clone_owned!(bench_clone_owned_06, 6, |fixture| KString::from_string( fixture )); bench_clone_owned!(bench_clone_owned_07, 7, |fixture| KString::from_string( fixture )); bench_clone_owned!(bench_clone_owned_08, 8, |fixture| KString::from_string( fixture )); bench_clone_owned!(bench_clone_owned_09, 9, |fixture| KString::from_string( fixture )); bench_clone_owned!(bench_clone_owned_10, 10, |fixture| KString::from_string( fixture )); bench_clone_owned!(bench_clone_owned_11, 11, |fixture| KString::from_string( fixture )); bench_clone_owned!(bench_clone_owned_12, 12, |fixture| KString::from_string( fixture )); bench_clone_owned!(bench_clone_owned_13, 13, |fixture| KString::from_string( fixture )); bench_eq_static!(bench_eq_static_00, 0, |fixture| KString::from_static( fixture )); bench_eq_static!(bench_eq_static_01, 1, |fixture| KString::from_static( fixture )); bench_eq_static!(bench_eq_static_02, 2, |fixture| KString::from_static( fixture )); bench_eq_static!(bench_eq_static_03, 3, |fixture| KString::from_static( fixture )); bench_eq_static!(bench_eq_static_04, 4, |fixture| KString::from_static( fixture )); bench_eq_static!(bench_eq_static_05, 5, |fixture| KString::from_static( fixture )); bench_eq_static!(bench_eq_static_06, 6, |fixture| KString::from_static( fixture )); bench_eq_static!(bench_eq_static_07, 7, |fixture| KString::from_static( fixture )); bench_eq_static!(bench_eq_static_08, 8, |fixture| KString::from_static( fixture )); bench_eq_static!(bench_eq_static_09, 9, |fixture| KString::from_static( fixture )); bench_eq_static!(bench_eq_static_10, 10, |fixture| KString::from_static( fixture )); bench_eq_static!(bench_eq_static_11, 11, |fixture| KString::from_static( fixture )); bench_eq_static!(bench_eq_static_12, 12, |fixture| KString::from_static( fixture )); bench_eq_static!(bench_eq_static_13, 13, |fixture| KString::from_static( fixture )); bench_eq_ref!(bench_eq_ref_00, 0, |fixture| KString::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_01, 1, |fixture| KString::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_02, 2, |fixture| KString::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_03, 3, |fixture| KString::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_04, 4, |fixture| KString::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_05, 5, |fixture| KString::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_06, 6, |fixture| KString::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_07, 7, |fixture| KString::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_08, 8, |fixture| KString::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_09, 9, |fixture| KString::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_10, 10, |fixture| KString::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_11, 11, |fixture| KString::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_12, 12, |fixture| KString::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_13, 13, |fixture| KString::from_ref(fixture)); bench_eq_owned!(bench_eq_owned_00, 0, |fixture| KString::from_string( fixture )); bench_eq_owned!(bench_eq_owned_01, 1, |fixture| KString::from_string( fixture )); bench_eq_owned!(bench_eq_owned_02, 2, |fixture| KString::from_string( fixture )); bench_eq_owned!(bench_eq_owned_03, 3, |fixture| KString::from_string( fixture )); bench_eq_owned!(bench_eq_owned_04, 4, |fixture| KString::from_string( fixture )); bench_eq_owned!(bench_eq_owned_05, 5, |fixture| KString::from_string( fixture )); bench_eq_owned!(bench_eq_owned_06, 6, |fixture| KString::from_string( fixture )); bench_eq_owned!(bench_eq_owned_07, 7, |fixture| KString::from_string( fixture )); bench_eq_owned!(bench_eq_owned_08, 8, |fixture| KString::from_string( fixture )); bench_eq_owned!(bench_eq_owned_09, 9, |fixture| KString::from_string( fixture )); bench_eq_owned!(bench_eq_owned_10, 10, |fixture| KString::from_string( fixture )); bench_eq_owned!(bench_eq_owned_11, 11, |fixture| KString::from_string( fixture )); bench_eq_owned!(bench_eq_owned_12, 12, |fixture| KString::from_string( fixture )); bench_eq_owned!(bench_eq_owned_13, 13, |fixture| KString::from_string( fixture )); } kstring-1.0.0/benches/kstringcow.rs010064400007650000024000000206411370113146300155610ustar0000000000000000#![feature(test)] extern crate test; use kstring::KStringCow; mod macros; mod kstringcow { use super::*; bench_clone_static!(bench_clone_static_00, 0, |fixture| KStringCow::from_static( fixture )); bench_clone_static!(bench_clone_static_01, 1, |fixture| KStringCow::from_static( fixture )); bench_clone_static!(bench_clone_static_02, 2, |fixture| KStringCow::from_static( fixture )); bench_clone_static!(bench_clone_static_03, 3, |fixture| KStringCow::from_static( fixture )); bench_clone_static!(bench_clone_static_04, 4, |fixture| KStringCow::from_static( fixture )); bench_clone_static!(bench_clone_static_05, 5, |fixture| KStringCow::from_static( fixture )); bench_clone_static!(bench_clone_static_06, 6, |fixture| KStringCow::from_static( fixture )); bench_clone_static!(bench_clone_static_07, 7, |fixture| KStringCow::from_static( fixture )); bench_clone_static!(bench_clone_static_08, 8, |fixture| KStringCow::from_static( fixture )); bench_clone_static!(bench_clone_static_09, 9, |fixture| KStringCow::from_static( fixture )); bench_clone_static!( bench_clone_static_10, 10, |fixture| KStringCow::from_static(fixture) ); bench_clone_static!( bench_clone_static_11, 11, |fixture| KStringCow::from_static(fixture) ); bench_clone_static!( bench_clone_static_12, 12, |fixture| KStringCow::from_static(fixture) ); bench_clone_static!( bench_clone_static_13, 13, |fixture| KStringCow::from_static(fixture) ); bench_clone_ref!(bench_clone_ref_00, 0, |fixture| KStringCow::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_01, 1, |fixture| KStringCow::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_02, 2, |fixture| KStringCow::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_03, 3, |fixture| KStringCow::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_04, 4, |fixture| KStringCow::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_05, 5, |fixture| KStringCow::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_06, 6, |fixture| KStringCow::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_07, 7, |fixture| KStringCow::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_08, 8, |fixture| KStringCow::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_09, 9, |fixture| KStringCow::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_10, 10, |fixture| KStringCow::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_11, 11, |fixture| KStringCow::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_12, 12, |fixture| KStringCow::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_13, 13, |fixture| KStringCow::from_ref( fixture )); bench_clone_owned!(bench_clone_owned_00, 0, |fixture| KStringCow::from_string( fixture )); bench_clone_owned!(bench_clone_owned_01, 1, |fixture| KStringCow::from_string( fixture )); bench_clone_owned!(bench_clone_owned_02, 2, |fixture| KStringCow::from_string( fixture )); bench_clone_owned!(bench_clone_owned_03, 3, |fixture| KStringCow::from_string( fixture )); bench_clone_owned!(bench_clone_owned_04, 4, |fixture| KStringCow::from_string( fixture )); bench_clone_owned!(bench_clone_owned_05, 5, |fixture| KStringCow::from_string( fixture )); bench_clone_owned!(bench_clone_owned_06, 6, |fixture| KStringCow::from_string( fixture )); bench_clone_owned!(bench_clone_owned_07, 7, |fixture| KStringCow::from_string( fixture )); bench_clone_owned!(bench_clone_owned_08, 8, |fixture| KStringCow::from_string( fixture )); bench_clone_owned!(bench_clone_owned_09, 9, |fixture| KStringCow::from_string( fixture )); bench_clone_owned!(bench_clone_owned_10, 10, |fixture| KStringCow::from_string( fixture )); bench_clone_owned!(bench_clone_owned_11, 11, |fixture| KStringCow::from_string( fixture )); bench_clone_owned!(bench_clone_owned_12, 12, |fixture| KStringCow::from_string( fixture )); bench_clone_owned!(bench_clone_owned_13, 13, |fixture| KStringCow::from_string( fixture )); bench_eq_static!(bench_eq_static_00, 0, |fixture| KStringCow::from_static( fixture )); bench_eq_static!(bench_eq_static_01, 1, |fixture| KStringCow::from_static( fixture )); bench_eq_static!(bench_eq_static_02, 2, |fixture| KStringCow::from_static( fixture )); bench_eq_static!(bench_eq_static_03, 3, |fixture| KStringCow::from_static( fixture )); bench_eq_static!(bench_eq_static_04, 4, |fixture| KStringCow::from_static( fixture )); bench_eq_static!(bench_eq_static_05, 5, |fixture| KStringCow::from_static( fixture )); bench_eq_static!(bench_eq_static_06, 6, |fixture| KStringCow::from_static( fixture )); bench_eq_static!(bench_eq_static_07, 7, |fixture| KStringCow::from_static( fixture )); bench_eq_static!(bench_eq_static_08, 8, |fixture| KStringCow::from_static( fixture )); bench_eq_static!(bench_eq_static_09, 9, |fixture| KStringCow::from_static( fixture )); bench_eq_static!(bench_eq_static_10, 10, |fixture| KStringCow::from_static( fixture )); bench_eq_static!(bench_eq_static_11, 11, |fixture| KStringCow::from_static( fixture )); bench_eq_static!(bench_eq_static_12, 12, |fixture| KStringCow::from_static( fixture )); bench_eq_static!(bench_eq_static_13, 13, |fixture| KStringCow::from_static( fixture )); bench_eq_ref!(bench_eq_ref_00, 0, |fixture| KStringCow::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_01, 1, |fixture| KStringCow::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_02, 2, |fixture| KStringCow::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_03, 3, |fixture| KStringCow::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_04, 4, |fixture| KStringCow::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_05, 5, |fixture| KStringCow::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_06, 6, |fixture| KStringCow::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_07, 7, |fixture| KStringCow::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_08, 8, |fixture| KStringCow::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_09, 9, |fixture| KStringCow::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_10, 10, |fixture| KStringCow::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_11, 11, |fixture| KStringCow::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_12, 12, |fixture| KStringCow::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_13, 13, |fixture| KStringCow::from_ref(fixture)); bench_eq_owned!(bench_eq_owned_00, 0, |fixture| KStringCow::from_string( fixture )); bench_eq_owned!(bench_eq_owned_01, 1, |fixture| KStringCow::from_string( fixture )); bench_eq_owned!(bench_eq_owned_02, 2, |fixture| KStringCow::from_string( fixture )); bench_eq_owned!(bench_eq_owned_03, 3, |fixture| KStringCow::from_string( fixture )); bench_eq_owned!(bench_eq_owned_04, 4, |fixture| KStringCow::from_string( fixture )); bench_eq_owned!(bench_eq_owned_05, 5, |fixture| KStringCow::from_string( fixture )); bench_eq_owned!(bench_eq_owned_06, 6, |fixture| KStringCow::from_string( fixture )); bench_eq_owned!(bench_eq_owned_07, 7, |fixture| KStringCow::from_string( fixture )); bench_eq_owned!(bench_eq_owned_08, 8, |fixture| KStringCow::from_string( fixture )); bench_eq_owned!(bench_eq_owned_09, 9, |fixture| KStringCow::from_string( fixture )); bench_eq_owned!(bench_eq_owned_10, 10, |fixture| KStringCow::from_string( fixture )); bench_eq_owned!(bench_eq_owned_11, 11, |fixture| KStringCow::from_string( fixture )); bench_eq_owned!(bench_eq_owned_12, 12, |fixture| KStringCow::from_string( fixture )); bench_eq_owned!(bench_eq_owned_13, 13, |fixture| KStringCow::from_string( fixture )); } kstring-1.0.0/benches/kstringref.rs010064400007650000024000000130671370113146300155510ustar0000000000000000#![feature(test)] extern crate test; use kstring::KStringRef; mod macros; mod kstringref { use super::*; bench_clone_static!(bench_clone_static_00, 0, |fixture| KStringRef::from_static( fixture )); bench_clone_static!(bench_clone_static_01, 1, |fixture| KStringRef::from_static( fixture )); bench_clone_static!(bench_clone_static_02, 2, |fixture| KStringRef::from_static( fixture )); bench_clone_static!(bench_clone_static_03, 3, |fixture| KStringRef::from_static( fixture )); bench_clone_static!(bench_clone_static_04, 4, |fixture| KStringRef::from_static( fixture )); bench_clone_static!(bench_clone_static_05, 5, |fixture| KStringRef::from_static( fixture )); bench_clone_static!(bench_clone_static_06, 6, |fixture| KStringRef::from_static( fixture )); bench_clone_static!(bench_clone_static_07, 7, |fixture| KStringRef::from_static( fixture )); bench_clone_static!(bench_clone_static_08, 8, |fixture| KStringRef::from_static( fixture )); bench_clone_static!(bench_clone_static_09, 9, |fixture| KStringRef::from_static( fixture )); bench_clone_static!( bench_clone_static_10, 10, |fixture| KStringRef::from_static(fixture) ); bench_clone_static!( bench_clone_static_11, 11, |fixture| KStringRef::from_static(fixture) ); bench_clone_static!( bench_clone_static_12, 12, |fixture| KStringRef::from_static(fixture) ); bench_clone_static!( bench_clone_static_13, 13, |fixture| KStringRef::from_static(fixture) ); bench_clone_ref!(bench_clone_ref_00, 0, |fixture| KStringRef::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_01, 1, |fixture| KStringRef::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_02, 2, |fixture| KStringRef::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_03, 3, |fixture| KStringRef::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_04, 4, |fixture| KStringRef::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_05, 5, |fixture| KStringRef::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_06, 6, |fixture| KStringRef::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_07, 7, |fixture| KStringRef::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_08, 8, |fixture| KStringRef::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_09, 9, |fixture| KStringRef::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_10, 10, |fixture| KStringRef::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_11, 11, |fixture| KStringRef::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_12, 12, |fixture| KStringRef::from_ref( fixture )); bench_clone_ref!(bench_clone_ref_13, 13, |fixture| KStringRef::from_ref( fixture )); bench_eq_static!(bench_eq_static_00, 0, |fixture| KStringRef::from_static( fixture )); bench_eq_static!(bench_eq_static_01, 1, |fixture| KStringRef::from_static( fixture )); bench_eq_static!(bench_eq_static_02, 2, |fixture| KStringRef::from_static( fixture )); bench_eq_static!(bench_eq_static_03, 3, |fixture| KStringRef::from_static( fixture )); bench_eq_static!(bench_eq_static_04, 4, |fixture| KStringRef::from_static( fixture )); bench_eq_static!(bench_eq_static_05, 5, |fixture| KStringRef::from_static( fixture )); bench_eq_static!(bench_eq_static_06, 6, |fixture| KStringRef::from_static( fixture )); bench_eq_static!(bench_eq_static_07, 7, |fixture| KStringRef::from_static( fixture )); bench_eq_static!(bench_eq_static_08, 8, |fixture| KStringRef::from_static( fixture )); bench_eq_static!(bench_eq_static_09, 9, |fixture| KStringRef::from_static( fixture )); bench_eq_static!(bench_eq_static_10, 10, |fixture| KStringRef::from_static( fixture )); bench_eq_static!(bench_eq_static_11, 11, |fixture| KStringRef::from_static( fixture )); bench_eq_static!(bench_eq_static_12, 12, |fixture| KStringRef::from_static( fixture )); bench_eq_static!(bench_eq_static_13, 13, |fixture| KStringRef::from_static( fixture )); bench_eq_ref!(bench_eq_ref_00, 0, |fixture| KStringRef::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_01, 1, |fixture| KStringRef::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_02, 2, |fixture| KStringRef::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_03, 3, |fixture| KStringRef::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_04, 4, |fixture| KStringRef::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_05, 5, |fixture| KStringRef::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_06, 6, |fixture| KStringRef::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_07, 7, |fixture| KStringRef::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_08, 8, |fixture| KStringRef::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_09, 9, |fixture| KStringRef::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_10, 10, |fixture| KStringRef::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_11, 11, |fixture| KStringRef::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_12, 12, |fixture| KStringRef::from_ref(fixture)); bench_eq_ref!(bench_eq_ref_13, 13, |fixture| KStringRef::from_ref(fixture)); } kstring-1.0.0/benches/macros.rs010064400007650000024000000044001370113146300146460ustar0000000000000000pub static FIXTURES: &[&'static str] = &[ "", "0", "01", "012", "0123", "01234", "012345", "0123456", "01234567", "012345678", "0123456789", "01234567890123456789", "0123456789012345678901234567890123456789", "01234567890123456789012345678901234567890123456789012345678901234567890123456789", ]; #[macro_export] macro_rules! bench_clone_static { ($name:ident, $index:literal, $expr:expr) => { #[bench] fn $name(b: &mut test::Bencher) { let fixture = crate::macros::FIXTURES[$index]; let uut = $expr(fixture); b.iter(|| uut.clone()); } }; } #[macro_export] macro_rules! bench_clone_ref { ($name:ident, $index:literal, $expr:expr) => { #[bench] fn $name(b: &mut test::Bencher) { let fixture = String::from(crate::macros::FIXTURES[$index]); let uut = $expr(fixture.as_str()); b.iter(|| uut.clone()); } }; } #[macro_export] macro_rules! bench_clone_owned { ($name:ident, $index:literal, $expr:expr) => { #[bench] fn $name(b: &mut test::Bencher) { let fixture = String::from(crate::macros::FIXTURES[$index]); let uut = $expr(fixture); b.iter(|| uut.clone()); } }; } #[macro_export] macro_rules! bench_eq_static { ($name:ident, $index:literal, $expr:expr) => { #[bench] fn $name(b: &mut test::Bencher) { let fixture = crate::macros::FIXTURES[$index]; let uut = $expr(fixture); b.iter(|| uut == fixture); } }; } #[macro_export] macro_rules! bench_eq_ref { ($name:ident, $index:literal, $expr:expr) => { #[bench] fn $name(b: &mut test::Bencher) { let fixture = String::from(crate::macros::FIXTURES[$index]); let uut = $expr(fixture.as_str()); b.iter(|| uut == fixture); } }; } #[macro_export] macro_rules! bench_eq_owned { ($name:ident, $index:literal, $expr:expr) => { #[bench] fn $name(b: &mut test::Bencher) { let fixture = String::from(crate::macros::FIXTURES[$index]); let uut = $expr(fixture.clone()); b.iter(|| uut == fixture); } }; } kstring-1.0.0/benches/str.rs010064400007650000024000000071461370113146300142040ustar0000000000000000#![feature(test)] extern crate test; mod macros; mod str { use super::*; bench_clone_static!(bench_clone_static_00, 0, |fixture| fixture); bench_clone_static!(bench_clone_static_01, 1, |fixture| fixture); bench_clone_static!(bench_clone_static_02, 2, |fixture| fixture); bench_clone_static!(bench_clone_static_03, 3, |fixture| fixture); bench_clone_static!(bench_clone_static_04, 4, |fixture| fixture); bench_clone_static!(bench_clone_static_05, 5, |fixture| fixture); bench_clone_static!(bench_clone_static_06, 6, |fixture| fixture); bench_clone_static!(bench_clone_static_07, 7, |fixture| fixture); bench_clone_static!(bench_clone_static_08, 8, |fixture| fixture); bench_clone_static!(bench_clone_static_09, 9, |fixture| fixture); bench_clone_static!(bench_clone_static_10, 10, |fixture| fixture); bench_clone_static!(bench_clone_static_11, 11, |fixture| fixture); bench_clone_static!(bench_clone_static_12, 12, |fixture| fixture); bench_clone_static!(bench_clone_static_13, 13, |fixture| fixture); bench_clone_ref!(bench_clone_ref_00, 0, |fixture| fixture); bench_clone_ref!(bench_clone_ref_01, 1, |fixture| fixture); bench_clone_ref!(bench_clone_ref_02, 2, |fixture| fixture); bench_clone_ref!(bench_clone_ref_03, 3, |fixture| fixture); bench_clone_ref!(bench_clone_ref_04, 4, |fixture| fixture); bench_clone_ref!(bench_clone_ref_05, 5, |fixture| fixture); bench_clone_ref!(bench_clone_ref_06, 6, |fixture| fixture); bench_clone_ref!(bench_clone_ref_07, 7, |fixture| fixture); bench_clone_ref!(bench_clone_ref_08, 8, |fixture| fixture); bench_clone_ref!(bench_clone_ref_09, 9, |fixture| fixture); bench_clone_ref!(bench_clone_ref_10, 10, |fixture| fixture); bench_clone_ref!(bench_clone_ref_11, 11, |fixture| fixture); bench_clone_ref!(bench_clone_ref_12, 12, |fixture| fixture); bench_clone_ref!(bench_clone_ref_13, 13, |fixture| fixture); bench_eq_static!(bench_eq_static_00, 0, |fixture| fixture); bench_eq_static!(bench_eq_static_01, 1, |fixture| fixture); bench_eq_static!(bench_eq_static_02, 2, |fixture| fixture); bench_eq_static!(bench_eq_static_03, 3, |fixture| fixture); bench_eq_static!(bench_eq_static_04, 4, |fixture| fixture); bench_eq_static!(bench_eq_static_05, 5, |fixture| fixture); bench_eq_static!(bench_eq_static_06, 6, |fixture| fixture); bench_eq_static!(bench_eq_static_07, 7, |fixture| fixture); bench_eq_static!(bench_eq_static_08, 8, |fixture| fixture); bench_eq_static!(bench_eq_static_09, 9, |fixture| fixture); bench_eq_static!(bench_eq_static_10, 10, |fixture| fixture); bench_eq_static!(bench_eq_static_11, 11, |fixture| fixture); bench_eq_static!(bench_eq_static_12, 12, |fixture| fixture); bench_eq_static!(bench_eq_static_13, 13, |fixture| fixture); bench_eq_ref!(bench_eq_ref_00, 0, |fixture| fixture); bench_eq_ref!(bench_eq_ref_01, 1, |fixture| fixture); bench_eq_ref!(bench_eq_ref_02, 2, |fixture| fixture); bench_eq_ref!(bench_eq_ref_03, 3, |fixture| fixture); bench_eq_ref!(bench_eq_ref_04, 4, |fixture| fixture); bench_eq_ref!(bench_eq_ref_05, 5, |fixture| fixture); bench_eq_ref!(bench_eq_ref_06, 6, |fixture| fixture); bench_eq_ref!(bench_eq_ref_07, 7, |fixture| fixture); bench_eq_ref!(bench_eq_ref_08, 8, |fixture| fixture); bench_eq_ref!(bench_eq_ref_09, 9, |fixture| fixture); bench_eq_ref!(bench_eq_ref_10, 10, |fixture| fixture); bench_eq_ref!(bench_eq_ref_11, 11, |fixture| fixture); bench_eq_ref!(bench_eq_ref_12, 12, |fixture| fixture); bench_eq_ref!(bench_eq_ref_13, 13, |fixture| fixture); } kstring-1.0.0/benches/string.rs010064400007650000024000000107511370113146300146760ustar0000000000000000#![feature(test)] extern crate test; mod macros; mod string { use super::*; bench_clone_static!(bench_clone_static_00, 0, |fixture| String::from(fixture)); bench_clone_static!(bench_clone_static_01, 1, |fixture| String::from(fixture)); bench_clone_static!(bench_clone_static_02, 2, |fixture| String::from(fixture)); bench_clone_static!(bench_clone_static_03, 3, |fixture| String::from(fixture)); bench_clone_static!(bench_clone_static_04, 4, |fixture| String::from(fixture)); bench_clone_static!(bench_clone_static_05, 5, |fixture| String::from(fixture)); bench_clone_static!(bench_clone_static_06, 6, |fixture| String::from(fixture)); bench_clone_static!(bench_clone_static_07, 7, |fixture| String::from(fixture)); bench_clone_static!(bench_clone_static_08, 8, |fixture| String::from(fixture)); bench_clone_static!(bench_clone_static_09, 9, |fixture| String::from(fixture)); bench_clone_static!(bench_clone_static_10, 10, |fixture| String::from(fixture)); bench_clone_static!(bench_clone_static_11, 11, |fixture| String::from(fixture)); bench_clone_static!(bench_clone_static_12, 12, |fixture| String::from(fixture)); bench_clone_static!(bench_clone_static_13, 13, |fixture| String::from(fixture)); bench_clone_owned!(bench_clone_owned_00, 0, |fixture| String::from(fixture)); bench_clone_owned!(bench_clone_owned_01, 1, |fixture| String::from(fixture)); bench_clone_owned!(bench_clone_owned_02, 2, |fixture| String::from(fixture)); bench_clone_owned!(bench_clone_owned_03, 3, |fixture| String::from(fixture)); bench_clone_owned!(bench_clone_owned_04, 4, |fixture| String::from(fixture)); bench_clone_owned!(bench_clone_owned_05, 5, |fixture| String::from(fixture)); bench_clone_owned!(bench_clone_owned_06, 6, |fixture| String::from(fixture)); bench_clone_owned!(bench_clone_owned_07, 7, |fixture| String::from(fixture)); bench_clone_owned!(bench_clone_owned_08, 8, |fixture| String::from(fixture)); bench_clone_owned!(bench_clone_owned_09, 9, |fixture| String::from(fixture)); bench_clone_owned!(bench_clone_owned_10, 10, |fixture| String::from(fixture)); bench_clone_owned!(bench_clone_owned_11, 11, |fixture| String::from(fixture)); bench_clone_owned!(bench_clone_owned_12, 12, |fixture| String::from(fixture)); bench_clone_owned!(bench_clone_owned_13, 13, |fixture| String::from(fixture)); bench_eq_static!(bench_eq_static_00, 0, |fixture| String::from(fixture)); bench_eq_static!(bench_eq_static_01, 1, |fixture| String::from(fixture)); bench_eq_static!(bench_eq_static_02, 2, |fixture| String::from(fixture)); bench_eq_static!(bench_eq_static_03, 3, |fixture| String::from(fixture)); bench_eq_static!(bench_eq_static_04, 4, |fixture| String::from(fixture)); bench_eq_static!(bench_eq_static_05, 5, |fixture| String::from(fixture)); bench_eq_static!(bench_eq_static_06, 6, |fixture| String::from(fixture)); bench_eq_static!(bench_eq_static_07, 7, |fixture| String::from(fixture)); bench_eq_static!(bench_eq_static_08, 8, |fixture| String::from(fixture)); bench_eq_static!(bench_eq_static_09, 9, |fixture| String::from(fixture)); bench_eq_static!(bench_eq_static_10, 10, |fixture| String::from(fixture)); bench_eq_static!(bench_eq_static_11, 11, |fixture| String::from(fixture)); bench_eq_static!(bench_eq_static_12, 12, |fixture| String::from(fixture)); bench_eq_static!(bench_eq_static_13, 13, |fixture| String::from(fixture)); bench_eq_owned!(bench_eq_owned_00, 0, |fixture| String::from(fixture)); bench_eq_owned!(bench_eq_owned_01, 1, |fixture| String::from(fixture)); bench_eq_owned!(bench_eq_owned_02, 2, |fixture| String::from(fixture)); bench_eq_owned!(bench_eq_owned_03, 3, |fixture| String::from(fixture)); bench_eq_owned!(bench_eq_owned_04, 4, |fixture| String::from(fixture)); bench_eq_owned!(bench_eq_owned_05, 5, |fixture| String::from(fixture)); bench_eq_owned!(bench_eq_owned_06, 6, |fixture| String::from(fixture)); bench_eq_owned!(bench_eq_owned_07, 7, |fixture| String::from(fixture)); bench_eq_owned!(bench_eq_owned_08, 8, |fixture| String::from(fixture)); bench_eq_owned!(bench_eq_owned_09, 9, |fixture| String::from(fixture)); bench_eq_owned!(bench_eq_owned_10, 10, |fixture| String::from(fixture)); bench_eq_owned!(bench_eq_owned_11, 11, |fixture| String::from(fixture)); bench_eq_owned!(bench_eq_owned_12, 12, |fixture| String::from(fixture)); bench_eq_owned!(bench_eq_owned_13, 13, |fixture| String::from(fixture)); } kstring-1.0.0/Cargo.toml.orig010064400007650000024000000007701370121303500142760ustar0000000000000000[package] name = "kstring" version = "1.0.0" authors = ["Ed Page "] description = "Key String: optimized for map keys" keywords = ["serde", "serialization", "string"] categories = ["data-structures", "text-processing"] repository = "https://github.com/cobalt-org/kstring" documentation = "https://docs.rs/kstring" readme = "README.md" license = "MIT OR Apache-2.0" edition = "2018" [badges] azure-devops = { project = "cobalt-org", pipeline = "kstring" } [dependencies] serde = "1.0" kstring-1.0.0/Cargo.toml0000644000000020041370121305000105730ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] edition = "2018" name = "kstring" version = "1.0.0" authors = ["Ed Page "] description = "Key String: optimized for map keys" documentation = "https://docs.rs/kstring" readme = "README.md" keywords = ["serde", "serialization", "string"] categories = ["data-structures", "text-processing"] license = "MIT OR Apache-2.0" repository = "https://github.com/cobalt-org/kstring" [dependencies.serde] version = "1.0" [badges.azure-devops] pipeline = "kstring" project = "cobalt-org" kstring-1.0.0/committed.toml010064400007650000024000000000631370113151000142610ustar0000000000000000style="conventional" ignore_author_re="dependabot" kstring-1.0.0/CONTRIBUTING.md010064400007650000024000000055431370113204500136440ustar0000000000000000# Contributing to kstring Thanks for wanting to contribute! There are many ways to contribute and we appreciate any level you're willing to do. ## Feature Requests Need some new functionality to help? You can let us know by opening an [issue][new issue]. It's helpful to look through [all issues][all issues] in case its already being talked about. ## Bug Reports Please let us know about what problems you run into, whether in behavior or ergonomics of API. You can do this by opening an [issue][new issue]. It's helpful to look through [all issues][all issues] in case its already being talked about. ## Pull Requests Looking for an idea? Check our [issues][issues]. If it's look more open ended, it is probably best to post on the issue how you are thinking of resolving the issue so you can get feedback early in the process. We want you to be successful and it can be discouraging to find out a lot of re-work is needed. Already have an idea? It might be good to first [create an issue][new issue] to propose it so we can make sure we are aligned and lower the risk of having to re-work some of it and the discouragement that goes along with that. ### Process When you first post a PR, we request that the commit history get cleaned up. We recommend avoiding this during the PR to make it easier to review how feedback was handled. Once the commit is ready, we'll ask you to clean up the commit history. Once you let us know this is done, we can move forward with merging! If you are uncomfortable with these parts of git, let us know and we can help. For commit messages, we use [Conventional](https://www.conventionalcommits.org) style. If you already wrote your commits and don't feel comfortable changing them, don't worry and go ahead and create your PR. We'll work with you on the best route forward. You can check your branch locally with [`committed`](https://github.com/crate-ci/committed). As a heads up, we'll be running your PR through the following gauntlet: - warnings turned to compile errors - `cargo test` - `rustfmt` - `clippy` - `rustdoc` - [`committed`](https://github.com/crate-ci/committed) ## Releasing When we're ready to release, a project owner should do the following - Determine what the next version is, according to semver - Bump version in a commit - Update CHANGELOG.md - Update the version in `Cargo.toml` - Update the dependency version in `src/lib.rs` - Update the dependency version in `README.md` - Tag the commit via `git tag -am "v.." v..` - `git push upstream master --tag v..` - Run `cargo publish` (run `cargo login` first if needed) [issues]: https://github.com/cobalt-org/kstring/issues [new issue]: https://github.com/cobalt-org/kstring/issues/new [all issues]: https://github.com/cobalt-org/kstring/issues?utf8=%E2%9C%93&q=is%3Aissue [travis]: https://github.com/cobalt-org/kstring/blob/master/.travis.yml kstring-1.0.0/LICENSE-APACHE010064400007650000024000000251371370113146300133430ustar0000000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. kstring-1.0.0/LICENSE-MIT010064400007650000024000000021271370113146300130450ustar0000000000000000The MIT License (MIT) Copyright (c) 2014-2016 Ning Sun and tojson_macros contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. kstring-1.0.0/README.md010064400007650000024000000025651370113275200127000ustar0000000000000000KString =========== > Key String: Optimized for map keys. [![Build Status](https://dev.azure.com/cobalt-org/cobalt-org/_apis/build/status/kstring?branchName=master)](https://dev.azure.com/cobalt-org/cobalt-org/_build/latest?definitionId=3&branchName=master) [![Crates Status](https://img.shields.io/crates/v/kstring.svg)](https://crates.io/crates/kstring) ## Background Considerations: - Large maps - Most keys live and drop without being used in any other way - Most keys are relatively small (single to double digit bytes) - Keys are immutable - Allow zero-cost abstractions between structs and maps (e.g. no allocating when dealing with struct field names) Ramifications: - Inline small strings rather than going to the heap. - Preserve `&'static str` across strings (`KString`), references (`KStringRef`), and lifetime abstractions (`KStringCow`) to avoid allocating for struct field names. - Use `Box` rather than `String` to use less memory. ## License Licensed under either of * Apache License, Version 2.0, (http://www.apache.org/licenses/LICENSE-2.0) * MIT license (http://opensource.org/licenses/MIT) at your option. ### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. kstring-1.0.0/release.toml010064400007650000024000000002411370113146300137210ustar0000000000000000pre-release-commit-message = "chore({{crate_name}}): Release {{version}}" no-dev-version = true tag-message = "{{tag_name}}" tag-name = "{{prefix}}v{{version}}" kstring-1.0.0/src/cow.rs010064400007650000024000000202511370113146300133340ustar0000000000000000use std::{borrow::Cow, fmt}; use crate::KString; use crate::KStringRef; use crate::KStringRefInner; type StdString = std::string::String; type BoxedStr = Box; /// A reference to a UTF-8 encoded, immutable string. #[derive(Clone)] #[repr(transparent)] pub struct KStringCow<'s> { pub(crate) inner: KStringCowInner<'s>, } #[derive(Clone, Debug)] pub(crate) enum KStringCowInner<'s> { Owned(KString), Borrowed(&'s str), } impl<'s> KStringCow<'s> { /// Create a new empty `KStringCow`. #[inline] pub fn new() -> Self { Default::default() } /// Create an owned `KStringCow`. #[inline] pub fn from_boxed(other: BoxedStr) -> Self { Self { inner: KStringCowInner::Owned(KString::from_boxed(other)), } } /// Create an owned `KStringCow`. #[inline] pub fn from_string(other: StdString) -> Self { Self::from_boxed(other.into_boxed_str()) } /// Create a reference to a borrowed data. #[inline] pub fn from_ref(other: &'s str) -> Self { Self { inner: KStringCowInner::Borrowed(other), } } /// Create a reference to a `'static` data. #[inline] pub fn from_static(other: &'static str) -> Self { Self { inner: KStringCowInner::Owned(KString::from_static(other)), } } /// Get a reference to the `KString`. #[inline] pub fn as_ref(&self) -> KStringRef<'_> { self.inner.as_ref() } /// Clone the data into an owned-type. #[inline] pub fn into_owned(self) -> KString { self.inner.into_owned() } /// Extracts a string slice containing the entire `KStringCow`. #[inline] pub fn as_str(&self) -> &str { self.inner.as_str() } /// Convert to a mutable string type, cloning the data if necessary. #[inline] pub fn into_string(self) -> StdString { String::from(self.into_boxed_str()) } /// Convert to a mutable string type, cloning the data if necessary. #[inline] pub fn into_boxed_str(self) -> BoxedStr { self.inner.into_boxed_str() } /// Convert to a Cow str #[inline] pub fn into_cow_str(self) -> Cow<'s, str> { self.inner.into_cow_str() } } impl<'s> KStringCowInner<'s> { #[inline] fn as_ref(&self) -> KStringRef<'_> { match self { Self::Owned(ref s) => s.as_ref(), Self::Borrowed(ref s) => KStringRef::from_ref(s), } } #[inline] fn into_owned(self) -> KString { match self { Self::Owned(s) => s, Self::Borrowed(s) => KString::from_ref(s), } } #[inline] fn as_str(&self) -> &str { match self { Self::Owned(ref s) => s.as_str(), Self::Borrowed(ref s) => s, } } #[inline] fn into_boxed_str(self) -> BoxedStr { match self { Self::Owned(s) => s.into_boxed_str(), Self::Borrowed(s) => BoxedStr::from(s), } } /// Convert to a Cow str #[inline] fn into_cow_str(self) -> Cow<'s, str> { match self { Self::Owned(s) => s.into_cow_str(), Self::Borrowed(s) => Cow::Borrowed(s), } } } impl<'s> std::ops::Deref for KStringCow<'s> { type Target = str; #[inline] fn deref(&self) -> &str { self.as_str() } } impl<'s> Eq for KStringCow<'s> {} impl<'s> PartialEq> for KStringCow<'s> { #[inline] fn eq(&self, other: &KStringCow<'s>) -> bool { PartialEq::eq(self.as_str(), other.as_str()) } } impl<'s> PartialEq for KStringCow<'s> { #[inline] fn eq(&self, other: &str) -> bool { PartialEq::eq(self.as_str(), other) } } impl<'s> PartialEq<&'s str> for KStringCow<'s> { #[inline] fn eq(&self, other: &&str) -> bool { PartialEq::eq(self.as_str(), *other) } } impl<'s> PartialEq for KStringCow<'s> { #[inline] fn eq(&self, other: &StdString) -> bool { PartialEq::eq(self.as_str(), other.as_str()) } } impl<'s> Ord for KStringCow<'s> { #[inline] fn cmp(&self, other: &Self) -> std::cmp::Ordering { self.as_str().cmp(other.as_str()) } } impl<'s> PartialOrd for KStringCow<'s> { #[inline] fn partial_cmp(&self, other: &Self) -> Option { self.as_str().partial_cmp(other.as_str()) } } impl<'s> std::hash::Hash for KStringCow<'s> { #[inline] fn hash(&self, state: &mut H) { self.as_str().hash(state); } } impl<'s> fmt::Debug for KStringCow<'s> { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&self.inner, f) } } impl<'s> fmt::Display for KStringCow<'s> { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(self.as_str(), f) } } impl<'s> AsRef for KStringCow<'s> { #[inline] fn as_ref(&self) -> &str { self.as_str() } } impl<'s> AsRef<[u8]> for KStringCow<'s> { #[inline] fn as_ref(&self) -> &[u8] { self.as_bytes() } } impl<'s> AsRef for KStringCow<'s> { #[inline] fn as_ref(&self) -> &std::ffi::OsStr { (&**self).as_ref() } } impl<'s> AsRef for KStringCow<'s> { #[inline] fn as_ref(&self) -> &std::path::Path { std::path::Path::new(self) } } impl<'s> std::borrow::Borrow for KStringCow<'s> { #[inline] fn borrow(&self) -> &str { self.as_str() } } impl<'s> Default for KStringCow<'s> { #[inline] fn default() -> Self { Self::from_static("") } } impl From for KStringCow<'static> { #[inline] fn from(other: KString) -> Self { let inner = KStringCowInner::Owned(other); Self { inner } } } impl<'s> From<&'s KString> for KStringCow<'s> { #[inline] fn from(other: &'s KString) -> Self { let other = other.as_ref(); other.into() } } impl<'s> From> for KStringCow<'s> { #[inline] fn from(other: KStringRef<'s>) -> Self { match other.inner { KStringRefInner::Borrowed(s) => Self::from_ref(s), KStringRefInner::Singleton(s) => Self::from_static(s), } } } impl<'s> From<&'s KStringRef<'s>> for KStringCow<'s> { #[inline] fn from(other: &'s KStringRef<'s>) -> Self { match other.inner { KStringRefInner::Borrowed(s) => Self::from_ref(s), KStringRefInner::Singleton(s) => Self::from_static(s), } } } impl From for KStringCow<'static> { #[inline] fn from(other: StdString) -> Self { // Since the memory is already allocated, don't bother moving it into a FixedString Self::from_boxed(other.into_boxed_str()) } } impl<'s> From<&'s StdString> for KStringCow<'s> { #[inline] fn from(other: &'s StdString) -> Self { Self::from_ref(other.as_str()) } } impl From for KStringCow<'static> { #[inline] fn from(other: BoxedStr) -> Self { // Since the memory is already allocated, don't bother moving it into a FixedString Self::from_boxed(other) } } impl<'s> From<&'s BoxedStr> for KStringCow<'s> { #[inline] fn from(other: &'s BoxedStr) -> Self { Self::from_ref(other) } } impl<'s> From<&'s str> for KStringCow<'s> { #[inline] fn from(other: &'s str) -> Self { Self::from_ref(other) } } impl<'s> serde::Serialize for KStringCow<'s> { #[inline] fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, { serializer.serialize_str(self.as_str()) } } impl<'de, 's> serde::Deserialize<'de> for KStringCow<'s> { fn deserialize(deserializer: D) -> Result where D: serde::Deserializer<'de>, { KString::deserialize(deserializer).map(|s| s.into()) } } #[cfg(test)] mod test { use super::*; #[test] fn test_size() { println!( "Cow: {}", std::mem::size_of::>() ); println!("KStringCow: {}", std::mem::size_of::>()); } } kstring-1.0.0/src/fixed.rs010064400007650000024000000027351370113146300136520ustar0000000000000000use std::fmt; macro_rules! fixed_string { ($name:ident, $len:literal) => { #[derive(Clone)] pub(crate) struct $name { array: [u8; $len], } impl $name { pub(crate) fn new(s: &str) -> Self { assert_eq!(s.as_bytes().len(), $len); let mut array = [0; $len]; array.copy_from_slice(&s.as_bytes()[0..$len]); Self { array } } #[inline] pub(crate) fn to_boxed_str(&self) -> Box { Box::from(self.as_str()) } #[inline] pub(crate) fn as_str(&self) -> &str { unsafe { std::str::from_utf8_unchecked(&self.array) } } } impl fmt::Debug for $name { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(self.as_str(), f) } } }; } fixed_string!(FixedString1, 1); fixed_string!(FixedString2, 2); fixed_string!(FixedString3, 3); fixed_string!(FixedString4, 4); fixed_string!(FixedString5, 5); fixed_string!(FixedString6, 6); fixed_string!(FixedString7, 7); fixed_string!(FixedString8, 8); fixed_string!(FixedString9, 9); fixed_string!(FixedString10, 10); fixed_string!(FixedString11, 11); fixed_string!(FixedString12, 12); fixed_string!(FixedString13, 13); fixed_string!(FixedString14, 14); fixed_string!(FixedString15, 15); fixed_string!(FixedString16, 16); kstring-1.0.0/src/lib.rs010064400007650000024000000014501370113146300133120ustar0000000000000000//! Key String: Optimized for map keys. //! //! # Background //! //! Considerations: //! - Large maps //! - Most keys live and drop without being used in any other way //! - Most keys are relatively small (single to double digit bytes) //! - Keys are immutable //! - Allow zero-cost abstractions between structs and maps (e.g. no allocating //! when dealing with struct field names) //! //! Ramifications: //! - Inline small strings rather than going to the heap. //! - Preserve `&'static str` across strings (`KString`), //! references (`KStringRef`), and lifetime abstractions (`KStringCow`) to avoid //! allocating for struct field names. //! - Use `Box` rather than `String` to use less memory. mod cow; mod fixed; mod r#ref; mod string; pub use cow::*; pub use r#ref::*; pub use string::*; kstring-1.0.0/src/ref.rs010064400007650000024000000133731370113146300133270ustar0000000000000000use std::fmt; use crate::KString; use crate::KStringCow; type StdString = std::string::String; type BoxedStr = Box; /// A reference to a UTF-8 encoded, immutable string. #[derive(Copy, Clone)] #[repr(transparent)] pub struct KStringRef<'s> { pub(crate) inner: KStringRefInner<'s>, } #[derive(Copy, Clone, Debug)] pub(crate) enum KStringRefInner<'s> { Borrowed(&'s str), Singleton(&'static str), } impl<'s> KStringRef<'s> { /// Create a new empty `KString`. #[inline] pub fn new() -> Self { Default::default() } /// Create a reference to a borrowed data. #[inline] pub fn from_ref(other: &'s str) -> Self { Self { inner: KStringRefInner::Borrowed(other), } } /// Create a reference to a `'static` data. #[inline] pub fn from_static(other: &'static str) -> Self { Self { inner: KStringRefInner::Singleton(other), } } /// Clone the data into an owned-type. #[inline] pub fn to_owned(&self) -> KString { self.inner.to_owned() } /// Extracts a string slice containing the entire `KStringRef`. #[inline] pub fn as_str(&self) -> &str { self.inner.as_str() } /// Convert to a mutable string type, cloning the data if necessary. #[inline] pub fn into_mut(self) -> StdString { self.inner.into_mut() } } impl<'s> KStringRefInner<'s> { #[inline] fn to_owned(&self) -> KString { match self { Self::Borrowed(s) => KString::from_ref(s), Self::Singleton(s) => KString::from_static(s), } } #[inline] fn as_str(&self) -> &str { match self { Self::Borrowed(ref s) => s, Self::Singleton(ref s) => s, } } #[inline] fn into_mut(self) -> StdString { self.as_str().to_owned() } } impl<'s> std::ops::Deref for KStringRef<'s> { type Target = str; #[inline] fn deref(&self) -> &str { self.as_str() } } impl<'s> Eq for KStringRef<'s> {} impl<'s> PartialEq> for KStringRef<'s> { #[inline] fn eq(&self, other: &KStringRef<'s>) -> bool { PartialEq::eq(self.as_str(), other.as_str()) } } impl<'s> PartialEq for KStringRef<'s> { #[inline] fn eq(&self, other: &str) -> bool { PartialEq::eq(self.as_str(), other) } } impl<'s> PartialEq<&'s str> for KStringRef<'s> { #[inline] fn eq(&self, other: &&str) -> bool { PartialEq::eq(self.as_str(), *other) } } impl<'s> PartialEq for KStringRef<'s> { #[inline] fn eq(&self, other: &StdString) -> bool { PartialEq::eq(self.as_str(), other.as_str()) } } impl<'s> Ord for KStringRef<'s> { #[inline] fn cmp(&self, other: &Self) -> std::cmp::Ordering { self.as_str().cmp(other.as_str()) } } impl<'s> PartialOrd for KStringRef<'s> { #[inline] fn partial_cmp(&self, other: &Self) -> Option { self.as_str().partial_cmp(other.as_str()) } } impl<'s> std::hash::Hash for KStringRef<'s> { #[inline] fn hash(&self, state: &mut H) { self.as_str().hash(state); } } impl<'s> fmt::Debug for KStringRef<'s> { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&self.inner, f) } } impl<'s> fmt::Display for KStringRef<'s> { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(self.as_str(), f) } } impl<'s> AsRef for KStringRef<'s> { #[inline] fn as_ref(&self) -> &str { self.as_str() } } impl<'s> AsRef<[u8]> for KStringRef<'s> { #[inline] fn as_ref(&self) -> &[u8] { self.as_bytes() } } impl<'s> AsRef for KStringRef<'s> { #[inline] fn as_ref(&self) -> &std::ffi::OsStr { (&**self).as_ref() } } impl<'s> AsRef for KStringRef<'s> { #[inline] fn as_ref(&self) -> &std::path::Path { std::path::Path::new(self) } } impl<'s> std::borrow::Borrow for KStringRef<'s> { #[inline] fn borrow(&self) -> &str { self.as_str() } } impl<'s> Default for KStringRef<'s> { #[inline] fn default() -> Self { Self::from_static("") } } impl<'s> From<&'s KString> for KStringRef<'s> { #[inline] fn from(other: &'s KString) -> Self { other.as_ref() } } impl<'s> From<&'s KStringCow<'s>> for KStringRef<'s> { #[inline] fn from(other: &'s KStringCow<'s>) -> Self { other.as_ref() } } impl<'s> From<&'s StdString> for KStringRef<'s> { #[inline] fn from(other: &'s StdString) -> Self { KStringRef::from_ref(other.as_str()) } } impl<'s> From<&'s BoxedStr> for KStringRef<'s> { #[inline] fn from(other: &'s BoxedStr) -> Self { Self::from_ref(other) } } impl<'s> From<&'s str> for KStringRef<'s> { #[inline] fn from(other: &'s str) -> Self { KStringRef::from_ref(other) } } impl<'s> serde::Serialize for KStringRef<'s> { #[inline] fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, { serializer.serialize_str(self.as_str()) } } impl<'de: 's, 's> serde::Deserialize<'de> for KStringRef<'s> { fn deserialize(deserializer: D) -> Result where D: serde::Deserializer<'de>, { let s: &'s str = serde::Deserialize::deserialize(deserializer)?; let s = KStringRef::from_ref(s); Ok(s) } } #[cfg(test)] mod test { use super::*; #[test] fn test_size() { println!("str: {}", std::mem::size_of::<&'static str>()); println!("KStringRef: {}", std::mem::size_of::>()); } } kstring-1.0.0/src/string.rs010064400007650000024000000331111370113146300140510ustar0000000000000000use std::{borrow::Cow, fmt}; use crate::fixed::*; use crate::KStringCow; use crate::KStringRef; type StdString = std::string::String; type BoxedStr = Box; /// A UTF-8 encoded, immutable string. #[derive(Clone)] #[repr(transparent)] pub struct KString { pub(crate) inner: KStringInner, } #[derive(Clone, Debug)] pub(crate) enum KStringInner { Owned(BoxedStr), Singleton(&'static str), Fixed1(FixedString1), Fixed2(FixedString2), Fixed3(FixedString3), Fixed4(FixedString4), Fixed5(FixedString5), Fixed6(FixedString6), Fixed7(FixedString7), Fixed8(FixedString8), Fixed9(FixedString9), Fixed10(FixedString10), Fixed11(FixedString11), Fixed12(FixedString12), Fixed13(FixedString13), Fixed14(FixedString14), Fixed15(FixedString15), Fixed16(FixedString16), } impl KString { /// Create a new empty `KString`. #[inline] pub fn new() -> Self { Default::default() } /// Create an owned `KString`. #[inline] pub fn from_boxed(other: BoxedStr) -> Self { Self { inner: KStringInner::Owned(other), } } /// Create an owned `KString`. #[inline] pub fn from_string(other: StdString) -> Self { Self::from_boxed(other.into_boxed_str()) } /// Create an owned `KString` optimally from a reference. #[inline] pub fn from_ref(other: &str) -> Self { let inner = match other.len() { 0 => KStringInner::Singleton(""), 1 => KStringInner::Fixed1(FixedString1::new(other)), 2 => KStringInner::Fixed2(FixedString2::new(other)), 3 => KStringInner::Fixed3(FixedString3::new(other)), 4 => KStringInner::Fixed4(FixedString4::new(other)), 5 => KStringInner::Fixed5(FixedString5::new(other)), 6 => KStringInner::Fixed6(FixedString6::new(other)), 7 => KStringInner::Fixed7(FixedString7::new(other)), 8 => KStringInner::Fixed8(FixedString8::new(other)), 9 => KStringInner::Fixed9(FixedString9::new(other)), 10 => KStringInner::Fixed10(FixedString10::new(other)), 11 => KStringInner::Fixed11(FixedString11::new(other)), 12 => KStringInner::Fixed12(FixedString12::new(other)), 13 => KStringInner::Fixed13(FixedString13::new(other)), 14 => KStringInner::Fixed14(FixedString14::new(other)), 15 => KStringInner::Fixed15(FixedString15::new(other)), 16 => KStringInner::Fixed16(FixedString16::new(other)), _ => KStringInner::Owned(BoxedStr::from(other)), }; Self { inner } } /// Create a reference to a `'static` data. #[inline] pub fn from_static(other: &'static str) -> Self { Self { inner: KStringInner::Singleton(other), } } /// Get a reference to the `KString`. #[inline] pub fn as_ref(&self) -> KStringRef<'_> { self.inner.as_ref() } /// Extracts a string slice containing the entire `KString`. #[inline] pub fn as_str(&self) -> &str { self.inner.as_str() } /// Convert to a mutable string type, cloning the data if necessary. #[inline] pub fn into_string(self) -> StdString { String::from(self.into_boxed_str()) } /// Convert to a mutable string type, cloning the data if necessary. #[inline] pub fn into_boxed_str(self) -> BoxedStr { self.inner.into_boxed_str() } /// Convert to a Cow str #[inline] pub fn into_cow_str(self) -> Cow<'static, str> { self.inner.into_cow_str() } } impl KStringInner { #[inline] fn as_ref(&self) -> KStringRef<'_> { match self { Self::Owned(ref s) => KStringRef::from_ref(s), Self::Singleton(ref s) => KStringRef::from_static(s), Self::Fixed1(ref s) => KStringRef::from_ref(s.as_str()), Self::Fixed2(ref s) => KStringRef::from_ref(s.as_str()), Self::Fixed3(ref s) => KStringRef::from_ref(s.as_str()), Self::Fixed4(ref s) => KStringRef::from_ref(s.as_str()), Self::Fixed5(ref s) => KStringRef::from_ref(s.as_str()), Self::Fixed6(ref s) => KStringRef::from_ref(s.as_str()), Self::Fixed7(ref s) => KStringRef::from_ref(s.as_str()), Self::Fixed8(ref s) => KStringRef::from_ref(s.as_str()), Self::Fixed9(ref s) => KStringRef::from_ref(s.as_str()), Self::Fixed10(ref s) => KStringRef::from_ref(s.as_str()), Self::Fixed11(ref s) => KStringRef::from_ref(s.as_str()), Self::Fixed12(ref s) => KStringRef::from_ref(s.as_str()), Self::Fixed13(ref s) => KStringRef::from_ref(s.as_str()), Self::Fixed14(ref s) => KStringRef::from_ref(s.as_str()), Self::Fixed15(ref s) => KStringRef::from_ref(s.as_str()), Self::Fixed16(ref s) => KStringRef::from_ref(s.as_str()), } } #[inline] fn as_str(&self) -> &str { match self { Self::Owned(ref s) => &s, Self::Singleton(ref s) => s, Self::Fixed1(ref s) => s.as_str(), Self::Fixed2(ref s) => s.as_str(), Self::Fixed3(ref s) => s.as_str(), Self::Fixed4(ref s) => s.as_str(), Self::Fixed5(ref s) => s.as_str(), Self::Fixed6(ref s) => s.as_str(), Self::Fixed7(ref s) => s.as_str(), Self::Fixed8(ref s) => s.as_str(), Self::Fixed9(ref s) => s.as_str(), Self::Fixed10(ref s) => s.as_str(), Self::Fixed11(ref s) => s.as_str(), Self::Fixed12(ref s) => s.as_str(), Self::Fixed13(ref s) => s.as_str(), Self::Fixed14(ref s) => s.as_str(), Self::Fixed15(ref s) => s.as_str(), Self::Fixed16(ref s) => s.as_str(), } } #[inline] fn into_boxed_str(self) -> BoxedStr { match self { Self::Owned(s) => s, Self::Singleton(s) => BoxedStr::from(s), Self::Fixed1(s) => s.to_boxed_str(), Self::Fixed2(s) => s.to_boxed_str(), Self::Fixed3(s) => s.to_boxed_str(), Self::Fixed4(s) => s.to_boxed_str(), Self::Fixed5(s) => s.to_boxed_str(), Self::Fixed6(s) => s.to_boxed_str(), Self::Fixed7(s) => s.to_boxed_str(), Self::Fixed8(s) => s.to_boxed_str(), Self::Fixed9(s) => s.to_boxed_str(), Self::Fixed10(s) => s.to_boxed_str(), Self::Fixed11(s) => s.to_boxed_str(), Self::Fixed12(s) => s.to_boxed_str(), Self::Fixed13(s) => s.to_boxed_str(), Self::Fixed14(s) => s.to_boxed_str(), Self::Fixed15(s) => s.to_boxed_str(), Self::Fixed16(s) => s.to_boxed_str(), } } /// Convert to a Cow str #[inline] fn into_cow_str(self) -> Cow<'static, str> { match self { Self::Owned(s) => Cow::Owned(s.into()), Self::Singleton(s) => Cow::Borrowed(s), Self::Fixed1(s) => Cow::Owned(s.to_boxed_str().into()), Self::Fixed2(s) => Cow::Owned(s.to_boxed_str().into()), Self::Fixed3(s) => Cow::Owned(s.to_boxed_str().into()), Self::Fixed4(s) => Cow::Owned(s.to_boxed_str().into()), Self::Fixed5(s) => Cow::Owned(s.to_boxed_str().into()), Self::Fixed6(s) => Cow::Owned(s.to_boxed_str().into()), Self::Fixed7(s) => Cow::Owned(s.to_boxed_str().into()), Self::Fixed8(s) => Cow::Owned(s.to_boxed_str().into()), Self::Fixed9(s) => Cow::Owned(s.to_boxed_str().into()), Self::Fixed10(s) => Cow::Owned(s.to_boxed_str().into()), Self::Fixed11(s) => Cow::Owned(s.to_boxed_str().into()), Self::Fixed12(s) => Cow::Owned(s.to_boxed_str().into()), Self::Fixed13(s) => Cow::Owned(s.to_boxed_str().into()), Self::Fixed14(s) => Cow::Owned(s.to_boxed_str().into()), Self::Fixed15(s) => Cow::Owned(s.to_boxed_str().into()), Self::Fixed16(s) => Cow::Owned(s.to_boxed_str().into()), } } } impl std::ops::Deref for KString { type Target = str; #[inline] fn deref(&self) -> &str { self.as_str() } } impl Eq for KString {} impl<'s> PartialEq for KString { #[inline] fn eq(&self, other: &KString) -> bool { PartialEq::eq(self.as_str(), other.as_str()) } } impl<'s> PartialEq for KString { #[inline] fn eq(&self, other: &str) -> bool { PartialEq::eq(self.as_str(), other) } } impl<'s> PartialEq<&'s str> for KString { #[inline] fn eq(&self, other: &&str) -> bool { PartialEq::eq(self.as_str(), *other) } } impl<'s> PartialEq for KString { #[inline] fn eq(&self, other: &StdString) -> bool { PartialEq::eq(self.as_str(), other.as_str()) } } impl Ord for KString { #[inline] fn cmp(&self, other: &Self) -> std::cmp::Ordering { self.as_str().cmp(other.as_str()) } } impl PartialOrd for KString { #[inline] fn partial_cmp(&self, other: &Self) -> Option { self.as_str().partial_cmp(other.as_str()) } } impl std::hash::Hash for KString { #[inline] fn hash(&self, state: &mut H) { self.as_str().hash(state); } } impl fmt::Debug for KString { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&self.inner, f) } } impl fmt::Display for KString { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(self.as_str(), f) } } impl AsRef for KString { #[inline] fn as_ref(&self) -> &str { self.as_str() } } impl AsRef<[u8]> for KString { #[inline] fn as_ref(&self) -> &[u8] { self.as_bytes() } } impl AsRef for KString { #[inline] fn as_ref(&self) -> &std::ffi::OsStr { (&**self).as_ref() } } impl AsRef for KString { #[inline] fn as_ref(&self) -> &std::path::Path { std::path::Path::new(self) } } impl std::borrow::Borrow for KString { #[inline] fn borrow(&self) -> &str { self.as_str() } } impl Default for KString { #[inline] fn default() -> Self { Self::from_static("") } } impl<'s> From> for KString { #[inline] fn from(other: KStringRef<'s>) -> Self { other.to_owned() } } impl<'s> From<&'s KStringRef<'s>> for KString { #[inline] fn from(other: &'s KStringRef<'s>) -> Self { other.to_owned() } } impl<'s> From> for KString { #[inline] fn from(other: KStringCow<'s>) -> Self { other.into_owned() } } impl<'s> From<&'s KStringCow<'s>> for KString { #[inline] fn from(other: &'s KStringCow<'s>) -> Self { other.clone().into_owned() } } impl From for KString { #[inline] fn from(other: StdString) -> Self { // Since the memory is already allocated, don't bother moving it into a FixedString Self::from_boxed(other.into_boxed_str()) } } impl From for KString { #[inline] fn from(other: BoxedStr) -> Self { // Since the memory is already allocated, don't bother moving it into a FixedString Self::from_boxed(other) } } impl<'s> From<&'s BoxedStr> for KString { #[inline] fn from(other: &'s BoxedStr) -> Self { Self::from_ref(other) } } impl From<&'static str> for KString { #[inline] fn from(other: &'static str) -> Self { Self::from_static(other) } } impl serde::Serialize for KString { #[inline] fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, { serializer.serialize_str(self.as_str()) } } impl<'de> serde::Deserialize<'de> for KString { fn deserialize(deserializer: D) -> Result where D: serde::Deserializer<'de>, { deserializer.deserialize_string(StringVisitor) } } struct StringVisitor; impl<'de> serde::de::Visitor<'de> for StringVisitor { type Value = KString; fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { formatter.write_str("a string") } fn visit_str(self, v: &str) -> Result where E: serde::de::Error, { Ok(KString::from_ref(v)) } fn visit_string(self, v: String) -> Result where E: serde::de::Error, { Ok(KString::from_string(v)) } fn visit_bytes(self, v: &[u8]) -> Result where E: serde::de::Error, { match std::str::from_utf8(v) { Ok(s) => Ok(KString::from_ref(s)), Err(_) => Err(serde::de::Error::invalid_value( serde::de::Unexpected::Bytes(v), &self, )), } } fn visit_byte_buf(self, v: Vec) -> Result where E: serde::de::Error, { match String::from_utf8(v) { Ok(s) => Ok(KString::from_string(s)), Err(e) => Err(serde::de::Error::invalid_value( serde::de::Unexpected::Bytes(&e.into_bytes()), &self, )), } } } #[cfg(test)] mod test { use super::*; #[test] fn test_size() { println!("String: {}", std::mem::size_of::()); println!("Box: {}", std::mem::size_of::()); println!("Box>: {}", std::mem::size_of::>()); println!("KString: {}", std::mem::size_of::()); } } kstring-1.0.0/.cargo_vcs_info.json0000644000000001121370121305000125730ustar00{ "git": { "sha1": "eac7f9a032e9d78be5c9c7b620167617aa742c46" } }