zbus_names-4.1.1/.cargo_vcs_info.json0000644000000001500000000000100132010ustar { "git": { "sha1": "db84fa90fdf36d5da87bee3b8de739abae18dabf" }, "path_in_vcs": "zbus_names" }zbus_names-4.1.1/Cargo.lock0000644000000452720000000000100111720ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "aho-corasick" version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] [[package]] name = "anes" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" [[package]] name = "anstyle" version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" [[package]] name = "autocfg" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bumpalo" version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "cast" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "ciborium" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" dependencies = [ "ciborium-io", "ciborium-ll", "serde", ] [[package]] name = "ciborium-io" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" [[package]] name = "ciborium-ll" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" dependencies = [ "ciborium-io", "half", ] [[package]] name = "clap" version = "4.5.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9560b07a799281c7e0958b9296854d6fafd4c5f31444a7e5bb1ad6dde5ccf1bd" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" version = "4.5.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "874e0dd3eb68bf99058751ac9712f622e61e6f393a94f7128fa26e3f02f5c7cd" dependencies = [ "anstyle", "clap_lex", ] [[package]] name = "clap_lex" version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" [[package]] name = "criterion" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" dependencies = [ "anes", "cast", "ciborium", "clap", "criterion-plot", "is-terminal", "itertools", "num-traits", "once_cell", "oorandom", "plotters", "rayon", "regex", "serde", "serde_derive", "serde_json", "tinytemplate", "walkdir", ] [[package]] name = "criterion-plot" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" dependencies = [ "cast", "itertools", ] [[package]] name = "crossbeam-deque" version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" dependencies = [ "crossbeam-epoch", "crossbeam-utils", ] [[package]] name = "crossbeam-epoch" version = "0.9.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" dependencies = [ "crossbeam-utils", ] [[package]] name = "crossbeam-utils" version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" [[package]] name = "crunchy" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "either" version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" [[package]] name = "endi" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3d8a32ae18130a3c84dd492d4215c3d913c3b07c6b63c2eb3eb7ff1101ab7bf" [[package]] name = "enumflags2" version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d232db7f5956f3f14313dc2f87985c58bd2c695ce124c8cdd984e08e15ac133d" dependencies = [ "enumflags2_derive", "serde", ] [[package]] name = "enumflags2_derive" version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de0d48a183585823424a4ce1aa132d174a6a81bd540895822eb4c8373a8e49e8" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "equivalent" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "half" version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" dependencies = [ "cfg-if", "crunchy", ] [[package]] name = "hashbrown" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] name = "hermit-abi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "indexmap" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", "hashbrown", ] [[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", ] [[package]] name = "itertools" version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" dependencies = [ "either", ] [[package]] name = "itoa" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "js-sys" version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" dependencies = [ "wasm-bindgen", ] [[package]] name = "libc" version = "0.2.169" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" [[package]] name = "log" version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "memchr" version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[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 = "oorandom" version = "11.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" [[package]] name = "plotters" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a15b6eccb8484002195a3e44fe65a4ce8e93a625797a063735536fd59cb01cf3" dependencies = [ "num-traits", "plotters-backend", "plotters-svg", "wasm-bindgen", "web-sys", ] [[package]] name = "plotters-backend" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "414cec62c6634ae900ea1c56128dfe87cf63e7caece0852ec76aba307cebadb7" [[package]] name = "plotters-svg" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81b30686a7d9c3e010b84284bdd26a29f2138574f52f5eb6f794fc0ad924e705" dependencies = [ "plotters-backend", ] [[package]] name = "proc-macro-crate" version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" dependencies = [ "toml_edit", ] [[package]] name = "proc-macro2" version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" dependencies = [ "unicode-ident", ] [[package]] name = "quote" version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" dependencies = [ "proc-macro2", ] [[package]] name = "rayon" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" dependencies = [ "either", "rayon-core", ] [[package]] name = "rayon-core" version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" dependencies = [ "crossbeam-deque", "crossbeam-utils", ] [[package]] name = "regex" version = "1.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" dependencies = [ "aho-corasick", "memchr", "regex-automata", "regex-syntax", ] [[package]] name = "regex-automata" version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", "regex-syntax", ] [[package]] name = "regex-syntax" version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "ryu" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "same-file" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" dependencies = [ "winapi-util", ] [[package]] name = "serde" version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "serde_json" version = "1.0.135" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b0d7ba2887406110130a978386c4e1befb98c674b4fba677954e4db976630d9" dependencies = [ "itoa", "memchr", "ryu", "serde", ] [[package]] name = "static_assertions" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "syn" version = "2.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46f71c0377baf4ef1cc3e3402ded576dccc315800fbc62dfc7fe04b009773b4a" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "tinytemplate" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" dependencies = [ "serde", "serde_json", ] [[package]] name = "toml_datetime" version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" [[package]] name = "toml_edit" version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ "indexmap", "toml_datetime", "winnow", ] [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "walkdir" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" dependencies = [ "same-file", "winapi-util", ] [[package]] name = "wasm-bindgen" version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ "cfg-if", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", "syn", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" dependencies = [ "quote", "wasm-bindgen-macro-support", ] [[package]] name = "wasm-bindgen-macro-support" version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "web-sys" version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" dependencies = [ "js-sys", "wasm-bindgen", ] [[package]] name = "winapi-util" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" dependencies = [ "windows-sys", ] [[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-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" [[package]] name = "winnow" version = "0.6.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8d71a593cc5c42ad7876e2c1fda56f314f3754c084128833e64f1345ff8a03a" dependencies = [ "memchr", ] [[package]] name = "zbus_names" version = "4.1.1" dependencies = [ "criterion", "serde", "static_assertions", "winnow", "zvariant", ] [[package]] name = "zvariant" version = "5.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55e6b9b5f1361de2d5e7d9fd1ee5f6f7fcb6060618a1f82f3472f58f2b8d4be9" dependencies = [ "endi", "enumflags2", "serde", "static_assertions", "winnow", "zvariant_derive", "zvariant_utils", ] [[package]] name = "zvariant_derive" version = "5.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "573a8dd76961957108b10f7a45bac6ab1ea3e9b7fe01aff88325dc57bb8f5c8b" dependencies = [ "proc-macro-crate", "proc-macro2", "quote", "syn", "zvariant_utils", ] [[package]] name = "zvariant_utils" version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddd46446ea2a1f353bfda53e35f17633afa79f4fe290a611c94645c69fe96a50" dependencies = [ "proc-macro2", "quote", "serde", "static_assertions", "syn", "winnow", ] zbus_names-4.1.1/Cargo.toml0000644000000030150000000000100112020ustar # 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.77" name = "zbus_names" version = "4.1.1" authors = ["Zeeshan Ali Khan "] build = false autolib = false autobins = false autoexamples = false autotests = false autobenches = false description = "A collection of D-Bus bus names types" readme = "README.md" keywords = [ "D-Bus", "DBus", "IPC", ] categories = ["os::unix-apis"] license = "MIT" repository = "https://github.com/dbus2/zbus/" [package.metadata.docs.rs] all-features = true targets = ["x86_64-unknown-linux-gnu"] [lib] name = "zbus_names" path = "src/lib.rs" bench = false [[bench]] name = "benchmarks" path = "benches/benchmarks.rs" harness = false [dependencies.serde] version = "1.0.200" features = ["derive"] [dependencies.static_assertions] version = "1.1.0" [dependencies.winnow] version = "0.6" [dependencies.zvariant] version = "5.0.0" features = ["enumflags2"] default-features = false [dev-dependencies.criterion] version = "0.5.1" [lints.rust.unexpected_cfgs] level = "warn" priority = 0 check-cfg = ["cfg(tokio_unstable)"] zbus_names-4.1.1/Cargo.toml.orig000064400000000000000000000014721046102023000146700ustar 00000000000000[package] name = "zbus_names" version = "4.1.1" authors = ["Zeeshan Ali Khan "] edition = { workspace = true } rust-version = { workspace = true } description = "A collection of D-Bus bus names types" repository = { workspace = true } keywords = ["D-Bus", "DBus", "IPC"] license = { workspace = true } categories = ["os::unix-apis"] readme = "README.md" [dependencies] serde = { version = "1.0.200", features = ["derive"] } zvariant = { path = "../zvariant", version = "5.0.0", default-features = false, features = [ "enumflags2", ] } static_assertions = "1.1.0" winnow = "0.6" [dev-dependencies] criterion = "0.5.1" [lib] bench = false [[bench]] name = "benchmarks" harness = false [package.metadata.docs.rs] all-features = true targets = ["x86_64-unknown-linux-gnu"] [lints] workspace = true zbus_names-4.1.1/LICENSE000064400000000000000000000020701046102023000130010ustar 00000000000000Copyright (c) 2024 Zeeshan Ali Khan & zbus 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. zbus_names-4.1.1/README.md000064400000000000000000000013721046102023000132570ustar 00000000000000# zbus_names [![](https://docs.rs/zbus_names/badge.svg)](https://docs.rs/zbus_names/) [![](https://img.shields.io/crates/v/zbus_names)](https://crates.io/crates/zbus_names) This crate provides collection of types for various [D-Bus bus names][dbn]. This is used by [`zbus`] (and in future by [`zbus_macros`] as well) crate. Other D-Bus crates are also encouraged to use this API in the spirit of cooperation. :) For convenience, `zbus` re-exports this crate as `names`, so you do not need to depend directly on this crate if you already depend on `zbus`. **Status:** Stable. [dbn]: https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names [`zbus`]: https://crates.io/crates/zbus [`zbus_macros`]: https://crates.io/crates/zbus_macros zbus_names-4.1.1/benches/benchmarks.rs000064400000000000000000000037441046102023000160770ustar 00000000000000use criterion::{black_box, criterion_group, criterion_main, Criterion}; fn name_parse(c: &mut Criterion) { const WELL_KNOWN_NAME: &str = "a.very.loooooooooooooooooo-ooooooo_0000o0ng.Name.\ That.Is.Valid.For.DBus.and_good.For.benchmarks.I-guess"; const UNIQUE_NAME: &str = ":a.very.loooooooooooooooooo-ooooooo_0000o0ng.Name.\ That.Is.Valid.For.DBus.and_good.For.benchmarks.I-guess"; const INTERFACE_NAME: &str = "a.very.loooooooooooooooooo_ooooooo_0000o0ng.Name.\ That.Is.Valid.For.DBus.and_good.For.benchmarks.I_guess"; const MEMBER_NAME: &str = "a_very_loooooooooooooooooo_ooooooo_0000o0ng_Name_\ That_Is_Valid_For_DBus_and_good_For_benchmarks_I_guess"; let mut group = c.benchmark_group("parse_name"); group.sample_size(1000); group.bench_function("well_known", |b| { b.iter(|| { zbus_names::WellKnownName::try_from(black_box(WELL_KNOWN_NAME)).unwrap(); }) }); group.bench_function("unique", |b| { b.iter(|| { zbus_names::UniqueName::try_from(black_box(UNIQUE_NAME)).unwrap(); }) }); group.bench_function("bus", |b| { b.iter(|| { // Use a well-known name since the parser first tries unique name. zbus_names::BusName::try_from(black_box(WELL_KNOWN_NAME)).unwrap(); }) }); group.bench_function("interface", |b| { b.iter(|| { zbus_names::InterfaceName::try_from(black_box(INTERFACE_NAME)).unwrap(); }) }); group.bench_function("error", |b| { b.iter(|| { // Error names follow the same rules are interface names. zbus_names::ErrorName::try_from(black_box(INTERFACE_NAME)).unwrap(); }) }); group.bench_function("member", |b| { b.iter(|| { zbus_names::MemberName::try_from(black_box(MEMBER_NAME)).unwrap(); }) }); group.finish(); } criterion_group!(benches, name_parse); criterion_main!(benches); zbus_names-4.1.1/src/bus_name.rs000064400000000000000000000346101046102023000147270ustar 00000000000000use core::{ borrow::Borrow, fmt::{self, Debug, Display, Formatter}, ops::Deref, }; use std::{borrow::Cow, sync::Arc}; use crate::{ unique_name, utils::impl_str_basic, well_known_name, Error, OwnedUniqueName, OwnedWellKnownName, Result, UniqueName, WellKnownName, }; use serde::{de, Deserialize, Serialize}; use static_assertions::assert_impl_all; use zvariant::{NoneValue, OwnedValue, Str, Type, Value}; /// String that identifies a [bus name]. /// /// # Examples /// /// ``` /// use zbus_names::BusName; /// /// // Valid well-known names. /// let name = BusName::try_from("org.gnome.Service-for_you").unwrap(); /// assert!(matches!(name, BusName::WellKnown(_))); /// assert_eq!(name, "org.gnome.Service-for_you"); /// let name = BusName::try_from("a.very.loooooooooooooooooo-ooooooo_0000o0ng.Name").unwrap(); /// assert!(matches!(name, BusName::WellKnown(_))); /// assert_eq!(name, "a.very.loooooooooooooooooo-ooooooo_0000o0ng.Name"); /// /// // Valid unique names. /// let name = BusName::try_from(":org.gnome.Service-for_you").unwrap(); /// assert!(matches!(name, BusName::Unique(_))); /// assert_eq!(name, ":org.gnome.Service-for_you"); /// let name = BusName::try_from(":a.very.loooooooooooooooooo-ooooooo_0000o0ng.Name").unwrap(); /// assert!(matches!(name, BusName::Unique(_))); /// assert_eq!(name, ":a.very.loooooooooooooooooo-ooooooo_0000o0ng.Name"); /// /// // Invalid bus names /// BusName::try_from("").unwrap_err(); /// BusName::try_from("double..dots").unwrap_err(); /// BusName::try_from(".").unwrap_err(); /// BusName::try_from(".start.with.dot").unwrap_err(); /// BusName::try_from("1start.with.digit").unwrap_err(); /// BusName::try_from("no-dots").unwrap_err(); /// ``` /// /// [bus name]: https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus #[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize)] #[serde(untagged)] pub enum BusName<'name> { #[serde(borrow)] Unique(UniqueName<'name>), #[serde(borrow)] WellKnown(WellKnownName<'name>), } assert_impl_all!(BusName<'_>: Send, Sync, Unpin); impl_str_basic!(BusName<'_>); impl BusName<'_> { /// This is faster than `Clone::clone` when `self` contains owned data. pub fn as_ref(&self) -> BusName<'_> { match self { BusName::Unique(name) => BusName::Unique(name.as_ref()), BusName::WellKnown(name) => BusName::WellKnown(name.as_ref()), } } /// The well-known-name as string. pub fn as_str(&self) -> &str { match self { BusName::Unique(name) => name.as_str(), BusName::WellKnown(name) => name.as_str(), } } /// Creates an owned clone of `self`. pub fn to_owned(&self) -> BusName<'static> { match self { BusName::Unique(name) => BusName::Unique(name.to_owned()), BusName::WellKnown(name) => BusName::WellKnown(name.to_owned()), } } /// Creates an owned clone of `self`. pub fn into_owned(self) -> BusName<'static> { match self { BusName::Unique(name) => BusName::Unique(name.into_owned()), BusName::WellKnown(name) => BusName::WellKnown(name.into_owned()), } } /// Same as `try_from`, except it takes a `&'static str`. pub fn from_static_str(name: &'static str) -> Result { match Self::try_from(name)? { BusName::Unique(_) => Ok(BusName::Unique(UniqueName::from_static_str_unchecked(name))), BusName::WellKnown(_) => Ok(BusName::WellKnown( WellKnownName::from_static_str_unchecked(name), )), } } } impl Deref for BusName<'_> { type Target = str; fn deref(&self) -> &Self::Target { self.as_str() } } impl Borrow for BusName<'_> { fn borrow(&self) -> &str { self.as_str() } } impl Debug for BusName<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { BusName::Unique(name) => f .debug_tuple("BusName::Unique") .field(&name.as_str()) .finish(), BusName::WellKnown(name) => f .debug_tuple("BusName::WellKnown") .field(&name.as_str()) .finish(), } } } impl Display for BusName<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { Display::fmt(&self.as_str(), f) } } impl PartialEq for BusName<'_> { fn eq(&self, other: &str) -> bool { self.as_str() == other } } impl PartialEq<&str> for BusName<'_> { fn eq(&self, other: &&str) -> bool { self.as_str() == *other } } impl PartialEq for BusName<'_> { fn eq(&self, other: &OwnedBusName) -> bool { *self == other.0 } } impl PartialEq> for BusName<'_> { fn eq(&self, other: &UniqueName<'_>) -> bool { match self { Self::Unique(name) => *name == *other, Self::WellKnown(_) => false, } } } impl PartialEq> for BusName<'_> { fn eq(&self, other: &WellKnownName<'_>) -> bool { match self { Self::Unique(_) => false, Self::WellKnown(name) => *name == *other, } } } impl<'name> NoneValue for BusName<'name> { type NoneType = &'name str; fn null_value() -> Self::NoneType { <&str>::default() } } // Manual deserialize implementation to get the desired error on invalid bus names. impl<'de: 'name, 'name> Deserialize<'de> for BusName<'name> { fn deserialize(deserializer: D) -> core::result::Result where D: serde::Deserializer<'de>, { let name = >::deserialize(deserializer)?; Self::try_from(name).map_err(|e| de::Error::custom(e.to_string())) } } impl Type for BusName<'_> { const SIGNATURE: &'static zvariant::Signature = &zvariant::Signature::Str; } impl<'name> From> for BusName<'name> { fn from(name: UniqueName<'name>) -> Self { BusName::Unique(name) } } impl<'name> From> for BusName<'name> { fn from(name: WellKnownName<'name>) -> Self { BusName::WellKnown(name) } } impl<'s> TryFrom> for BusName<'s> { type Error = Error; fn try_from(value: Str<'s>) -> Result { if unique_name::validate_bytes(value.as_bytes()).is_ok() { Ok(BusName::Unique(UniqueName(value))) } else if well_known_name::validate_bytes(value.as_bytes()).is_ok() { Ok(BusName::WellKnown(WellKnownName(value))) } else { Err(Error::InvalidName(INVALID_BUS_NAME_ERROR)) } } } impl<'s> TryFrom> for WellKnownName<'s> { type Error = Error; fn try_from(value: BusName<'s>) -> Result { match value { BusName::Unique(_) => Err(Error::InvalidNameConversion { from: "UniqueName", to: "WellKnownName", }), BusName::WellKnown(name) => Ok(name), } } } impl<'s> TryFrom> for UniqueName<'s> { type Error = Error; fn try_from(value: BusName<'s>) -> Result { match value { BusName::Unique(name) => Ok(name), BusName::WellKnown(_) => Err(Error::InvalidNameConversion { from: "WellKnownName", to: "UniqueName", }), } } } impl<'s> TryFrom<&'s str> for BusName<'s> { type Error = Error; fn try_from(value: &'s str) -> Result { Str::from(value).try_into() } } impl TryFrom for BusName<'_> { type Error = Error; fn try_from(value: String) -> Result { Str::from(value).try_into() } } impl TryFrom> for BusName<'_> { type Error = Error; fn try_from(value: Arc) -> Result { Str::from(value).try_into() } } impl<'s> TryFrom> for BusName<'s> { type Error = Error; fn try_from(value: Value<'s>) -> Result { Str::try_from(value) .map_err(Into::into) .and_then(TryInto::try_into) } } /// This never succeeds but is provided so it's easier to pass `Option::None` values for API /// requiring `Option>`, since type inference won't work here. impl TryFrom<()> for BusName<'_> { type Error = Error; fn try_from(_value: ()) -> Result { unreachable!("Conversion from `()` is not meant to actually work."); } } impl<'name> TryFrom> for BusName<'name> { type Error = Error; fn try_from(value: Cow<'name, str>) -> Result { Str::from(value).try_into() } } impl<'s> From> for Value<'s> { fn from(name: BusName<'s>) -> Self { match name { BusName::Unique(name) => name.into(), BusName::WellKnown(name) => name.into(), } } } impl<'name> From> for Str<'name> { fn from(value: BusName<'name>) -> Self { match value { BusName::Unique(name) => name.into(), BusName::WellKnown(name) => name.into(), } } } impl<'name> From<&BusName<'name>> for BusName<'name> { fn from(name: &BusName<'name>) -> Self { name.clone() } } impl TryFrom for BusName<'_> { type Error = Error; fn try_from(value: OwnedValue) -> Result { Str::try_from(value) .map_err(Into::into) .and_then(TryInto::try_into) } } impl TryFrom> for OwnedValue { type Error = Error; fn try_from(name: BusName<'static>) -> Result { match name { BusName::Unique(name) => name.try_into(), BusName::WellKnown(name) => name.try_into(), } .map_err(Into::into) } } impl From for BusName<'_> { fn from(name: OwnedUniqueName) -> Self { BusName::Unique(name.into()) } } impl<'a> From<&'a OwnedUniqueName> for BusName<'a> { fn from(name: &'a OwnedUniqueName) -> Self { BusName::Unique(name.into()) } } impl From for BusName<'_> { fn from(name: OwnedWellKnownName) -> Self { BusName::WellKnown(name.into()) } } impl<'a> From<&'a OwnedWellKnownName> for BusName<'a> { fn from(name: &'a OwnedWellKnownName) -> Self { BusName::WellKnown(name.into()) } } /// Owned sibling of [`BusName`]. #[derive(Clone, Hash, PartialEq, Eq, Serialize, PartialOrd, Ord, Type)] pub struct OwnedBusName(#[serde(borrow)] BusName<'static>); impl_str_basic!(OwnedBusName); impl OwnedBusName { /// Convert to the inner `BusName`, consuming `self`. pub fn into_inner(self) -> BusName<'static> { self.0 } /// Get a reference to the inner `BusName`. pub fn inner(&self) -> &BusName<'static> { &self.0 } } impl Deref for OwnedBusName { type Target = BusName<'static>; fn deref(&self) -> &Self::Target { &self.0 } } impl Borrow for OwnedBusName { fn borrow(&self) -> &str { self.0.as_str() } } impl Debug for OwnedBusName { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match &self.0 { BusName::Unique(name) => f .debug_tuple("OwnedBusName::Unique") .field(&name.as_str()) .finish(), BusName::WellKnown(name) => f .debug_tuple("OwnedBusName::WellKnown") .field(&name.as_str()) .finish(), } } } impl Display for OwnedBusName { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { Display::fmt(&BusName::from(self), f) } } impl From for BusName<'_> { fn from(name: OwnedBusName) -> Self { name.into_inner() } } impl<'unowned, 'owned: 'unowned> From<&'owned OwnedBusName> for BusName<'unowned> { fn from(name: &'owned OwnedBusName) -> Self { match &name.0 { BusName::Unique(name) => BusName::Unique(UniqueName::from_str_unchecked(name)), BusName::WellKnown(name) => BusName::WellKnown(WellKnownName::from_str_unchecked(name)), } } } impl From> for OwnedBusName { fn from(name: BusName<'_>) -> Self { OwnedBusName(name.into_owned()) } } impl TryFrom<&'_ str> for OwnedBusName { type Error = Error; fn try_from(value: &str) -> Result { BusName::try_from(value).map(Self::from) } } impl TryFrom for OwnedBusName { type Error = Error; fn try_from(value: String) -> Result { BusName::try_from(value).map(Self::from) } } impl TryFrom> for OwnedBusName { type Error = Error; fn try_from(value: Cow<'_, str>) -> Result { BusName::try_from(value).map(Self::from) } } impl TryFrom> for OwnedBusName { type Error = Error; fn try_from(value: Value<'static>) -> Result { BusName::try_from(value).map(Self::from) } } impl From for Value<'_> { fn from(name: OwnedBusName) -> Self { name.0.into() } } impl TryFrom for OwnedBusName { type Error = Error; fn try_from(value: OwnedValue) -> Result { BusName::try_from(value).map(Self::from) } } impl TryFrom for OwnedValue { type Error = Error; fn try_from(name: OwnedBusName) -> Result { name.0.try_into() } } impl From for Str<'_> { fn from(value: OwnedBusName) -> Self { match value.0 { BusName::Unique(name) => name.into(), BusName::WellKnown(name) => name.into(), } } } impl<'de> Deserialize<'de> for OwnedBusName { fn deserialize(deserializer: D) -> std::result::Result where D: de::Deserializer<'de>, { String::deserialize(deserializer) .and_then(|n| BusName::try_from(n).map_err(|e| de::Error::custom(e.to_string()))) .map(Self) } } impl PartialEq<&str> for OwnedBusName { fn eq(&self, other: &&str) -> bool { self.as_str() == *other } } impl PartialEq> for OwnedBusName { fn eq(&self, other: &BusName<'_>) -> bool { self.0 == *other } } impl NoneValue for OwnedBusName { type NoneType = as NoneValue>::NoneType; fn null_value() -> Self::NoneType { BusName::null_value() } } const INVALID_BUS_NAME_ERROR: &str = "Invalid bus name. \ See https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus"; zbus_names-4.1.1/src/error.rs000064400000000000000000000125721046102023000142720ustar 00000000000000use static_assertions::assert_impl_all; use std::{convert::Infallible, error, fmt}; use zvariant::Error as VariantError; /// The error type for `zbus_names`. /// /// The various errors that can be reported by this crate. #[derive(Clone, Debug)] #[non_exhaustive] pub enum Error { Variant(VariantError), /// Invalid bus name. The strings describe why the bus name is neither a valid unique nor /// well-known name, respectively. #[deprecated( since = "4.1.0", note = "This variant is no longer returned from any of our API.\ Use `Error::InvalidName` instead." )] InvalidBusName(String, String), /// Invalid well-known bus name. #[deprecated( since = "4.1.0", note = "This variant is no longer returned from any of our API.\ Use `Error::InvalidName` instead." )] InvalidWellKnownName(String), /// Invalid unique bus name. #[deprecated( since = "4.1.0", note = "This variant is no longer returned from any of our API.\ Use `Error::InvalidName` instead." )] InvalidUniqueName(String), /// Invalid interface name. #[deprecated( since = "4.1.0", note = "This variant is no longer returned from any of our API.\ Use `Error::InvalidName` instead." )] InvalidInterfaceName(String), /// Invalid member (method or signal) name. #[deprecated( since = "4.1.0", note = "This variant is no longer returned from any of our API.\ Use `Error::InvalidName` instead." )] InvalidMemberName(String), /// Invalid property name. #[deprecated( since = "4.1.0", note = "This variant is no longer returned from any of our API.\ Use `Error::InvalidName` instead." )] InvalidPropertyName(String), /// Invalid error name. #[deprecated( since = "4.1.0", note = "This variant is no longer returned from any of our API.\ Use `Error::InvalidName` instead." )] InvalidErrorName(String), /// An invalid name. InvalidName(&'static str), /// Invalid conversion from name type `from` to name type `to`. InvalidNameConversion { from: &'static str, to: &'static str, }, } assert_impl_all!(Error: Send, Sync, Unpin); impl PartialEq for Error { #[allow(deprecated)] fn eq(&self, other: &Self) -> bool { match (self, other) { (Self::InvalidBusName(_, _), Self::InvalidBusName(_, _)) => true, (Self::InvalidWellKnownName(_), Self::InvalidWellKnownName(_)) => true, (Self::InvalidUniqueName(_), Self::InvalidUniqueName(_)) => true, (Self::InvalidInterfaceName(_), Self::InvalidInterfaceName(_)) => true, (Self::InvalidMemberName(_), Self::InvalidMemberName(_)) => true, (Self::InvalidPropertyName(_), Self::InvalidPropertyName(_)) => true, (Self::InvalidErrorName(_), Self::InvalidErrorName(_)) => true, (Self::InvalidName(_), Self::InvalidName(_)) => true, (Self::InvalidNameConversion { .. }, Self::InvalidNameConversion { .. }) => true, (Self::Variant(s), Self::Variant(o)) => s == o, (_, _) => false, } } } impl error::Error for Error { #[allow(deprecated)] fn source(&self) -> Option<&(dyn error::Error + 'static)> { match self { Error::InvalidBusName(_, _) => None, Error::InvalidWellKnownName(_) => None, Error::InvalidUniqueName(_) => None, Error::InvalidInterfaceName(_) => None, Error::InvalidErrorName(_) => None, Error::InvalidMemberName(_) => None, Error::InvalidPropertyName(_) => None, Error::InvalidName(_) => None, Error::InvalidNameConversion { .. } => None, Error::Variant(e) => Some(e), } } } impl fmt::Display for Error { #[allow(deprecated)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Error::Variant(e) => write!(f, "{e}"), Error::InvalidBusName(unique_err, well_known_err) => { write!( f, "Neither a valid unique ({unique_err}) nor a well-known ({well_known_err}) bus name" ) } Error::InvalidWellKnownName(s) => write!(f, "Invalid well-known bus name: {s}"), Error::InvalidUniqueName(s) => write!(f, "Invalid unique bus name: {s}"), Error::InvalidInterfaceName(s) => write!(f, "Invalid interface or error name: {s}"), Error::InvalidErrorName(s) => write!(f, "Invalid interface or error name: {s}"), Error::InvalidMemberName(s) => write!(f, "Invalid method or signal name: {s}"), Error::InvalidPropertyName(s) => write!(f, "Invalid property name: {s}"), Error::InvalidName(s) => write!(f, "{s}"), Error::InvalidNameConversion { from, to } => { write!(f, "Invalid conversion from `{from}` to `{to}`") } } } } impl From for Error { fn from(val: VariantError) -> Self { Error::Variant(val) } } impl From for Error { fn from(i: Infallible) -> Self { match i {} } } /// Alias for a `Result` with the error type `zbus_names::Error`. pub type Result = std::result::Result; zbus_names-4.1.1/src/error_name.rs000064400000000000000000000177771046102023000153060ustar 00000000000000use crate::{ utils::{impl_str_basic, impl_try_from}, Error, Result, }; use serde::{de, Deserialize, Serialize}; use static_assertions::assert_impl_all; use std::{ borrow::{Borrow, Cow}, fmt::{self, Debug, Display, Formatter}, ops::Deref, sync::Arc, }; use zvariant::{NoneValue, OwnedValue, Str, Type, Value}; /// String that identifies an [error name][en] on the bus. /// /// Error names have same constraints as error names. /// /// # Examples /// /// ``` /// use zbus_names::ErrorName; /// /// // Valid error names. /// let name = ErrorName::try_from("org.gnome.Error_for_you").unwrap(); /// assert_eq!(name, "org.gnome.Error_for_you"); /// let name = ErrorName::try_from("a.very.loooooooooooooooooo_ooooooo_0000o0ng.ErrorName").unwrap(); /// assert_eq!(name, "a.very.loooooooooooooooooo_ooooooo_0000o0ng.ErrorName"); /// /// // Invalid error names /// ErrorName::try_from("").unwrap_err(); /// ErrorName::try_from(":start.with.a.colon").unwrap_err(); /// ErrorName::try_from("double..dots").unwrap_err(); /// ErrorName::try_from(".").unwrap_err(); /// ErrorName::try_from(".start.with.dot").unwrap_err(); /// ErrorName::try_from("no-dots").unwrap_err(); /// ErrorName::try_from("1st.element.starts.with.digit").unwrap_err(); /// ErrorName::try_from("the.2nd.element.starts.with.digit").unwrap_err(); /// ErrorName::try_from("contains.dashes-in.the.name").unwrap_err(); /// ``` /// /// [en]: https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-error #[derive( Clone, Debug, Hash, PartialEq, Eq, Serialize, Type, Value, PartialOrd, Ord, OwnedValue, )] pub struct ErrorName<'name>(Str<'name>); assert_impl_all!(ErrorName<'_>: Send, Sync, Unpin); impl_str_basic!(ErrorName<'_>); impl<'name> ErrorName<'name> { /// This is faster than `Clone::clone` when `self` contains owned data. pub fn as_ref(&self) -> ErrorName<'_> { ErrorName(self.0.as_ref()) } /// The error name as string. pub fn as_str(&self) -> &str { self.0.as_str() } /// Create a new `ErrorName` from the given string. /// /// Since the passed string is not checked for correctness, prefer using the /// `TryFrom<&str>` implementation. pub fn from_str_unchecked(name: &'name str) -> Self { Self(Str::from(name)) } /// Same as `try_from`, except it takes a `&'static str`. pub fn from_static_str(name: &'static str) -> Result { validate(name)?; Ok(Self(Str::from_static(name))) } /// Same as `from_str_unchecked`, except it takes a `&'static str`. pub const fn from_static_str_unchecked(name: &'static str) -> Self { Self(Str::from_static(name)) } /// Same as `from_str_unchecked`, except it takes an owned `String`. /// /// Since the passed string is not checked for correctness, prefer using the /// `TryFrom` implementation. pub fn from_string_unchecked(name: String) -> Self { Self(Str::from(name)) } /// Creates an owned clone of `self`. pub fn to_owned(&self) -> ErrorName<'static> { ErrorName(self.0.to_owned()) } /// Creates an owned clone of `self`. pub fn into_owned(self) -> ErrorName<'static> { ErrorName(self.0.into_owned()) } } impl Deref for ErrorName<'_> { type Target = str; fn deref(&self) -> &Self::Target { self.as_str() } } impl Borrow for ErrorName<'_> { fn borrow(&self) -> &str { self.as_str() } } impl Display for ErrorName<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { Display::fmt(&self.as_str(), f) } } impl PartialEq for ErrorName<'_> { fn eq(&self, other: &str) -> bool { self.as_str() == other } } impl PartialEq<&str> for ErrorName<'_> { fn eq(&self, other: &&str) -> bool { self.as_str() == *other } } impl PartialEq for ErrorName<'_> { fn eq(&self, other: &OwnedErrorName) -> bool { *self == other.0 } } impl<'de: 'name, 'name> Deserialize<'de> for ErrorName<'name> { fn deserialize(deserializer: D) -> core::result::Result where D: serde::Deserializer<'de>, { let name = >::deserialize(deserializer)?; Self::try_from(name).map_err(|e| de::Error::custom(e.to_string())) } } impl_try_from! { ty: ErrorName<'s>, owned_ty: OwnedErrorName, validate_fn: validate, try_from: [&'s str, String, Arc, Cow<'s, str>, Str<'s>], } fn validate(name: &str) -> Result<()> { // Error names follow the same rules as interface names. crate::interface_name::validate_bytes(name.as_bytes()).map_err(|_| { Error::InvalidName( "Invalid error name. See \ https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-error", ) }) } /// This never succeeds but is provided so it's easier to pass `Option::None` values for API /// requiring `Option>`, since type inference won't work here. impl TryFrom<()> for ErrorName<'_> { type Error = Error; fn try_from(_value: ()) -> Result { unreachable!("Conversion from `()` is not meant to actually work"); } } impl<'name> From<&ErrorName<'name>> for ErrorName<'name> { fn from(name: &ErrorName<'name>) -> Self { name.clone() } } impl<'name> From> for Str<'name> { fn from(value: ErrorName<'name>) -> Self { value.0 } } impl<'name> NoneValue for ErrorName<'name> { type NoneType = &'name str; fn null_value() -> Self::NoneType { <&str>::default() } } /// Owned sibling of [`ErrorName`]. #[derive(Clone, Hash, PartialEq, Eq, Serialize, Type, Value, PartialOrd, Ord, OwnedValue)] pub struct OwnedErrorName(#[serde(borrow)] ErrorName<'static>); assert_impl_all!(OwnedErrorName: Send, Sync, Unpin); impl_str_basic!(OwnedErrorName); impl OwnedErrorName { /// Convert to the inner `ErrorName`, consuming `self`. pub fn into_inner(self) -> ErrorName<'static> { self.0 } /// Get a reference to the inner `ErrorName`. pub fn inner(&self) -> &ErrorName<'static> { &self.0 } } impl Deref for OwnedErrorName { type Target = ErrorName<'static>; fn deref(&self) -> &Self::Target { &self.0 } } impl Borrow for OwnedErrorName { fn borrow(&self) -> &str { self.0.as_str() } } impl From for ErrorName<'_> { fn from(o: OwnedErrorName) -> Self { o.into_inner() } } impl<'unowned, 'owned: 'unowned> From<&'owned OwnedErrorName> for ErrorName<'unowned> { fn from(name: &'owned OwnedErrorName) -> Self { ErrorName::from_str_unchecked(name.as_str()) } } impl From> for OwnedErrorName { fn from(name: ErrorName<'_>) -> Self { OwnedErrorName(name.into_owned()) } } impl From for Str<'_> { fn from(value: OwnedErrorName) -> Self { value.into_inner().0 } } impl<'de> Deserialize<'de> for OwnedErrorName { fn deserialize(deserializer: D) -> std::result::Result where D: de::Deserializer<'de>, { String::deserialize(deserializer) .and_then(|n| ErrorName::try_from(n).map_err(|e| de::Error::custom(e.to_string()))) .map(Self) } } impl PartialEq<&str> for OwnedErrorName { fn eq(&self, other: &&str) -> bool { self.as_str() == *other } } impl PartialEq> for OwnedErrorName { fn eq(&self, other: &ErrorName<'_>) -> bool { self.0 == *other } } impl Debug for OwnedErrorName { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_tuple("OwnedErrorName") .field(&self.as_str()) .finish() } } impl Display for OwnedErrorName { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { Display::fmt(&ErrorName::from(self), f) } } impl NoneValue for OwnedErrorName { type NoneType = as NoneValue>::NoneType; fn null_value() -> Self::NoneType { ErrorName::null_value() } } zbus_names-4.1.1/src/interface_name.rs000064400000000000000000000225241046102023000160770ustar 00000000000000use crate::{ utils::{impl_str_basic, impl_try_from}, Error, Result, }; use serde::{de, Deserialize, Serialize}; use static_assertions::assert_impl_all; use std::{ borrow::{Borrow, Cow}, fmt::{self, Debug, Display, Formatter}, ops::Deref, sync::Arc, }; use zvariant::{NoneValue, OwnedValue, Str, Type, Value}; /// String that identifies an [interface name][in] on the bus. /// /// # Examples /// /// ``` /// use zbus_names::InterfaceName; /// /// // Valid interface names. /// let name = InterfaceName::try_from("org.gnome.Interface_for_you").unwrap(); /// assert_eq!(name, "org.gnome.Interface_for_you"); /// let name = InterfaceName::try_from("a.very.loooooooooooooooooo_ooooooo_0000o0ng.Name").unwrap(); /// assert_eq!(name, "a.very.loooooooooooooooooo_ooooooo_0000o0ng.Name"); /// /// // Invalid interface names /// InterfaceName::try_from("").unwrap_err(); /// InterfaceName::try_from(":start.with.a.colon").unwrap_err(); /// InterfaceName::try_from("double..dots").unwrap_err(); /// InterfaceName::try_from(".").unwrap_err(); /// InterfaceName::try_from(".start.with.dot").unwrap_err(); /// InterfaceName::try_from("no-dots").unwrap_err(); /// InterfaceName::try_from("1st.element.starts.with.digit").unwrap_err(); /// InterfaceName::try_from("the.2nd.element.starts.with.digit").unwrap_err(); /// InterfaceName::try_from("contains.dashes-in.the.name").unwrap_err(); /// ``` /// /// [in]: https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-interface #[derive( Clone, Debug, Hash, PartialEq, Eq, Serialize, Type, Value, PartialOrd, Ord, OwnedValue, )] pub struct InterfaceName<'name>(Str<'name>); impl_str_basic!(InterfaceName<'_>); assert_impl_all!(InterfaceName<'_>: Send, Sync, Unpin); impl<'name> InterfaceName<'name> { /// This is faster than `Clone::clone` when `self` contains owned data. pub fn as_ref(&self) -> InterfaceName<'_> { InterfaceName(self.0.as_ref()) } /// The interface name as string. pub fn as_str(&self) -> &str { self.0.as_str() } /// Create a new `InterfaceName` from the given string. /// /// Since the passed string is not checked for correctness, prefer using the /// `TryFrom<&str>` implementation. pub fn from_str_unchecked(name: &'name str) -> Self { Self(Str::from(name)) } /// Same as `try_from`, except it takes a `&'static str`. pub fn from_static_str(name: &'static str) -> Result { validate(name)?; Ok(Self(Str::from_static(name))) } /// Same as `from_str_unchecked`, except it takes a `&'static str`. pub const fn from_static_str_unchecked(name: &'static str) -> Self { Self(Str::from_static(name)) } /// Same as `from_str_unchecked`, except it takes an owned `String`. /// /// Since the passed string is not checked for correctness, prefer using the /// `TryFrom` implementation. pub fn from_string_unchecked(name: String) -> Self { Self(Str::from(name)) } /// Creates an owned clone of `self`. pub fn to_owned(&self) -> InterfaceName<'static> { InterfaceName(self.0.to_owned()) } /// Creates an owned clone of `self`. pub fn into_owned(self) -> InterfaceName<'static> { InterfaceName(self.0.into_owned()) } } impl Deref for InterfaceName<'_> { type Target = str; fn deref(&self) -> &Self::Target { self.as_str() } } impl Borrow for InterfaceName<'_> { fn borrow(&self) -> &str { self.as_str() } } impl Display for InterfaceName<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { Display::fmt(&self.as_str(), f) } } impl PartialEq for InterfaceName<'_> { fn eq(&self, other: &str) -> bool { self.as_str() == other } } impl PartialEq<&str> for InterfaceName<'_> { fn eq(&self, other: &&str) -> bool { self.as_str() == *other } } impl PartialEq for InterfaceName<'_> { fn eq(&self, other: &OwnedInterfaceName) -> bool { *self == other.0 } } impl<'de: 'name, 'name> Deserialize<'de> for InterfaceName<'name> { fn deserialize(deserializer: D) -> core::result::Result where D: serde::Deserializer<'de>, { let name = >::deserialize(deserializer)?; Self::try_from(name).map_err(|e| de::Error::custom(e.to_string())) } } impl_try_from! { ty:InterfaceName<'s>, owned_ty: OwnedInterfaceName, validate_fn: validate, try_from: [&'s str, String, Arc, Cow<'s, str>, Str<'s>], } impl<'name> From> for Str<'name> { fn from(value: InterfaceName<'name>) -> Self { value.0 } } fn validate(name: &str) -> Result<()> { validate_bytes(name.as_bytes()).map_err(|_| { Error::InvalidName( "Invalid interface name. See \ https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-interface" ) }) } pub(crate) fn validate_bytes(bytes: &[u8]) -> std::result::Result<(), ()> { use winnow::{ combinator::separated, stream::AsChar, token::{one_of, take_while}, Parser, }; // Rules // // * Only ASCII alphanumeric and `_` // * Must not begin with a `.`. // * Must contain at least one `.`. // * Each element must: // * not begin with a digit. // * be 1 character (so name must be minimum 3 characters long). // * <= 255 characters. // // Note: A `-` not allowed, which is why we can't use the same parser as for `WellKnownName`. let first_element_char = one_of((AsChar::is_alpha, b'_')); let subsequent_element_chars = take_while::<_, _, ()>(0.., (AsChar::is_alphanum, b'_')); let element = (first_element_char, subsequent_element_chars); let mut interface_name = separated(2.., element, b'.'); interface_name .parse(bytes) .map_err(|_| ()) .and_then(|_: ()| { // Least likely scenario so we check this last. if bytes.len() > 255 { return Err(()); } Ok(()) }) } /// This never succeeds but is provided so it's easier to pass `Option::None` values for API /// requiring `Option>`, since type inference won't work here. impl TryFrom<()> for InterfaceName<'_> { type Error = Error; fn try_from(_value: ()) -> Result { unreachable!("Conversion from `()` is not meant to actually work"); } } impl<'name> From<&InterfaceName<'name>> for InterfaceName<'name> { fn from(name: &InterfaceName<'name>) -> Self { name.clone() } } impl<'name> NoneValue for InterfaceName<'name> { type NoneType = &'name str; fn null_value() -> Self::NoneType { <&str>::default() } } /// Owned sibling of [`InterfaceName`]. #[derive(Clone, Hash, PartialEq, Eq, Serialize, Type, Value, PartialOrd, Ord, OwnedValue)] pub struct OwnedInterfaceName(#[serde(borrow)] InterfaceName<'static>); assert_impl_all!(OwnedInterfaceName: Send, Sync, Unpin); impl_str_basic!(OwnedInterfaceName); impl OwnedInterfaceName { /// Convert to the inner `InterfaceName`, consuming `self`. pub fn into_inner(self) -> InterfaceName<'static> { self.0 } /// Get a reference to the inner `InterfaceName`. pub fn inner(&self) -> &InterfaceName<'static> { &self.0 } } impl Deref for OwnedInterfaceName { type Target = InterfaceName<'static>; fn deref(&self) -> &Self::Target { &self.0 } } impl Borrow for OwnedInterfaceName { fn borrow(&self) -> &str { self.0.as_str() } } impl From for InterfaceName<'_> { fn from(o: OwnedInterfaceName) -> Self { o.into_inner() } } impl<'unowned, 'owned: 'unowned> From<&'owned OwnedInterfaceName> for InterfaceName<'unowned> { fn from(name: &'owned OwnedInterfaceName) -> Self { InterfaceName::from_str_unchecked(name.as_str()) } } impl From> for OwnedInterfaceName { fn from(name: InterfaceName<'_>) -> Self { OwnedInterfaceName(name.into_owned()) } } impl From for Str<'_> { fn from(value: OwnedInterfaceName) -> Self { value.into_inner().0 } } impl<'de> Deserialize<'de> for OwnedInterfaceName { fn deserialize(deserializer: D) -> std::result::Result where D: de::Deserializer<'de>, { String::deserialize(deserializer) .and_then(|n| InterfaceName::try_from(n).map_err(|e| de::Error::custom(e.to_string()))) .map(Self) } } impl PartialEq<&str> for OwnedInterfaceName { fn eq(&self, other: &&str) -> bool { self.as_str() == *other } } impl PartialEq> for OwnedInterfaceName { fn eq(&self, other: &InterfaceName<'_>) -> bool { self.0 == *other } } impl Debug for OwnedInterfaceName { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_tuple("OwnedInterfaceName") .field(&self.as_str()) .finish() } } impl Display for OwnedInterfaceName { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { Display::fmt(&InterfaceName::from(self), f) } } impl NoneValue for OwnedInterfaceName { type NoneType = as NoneValue>::NoneType; fn null_value() -> Self::NoneType { InterfaceName::null_value() } } zbus_names-4.1.1/src/lib.rs000064400000000000000000000013361046102023000137030ustar 00000000000000#![deny(rust_2018_idioms)] #![doc( html_logo_url = "https://raw.githubusercontent.com/dbus2/zbus/9f7a90d2b594ddc48b7a5f39fda5e00cd56a7dfb/logo.png" )] #![doc = include_str!("../README.md")] #![doc(test(attr( warn(unused), deny(warnings), allow(dead_code), // W/o this, we seem to get some bogus warning about `extern crate zbus`. allow(unused_extern_crates), )))] mod bus_name; pub use bus_name::*; mod unique_name; pub use unique_name::*; mod well_known_name; pub use well_known_name::*; mod interface_name; pub use interface_name::*; mod member_name; pub use member_name::*; mod property_name; pub use property_name::*; mod error; pub use error::*; mod error_name; pub use error_name::*; mod utils; zbus_names-4.1.1/src/member_name.rs000064400000000000000000000211041046102023000153770ustar 00000000000000use crate::{ utils::{impl_str_basic, impl_try_from}, Error, Result, }; use serde::{de, Deserialize, Serialize}; use static_assertions::assert_impl_all; use std::{ borrow::{Borrow, Cow}, fmt::{self, Debug, Display, Formatter}, ops::Deref, sync::Arc, }; use zvariant::{NoneValue, OwnedValue, Str, Type, Value}; /// String that identifies an [member (method or signal) name][in] on the bus. /// /// # Examples /// /// ``` /// use zbus_names::MemberName; /// /// // Valid member names. /// let name = MemberName::try_from("Member_for_you").unwrap(); /// assert_eq!(name, "Member_for_you"); /// let name = MemberName::try_from("CamelCase101").unwrap(); /// assert_eq!(name, "CamelCase101"); /// let name = MemberName::try_from("a_very_loooooooooooooooooo_ooooooo_0000o0ngName").unwrap(); /// assert_eq!(name, "a_very_loooooooooooooooooo_ooooooo_0000o0ngName"); /// /// // Invalid member names /// MemberName::try_from("").unwrap_err(); /// MemberName::try_from(".").unwrap_err(); /// MemberName::try_from("1startWith_a_Digit").unwrap_err(); /// MemberName::try_from("contains.dots_in_the_name").unwrap_err(); /// MemberName::try_from("contains-dashes-in_the_name").unwrap_err(); /// ``` /// /// [in]: https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-member #[derive( Clone, Debug, Hash, PartialEq, Eq, Serialize, Type, Value, PartialOrd, Ord, OwnedValue, )] pub struct MemberName<'name>(Str<'name>); assert_impl_all!(MemberName<'_>: Send, Sync, Unpin); impl_str_basic!(MemberName<'_>); impl<'name> MemberName<'name> { /// This is faster than `Clone::clone` when `self` contains owned data. pub fn as_ref(&self) -> MemberName<'_> { MemberName(self.0.as_ref()) } /// The member name as string. pub fn as_str(&self) -> &str { self.0.as_str() } /// Create a new `MemberName` from the given string. /// /// Since the passed string is not checked for correctness, prefer using the /// `TryFrom<&str>` implementation. pub fn from_str_unchecked(name: &'name str) -> Self { Self(Str::from(name)) } /// Same as `try_from`, except it takes a `&'static str`. pub fn from_static_str(name: &'static str) -> Result { validate(name)?; Ok(Self(Str::from_static(name))) } /// Same as `from_str_unchecked`, except it takes a `&'static str`. pub const fn from_static_str_unchecked(name: &'static str) -> Self { Self(Str::from_static(name)) } /// Same as `from_str_unchecked`, except it takes an owned `String`. /// /// Since the passed string is not checked for correctness, prefer using the /// `TryFrom` implementation. pub fn from_string_unchecked(name: String) -> Self { Self(Str::from(name)) } /// Creates an owned clone of `self`. pub fn to_owned(&self) -> MemberName<'static> { MemberName(self.0.to_owned()) } /// Creates an owned clone of `self`. pub fn into_owned(self) -> MemberName<'static> { MemberName(self.0.into_owned()) } } impl Deref for MemberName<'_> { type Target = str; fn deref(&self) -> &Self::Target { self.as_str() } } impl Borrow for MemberName<'_> { fn borrow(&self) -> &str { self.as_str() } } impl Display for MemberName<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { Display::fmt(&self.as_str(), f) } } impl PartialEq for MemberName<'_> { fn eq(&self, other: &str) -> bool { self.as_str() == other } } impl PartialEq<&str> for MemberName<'_> { fn eq(&self, other: &&str) -> bool { self.as_str() == *other } } impl PartialEq for MemberName<'_> { fn eq(&self, other: &OwnedMemberName) -> bool { *self == other.0 } } impl<'de: 'name, 'name> Deserialize<'de> for MemberName<'name> { fn deserialize(deserializer: D) -> core::result::Result where D: serde::Deserializer<'de>, { let name = >::deserialize(deserializer)?; Self::try_from(name).map_err(|e| de::Error::custom(e.to_string())) } } impl<'name> From> for Str<'name> { fn from(value: MemberName<'name>) -> Self { value.0 } } impl_try_from! { ty: MemberName<'s>, owned_ty: OwnedMemberName, validate_fn: validate, try_from: [&'s str, String, Arc, Cow<'s, str>, Str<'s>], } fn validate(name: &str) -> Result<()> { validate_bytes(name.as_bytes()).map_err(|_| { Error::InvalidName( "Invalid member name. See \ https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-member", ) }) } pub(crate) fn validate_bytes(bytes: &[u8]) -> std::result::Result<(), ()> { use winnow::{ stream::AsChar, token::{one_of, take_while}, Parser, }; // Rules // // * Only ASCII alphanumeric or `_`. // * Must not begin with a digit. // * Must contain at least 1 character. // * <= 255 characters. let first_element_char = one_of((AsChar::is_alpha, b'_')); let subsequent_element_chars = take_while::<_, _, ()>(0.., (AsChar::is_alphanum, b'_')); let mut member_name = (first_element_char, subsequent_element_chars); member_name.parse(bytes).map_err(|_| ()).and_then(|_| { // Least likely scenario so we check this last. if bytes.len() > 255 { return Err(()); } Ok(()) }) } /// This never succeeds but is provided so it's easier to pass `Option::None` values for API /// requiring `Option>`, since type inference won't work here. impl TryFrom<()> for MemberName<'_> { type Error = Error; fn try_from(_value: ()) -> Result { unreachable!("Conversion from `()` is not meant to actually work"); } } impl<'name> From<&MemberName<'name>> for MemberName<'name> { fn from(name: &MemberName<'name>) -> Self { name.clone() } } impl<'name> NoneValue for MemberName<'name> { type NoneType = &'name str; fn null_value() -> Self::NoneType { <&str>::default() } } /// Owned sibling of [`MemberName`]. #[derive(Clone, Hash, PartialEq, Eq, Serialize, Type, Value, PartialOrd, Ord, OwnedValue)] pub struct OwnedMemberName(#[serde(borrow)] MemberName<'static>); assert_impl_all!(OwnedMemberName: Send, Sync, Unpin); impl_str_basic!(OwnedMemberName); impl OwnedMemberName { /// Convert to the inner `MemberName`, consuming `self`. pub fn into_inner(self) -> MemberName<'static> { self.0 } /// Get a reference to the inner `MemberName`. pub fn inner(&self) -> &MemberName<'static> { &self.0 } } impl Deref for OwnedMemberName { type Target = MemberName<'static>; fn deref(&self) -> &Self::Target { &self.0 } } impl Borrow for OwnedMemberName { fn borrow(&self) -> &str { self.0.as_str() } } impl From for MemberName<'_> { fn from(o: OwnedMemberName) -> Self { o.into_inner() } } impl<'unowned, 'owned: 'unowned> From<&'owned OwnedMemberName> for MemberName<'unowned> { fn from(name: &'owned OwnedMemberName) -> Self { MemberName::from_str_unchecked(name.as_str()) } } impl From> for OwnedMemberName { fn from(name: MemberName<'_>) -> Self { OwnedMemberName(name.into_owned()) } } impl From for Str<'_> { fn from(value: OwnedMemberName) -> Self { value.into_inner().0 } } impl<'de> Deserialize<'de> for OwnedMemberName { fn deserialize(deserializer: D) -> std::result::Result where D: de::Deserializer<'de>, { String::deserialize(deserializer) .and_then(|n| MemberName::try_from(n).map_err(|e| de::Error::custom(e.to_string()))) .map(Self) } } impl PartialEq<&str> for OwnedMemberName { fn eq(&self, other: &&str) -> bool { self.as_str() == *other } } impl PartialEq> for OwnedMemberName { fn eq(&self, other: &MemberName<'_>) -> bool { self.0 == *other } } impl Debug for OwnedMemberName { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_tuple("OwnedMemberName") .field(&self.as_str()) .finish() } } impl Display for OwnedMemberName { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { Display::fmt(&MemberName::from(self), f) } } impl NoneValue for OwnedMemberName { type NoneType = as NoneValue>::NoneType; fn null_value() -> Self::NoneType { MemberName::null_value() } } zbus_names-4.1.1/src/property_name.rs000064400000000000000000000176001046102023000160220ustar 00000000000000use crate::{ utils::{impl_str_basic, impl_try_from}, Error, Result, }; use serde::{de, Deserialize, Serialize}; use static_assertions::assert_impl_all; use std::{ borrow::{Borrow, Cow}, fmt::{self, Debug, Display, Formatter}, ops::Deref, sync::Arc, }; use zvariant::{NoneValue, OwnedValue, Str, Type, Value}; /// String that identifies a [property][pn] name on the bus. /// /// # Examples /// /// ``` /// use zbus_names::PropertyName; /// /// // Valid property names. /// let name = PropertyName::try_from("Property_for_you").unwrap(); /// assert_eq!(name, "Property_for_you"); /// let name = PropertyName::try_from("CamelCase101").unwrap(); /// assert_eq!(name, "CamelCase101"); /// let name = PropertyName::try_from("a_very_loooooooooooooooooo_ooooooo_0000o0ngName").unwrap(); /// assert_eq!(name, "a_very_loooooooooooooooooo_ooooooo_0000o0ngName"); /// let name = PropertyName::try_from("Property_for_you-1").unwrap(); /// assert_eq!(name, "Property_for_you-1"); /// ``` /// /// [pn]: https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties #[derive( Clone, Debug, Hash, PartialEq, Eq, Serialize, Type, Value, PartialOrd, Ord, OwnedValue, )] pub struct PropertyName<'name>(Str<'name>); assert_impl_all!(PropertyName<'_>: Send, Sync, Unpin); impl_str_basic!(PropertyName<'_>); impl<'name> PropertyName<'name> { /// This is faster than `Clone::clone` when `self` contains owned data. pub fn as_ref(&self) -> PropertyName<'_> { PropertyName(self.0.as_ref()) } /// The property name as string. pub fn as_str(&self) -> &str { self.0.as_str() } /// Create a new `PropertyName` from the given string. /// /// Since the passed string is not checked for correctness, prefer using the /// `TryFrom<&str>` implementation. pub fn from_str_unchecked(name: &'name str) -> Self { Self(Str::from(name)) } /// Same as `try_from`, except it takes a `&'static str`. pub fn from_static_str(name: &'static str) -> Result { ensure_correct_property_name(name)?; Ok(Self(Str::from_static(name))) } /// Same as `from_str_unchecked`, except it takes a `&'static str`. pub const fn from_static_str_unchecked(name: &'static str) -> Self { Self(Str::from_static(name)) } /// Same as `from_str_unchecked`, except it takes an owned `String`. /// /// Since the passed string is not checked for correctness, prefer using the /// `TryFrom` implementation. pub fn from_string_unchecked(name: String) -> Self { Self(Str::from(name)) } /// Creates an owned clone of `self`. pub fn to_owned(&self) -> PropertyName<'static> { PropertyName(self.0.to_owned()) } /// Creates an owned clone of `self`. pub fn into_owned(self) -> PropertyName<'static> { PropertyName(self.0.into_owned()) } } impl Deref for PropertyName<'_> { type Target = str; fn deref(&self) -> &Self::Target { self.as_str() } } impl Borrow for PropertyName<'_> { fn borrow(&self) -> &str { self.as_str() } } impl Display for PropertyName<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { Display::fmt(&self.as_str(), f) } } impl PartialEq for PropertyName<'_> { fn eq(&self, other: &str) -> bool { self.as_str() == other } } impl PartialEq<&str> for PropertyName<'_> { fn eq(&self, other: &&str) -> bool { self.as_str() == *other } } impl PartialEq for PropertyName<'_> { fn eq(&self, other: &OwnedPropertyName) -> bool { *self == other.0 } } impl<'de: 'name, 'name> Deserialize<'de> for PropertyName<'name> { fn deserialize(deserializer: D) -> core::result::Result where D: serde::Deserializer<'de>, { let name = >::deserialize(deserializer)?; Self::try_from(name).map_err(|e| de::Error::custom(e.to_string())) } } impl<'name> From> for Str<'name> { fn from(value: PropertyName<'name>) -> Self { value.0 } } impl_try_from! { ty: PropertyName<'s>, owned_ty: OwnedPropertyName, validate_fn: ensure_correct_property_name, try_from: [&'s str, String, Arc, Cow<'s, str>, Str<'s>], } fn ensure_correct_property_name(name: &str) -> Result<()> { if name.is_empty() { return Err(Error::InvalidName( "Invalid property name. It has to be at least 1 character long.", )); } else if name.len() > 255 { return Err(Error::InvalidName( "Invalid property name. It can not be longer than 255 characters.", )); } Ok(()) } /// This never succeeds but is provided so it's easier to pass `Option::None` values for API /// requiring `Option>`, since type inference won't work here. impl TryFrom<()> for PropertyName<'_> { type Error = Error; fn try_from(_value: ()) -> Result { unreachable!("Conversion from `()` is not meant to actually work"); } } impl<'name> From<&PropertyName<'name>> for PropertyName<'name> { fn from(name: &PropertyName<'name>) -> Self { name.clone() } } impl<'name> NoneValue for PropertyName<'name> { type NoneType = &'name str; fn null_value() -> Self::NoneType { <&str>::default() } } /// Owned sibling of [`PropertyName`]. #[derive(Clone, Hash, PartialEq, Eq, Serialize, Type, Value, PartialOrd, Ord, OwnedValue)] pub struct OwnedPropertyName(#[serde(borrow)] PropertyName<'static>); assert_impl_all!(OwnedPropertyName: Send, Sync, Unpin); impl_str_basic!(OwnedPropertyName); impl OwnedPropertyName { /// Convert to the inner `PropertyName`, consuming `self`. pub fn into_inner(self) -> PropertyName<'static> { self.0 } /// Get a reference to the inner `PropertyName`. pub fn inner(&self) -> &PropertyName<'static> { &self.0 } } impl Deref for OwnedPropertyName { type Target = PropertyName<'static>; fn deref(&self) -> &Self::Target { &self.0 } } impl Borrow for OwnedPropertyName { fn borrow(&self) -> &str { self.0.as_str() } } impl From for PropertyName<'_> { fn from(o: OwnedPropertyName) -> Self { o.into_inner() } } impl<'unowned, 'owned: 'unowned> From<&'owned OwnedPropertyName> for PropertyName<'unowned> { fn from(name: &'owned OwnedPropertyName) -> Self { PropertyName::from_str_unchecked(name.as_str()) } } impl From> for OwnedPropertyName { fn from(name: PropertyName<'_>) -> Self { OwnedPropertyName(name.into_owned()) } } impl From for Str<'_> { fn from(value: OwnedPropertyName) -> Self { value.into_inner().0 } } impl<'de> Deserialize<'de> for OwnedPropertyName { fn deserialize(deserializer: D) -> std::result::Result where D: de::Deserializer<'de>, { String::deserialize(deserializer) .and_then(|n| PropertyName::try_from(n).map_err(|e| de::Error::custom(e.to_string()))) .map(Self) } } impl PartialEq<&str> for OwnedPropertyName { fn eq(&self, other: &&str) -> bool { self.as_str() == *other } } impl PartialEq> for OwnedPropertyName { fn eq(&self, other: &PropertyName<'_>) -> bool { self.0 == *other } } impl Debug for OwnedPropertyName { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_tuple("OwnedPropertyName") .field(&self.as_str()) .finish() } } impl Display for OwnedPropertyName { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { Display::fmt(&PropertyName::from(self), f) } } impl NoneValue for OwnedPropertyName { type NoneType = as NoneValue>::NoneType; fn null_value() -> Self::NoneType { PropertyName::null_value() } } zbus_names-4.1.1/src/unique_name.rs000064400000000000000000000212441046102023000154430ustar 00000000000000use crate::{ utils::{impl_str_basic, impl_try_from}, Error, Result, }; use serde::{de, Deserialize, Serialize}; use static_assertions::assert_impl_all; use std::{ borrow::{Borrow, Cow}, fmt::{self, Debug, Display, Formatter}, ops::Deref, sync::Arc, }; use zvariant::{NoneValue, OwnedValue, Str, Type, Value}; /// String that identifies a [unique bus name][ubn]. /// /// # Examples /// /// ``` /// use zbus_names::UniqueName; /// /// // Valid unique names. /// let name = UniqueName::try_from(":org.gnome.Service-for_you").unwrap(); /// assert_eq!(name, ":org.gnome.Service-for_you"); /// let name = UniqueName::try_from(":a.very.loooooooooooooooooo-ooooooo_0000o0ng.Name").unwrap(); /// assert_eq!(name, ":a.very.loooooooooooooooooo-ooooooo_0000o0ng.Name"); /// /// // Invalid unique names /// UniqueName::try_from("").unwrap_err(); /// UniqueName::try_from("dont.start.with.a.colon").unwrap_err(); /// UniqueName::try_from(":double..dots").unwrap_err(); /// UniqueName::try_from(".").unwrap_err(); /// UniqueName::try_from(".start.with.dot").unwrap_err(); /// UniqueName::try_from(":no-dots").unwrap_err(); /// ``` /// /// [ubn]: https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus #[derive( Clone, Debug, Hash, PartialEq, Eq, Serialize, Type, Value, PartialOrd, Ord, OwnedValue, )] pub struct UniqueName<'name>(pub(crate) Str<'name>); assert_impl_all!(UniqueName<'_>: Send, Sync, Unpin); impl_str_basic!(UniqueName<'_>); impl<'name> UniqueName<'name> { /// This is faster than `Clone::clone` when `self` contains owned data. pub fn as_ref(&self) -> UniqueName<'_> { UniqueName(self.0.as_ref()) } /// The unique name as string. pub fn as_str(&self) -> &str { self.0.as_str() } /// Create a new `UniqueName` from the given string. /// /// Since the passed string is not checked for correctness, prefer using the /// `TryFrom<&str>` implementation. pub fn from_str_unchecked(name: &'name str) -> Self { Self(Str::from(name)) } /// Same as `try_from`, except it takes a `&'static str`. pub fn from_static_str(name: &'static str) -> Result { validate(name)?; Ok(Self(Str::from_static(name))) } /// Same as `from_str_unchecked`, except it takes a `&'static str`. pub const fn from_static_str_unchecked(name: &'static str) -> Self { Self(Str::from_static(name)) } /// Same as `from_str_unchecked`, except it takes an owned `String`. /// /// Since the passed string is not checked for correctness, prefer using the /// `TryFrom` implementation. pub fn from_string_unchecked(name: String) -> Self { Self(Str::from(name)) } /// Creates an owned clone of `self`. pub fn to_owned(&self) -> UniqueName<'static> { UniqueName(self.0.to_owned()) } /// Creates an owned clone of `self`. pub fn into_owned(self) -> UniqueName<'static> { UniqueName(self.0.into_owned()) } } impl Deref for UniqueName<'_> { type Target = str; fn deref(&self) -> &Self::Target { self.as_str() } } impl Borrow for UniqueName<'_> { fn borrow(&self) -> &str { self.as_str() } } impl Display for UniqueName<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { Display::fmt(&self.as_str(), f) } } impl PartialEq for UniqueName<'_> { fn eq(&self, other: &str) -> bool { self.as_str() == other } } impl PartialEq<&str> for UniqueName<'_> { fn eq(&self, other: &&str) -> bool { self.as_str() == *other } } impl PartialEq for UniqueName<'_> { fn eq(&self, other: &OwnedUniqueName) -> bool { *self == other.0 } } impl<'de: 'name, 'name> Deserialize<'de> for UniqueName<'name> { fn deserialize(deserializer: D) -> core::result::Result where D: serde::Deserializer<'de>, { let name = >::deserialize(deserializer)?; Self::try_from(name).map_err(|e| de::Error::custom(e.to_string())) } } fn validate(name: &str) -> Result<()> { validate_bytes(name.as_bytes()).map_err(|_| { Error::InvalidName( "Invalid unique name. \ See https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus" ) }) } pub(crate) fn validate_bytes(bytes: &[u8]) -> std::result::Result<(), ()> { use winnow::{ combinator::{alt, separated}, stream::AsChar, token::take_while, Parser, }; // Rules // // * Only ASCII alphanumeric, `_` or '-' // * Must begin with a `:`. // * Must contain at least one `.`. // * Each element must be 1 character (so name must be minimum 4 characters long). // * <= 255 characters. let element = take_while::<_, _, ()>(1.., (AsChar::is_alphanum, b'_', b'-')); let peer_name = (b':', (separated(2.., element, b'.'))).map(|_: (_, ())| ()); let bus_name = b"org.freedesktop.DBus".map(|_| ()); let mut unique_name = alt((bus_name, peer_name)); unique_name.parse(bytes).map_err(|_| ()).and_then(|_: ()| { // Least likely scenario so we check this last. if bytes.len() > 255 { return Err(()); } Ok(()) }) } /// This never succeeds but is provided so it's easier to pass `Option::None` values for API /// requiring `Option>`, since type inference won't work here. impl TryFrom<()> for UniqueName<'_> { type Error = Error; fn try_from(_value: ()) -> Result { unreachable!("Conversion from `()` is not meant to actually work"); } } impl<'name> From<&UniqueName<'name>> for UniqueName<'name> { fn from(name: &UniqueName<'name>) -> Self { name.clone() } } impl<'name> From> for Str<'name> { fn from(value: UniqueName<'name>) -> Self { value.0 } } impl<'name> NoneValue for UniqueName<'name> { type NoneType = &'name str; fn null_value() -> Self::NoneType { <&str>::default() } } /// Owned sibling of [`UniqueName`]. #[derive(Clone, Hash, PartialEq, Eq, Serialize, Type, Value, PartialOrd, Ord, OwnedValue)] pub struct OwnedUniqueName(#[serde(borrow)] UniqueName<'static>); assert_impl_all!(OwnedUniqueName: Send, Sync, Unpin); impl_str_basic!(OwnedUniqueName); impl OwnedUniqueName { /// Convert to the inner `UniqueName`, consuming `self`. pub fn into_inner(self) -> UniqueName<'static> { self.0 } /// Get a reference to the inner `UniqueName`. pub fn inner(&self) -> &UniqueName<'static> { &self.0 } } impl Deref for OwnedUniqueName { type Target = UniqueName<'static>; fn deref(&self) -> &Self::Target { &self.0 } } impl Borrow for OwnedUniqueName { fn borrow(&self) -> &str { self.0.as_str() } } impl From for UniqueName<'_> { fn from(o: OwnedUniqueName) -> Self { o.into_inner() } } impl<'unowned, 'owned: 'unowned> From<&'owned OwnedUniqueName> for UniqueName<'unowned> { fn from(name: &'owned OwnedUniqueName) -> Self { UniqueName::from_str_unchecked(name.as_str()) } } impl From> for OwnedUniqueName { fn from(name: UniqueName<'_>) -> Self { OwnedUniqueName(name.into_owned()) } } impl_try_from! { ty: UniqueName<'s>, owned_ty: OwnedUniqueName, validate_fn: validate, try_from: [&'s str, String, Arc, Cow<'s, str>, Str<'s>], } impl From for Str<'_> { fn from(value: OwnedUniqueName) -> Self { value.into_inner().0 } } impl<'de> Deserialize<'de> for OwnedUniqueName { fn deserialize(deserializer: D) -> std::result::Result where D: de::Deserializer<'de>, { String::deserialize(deserializer) .and_then(|n| UniqueName::try_from(n).map_err(|e| de::Error::custom(e.to_string()))) .map(Self) } } impl PartialEq<&str> for OwnedUniqueName { fn eq(&self, other: &&str) -> bool { self.as_str() == *other } } impl PartialEq> for OwnedUniqueName { fn eq(&self, other: &UniqueName<'_>) -> bool { self.0 == *other } } impl NoneValue for OwnedUniqueName { type NoneType = as NoneValue>::NoneType; fn null_value() -> Self::NoneType { UniqueName::null_value() } } impl Debug for OwnedUniqueName { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_tuple("OwnedUniqueName") .field(&self.as_str()) .finish() } } impl Display for OwnedUniqueName { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { Display::fmt(&UniqueName::from(self), f) } } zbus_names-4.1.1/src/utils.rs000064400000000000000000000020521046102023000142710ustar 00000000000000macro_rules! impl_str_basic { ($type:ty) => { impl zvariant::Basic for $type { const SIGNATURE_CHAR: char = >::SIGNATURE_CHAR; const SIGNATURE_STR: &'static str = >::SIGNATURE_STR; } }; } macro_rules! impl_try_from { (ty: $type:ty, owned_ty: $owned_type:ty, validate_fn: $validate_fn:ident, try_from: [$($from:ty),*],) => { $( impl<'s> TryFrom<$from> for $type { type Error = Error; fn try_from(value: $from) -> Result { let value = Str::from(value); $validate_fn(value.as_str())?; Ok(Self(value)) } } impl<'s> TryFrom<$from> for $owned_type { type Error = Error; fn try_from(value: $from) -> Result { Ok(Self::from(<$type>::try_from(value)?)) } } )* }; } pub(crate) use impl_str_basic; pub(crate) use impl_try_from; zbus_names-4.1.1/src/well_known_name.rs000064400000000000000000000223361046102023000163170ustar 00000000000000use crate::{ utils::{impl_str_basic, impl_try_from}, Error, Result, }; use serde::{de, Deserialize, Serialize}; use static_assertions::assert_impl_all; use std::{ borrow::{Borrow, Cow}, fmt::{self, Debug, Display, Formatter}, ops::Deref, sync::Arc, }; use zvariant::{NoneValue, OwnedValue, Str, Type, Value}; /// String that identifies a [well-known bus name][wbn]. /// /// # Examples /// /// ``` /// use zbus_names::WellKnownName; /// /// // Valid well-known names. /// let name = WellKnownName::try_from("org.gnome.Service-for_you").unwrap(); /// assert_eq!(name, "org.gnome.Service-for_you"); /// let name = WellKnownName::try_from("a.very.loooooooooooooooooo-ooooooo_0000o0ng.Name").unwrap(); /// assert_eq!(name, "a.very.loooooooooooooooooo-ooooooo_0000o0ng.Name"); /// /// // Invalid well-known names /// WellKnownName::try_from("").unwrap_err(); /// WellKnownName::try_from("double..dots").unwrap_err(); /// WellKnownName::try_from(".").unwrap_err(); /// WellKnownName::try_from(".start.with.dot").unwrap_err(); /// WellKnownName::try_from("1st.element.starts.with.digit").unwrap_err(); /// WellKnownName::try_from("the.2nd.element.starts.with.digit").unwrap_err(); /// WellKnownName::try_from("no-dots").unwrap_err(); /// ``` /// /// [wbn]: https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus #[derive( Clone, Debug, Hash, PartialEq, Eq, Serialize, Type, Value, PartialOrd, Ord, OwnedValue, )] pub struct WellKnownName<'name>(pub(crate) Str<'name>); impl_str_basic!(WellKnownName<'_>); assert_impl_all!(WellKnownName<'_>: Send, Sync, Unpin); impl<'name> WellKnownName<'name> { /// This is faster than `Clone::clone` when `self` contains owned data. pub fn as_ref(&self) -> WellKnownName<'_> { WellKnownName(self.0.as_ref()) } /// The well-known-name as string. pub fn as_str(&self) -> &str { self.0.as_str() } /// Create a new `WellKnownName` from the given string. /// /// Since the passed string is not checked for correctness, prefer using the /// `TryFrom<&str>` implementation. pub fn from_str_unchecked(name: &'name str) -> Self { Self(Str::from(name)) } /// Same as `try_from`, except it takes a `&'static str`. pub fn from_static_str(name: &'static str) -> Result { validate(name)?; Ok(Self(Str::from_static(name))) } /// Same as `from_str_unchecked`, except it takes a `&'static str`. pub const fn from_static_str_unchecked(name: &'static str) -> Self { Self(Str::from_static(name)) } /// Same as `from_str_unchecked`, except it takes an owned `String`. /// /// Since the passed string is not checked for correctness, prefer using the /// `TryFrom` implementation. pub fn from_string_unchecked(name: String) -> Self { Self(Str::from(name)) } /// Creates an owned clone of `self`. pub fn to_owned(&self) -> WellKnownName<'static> { WellKnownName(self.0.to_owned()) } /// Creates an owned clone of `self`. pub fn into_owned(self) -> WellKnownName<'static> { WellKnownName(self.0.into_owned()) } } impl Deref for WellKnownName<'_> { type Target = str; fn deref(&self) -> &Self::Target { self.as_str() } } impl Borrow for WellKnownName<'_> { fn borrow(&self) -> &str { self.as_str() } } impl Display for WellKnownName<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { Display::fmt(&self.as_str(), f) } } impl PartialEq for WellKnownName<'_> { fn eq(&self, other: &str) -> bool { self.as_str() == other } } impl PartialEq<&str> for WellKnownName<'_> { fn eq(&self, other: &&str) -> bool { self.as_str() == *other } } impl PartialEq for WellKnownName<'_> { fn eq(&self, other: &OwnedWellKnownName) -> bool { *self == other.0 } } impl<'de: 'name, 'name> Deserialize<'de> for WellKnownName<'name> { fn deserialize(deserializer: D) -> core::result::Result where D: serde::Deserializer<'de>, { let name = >::deserialize(deserializer)?; Self::try_from(name).map_err(|e| de::Error::custom(e.to_string())) } } fn validate(name: &str) -> Result<()> { validate_bytes(name.as_bytes()).map_err(|_| { Error::InvalidName( "Invalid well-known name. \ See https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus" ) }) } pub(crate) fn validate_bytes(bytes: &[u8]) -> std::result::Result<(), ()> { use winnow::{ combinator::separated, stream::AsChar, token::{one_of, take_while}, Parser, }; // Rules // // * Only ASCII alphanumeric, `_` or '-'. // * Must not begin with a `.`. // * Must contain at least one `.`. // * Each element must: // * not begin with a digit. // * be 1 character (so name must be minimum 3 characters long). // * <= 255 characters. let first_element_char = one_of((AsChar::is_alpha, b'_', b'-')); let subsequent_element_chars = take_while::<_, _, ()>(0.., (AsChar::is_alphanum, b'_', b'-')); let element = (first_element_char, subsequent_element_chars); let mut well_known_name = separated(2.., element, b'.'); well_known_name .parse(bytes) .map_err(|_| ()) .and_then(|_: ()| { // Least likely scenario so we check this last. if bytes.len() > 255 { return Err(()); } Ok(()) }) } /// This never succeeds but is provided so it's easier to pass `Option::None` values for API /// requiring `Option>`, since type inference won't work here. impl TryFrom<()> for WellKnownName<'_> { type Error = Error; fn try_from(_value: ()) -> Result { unreachable!("Conversion from `()` is not meant to actually work"); } } impl<'name> From<&WellKnownName<'name>> for WellKnownName<'name> { fn from(name: &WellKnownName<'name>) -> Self { name.clone() } } impl<'name> From> for Str<'name> { fn from(value: WellKnownName<'name>) -> Self { value.0 } } impl<'name> NoneValue for WellKnownName<'name> { type NoneType = &'name str; fn null_value() -> Self::NoneType { <&str>::default() } } /// Owned sibling of [`WellKnownName`]. #[derive(Clone, Hash, PartialEq, Eq, Serialize, Type, Value, PartialOrd, Ord, OwnedValue)] pub struct OwnedWellKnownName(#[serde(borrow)] WellKnownName<'static>); assert_impl_all!(OwnedWellKnownName: Send, Sync, Unpin); impl OwnedWellKnownName { /// Convert to the inner `WellKnownName`, consuming `self`. pub fn into_inner(self) -> WellKnownName<'static> { self.0 } /// Get a reference to the inner `WellKnownName`. pub fn inner(&self) -> &WellKnownName<'static> { &self.0 } } impl_str_basic!(OwnedWellKnownName); impl Deref for OwnedWellKnownName { type Target = WellKnownName<'static>; fn deref(&self) -> &Self::Target { &self.0 } } impl Borrow for OwnedWellKnownName { fn borrow(&self) -> &str { self.0.as_str() } } impl AsRef for OwnedWellKnownName { fn as_ref(&self) -> &str { self.0.as_str() } } impl Debug for OwnedWellKnownName { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_tuple("OwnedWellKnownName") .field(&self.as_str()) .finish() } } impl Display for OwnedWellKnownName { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { Display::fmt(&WellKnownName::from(self), f) } } impl From for WellKnownName<'_> { fn from(name: OwnedWellKnownName) -> Self { name.into_inner() } } impl<'unowned, 'owned: 'unowned> From<&'owned OwnedWellKnownName> for WellKnownName<'unowned> { fn from(name: &'owned OwnedWellKnownName) -> Self { WellKnownName::from_str_unchecked(name.as_str()) } } impl From> for OwnedWellKnownName { fn from(name: WellKnownName<'_>) -> Self { OwnedWellKnownName(name.into_owned()) } } impl_try_from! { ty: WellKnownName<'s>, owned_ty: OwnedWellKnownName, validate_fn: validate, try_from: [&'s str, String, Arc, Cow<'s, str>, Str<'s>], } impl From for Str<'_> { fn from(value: OwnedWellKnownName) -> Self { value.into_inner().0 } } impl<'de> Deserialize<'de> for OwnedWellKnownName { fn deserialize(deserializer: D) -> std::result::Result where D: de::Deserializer<'de>, { String::deserialize(deserializer) .and_then(|n| WellKnownName::try_from(n).map_err(|e| de::Error::custom(e.to_string()))) .map(Self) } } impl PartialEq<&str> for OwnedWellKnownName { fn eq(&self, other: &&str) -> bool { self.as_str() == *other } } impl PartialEq> for OwnedWellKnownName { fn eq(&self, other: &WellKnownName<'_>) -> bool { self.0 == *other } } impl NoneValue for OwnedWellKnownName { type NoneType = as NoneValue>::NoneType; fn null_value() -> Self::NoneType { WellKnownName::null_value() } }