Debian Codegraph @

src/core_impls.rs

raw symbols SCIP
1 //! Implementations for core types.
2
3 use craterust-analyzer cargo daft 0.1.5 crate/::{Diffablerust-analyzer cargo daft 0.1.5 diffable/Diffable#, Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf#};
4 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::{
5 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#,
6 markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#,
7 netrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/::{IpAddrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#, Ipv4Addrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/Ipv4Addr#, Ipv6Addrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/Ipv6Addr#, SocketAddrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/socket_addr/SocketAddr#, SocketAddrV4rust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/socket_addr/SocketAddrV4#, SocketAddrV6rust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/socket_addr/SocketAddrV6#},
8 numrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/::{
9 NonZeroI128rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroI128#, NonZeroI16rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroI16#, NonZeroI32rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroI32#, NonZeroI64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroI64#, NonZeroI8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroI8#,
10 NonZeroIsizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroIsize#, NonZeroU128rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU128#, NonZeroU16rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU16#, NonZeroU32rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU32#, NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64#,
11 NonZeroU8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU8#, NonZeroUsizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroUsize#,
12 },
13 };
14
15 leafrust-analyzer cargo daft 0.1.5 macros/leaf!! { i64, i32, i16, i8, u64, u32, u16, u8, char, bool, isize, usize, NonZeroU8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU8#, NonZeroU16rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU16#, NonZeroU32rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU32#, NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64#, NonZeroU128rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU128#, NonZeroI8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroI8#, NonZeroI16rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroI16#, NonZeroI32rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroI32#, NonZeroI64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroI64#, NonZeroI128rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroI128#, NonZeroIsizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroIsize#, NonZeroUsizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroUsize#, () }
16 leafrust-analyzer cargo daft 0.1.5 macros/leaf!! { IpAddrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/IpAddr#, Ipv4Addrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/Ipv4Addr#, Ipv6Addrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/Ipv6Addr#, SocketAddrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/socket_addr/SocketAddr#, SocketAddrV4rust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/socket_addr/SocketAddrV4#, SocketAddrV6rust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/socket_addr/SocketAddrV6# }
17 leafrust-analyzer cargo daft 0.1.5 macros/leaf!! { str }
18
19 impl<T> Diffablerust-analyzer cargo daft 0.1.5 diffable/Diffable# for Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T> {
20 type Diffrust-analyzer cargo daft 0.1.5 core_impls/impl#[`Option<T>`][Diffable]Diff#<'daft>
21 = Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'daft T>>
22 where
23 T: 'daft;
24
25 fn diffrust-analyzer cargo daft 0.1.5 core_impls/impl#[`Option<T>`][Diffable]diff().<'daft>(&'daft self, other: &'daft Selfrust-analyzer cargo daft 0.1.5 core_impls/impl#[`Option<T>`][Diffable]) -> Selfrust-analyzer cargo daft 0.1.5 core_impls/impl#[`Option<T>`][Diffable]::Diffrust-analyzer cargo daft 0.1.5 diffable/Diffable#Diff#<'daft> {
26 Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf# { beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before.: self.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().(), afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after.: other.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() }
27 }
28 }
29
30 impl<T, U> Diffablerust-analyzer cargo daft 0.1.5 diffable/Diffable# for Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, U> {
31 type Diffrust-analyzer cargo daft 0.1.5 core_impls/impl#[`Result<T, U>`][Diffable]Diff#<'daft>
32 = Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf#<Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&'daft T, &'daft U>>
33 where
34 T: 'daft,
35 U: 'daft;
36 fn diffrust-analyzer cargo daft 0.1.5 core_impls/impl#[`Result<T, U>`][Diffable]diff().<'daft>(&'daft self, other: &'daft Selfrust-analyzer cargo daft 0.1.5 core_impls/impl#[`Result<T, U>`][Diffable]) -> Selfrust-analyzer cargo daft 0.1.5 core_impls/impl#[`Result<T, U>`][Diffable]::Diffrust-analyzer cargo daft 0.1.5 diffable/Diffable#Diff#<'daft> {
37 Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf# { beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before.: self.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]as_ref().(), afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after.: other.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]as_ref().() }
38 }
39 }
40
41 impl<'a, T: Diffablerust-analyzer cargo daft 0.1.5 diffable/Diffable# + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#> Diffablerust-analyzer cargo daft 0.1.5 diffable/Diffable# for &'a T {
42 // It would be nice to extend the lifetime of the diff to `'a` (e.g. diffing
43 // &'static str`s results in a Leaf<&'static str>), and it does actually
44 // work for that simpler case, but rustc (1.84.1) complains about cases with
45 // multiple references like &'a &'b T (see complex-lifetimes.rs for an
46 // example). This is probably a bug in rustc: see
47 // https://gist.github.com/sunshowers/25fcc2f590f1c6b19daa99e11e927dc7 for
48 // the error with Rust 1.84.1.
49 type Diffrust-analyzer cargo daft 0.1.5 core_impls/impl#[`&'a T`][Diffable]Diff#<'daft>
50 = <T as Diffablerust-analyzer cargo daft 0.1.5 diffable/Diffable#>::Diffrust-analyzer cargo daft 0.1.5 diffable/Diffable#Diff#<'daft>
51 where
52 'a: 'daft;
53
54 fn diffrust-analyzer cargo daft 0.1.5 core_impls/impl#[`&'a T`][Diffable]diff().<'daft>(&'daft self, other: &'daft Selfrust-analyzer cargo daft 0.1.5 core_impls/impl#[`&'a T`][Diffable]) -> Selfrust-analyzer cargo daft 0.1.5 core_impls/impl#[`&'a T`][Diffable]::Diffrust-analyzer cargo daft 0.1.5 diffable/Diffable#Diff#<'daft> {
55 (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self).diffrust-analyzer cargo daft 0.1.5 diffable/Diffable#diff().(other)
56 }
57 }
58
59 // Can't express lifetimes due to `RefCell`'s limited borrows, so we must return
60 // a leaf node that can be recursively diffed.
61 impl<T: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#> Diffablerust-analyzer cargo daft 0.1.5 diffable/Diffable# for RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#<T> {
62 type Diffrust-analyzer cargo daft 0.1.5 core_impls/impl#[`RefCell<T>`][Diffable]Diff#<'daft>
63 = Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf#<&'daft Selfrust-analyzer cargo daft 0.1.5 core_impls/impl#[`RefCell<T>`][Diffable]>
64 where
65 T: 'daft;
66
67 fn diffrust-analyzer cargo daft 0.1.5 core_impls/impl#[`RefCell<T>`][Diffable]diff().<'daft>(&'daft self, other: &'daft Selfrust-analyzer cargo daft 0.1.5 core_impls/impl#[`RefCell<T>`][Diffable]) -> Selfrust-analyzer cargo daft 0.1.5 core_impls/impl#[`RefCell<T>`][Diffable]::Diffrust-analyzer cargo daft 0.1.5 diffable/Diffable#Diff#<'daft> {
68 Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf# { beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before.: self, afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after.: other }
69 }
70 }
71
72 impl<T: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#> Diffablerust-analyzer cargo daft 0.1.5 diffable/Diffable# for PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<T> {
73 type Diffrust-analyzer cargo daft 0.1.5 core_impls/impl#[`PhantomData<T>`][Diffable]Diff#<'daft>
74 = Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf#<&'daft PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<T>>
75 where
76 Selfrust-analyzer cargo daft 0.1.5 core_impls/impl#[`PhantomData<T>`][Diffable]: 'daft;
77
78 fn diffrust-analyzer cargo daft 0.1.5 core_impls/impl#[`PhantomData<T>`][Diffable]diff().<'daft>(&'daft self, other: &'daft Selfrust-analyzer cargo daft 0.1.5 core_impls/impl#[`PhantomData<T>`][Diffable]) -> Selfrust-analyzer cargo daft 0.1.5 core_impls/impl#[`PhantomData<T>`][Diffable]::Diffrust-analyzer cargo daft 0.1.5 diffable/Diffable#Diff#<'daft> {
79 Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf# { beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before.: self, afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after.: other }
80 }
81 }
82
83 /// Treat slices as leaf nodes.
84 impl<T: Diffablerust-analyzer cargo daft 0.1.5 diffable/Diffable#> Diffablerust-analyzer cargo daft 0.1.5 diffable/Diffable# for [T] {
85 type Diffrust-analyzer cargo daft 0.1.5 core_impls/impl#[`[T]`][Diffable]Diff#<'daft>
86 = Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf#<&'daft [T]>
87 where
88 T: 'daft;
89
90 fn diffrust-analyzer cargo daft 0.1.5 core_impls/impl#[`[T]`][Diffable]diff().<'daft>(&'daft self, other: &'daft Selfrust-analyzer cargo daft 0.1.5 core_impls/impl#[`[T]`][Diffable]) -> Selfrust-analyzer cargo daft 0.1.5 core_impls/impl#[`[T]`][Diffable]::Diffrust-analyzer cargo daft 0.1.5 diffable/Diffable#Diff#<'daft> {
91 Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf# { beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before.: self, afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after.: other }
92 }
93 }
94
95 macro_rules! tuple_diffablerust-analyzer cargo daft 0.1.5 core_impls/tuple_diffable! {
96 ($(($($name:ident $ix:tt),+)),+) => {
97 $(
98 impl<$($name: Diffable),+> Diffable for ($($name,)+) {
99 type Diff<'daft> = ($($name::Diff<'daft>,)+)
100 where
101 $($name: 'daft,)+;
102
103 fn diff<'daft>(&'daft self, other: &'daft Self) -> Self::Diff<'daft> {
104 ($(self.$ix.diff(&other.$ix),)+)
105 }
106 }
107 )+
108 }
109 }
110
111 tuple_diffablerust-analyzer cargo daft 0.1.5 core_impls/tuple_diffable!! {
112 (A 0),
113 (A 0, B 1),
114 (A 0, B 1, C 2),
115 (A 0, B 1, C 2, D 3),
116 (A 0, B 1, C 2, D 3, E 4),
117 (A 0, B 1, C 2, D 3, E 4, F 5),
118 (A 0, B 1, C 2, D 3, E 4, F 5, G 6),
119 (A 0, B 1, C 2, D 3, E 4, F 5, G 6, H 7),
120 (A 0, B 1, C 2, D 3, E 4, F 5, G 6, H 7, I 8),
121 (A 0, B 1, C 2, D 3, E 4, F 5, G 6, H 7, I 8, J 9)
122 }
123
124 #[cfg(test)]
125 mod testsrust-analyzer cargo daft 0.1.5 core_impls/tests/ {
126 use superrust-analyzer cargo daft 0.1.5 core_impls/::*;
127
128 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
129 fn reference_diffablerust-analyzer cargo daft 0.1.5 core_impls/tests/reference_diffable().() {
130 // Test that a reference to a diffable type can be diffed.
131 let before = &&&&&&"hello";
132 let after = &&&&&&"world";
133
134 // This should automatically dereference the references.
135 let diff: Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf#<&str> = before.diffrust-analyzer cargo daft 0.1.5 core_impls/impl#[`&'a T`][Diffable]diff().(after);
136 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(diff.beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before., *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().before);
137 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(diff.afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after., *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().after);
138 }
139
140 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
141 fn tuple_diffablerust-analyzer cargo daft 0.1.5 core_impls/tests/tuple_diffable().() {
142 let before = (1usize, 2usize, 3usize);
143 let after = (4, 5, 6);
144
145 let diff = before.diffrust-analyzer cargo daft 0.1.5 core_impls/impl#[`(A, B, C)`][Diffable]diff().(&after);
146 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
147 diff,
148 (
149 Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf# { beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before.: &1, afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after.: &4 },
150 Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf# { beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before.: &2, afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after.: &5 },
151 Leafrust-analyzer cargo daft 0.1.5 leaf/Leaf# { beforerust-analyzer cargo daft 0.1.5 leaf/Leaf#before.: &3, afterrust-analyzer cargo daft 0.1.5 leaf/Leaf#after.: &6 },
152 )
153 );
154 }
155 }