toml_writer-1.0.6+spec-1.1.0/.cargo_vcs_info.json0000644000000001600000000000100147650ustar { "git": { "sha1": "e32c7a2f9b126d42fab0705e9783fec42b88e861" }, "path_in_vcs": "crates/toml_writer" }toml_writer-1.0.6+spec-1.1.0/Cargo.lock0000644000000354310000000000100127510ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "anstream" version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ae563653d1938f79b1ab1b5e668c87c76a9930414574a6583a7b7e11a8e6192" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", "is_terminal_polyfill", "utf8parse", ] [[package]] name = "anstyle" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" [[package]] name = "anstyle-parse" version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2" dependencies = [ "windows-sys 0.60.2", ] [[package]] name = "anstyle-wincon" version = "3.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a" dependencies = [ "anstyle", "once_cell_polyfill", "windows-sys 0.60.2", ] [[package]] name = "autocfg" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" [[package]] name = "bit-set" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3" dependencies = [ "bit-vec", ] [[package]] name = "bit-vec" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7" [[package]] name = "bitflags" version = "2.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394" [[package]] name = "cfg-if" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" [[package]] name = "colorchoice" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" [[package]] name = "errno" version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", "windows-sys 0.61.0", ] [[package]] name = "fastrand" version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "getrandom" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" dependencies = [ "cfg-if", "libc", "r-efi", "wasi", ] [[package]] name = "is_terminal_polyfill" version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" version = "0.2.175" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" [[package]] name = "linux-raw-sys" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" [[package]] name = "normalize-line-endings" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" [[package]] name = "num-traits" version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] [[package]] name = "once_cell" version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] name = "once_cell_polyfill" version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" [[package]] name = "ppv-lite86" version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" dependencies = [ "zerocopy", ] [[package]] name = "proc-macro2" version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" dependencies = [ "unicode-ident", ] [[package]] name = "proptest" version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fcdab19deb5195a31cf7726a210015ff1496ba1464fd42cb4f537b8b01b471f" dependencies = [ "bit-set", "bit-vec", "bitflags", "lazy_static", "num-traits", "rand", "rand_chacha", "rand_xorshift", "regex-syntax", "rusty-fork", "tempfile", "unarray", ] [[package]] name = "quick-error" version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" dependencies = [ "proc-macro2", ] [[package]] name = "r-efi" version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" [[package]] name = "rand" version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" dependencies = [ "rand_chacha", "rand_core", ] [[package]] name = "rand_chacha" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" dependencies = [ "ppv-lite86", "rand_core", ] [[package]] name = "rand_core" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" dependencies = [ "getrandom", ] [[package]] name = "rand_xorshift" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a" dependencies = [ "rand_core", ] [[package]] name = "regex-syntax" version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "caf4aa5b0f434c91fe5c7f1ecb6a5ece2130b02ad2a590589dda5146df959001" [[package]] name = "rustix" version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" dependencies = [ "bitflags", "errno", "libc", "linux-raw-sys", "windows-sys 0.61.0", ] [[package]] name = "rusty-fork" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" dependencies = [ "fnv", "quick-error", "tempfile", "wait-timeout", ] [[package]] name = "serde" version = "1.0.225" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd6c24dee235d0da097043389623fb913daddf92c76e9f5a1db88607a0bcbd1d" dependencies = [ "serde_core", ] [[package]] name = "serde_core" version = "1.0.225" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "659356f9a0cb1e529b24c01e43ad2bdf520ec4ceaf83047b83ddcc2251f96383" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" version = "1.0.225" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ea936adf78b1f766949a4977b91d2f5595825bd6ec079aa9543ad2685fc4516" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "similar" version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbbb5d9659141646ae647b42fe094daf6c6192d1620870b449d9557f748b2daa" [[package]] name = "snapbox" version = "0.6.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96dcfc4581e3355d70ac2ee14cfdf81dce3d85c85f1ed9e2c1d3013f53b3436b" dependencies = [ "anstream", "anstyle", "normalize-line-endings", "similar", "snapbox-macros", ] [[package]] name = "snapbox-macros" version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16569f53ca23a41bb6f62e0a5084aa1661f4814a67fa33696a79073e03a664af" dependencies = [ "anstream", ] [[package]] name = "syn" version = "2.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "tempfile" version = "3.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84fa4d11fadde498443cca10fd3ac23c951f0dc59e080e9f4b93d4df4e4eea53" dependencies = [ "fastrand", "getrandom", "once_cell", "rustix", "windows-sys 0.61.0", ] [[package]] name = "toml" version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" dependencies = [ "serde", ] [[package]] name = "toml_writer" version = "1.0.6+spec-1.1.0" dependencies = [ "proptest", "snapbox", "toml", ] [[package]] name = "unarray" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" [[package]] name = "unicode-ident" version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" [[package]] name = "utf8parse" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "wait-timeout" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11" dependencies = [ "libc", ] [[package]] name = "wasi" version = "0.14.4+wasi-0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88a5f4a424faf49c3c2c344f166f0662341d470ea185e939657aaff130f0ec4a" dependencies = [ "wit-bindgen", ] [[package]] name = "windows-link" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" [[package]] name = "windows-link" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "45e46c0661abb7180e7b9c281db115305d49ca1709ab8242adf09666d2173c65" [[package]] name = "windows-sys" version = "0.60.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" dependencies = [ "windows-targets", ] [[package]] name = "windows-sys" version = "0.61.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e201184e40b2ede64bc2ea34968b28e33622acdbbf37104f0e4a33f7abe657aa" dependencies = [ "windows-link 0.2.0", ] [[package]] name = "windows-targets" version = "0.53.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91" dependencies = [ "windows-link 0.1.3", "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", "windows_i686_gnullvm", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" [[package]] name = "windows_aarch64_msvc" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" [[package]] name = "windows_i686_gnu" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" [[package]] name = "windows_i686_gnullvm" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" [[package]] name = "windows_i686_msvc" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" [[package]] name = "windows_x86_64_gnu" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" [[package]] name = "windows_x86_64_gnullvm" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" [[package]] name = "windows_x86_64_msvc" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" [[package]] name = "wit-bindgen" version = "0.45.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c573471f125075647d03df72e026074b7203790d41351cd6edc96f46bcccd36" [[package]] name = "zerocopy" version = "0.8.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" version = "0.8.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" dependencies = [ "proc-macro2", "quote", "syn", ] toml_writer-1.0.6+spec-1.1.0/Cargo.toml0000644000000102160000000000100127660ustar # 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 are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" rust-version = "1.76" name = "toml_writer" version = "1.0.6+spec-1.1.0" build = false include = [ "build.rs", "src/**/*", "Cargo.toml", "Cargo.lock", "LICENSE*", "README.md", "examples/**/*", ] autolib = false autobins = false autoexamples = false autotests = false autobenches = false description = """ A low-level interface for writing out TOML """ readme = "README.md" keywords = [ "encoding", "toml", "no_std", ] categories = ["encoding"] license = "MIT OR Apache-2.0" repository = "https://github.com/toml-rs/toml" [package.metadata.docs.rs] all-features = true rustdoc-args = ["--generate-link-to-definition"] [[package.metadata.release.pre-release-replacements]] file = "CHANGELOG.md" search = "Unreleased" replace = "{{version}}" min = 1 [[package.metadata.release.pre-release-replacements]] file = "CHANGELOG.md" search = '\.\.\.HEAD' replace = "...{{tag_name}}" exactly = 1 [[package.metadata.release.pre-release-replacements]] file = "CHANGELOG.md" search = "ReleaseDate" replace = "{{date}}" min = 1 [[package.metadata.release.pre-release-replacements]] file = "CHANGELOG.md" search = "" replace = """ ## [Unreleased] - ReleaseDate """ exactly = 1 [[package.metadata.release.pre-release-replacements]] file = "CHANGELOG.md" search = "" replace = """ [Unreleased]: https://github.com/toml-rs/toml/compare/{{tag_name}}...HEAD""" exactly = 1 [features] alloc = [] default = ["std"] std = ["alloc"] [lib] name = "toml_writer" path = "src/lib.rs" [dependencies] [dev-dependencies.proptest] version = "1.7.0" [dev-dependencies.snapbox] version = "0.6.21" [dev-dependencies.toml_old] version = "0.5.11" package = "toml" [lints.clippy] bool_assert_comparison = "allow" branches_sharing_code = "allow" checked_conversions = "warn" collapsible_else_if = "allow" create_dir = "warn" dbg_macro = "warn" debug_assert_with_mut_call = "warn" doc_markdown = "warn" empty_enum = "warn" enum_glob_use = "warn" expl_impl_clone_on_copy = "warn" explicit_deref_methods = "warn" explicit_into_iter_loop = "warn" fallible_impl_from = "warn" filter_map_next = "warn" flat_map_option = "warn" float_cmp_const = "warn" fn_params_excessive_bools = "warn" from_iter_instead_of_collect = "warn" get_first = "allow" if_same_then_else = "allow" implicit_clone = "warn" imprecise_flops = "warn" inconsistent_struct_constructor = "warn" inefficient_to_string = "warn" infinite_loop = "warn" invalid_upcast_comparisons = "warn" large_digit_groups = "warn" large_stack_arrays = "warn" large_types_passed_by_value = "warn" let_and_return = "allow" linkedlist = "warn" lossy_float_literal = "warn" macro_use_imports = "warn" mem_forget = "warn" mutex_integer = "warn" needless_bool = "allow" needless_continue = "allow" needless_for_each = "warn" negative_feature_names = "warn" path_buf_push_overwrite = "warn" ptr_as_ptr = "warn" rc_mutex = "warn" redundant_feature_names = "warn" ref_option_ref = "warn" rest_pat_in_fully_bound_structs = "warn" result_large_err = "allow" same_functions_in_if_condition = "warn" self_named_module_files = "warn" semicolon_if_nothing_returned = "warn" str_to_string = "warn" string_add = "warn" string_add_assign = "warn" string_lit_as_bytes = "warn" string_to_string = "warn" todo = "warn" trait_duplication_in_bounds = "warn" uninlined_format_args = "warn" use_self = "warn" verbose_file_reads = "warn" wildcard_imports = "warn" zero_sized_map_values = "warn" [lints.rust] unnameable_types = "allow" unreachable_pub = "warn" unsafe_op_in_unsafe_fn = "warn" unused_lifetimes = "warn" unused_macro_rules = "warn" unused_qualifications = "warn" [lints.rust.rust_2018_idioms] level = "warn" priority = -1 toml_writer-1.0.6+spec-1.1.0/Cargo.toml.orig000064400000000000000000000023141046102023000164470ustar 00000000000000[package] name = "toml_writer" version = "1.0.6+spec-1.1.0" description = """ A low-level interface for writing out TOML """ categories = ["encoding"] keywords = ["encoding", "toml", "no_std"] repository.workspace = true license.workspace = true edition.workspace = true rust-version.workspace = true include.workspace = true [package.metadata.docs.rs] all-features = true rustdoc-args = ["--generate-link-to-definition"] [package.metadata.release] pre-release-replacements = [ {file="CHANGELOG.md", search="Unreleased", replace="{{version}}", min=1}, {file="CHANGELOG.md", search="\\.\\.\\.HEAD", replace="...{{tag_name}}", exactly=1}, {file="CHANGELOG.md", search="ReleaseDate", replace="{{date}}", min=1}, {file="CHANGELOG.md", search="", replace="\n## [Unreleased] - ReleaseDate\n", exactly=1}, {file="CHANGELOG.md", search="", replace="\n[Unreleased]: https://github.com/toml-rs/toml/compare/{{tag_name}}...HEAD", exactly=1}, ] [features] default = ["std"] std = ["alloc"] alloc = [] [dependencies] [dev-dependencies] proptest = "1.7.0" snapbox = "0.6.21" toml_old = { version = "0.5.11", package = "toml" } [lints] workspace = true toml_writer-1.0.6+spec-1.1.0/LICENSE-APACHE000064400000000000000000000261361046102023000155140ustar 00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS 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. toml_writer-1.0.6+spec-1.1.0/LICENSE-MIT000064400000000000000000000020461046102023000152160ustar 00000000000000Copyright (c) Individual 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. toml_writer-1.0.6+spec-1.1.0/README.md000064400000000000000000000014721046102023000150430ustar 00000000000000# toml_writer [![Documentation](https://img.shields.io/badge/docs-master-blue.svg)](https://docs.rs/toml_writer) ![License](https://img.shields.io/crates/l/toml_writer.svg) [![Crates Status](https://img.shields.io/crates/v/toml_writer.svg)](https://crates.io/crates/toml_writer) A low-level interface for writing out TOML ## License Licensed under either of * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or ) * MIT license ([LICENSE-MIT](LICENSE-MIT) or ) 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. toml_writer-1.0.6+spec-1.1.0/src/integer.rs000064400000000000000000000137361046102023000163640ustar 00000000000000use core::fmt::{self, Display}; /// Describes how a TOML integer should be formatted. /// /// # Example /// /// ```rust /// # #[cfg(feature = "alloc")] { /// # use toml_writer::ToTomlValue as _; /// let format = toml_writer::TomlIntegerFormat::new().as_hex_lower(); /// let number = 10; /// let number = format.format(number).unwrap_or(toml_writer::TomlInteger::new(number)); /// let number = number.to_toml_value(); /// assert_eq!(number, "0xa"); /// # } /// ``` #[derive(Copy, Clone, Debug)] pub struct TomlIntegerFormat { radix: Radix, } impl TomlIntegerFormat { /// Creates a new integer format (decimal). pub fn new() -> Self { Self { radix: Radix::Decimal, } } /// Sets the format to decimal. pub fn as_decimal(mut self) -> Self { self.radix = Radix::Decimal; self } /// Sets the format to hexadecimal with all characters in uppercase. pub fn as_hex_upper(mut self) -> Self { self.radix = Radix::Hexadecimal { case: HexCase::Upper, }; self } /// Sets the format to hexadecimal with all characters in lowercase. pub fn as_hex_lower(mut self) -> Self { self.radix = Radix::Hexadecimal { case: HexCase::Lower, }; self } /// Sets the format to octal. pub fn as_octal(mut self) -> Self { self.radix = Radix::Octal; self } /// Sets the format to binary. pub fn as_binary(mut self) -> Self { self.radix = Radix::Binary; self } /// Formats `value` as a TOML integer. /// /// Returns `None` if the value cannot be formatted /// (e.g. value is negative and the radix is not decimal). pub fn format>(self, value: N) -> Option> where TomlInteger: crate::WriteTomlValue, { match self.radix { Radix::Decimal => (), Radix::Hexadecimal { .. } | Radix::Octal | Radix::Binary => { if value < 0 { return None; } } } Some(TomlInteger { value, format: self, }) } } impl Default for TomlIntegerFormat { fn default() -> Self { Self::new() } } /// Helper struct for formatting TOML integers. /// /// This may be constructed by calling [`TomlIntegerFormat::format()`]. #[derive(Copy, Clone, Debug)] pub struct TomlInteger { value: N, format: TomlIntegerFormat, } impl TomlInteger where Self: crate::WriteTomlValue, { /// Apply default formatting pub fn new(value: N) -> Self { Self { value, format: TomlIntegerFormat::new(), } } } impl crate::WriteTomlValue for TomlInteger { fn write_toml_value(&self, writer: &mut W) -> fmt::Result { write_toml_value(self.value, &self.format, writer) } } impl crate::WriteTomlValue for TomlInteger { fn write_toml_value(&self, writer: &mut W) -> fmt::Result { write_toml_value(self.value, &self.format, writer) } } impl crate::WriteTomlValue for TomlInteger { fn write_toml_value(&self, writer: &mut W) -> fmt::Result { write_toml_value(self.value, &self.format, writer) } } impl crate::WriteTomlValue for TomlInteger { fn write_toml_value(&self, writer: &mut W) -> fmt::Result { write_toml_value(self.value, &self.format, writer) } } impl crate::WriteTomlValue for TomlInteger { fn write_toml_value(&self, writer: &mut W) -> fmt::Result { write_toml_value(self.value, &self.format, writer) } } impl crate::WriteTomlValue for TomlInteger { fn write_toml_value(&self, writer: &mut W) -> fmt::Result { write_toml_value(self.value, &self.format, writer) } } impl crate::WriteTomlValue for TomlInteger { fn write_toml_value(&self, writer: &mut W) -> fmt::Result { write_toml_value(self.value, &self.format, writer) } } impl crate::WriteTomlValue for TomlInteger { fn write_toml_value(&self, writer: &mut W) -> fmt::Result { write_toml_value(self.value, &self.format, writer) } } impl crate::WriteTomlValue for TomlInteger { fn write_toml_value(&self, writer: &mut W) -> fmt::Result { write_toml_value(self.value, &self.format, writer) } } impl crate::WriteTomlValue for TomlInteger { fn write_toml_value(&self, writer: &mut W) -> fmt::Result { write_toml_value(self.value, &self.format, writer) } } impl crate::WriteTomlValue for TomlInteger { fn write_toml_value(&self, writer: &mut W) -> fmt::Result { write_toml_value(self.value, &self.format, writer) } } impl crate::WriteTomlValue for TomlInteger { fn write_toml_value(&self, writer: &mut W) -> fmt::Result { write_toml_value(self.value, &self.format, writer) } } #[derive(Copy, Clone, Debug)] enum Radix { Decimal, Hexadecimal { case: HexCase }, Octal, Binary, } #[derive(Copy, Clone, Debug)] enum HexCase { Upper, Lower, } fn write_toml_value< N: Display + fmt::UpperHex + fmt::LowerHex + fmt::Octal + fmt::Binary, W: crate::TomlWrite + ?Sized, >( value: N, format: &TomlIntegerFormat, writer: &mut W, ) -> fmt::Result { match format.radix { Radix::Decimal => write!(writer, "{value}")?, Radix::Hexadecimal { case } => match case { HexCase::Upper => write!(writer, "0x{value:X}")?, HexCase::Lower => write!(writer, "0x{value:x}")?, }, Radix::Octal => write!(writer, "0o{value:o}")?, Radix::Binary => write!(writer, "0b{value:b}")?, } Ok(()) } toml_writer-1.0.6+spec-1.1.0/src/key.rs000064400000000000000000000025751046102023000155160ustar 00000000000000#[cfg(feature = "alloc")] use alloc::borrow::Cow; #[cfg(feature = "alloc")] use alloc::string::String; use crate::TomlWrite; #[cfg(feature = "alloc")] pub trait ToTomlKey { fn to_toml_key(&self) -> String; } #[cfg(feature = "alloc")] impl ToTomlKey for T where T: WriteTomlKey + ?Sized, { fn to_toml_key(&self) -> String { let mut result = String::new(); let _ = self.write_toml_key(&mut result); result } } pub trait WriteTomlKey { fn write_toml_key(&self, writer: &mut W) -> core::fmt::Result; } impl WriteTomlKey for str { fn write_toml_key(&self, writer: &mut W) -> core::fmt::Result { crate::TomlKeyBuilder::new(self) .as_default() .write_toml_key(writer) } } #[cfg(feature = "alloc")] impl WriteTomlKey for String { fn write_toml_key(&self, writer: &mut W) -> core::fmt::Result { self.as_str().write_toml_key(writer) } } #[cfg(feature = "alloc")] impl WriteTomlKey for Cow<'_, str> { fn write_toml_key(&self, writer: &mut W) -> core::fmt::Result { self.as_ref().write_toml_key(writer) } } impl WriteTomlKey for &V { fn write_toml_key(&self, writer: &mut W) -> core::fmt::Result { (*self).write_toml_key(writer) } } toml_writer-1.0.6+spec-1.1.0/src/lib.rs000064400000000000000000000050101046102023000154570ustar 00000000000000//! A low-level interface for writing out TOML //! //! Considerations when serializing arbitrary data: //! - Verify the implementation with [`toml-test-harness`](https://docs.rs/toml-test-harness) //! - Be sure to group keys under a table before writing another table //! - Watch for extra trailing newlines and leading newlines, both when starting with top-level //! keys or a table //! - When serializing an array-of-tables, be sure to verify that all elements of the array //! serialize as tables //! - Standard tables and inline tables may need separate implementations of corner cases, //! requiring verifying them both //! //! When serializing Rust data structures //! - `Option`: Skip key-value pairs with a value of `None`, otherwise error when seeing `None` //! - When skipping key-value pairs, be careful that a deeply nested `None` doesn't get skipped //! - Scalars and arrays are unsupported as top-level data types //! - Tuples and tuple variants seriallize as arrays //! - Structs, struct variants, and maps serialize as tables //! - Newtype variants serialize as to the inner type //! - Unit variants serialize to a string //! - Unit and unit structs don't have a clear meaning in TOML //! //! # Example //! //! ```rust //! use toml_writer::TomlWrite as _; //! //! # fn main() -> std::fmt::Result { //! let mut output = String::new(); //! output.newline()?; //! output.open_table_header()?; //! output.key("table")?; //! output.close_table_header()?; //! output.newline()?; //! //! output.key("key")?; //! output.space()?; //! output.keyval_sep()?; //! output.space()?; //! output.value("value")?; //! output.newline()?; //! //! assert_eq!(output, r#" //! [table] //! key = "value" //! "#); //! # Ok(()) //! # } //! ``` #![cfg_attr(all(not(feature = "std"), not(test)), no_std)] #![cfg_attr(docsrs, feature(doc_cfg))] #![forbid(unsafe_code)] #![warn(clippy::std_instead_of_core)] #![warn(clippy::std_instead_of_alloc)] #![warn(clippy::print_stderr)] #![warn(clippy::print_stdout)] #[cfg(feature = "alloc")] extern crate alloc; mod integer; mod key; mod string; mod value; mod write; pub use integer::TomlInteger; pub use integer::TomlIntegerFormat; #[cfg(feature = "alloc")] pub use key::ToTomlKey; pub use key::WriteTomlKey; pub use string::TomlKey; pub use string::TomlKeyBuilder; pub use string::TomlString; pub use string::TomlStringBuilder; #[cfg(feature = "alloc")] pub use value::ToTomlValue; pub use value::WriteTomlValue; pub use write::TomlWrite; #[doc = include_str!("../README.md")] #[cfg(doctest)] pub struct ReadmeDoctests; toml_writer-1.0.6+spec-1.1.0/src/string.rs000064400000000000000000000307561046102023000162360ustar 00000000000000/// Describes how a TOML string (key or value) should be formatted. /// /// # Example /// /// ```rust /// # #[cfg(feature = "alloc")] { /// # use toml_writer::ToTomlValue as _; /// let string = "Hello /// world! /// "; /// let string = toml_writer::TomlStringBuilder::new(string).as_default(); /// let string = string.to_toml_value(); /// assert_eq!(string, r#"""" /// Hello /// world! /// """"#); /// # } /// ``` #[derive(Copy, Clone, Debug)] pub struct TomlStringBuilder<'s> { decoded: &'s str, metrics: ValueMetrics, } impl<'s> TomlStringBuilder<'s> { pub fn new(decoded: &'s str) -> Self { Self { decoded, metrics: ValueMetrics::calculate(decoded), } } pub fn as_default(&self) -> TomlString<'s> { self.as_basic_pretty() .or_else(|| self.as_literal()) .or_else(|| self.as_ml_basic_pretty()) .or_else(|| self.as_ml_literal()) .unwrap_or_else(|| { if self.metrics.newline { self.as_ml_basic() } else { self.as_basic() } }) } pub fn as_literal(&self) -> Option> { if self.metrics.escape_codes || 0 < self.metrics.max_seq_single_quotes || self.metrics.newline { None } else { Some(TomlString { decoded: self.decoded, encoding: Encoding::LiteralString, newline: self.metrics.newline, }) } } pub fn as_ml_literal(&self) -> Option> { if self.metrics.escape_codes || 2 < self.metrics.max_seq_single_quotes { None } else { Some(TomlString { decoded: self.decoded, encoding: Encoding::MlLiteralString, newline: self.metrics.newline, }) } } pub fn as_basic_pretty(&self) -> Option> { if self.metrics.escape_codes || self.metrics.escape || 0 < self.metrics.max_seq_double_quotes || self.metrics.newline { None } else { Some(self.as_basic()) } } pub fn as_ml_basic_pretty(&self) -> Option> { if self.metrics.escape_codes || self.metrics.escape || 2 < self.metrics.max_seq_double_quotes { None } else { Some(self.as_ml_basic()) } } pub fn as_basic(&self) -> TomlString<'s> { TomlString { decoded: self.decoded, encoding: Encoding::BasicString, newline: self.metrics.newline, } } pub fn as_ml_basic(&self) -> TomlString<'s> { TomlString { decoded: self.decoded, encoding: Encoding::MlBasicString, newline: self.metrics.newline, } } } #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] pub struct TomlString<'s> { decoded: &'s str, encoding: Encoding, newline: bool, } impl crate::WriteTomlValue for TomlString<'_> { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result { write_toml_value(self.decoded, Some(self.encoding), self.newline, writer) } } #[derive(Copy, Clone, Debug)] pub struct TomlKeyBuilder<'s> { decoded: &'s str, metrics: KeyMetrics, } impl<'s> TomlKeyBuilder<'s> { pub fn new(decoded: &'s str) -> Self { Self { decoded, metrics: KeyMetrics::calculate(decoded), } } pub fn as_default(&self) -> TomlKey<'s> { self.as_unquoted() .or_else(|| self.as_basic_pretty()) .or_else(|| self.as_literal()) .unwrap_or_else(|| self.as_basic()) } pub fn as_unquoted(&self) -> Option> { if self.metrics.unquoted { Some(TomlKey { decoded: self.decoded, encoding: None, }) } else { None } } pub fn as_literal(&self) -> Option> { if self.metrics.escape_codes || self.metrics.single_quotes { None } else { Some(TomlKey { decoded: self.decoded, encoding: Some(Encoding::LiteralString), }) } } pub fn as_basic_pretty(&self) -> Option> { if self.metrics.escape_codes || self.metrics.escape || self.metrics.double_quotes { None } else { Some(self.as_basic()) } } pub fn as_basic(&self) -> TomlKey<'s> { TomlKey { decoded: self.decoded, encoding: Some(Encoding::BasicString), } } } #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] pub struct TomlKey<'s> { decoded: &'s str, encoding: Option, } impl crate::WriteTomlKey for TomlKey<'_> { fn write_toml_key(&self, writer: &mut W) -> core::fmt::Result { let newline = false; write_toml_value(self.decoded, self.encoding, newline, writer) } } #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] #[repr(u8)] #[allow(clippy::enum_variant_names)] enum Encoding { LiteralString, BasicString, MlLiteralString, MlBasicString, } impl Encoding {} fn write_toml_value( decoded: &str, encoding: Option, newline: bool, writer: &mut W, ) -> core::fmt::Result { let delimiter = match encoding { Some(Encoding::LiteralString) => "'", Some(Encoding::BasicString) => "\"", Some(Encoding::MlLiteralString) => "'''", Some(Encoding::MlBasicString) => "\"\"\"", None => "", }; let escaped = match encoding { Some(Encoding::LiteralString) | Some(Encoding::MlLiteralString) => false, Some(Encoding::BasicString) | Some(Encoding::MlBasicString) => true, None => false, }; let is_ml = match encoding { Some(Encoding::LiteralString) | Some(Encoding::BasicString) => false, Some(Encoding::MlLiteralString) | Some(Encoding::MlBasicString) => true, None => false, }; let newline_prefix = newline && is_ml; write!(writer, "{delimiter}")?; if newline_prefix { writer.newline()?; } if escaped { // ```bnf // basic-unescaped = wschar / %x21 / %x23-5B / %x5D-7E / non-ascii // wschar = %x20 ; Space // wschar =/ %x09 ; Horizontal tab // escape = %x5C ; \ // ``` let max_seq_double_quotes = if is_ml { 2 } else { 0 }; let mut stream = decoded; while !stream.is_empty() { let mut unescaped_end = 0; let mut escaped = None; let mut seq_double_quotes = 0; for (i, b) in stream.as_bytes().iter().enumerate() { if *b == b'"' { seq_double_quotes += 1; if max_seq_double_quotes < seq_double_quotes { escaped = Some(r#"\""#); break; } } else { seq_double_quotes = 0; } match *b { 0x8 => { escaped = Some(r#"\b"#); break; } 0x9 => { escaped = Some(r#"\t"#); break; } 0xa => { if !is_ml { escaped = Some(r#"\n"#); break; } } 0xc => { escaped = Some(r#"\f"#); break; } 0xd => { escaped = Some(r#"\r"#); break; } 0x22 => {} // double quote handled earlier 0x5c => { escaped = Some(r#"\\"#); break; } c if c <= 0x1f || c == 0x7f => { break; } _ => {} } unescaped_end = i + 1; } let unescaped = &stream[0..unescaped_end]; let escaped_str = escaped.unwrap_or(""); let end = unescaped_end + if escaped.is_some() { 1 } else { 0 }; stream = &stream[end..]; write!(writer, "{unescaped}{escaped_str}")?; if escaped.is_none() && !stream.is_empty() { let b = stream.as_bytes().first().unwrap(); write!(writer, "\\u{:04X}", *b as u32)?; stream = &stream[1..]; } } } else { write!(writer, "{decoded}")?; } write!(writer, "{delimiter}")?; Ok(()) } #[derive(Copy, Clone, Debug)] struct ValueMetrics { max_seq_single_quotes: u8, max_seq_double_quotes: u8, escape_codes: bool, escape: bool, newline: bool, } impl ValueMetrics { fn new() -> Self { Self { max_seq_single_quotes: 0, max_seq_double_quotes: 0, escape_codes: false, escape: false, newline: false, } } fn calculate(s: &str) -> Self { let mut metrics = Self::new(); let mut prev_single_quotes = 0; let mut prev_double_quotes = 0; for byte in s.as_bytes() { if *byte == b'\'' { prev_single_quotes += 1; metrics.max_seq_single_quotes = metrics.max_seq_single_quotes.max(prev_single_quotes); } else { prev_single_quotes = 0; } if *byte == b'"' { prev_double_quotes += 1; metrics.max_seq_double_quotes = metrics.max_seq_double_quotes.max(prev_double_quotes); } else { prev_double_quotes = 0; } // ```bnf // literal-char = %x09 / %x20-26 / %x28-7E / non-ascii // // basic-unescaped = wschar / %x21 / %x23-5B / %x5D-7E / non-ascii // wschar = %x20 ; Space // wschar =/ %x09 ; Horizontal tab // escape = %x5C ; \ // ``` match *byte { b'\\' => metrics.escape = true, // Escape codes are needed if any ascii control // characters are present, including \b \f \r. b'\t' => {} // always allowed; remaining neutral on this b'\n' => metrics.newline = true, c if c <= 0x1f || c == 0x7f => metrics.escape_codes = true, _ => {} } } metrics } } #[derive(Copy, Clone, Debug)] struct KeyMetrics { unquoted: bool, single_quotes: bool, double_quotes: bool, escape_codes: bool, escape: bool, } impl KeyMetrics { fn new() -> Self { Self { unquoted: true, single_quotes: false, double_quotes: false, escape_codes: false, escape: false, } } fn calculate(s: &str) -> Self { let mut metrics = Self::new(); metrics.unquoted = !s.is_empty(); for byte in s.as_bytes() { if !matches!(*byte, b'a'..=b'z' | b'A'..=b'Z' | b'0'..=b'9' | b'-' | b'_') { metrics.unquoted = false; } // ```bnf // unquoted-key = 1*( ALPHA / DIGIT / %x2D / %x5F ) ; A-Z / a-z / 0-9 / - / _ // // literal-char = %x09 / %x20-26 / %x28-7E / non-ascii // // basic-unescaped = wschar / %x21 / %x23-5B / %x5D-7E / non-ascii // wschar = %x20 ; Space // wschar =/ %x09 ; Horizontal tab // escape = %x5C ; \ // ``` match *byte { b'\'' => metrics.single_quotes = true, b'"' => metrics.double_quotes = true, b'\\' => metrics.escape = true, // Escape codes are needed if any ascii control // characters are present, including \b \f \r. b'\t' => {} // always allowed c if c <= 0x1f || c == 0x7f => metrics.escape_codes = true, _ => {} } } metrics } } toml_writer-1.0.6+spec-1.1.0/src/value.rs000064400000000000000000000161041046102023000160330ustar 00000000000000#[cfg(feature = "alloc")] use alloc::borrow::Cow; #[cfg(feature = "alloc")] use alloc::string::String; #[cfg(feature = "alloc")] use alloc::vec::Vec; use crate::TomlWrite; use crate::WriteTomlKey; #[cfg(feature = "alloc")] pub trait ToTomlValue { fn to_toml_value(&self) -> String; } #[cfg(feature = "alloc")] impl ToTomlValue for T where T: WriteTomlValue + ?Sized, { fn to_toml_value(&self) -> String { let mut result = String::new(); let _ = self.write_toml_value(&mut result); result } } pub trait WriteTomlValue { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result; } impl WriteTomlValue for bool { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result { write!(writer, "{self}") } } impl WriteTomlValue for u8 { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result { write!(writer, "{self}") } } impl WriteTomlValue for i8 { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result { write!(writer, "{self}") } } impl WriteTomlValue for u16 { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result { write!(writer, "{self}") } } impl WriteTomlValue for i16 { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result { write!(writer, "{self}") } } impl WriteTomlValue for u32 { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result { write!(writer, "{self}") } } impl WriteTomlValue for i32 { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result { write!(writer, "{self}") } } impl WriteTomlValue for u64 { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result { write!(writer, "{self}") } } impl WriteTomlValue for i64 { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result { write!(writer, "{self}") } } impl WriteTomlValue for u128 { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result { write!(writer, "{self}") } } impl WriteTomlValue for i128 { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result { write!(writer, "{self}") } } impl WriteTomlValue for f32 { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result { match (self.is_sign_negative(), self.is_nan(), *self == 0.0) { (true, true, _) => write!(writer, "-nan"), (false, true, _) => write!(writer, "nan"), (true, false, true) => write!(writer, "-0.0"), (false, false, true) => write!(writer, "0.0"), (_, false, false) => { if self % 1.0 == 0.0 { write!(writer, "{self}.0") } else { write!(writer, "{self}") } } } } } impl WriteTomlValue for f64 { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result { match (self.is_sign_negative(), self.is_nan(), *self == 0.0) { (true, true, _) => write!(writer, "-nan"), (false, true, _) => write!(writer, "nan"), (true, false, true) => write!(writer, "-0.0"), (false, false, true) => write!(writer, "0.0"), (_, false, false) => { if self % 1.0 == 0.0 { write!(writer, "{self}.0") } else { write!(writer, "{self}") } } } } } impl WriteTomlValue for char { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result { let mut buf = [0; 4]; let v = self.encode_utf8(&mut buf); v.write_toml_value(writer) } } impl WriteTomlValue for str { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result { crate::TomlStringBuilder::new(self) .as_default() .write_toml_value(writer) } } #[cfg(feature = "alloc")] impl WriteTomlValue for String { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result { self.as_str().write_toml_value(writer) } } #[cfg(feature = "alloc")] impl WriteTomlValue for Cow<'_, str> { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result { self.as_ref().write_toml_value(writer) } } impl WriteTomlValue for [V] { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result { writer.open_array()?; let mut iter = self.iter(); if let Some(v) = iter.next() { writer.value(v)?; } for v in iter { writer.val_sep()?; writer.space()?; writer.value(v)?; } writer.close_array()?; Ok(()) } } impl WriteTomlValue for [V; N] { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result { self.as_slice().write_toml_value(writer) } } #[cfg(feature = "alloc")] impl WriteTomlValue for Vec { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result { self.as_slice().write_toml_value(writer) } } #[cfg(feature = "alloc")] impl WriteTomlValue for alloc::collections::BTreeMap { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result { write_toml_inline_table(self.iter(), writer) } } #[cfg(feature = "std")] impl WriteTomlValue for std::collections::HashMap { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result { write_toml_inline_table(self.iter(), writer) } } fn write_toml_inline_table< 'i, I: Iterator, K: WriteTomlKey + 'i, V: WriteTomlValue + 'i, W: TomlWrite + ?Sized, >( mut iter: I, writer: &mut W, ) -> core::fmt::Result { writer.open_inline_table()?; let mut trailing_space = false; if let Some((key, value)) = iter.next() { writer.space()?; writer.key(key)?; writer.space()?; writer.keyval_sep()?; writer.space()?; writer.value(value)?; trailing_space = true; } for (key, value) in iter { writer.val_sep()?; writer.space()?; writer.key(key)?; writer.space()?; writer.keyval_sep()?; writer.space()?; writer.value(value)?; } if trailing_space { writer.space()?; } writer.close_inline_table()?; Ok(()) } impl WriteTomlValue for &V { fn write_toml_value(&self, writer: &mut W) -> core::fmt::Result { (*self).write_toml_value(writer) } } toml_writer-1.0.6+spec-1.1.0/src/write.rs000064400000000000000000000046461046102023000160610ustar 00000000000000pub trait TomlWrite: core::fmt::Write { fn open_table_header(&mut self) -> core::fmt::Result { write!(self, "[") } fn close_table_header(&mut self) -> core::fmt::Result { write!(self, "]") } fn open_array_of_tables_header(&mut self) -> core::fmt::Result { write!(self, "[[") } fn close_array_of_tables_header(&mut self) -> core::fmt::Result { write!(self, "]]") } fn open_inline_table(&mut self) -> core::fmt::Result { write!(self, "{{") } fn close_inline_table(&mut self) -> core::fmt::Result { write!(self, "}}") } fn open_array(&mut self) -> core::fmt::Result { write!(self, "[") } fn close_array(&mut self) -> core::fmt::Result { write!(self, "]") } fn key_sep(&mut self) -> core::fmt::Result { write!(self, ".") } fn keyval_sep(&mut self) -> core::fmt::Result { write!(self, "=") } /// Write an encoded TOML key /// /// To customize the encoding, see [`TomlStringBuilder`][crate::TomlStringBuilder]. fn key(&mut self, value: impl crate::WriteTomlKey) -> core::fmt::Result { value.write_toml_key(self) } /// Write an encoded TOML scalar value /// /// To customize the encoding, see /// - [`TomlStringBuilder`][crate::TomlStringBuilder] /// - [`TomlIntegerFormat`][crate::TomlIntegerFormat] /// ///
/// /// For floats, this preserves the sign bit for [`f32::NAN`] / [`f64::NAN`] for the sake of /// format-preserving editing. /// However, in most cases the sign bit is indeterminate and outputting signed NANs can be a /// cause of non-repeatable behavior. /// /// For general serialization, you should discard the sign bit. For example: /// ``` /// # let mut v = f64::NAN; /// if v.is_nan() { /// v = v.copysign(1.0); /// } /// ``` /// ///
fn value(&mut self, value: impl crate::WriteTomlValue) -> core::fmt::Result { value.write_toml_value(self) } fn val_sep(&mut self) -> core::fmt::Result { write!(self, ",") } fn space(&mut self) -> core::fmt::Result { write!(self, " ") } fn open_comment(&mut self) -> core::fmt::Result { write!(self, "#") } fn newline(&mut self) -> core::fmt::Result { writeln!(self) } } impl TomlWrite for W where W: core::fmt::Write {}