feat: add display UI with splash screen, dashboard, and RSSI sparkline
Implement full SSD1306 OLED display support: - Splash screen on boot (1.5s) with project name, version, board - Dashboard showing radio state, config, counters, RSSI/SNR - RSSI history sparkline (64-sample ring buffer, 2px-wide bars) - DisplayOn/DisplayOff host commands routed via dedicated channel - Pure render functions against generic DrawTarget (no hardware coupling) - Display on/off control bypasses radio task entirely Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
17624 files changed
+4564928
-38
No files matched your search
+1
@@ -0,0 +1 @@
|
||||
{"files":{".cargo_vcs_info.json":"602ebc15c44cbab3ff3084aafcc6f25d1030b2cf730a278399ced751990af9bb","Cargo.lock":"672105159ed0242de4c6c9ff5cee26a663f04ea00393b14f8bd5a2a0fe574f0e","Cargo.toml":"9e153d497c0bd6fa5d5fbd29e56d86c9c3c9cc7bade9b2f7f321858462b6f014","Cargo.toml.orig":"cdb4497ce6745d9971b340b3ef34244f89bd2116793ec2b60683dca9a057fa0a","LICENSE-APACHE":"c6596eb7be8581c18be736c846fb9173b69eccf6ef94c5135893ec56bd92ba08","LICENSE-MIT":"6efb0476a1cc085077ed49357026d8c173bf33017278ef440f222fb9cbcb66e6","README.md":"f6513c96520124ab4d374fa8c959bc064a78522535207a922fb594709c39c48c","src/key.rs":"69e65eb19dfe3ce1b59528b5789fb51c2847276c26bb1a4f0a5ae25b7e7ec127","src/lib.rs":"252a343f0ed17d6322404dda1bf6323074264682d4831f6206643b8c43b7710a","src/string.rs":"e762cf0b8f0f1e7ef6a4ff8636312d9c5c0e3d072d02235a9fedc22b6c8e548f","src/value.rs":"35a959654ab1bcedfd73e5cf5cd6e2c28926ef3ef6838b80f200e12d6bf8ed8c","src/write.rs":"ace21e85cb10bb7db0e0eedcec35be6a5e8cea73faaf24a7948711e2ff9d18ce"},"package":"5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801"}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"git": {
|
||||
"sha1": "838a0223142a2137b530e020cb7231aba46f7946"
|
||||
},
|
||||
"path_in_vcs": "crates/toml_write"
|
||||
}
|
||||
+523
@@ -0,0 +1,523 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
"anstyle-query",
|
||||
"anstyle-wincon",
|
||||
"colorchoice",
|
||||
"is_terminal_polyfill",
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "1.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1"
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-parse"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4"
|
||||
dependencies = [
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-query"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5"
|
||||
dependencies = [
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-wincon"
|
||||
version = "3.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6680de5231bd6ee4c6191b8a1325daa282b415391ec9d3a37bd34f2060dc73fa"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"once_cell_polyfill",
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
|
||||
|
||||
[[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.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "colorchoice"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422"
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fastrand"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a"
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
|
||||
|
||||
[[package]]
|
||||
name = "is-terminal"
|
||||
version = "0.4.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is_terminal_polyfill"
|
||||
version = "1.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b52b2de84ed0341893ce61ca1af04fa54eea0a764ecc38c6855cc5db84dc1927"
|
||||
dependencies = [
|
||||
"is-terminal",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.154"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346"
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.4.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89"
|
||||
|
||||
[[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.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell_polyfill"
|
||||
version = "1.56.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ecf5dec444661aad892044dfcc6ea9b2d1be3db6c78916b91bbf9d903fc3006"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.89"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proptest"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "14cae93065090804185d3b75f0bf93b8eeda30c7a9b4a33d3bdb3988d6229e50"
|
||||
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.36"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_xorshift"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56"
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.38.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys 0.52.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.219"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.219"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "similar"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fa42c91313f1d05da9b26f267f931cf178d4aba455b4c4622dd7355eb80c6640"
|
||||
|
||||
[[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.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e89275301d38033efb81a6e60e3497e734dfcc62571f2854bf4b16690398824c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"fastrand",
|
||||
"rustix",
|
||||
"windows-sys 0.52.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_write"
|
||||
version = "0.1.2"
|
||||
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.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
|
||||
|
||||
[[package]]
|
||||
name = "wait-timeout"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.59.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
||||
dependencies = [
|
||||
"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.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||
Vendored
+179
@@ -0,0 +1,179 @@
|
||||
# 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.66"
|
||||
name = "toml_write"
|
||||
version = "0.1.2"
|
||||
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",
|
||||
]
|
||||
categories = ["encoding"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/toml-rs/toml"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
rustdoc-args = [
|
||||
"--cfg",
|
||||
"docsrs",
|
||||
"--generate-link-to-definition",
|
||||
]
|
||||
|
||||
[[package.metadata.release.pre-release-replacements]]
|
||||
file = "CHANGELOG.md"
|
||||
min = 1
|
||||
replace = "{{version}}"
|
||||
search = "Unreleased"
|
||||
|
||||
[[package.metadata.release.pre-release-replacements]]
|
||||
exactly = 1
|
||||
file = "CHANGELOG.md"
|
||||
replace = "...{{tag_name}}"
|
||||
search = '\.\.\.HEAD'
|
||||
|
||||
[[package.metadata.release.pre-release-replacements]]
|
||||
file = "CHANGELOG.md"
|
||||
min = 1
|
||||
replace = "{{date}}"
|
||||
search = "ReleaseDate"
|
||||
|
||||
[[package.metadata.release.pre-release-replacements]]
|
||||
exactly = 1
|
||||
file = "CHANGELOG.md"
|
||||
replace = """
|
||||
<!-- next-header -->
|
||||
## [Unreleased] - ReleaseDate
|
||||
"""
|
||||
search = "<!-- next-header -->"
|
||||
|
||||
[[package.metadata.release.pre-release-replacements]]
|
||||
exactly = 1
|
||||
file = "CHANGELOG.md"
|
||||
replace = """
|
||||
<!-- next-url -->
|
||||
[Unreleased]: https://github.com/toml-rs/toml/compare/{{tag_name}}...HEAD"""
|
||||
search = "<!-- next-url -->"
|
||||
|
||||
[features]
|
||||
alloc = []
|
||||
default = ["std"]
|
||||
std = ["alloc"]
|
||||
|
||||
[lib]
|
||||
name = "toml_write"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
|
||||
[dev-dependencies.proptest]
|
||||
version = "1.6.0"
|
||||
|
||||
[dev-dependencies.snapbox]
|
||||
version = "0.6.0"
|
||||
|
||||
[dev-dependencies.toml_old]
|
||||
version = "0.5.10"
|
||||
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"
|
||||
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_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"
|
||||
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
|
||||
Vendored
+202
@@ -0,0 +1,202 @@
|
||||
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.
|
||||
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
Copyright (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.
|
||||
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
# toml_write
|
||||
|
||||
[](https://crates.io/crates/toml)
|
||||
[](https://docs.rs/toml)
|
||||
|
||||
A low-level interface for writing out TOML
|
||||
|
||||
## License
|
||||
|
||||
Licensed under either of
|
||||
|
||||
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0>)
|
||||
* MIT license ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)
|
||||
|
||||
at your option.
|
||||
|
||||
### Contribution
|
||||
|
||||
Unless you explicitly state otherwise, any contribution intentionally
|
||||
submitted for inclusion in the work by you, as defined in the Apache-2.0
|
||||
license, shall be dual-licensed as above, without any additional terms or
|
||||
conditions.
|
||||
Vendored
+55
@@ -0,0 +1,55 @@
|
||||
#[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<T> 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<W: TomlWrite + ?Sized>(&self, writer: &mut W) -> core::fmt::Result;
|
||||
}
|
||||
|
||||
impl WriteTomlKey for str {
|
||||
fn write_toml_key<W: TomlWrite + ?Sized>(&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<W: TomlWrite + ?Sized>(&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<W: TomlWrite + ?Sized>(&self, writer: &mut W) -> core::fmt::Result {
|
||||
self.as_ref().write_toml_key(writer)
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: WriteTomlKey + ?Sized> WriteTomlKey for &V {
|
||||
fn write_toml_key<W: TomlWrite + ?Sized>(&self, writer: &mut W) -> core::fmt::Result {
|
||||
(*self).write_toml_key(writer)
|
||||
}
|
||||
}
|
||||
Vendored
+81
@@ -0,0 +1,81 @@
|
||||
//! 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_write::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_auto_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 key;
|
||||
mod string;
|
||||
mod value;
|
||||
mod write;
|
||||
|
||||
#[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;
|
||||
Vendored
+418
@@ -0,0 +1,418 @@
|
||||
#[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<TomlString<'s>> {
|
||||
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<TomlString<'s>> {
|
||||
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<TomlString<'s>> {
|
||||
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<TomlString<'s>> {
|
||||
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<W: crate::TomlWrite + ?Sized>(&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<TomlKey<'s>> {
|
||||
if self.metrics.unquoted {
|
||||
Some(TomlKey {
|
||||
decoded: self.decoded,
|
||||
encoding: None,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_literal(&self) -> Option<TomlKey<'s>> {
|
||||
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<TomlKey<'s>> {
|
||||
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<Encoding>,
|
||||
}
|
||||
|
||||
impl crate::WriteTomlKey for TomlKey<'_> {
|
||||
fn write_toml_key<W: crate::TomlWrite + ?Sized>(&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<W: crate::TomlWrite + ?Sized>(
|
||||
decoded: &str,
|
||||
encoding: Option<Encoding>,
|
||||
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
|
||||
}
|
||||
}
|
||||
Vendored
+249
@@ -0,0 +1,249 @@
|
||||
#[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<T> 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<W: TomlWrite + ?Sized>(&self, writer: &mut W) -> core::fmt::Result;
|
||||
}
|
||||
|
||||
impl WriteTomlValue for bool {
|
||||
fn write_toml_value<W: TomlWrite + ?Sized>(&self, writer: &mut W) -> core::fmt::Result {
|
||||
write!(writer, "{self}")
|
||||
}
|
||||
}
|
||||
|
||||
impl WriteTomlValue for u8 {
|
||||
fn write_toml_value<W: TomlWrite + ?Sized>(&self, writer: &mut W) -> core::fmt::Result {
|
||||
write!(writer, "{self}")
|
||||
}
|
||||
}
|
||||
|
||||
impl WriteTomlValue for i8 {
|
||||
fn write_toml_value<W: TomlWrite + ?Sized>(&self, writer: &mut W) -> core::fmt::Result {
|
||||
write!(writer, "{self}")
|
||||
}
|
||||
}
|
||||
|
||||
impl WriteTomlValue for u16 {
|
||||
fn write_toml_value<W: TomlWrite + ?Sized>(&self, writer: &mut W) -> core::fmt::Result {
|
||||
write!(writer, "{self}")
|
||||
}
|
||||
}
|
||||
|
||||
impl WriteTomlValue for i16 {
|
||||
fn write_toml_value<W: TomlWrite + ?Sized>(&self, writer: &mut W) -> core::fmt::Result {
|
||||
write!(writer, "{self}")
|
||||
}
|
||||
}
|
||||
|
||||
impl WriteTomlValue for u32 {
|
||||
fn write_toml_value<W: TomlWrite + ?Sized>(&self, writer: &mut W) -> core::fmt::Result {
|
||||
write!(writer, "{self}")
|
||||
}
|
||||
}
|
||||
|
||||
impl WriteTomlValue for i32 {
|
||||
fn write_toml_value<W: TomlWrite + ?Sized>(&self, writer: &mut W) -> core::fmt::Result {
|
||||
write!(writer, "{self}")
|
||||
}
|
||||
}
|
||||
|
||||
impl WriteTomlValue for u64 {
|
||||
fn write_toml_value<W: TomlWrite + ?Sized>(&self, writer: &mut W) -> core::fmt::Result {
|
||||
write!(writer, "{self}")
|
||||
}
|
||||
}
|
||||
|
||||
impl WriteTomlValue for i64 {
|
||||
fn write_toml_value<W: TomlWrite + ?Sized>(&self, writer: &mut W) -> core::fmt::Result {
|
||||
write!(writer, "{self}")
|
||||
}
|
||||
}
|
||||
|
||||
impl WriteTomlValue for u128 {
|
||||
fn write_toml_value<W: TomlWrite + ?Sized>(&self, writer: &mut W) -> core::fmt::Result {
|
||||
write!(writer, "{self}")
|
||||
}
|
||||
}
|
||||
|
||||
impl WriteTomlValue for i128 {
|
||||
fn write_toml_value<W: TomlWrite + ?Sized>(&self, writer: &mut W) -> core::fmt::Result {
|
||||
write!(writer, "{self}")
|
||||
}
|
||||
}
|
||||
|
||||
impl WriteTomlValue for f32 {
|
||||
fn write_toml_value<W: TomlWrite + ?Sized>(&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<W: TomlWrite + ?Sized>(&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<W: TomlWrite + ?Sized>(&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<W: TomlWrite + ?Sized>(&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<W: TomlWrite + ?Sized>(&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<W: TomlWrite + ?Sized>(&self, writer: &mut W) -> core::fmt::Result {
|
||||
self.as_ref().write_toml_value(writer)
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: WriteTomlValue> WriteTomlValue for [V] {
|
||||
fn write_toml_value<W: TomlWrite + ?Sized>(&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<V: WriteTomlValue, const N: usize> WriteTomlValue for [V; N] {
|
||||
fn write_toml_value<W: TomlWrite + ?Sized>(&self, writer: &mut W) -> core::fmt::Result {
|
||||
self.as_slice().write_toml_value(writer)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl<V: WriteTomlValue> WriteTomlValue for Vec<V> {
|
||||
fn write_toml_value<W: TomlWrite + ?Sized>(&self, writer: &mut W) -> core::fmt::Result {
|
||||
self.as_slice().write_toml_value(writer)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl<K: WriteTomlKey, V: WriteTomlValue> WriteTomlValue for alloc::collections::BTreeMap<K, V> {
|
||||
fn write_toml_value<W: TomlWrite + ?Sized>(&self, writer: &mut W) -> core::fmt::Result {
|
||||
write_toml_inline_table(self.iter(), writer)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<K: WriteTomlKey, V: WriteTomlValue> WriteTomlValue for std::collections::HashMap<K, V> {
|
||||
fn write_toml_value<W: TomlWrite + ?Sized>(&self, writer: &mut W) -> core::fmt::Result {
|
||||
write_toml_inline_table(self.iter(), writer)
|
||||
}
|
||||
}
|
||||
|
||||
fn write_toml_inline_table<
|
||||
'i,
|
||||
I: Iterator<Item = (&'i K, &'i V)>,
|
||||
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<V: WriteTomlValue + ?Sized> WriteTomlValue for &V {
|
||||
fn write_toml_value<W: TomlWrite + ?Sized>(&self, writer: &mut W) -> core::fmt::Result {
|
||||
(*self).write_toml_value(writer)
|
||||
}
|
||||
}
|
||||
Vendored
+79
@@ -0,0 +1,79 @@
|
||||
pub 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, "=")
|
||||
}
|
||||
|
||||
fn key(&mut self, value: impl crate::WriteTomlKey) -> core::fmt::Result {
|
||||
value.write_toml_key(self)
|
||||
}
|
||||
|
||||
/// <div class="warning">
|
||||
///
|
||||
/// 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);
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// </div>
|
||||
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<W> TomlWrite for W where W: core::fmt::Write {}
|
||||
Reference in new issue
Block a user