| 1 | use serderust-analyzer cargo serde 1.0.222 crate/::Serializerust-analyzer cargo serde_core 1.0.222 ser/Serialize#; |
| 2 | use serde_deriverust-analyzer cargo serde_derive 1.0.222 crate/::Serializerust-analyzer cargo serde_derive 1.0.222 Serialize:; |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/::RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#; |
| 4 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#; |
| 5 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#; |
| 6 | |
| 7 | fn testrust-analyzer cargo serde_path_to_error 0.1.20 test().<T>(value: &T, expected: &str) |
| 8 | where |
| 9 | T: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + Serializerust-analyzer cargo serde_core 1.0.222 ser/Serialize# + Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, |
| 10 | { |
| 11 | let mut out = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 12 | let ser = &mut serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::Serializerrust-analyzer cargo serde_json 1.0.145 ser/Serializer#::newrust-analyzer cargo serde_json 1.0.145 ser/impl#[`Serializer<W>`]new().(&mut out); |
| 13 | let result = serde_path_to_errorrust-analyzer cargo serde_path_to_error 0.1.20 crate/::serializerust-analyzer cargo serde_path_to_error 0.1.20 ser/serialize().(value, ser); |
| 14 | let path = result.unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().().pathrust-analyzer cargo serde_path_to_error 0.1.20 impl#[`Error<E>`]path().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 15 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(path, expected); |
| 16 | } |
| 17 | |
| 18 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 19 | fn test_refcell_already_borrowedrust-analyzer cargo serde_path_to_error 0.1.20 test_refcell_already_borrowed().() { |
| 20 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Serializerust-analyzer cargo serde_derive 1.0.222 Serialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 21 | struct Outerrust-analyzer cargo serde_path_to_error 0.1.20 Outer#<'a> { |
| 22 | krust-analyzer cargo serde_path_to_error 0.1.20 Outer#k.: Innerrust-analyzer cargo serde_path_to_error 0.1.20 Inner#<'a>, |
| 23 | } |
| 24 | |
| 25 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Serializerust-analyzer cargo serde_derive 1.0.222 Serialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 26 | struct Innerrust-analyzer cargo serde_path_to_error 0.1.20 Inner#<'a> { |
| 27 | refcellrust-analyzer cargo serde_path_to_error 0.1.20 Inner#refcell.: &'a RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 28 | } |
| 29 | |
| 30 | let refcell = RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]new().(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().()); |
| 31 | let outer = Outerrust-analyzer cargo serde_path_to_error 0.1.20 Outer# { |
| 32 | krust-analyzer cargo serde_path_to_error 0.1.20 Outer#k.: Innerrust-analyzer cargo serde_path_to_error 0.1.20 Inner# { refcellrust-analyzer cargo serde_path_to_error 0.1.20 Inner#refcell.: &refcell }, |
| 33 | }; |
| 34 | |
| 35 | let _borrowed = refcell.borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().(); |
| 36 | testrust-analyzer cargo serde_path_to_error 0.1.20 test().(&outer, "k.refcell"); |
| 37 | } |
| 38 | |
| 39 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 40 | fn test_map_nonstring_keyrust-analyzer cargo serde_path_to_error 0.1.20 test_map_nonstring_key().() { |
| 41 | fn singleton_maprust-analyzer cargo serde_path_to_error 0.1.20 singleton_map().<K: Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#, V>(key: K, value: V) -> BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<K, V> { |
| 42 | let mut map = BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V>`]new().(); |
| 43 | map.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().(key, value); |
| 44 | map |
| 45 | } |
| 46 | |
| 47 | let map = singleton_maprust-analyzer cargo serde_path_to_error 0.1.20 singleton_map().(b"", 0); |
| 48 | let map = singleton_maprust-analyzer cargo serde_path_to_error 0.1.20 singleton_map().("k", map); |
| 49 | let map = singleton_maprust-analyzer cargo serde_path_to_error 0.1.20 singleton_map().(100, map); |
| 50 | |
| 51 | testrust-analyzer cargo serde_path_to_error 0.1.20 test().(&map, "100.k"); |
| 52 | } |