Debian Codegraph @

src/list.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#;
2
3 /// An immutable singly-linked list.
4 pub struct Listrust-analyzer cargo referencing 0.37.4 list/List#<T> {
5 headrust-analyzer cargo referencing 0.37.4 list/List#head.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Noderust-analyzer cargo referencing 0.37.4 list/Node#<T>>>,
6 }
7
8 impl<T: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# for Listrust-analyzer cargo referencing 0.37.4 list/List#<T> {
9 fn clonerust-analyzer cargo referencing 0.37.4 list/impl#[`List<T>`][Clone]clone().(&self) -> Selfrust-analyzer cargo referencing 0.37.4 list/impl#[`List<T>`][Clone] {
10 Listrust-analyzer cargo referencing 0.37.4 list/List# {
11 headrust-analyzer cargo referencing 0.37.4 list/List#head.: self.headrust-analyzer cargo referencing 0.37.4 list/List#head..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Clone]clone().(),
12 }
13 }
14 }
15
16 impl<T: 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#> 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# for Listrust-analyzer cargo referencing 0.37.4 list/List#<T> {
17 fn fmtrust-analyzer cargo referencing 0.37.4 list/impl#[`List<T>`][Debug]fmt().(&self, f: &mut 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/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> 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/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
18 f.debug_listrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_list().().entriesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugList<'a, 'b>`]entries().(self.iterrust-analyzer cargo referencing 0.37.4 list/impl#[`List<T>`]iter().()).finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugList<'a, 'b>`]finish().()
19 }
20 }
21
22 impl<T: PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#> PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq# for Listrust-analyzer cargo referencing 0.37.4 list/List#<T> {
23 fn eqrust-analyzer cargo referencing 0.37.4 list/impl#[`List<T>`][`PartialEq<Self>`]eq().(&self, other: &Selfrust-analyzer cargo referencing 0.37.4 list/impl#[`List<T>`][`PartialEq<Self>`]) -> bool {
24 self.iterrust-analyzer cargo referencing 0.37.4 list/impl#[`List<T>`]iter().().eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#eq().(other.iterrust-analyzer cargo referencing 0.37.4 list/impl#[`List<T>`]iter().())
25 }
26 }
27
28 impl<T: Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq#> Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# for Listrust-analyzer cargo referencing 0.37.4 list/List#<T> {}
29
30 impl<T: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::hashrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/::Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::hashrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/::Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# for Listrust-analyzer cargo referencing 0.37.4 list/List#<T> {
31 fn hashrust-analyzer cargo referencing 0.37.4 list/impl#[`List<T>`][Hash]hash().<H: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::hashrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/::Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#>(&self, state: &mut H) {
32 for item in self {
33 item.hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#hash().(state);
34 }
35 }
36 }
37
38 impl<T> Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for Listrust-analyzer cargo referencing 0.37.4 list/List#<T> {
39 fn droprust-analyzer cargo referencing 0.37.4 list/impl#[`List<T>`][Drop]drop().(&mut self) {
40 let mut current = self.headrust-analyzer cargo referencing 0.37.4 list/List#head..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().();
41 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(node) = current {
42 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(mut node) = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::try_unwraprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`]try_unwrap().(node) {
43 current = node.nextrust-analyzer cargo referencing 0.37.4 list/Node#next..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().();
44 } else {
45 break;
46 }
47 }
48 }
49 }
50
51 impl<T> Listrust-analyzer cargo referencing 0.37.4 list/List#<T> {
52 pub(craterust-analyzer cargo referencing 0.37.4 crate/) fn newrust-analyzer cargo referencing 0.37.4 list/impl#[`List<T>`]new().() -> Selfrust-analyzer cargo referencing 0.37.4 list/impl#[`List<T>`] {
53 Selfrust-analyzer cargo referencing 0.37.4 list/impl#[`List<T>`] { headrust-analyzer cargo referencing 0.37.4 list/List#head.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# }
54 }
55 /// Returns true if the list contains no elements.
56 #[must_use]
57 pub fn is_emptyrust-analyzer cargo referencing 0.37.4 list/impl#[`List<T>`]is_empty().(&self) -> bool {
58 self.headrust-analyzer cargo referencing 0.37.4 list/List#head..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()
59 }
60 /// Creates a new list with the given value at the front, sharing the rest of the nodes.
61 #[must_use]
62 pub fn push_frontrust-analyzer cargo referencing 0.37.4 list/impl#[`List<T>`]push_front().(&self, value: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<T>) -> Selfrust-analyzer cargo referencing 0.37.4 list/impl#[`List<T>`] {
63 Listrust-analyzer cargo referencing 0.37.4 list/List# {
64 headrust-analyzer cargo referencing 0.37.4 list/List#head.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(Noderust-analyzer cargo referencing 0.37.4 list/Node# {
65 valuerust-analyzer cargo referencing 0.37.4 list/Node#value.,
66 nextrust-analyzer cargo referencing 0.37.4 list/Node#next.: self.headrust-analyzer cargo referencing 0.37.4 list/List#head..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Clone]clone().(),
67 })),
68 }
69 }
70 /// Returns an iterator over references to the list elements.
71 #[must_use]
72 pub fn iterrust-analyzer cargo referencing 0.37.4 list/impl#[`List<T>`]iter().(&self) -> Iterrust-analyzer cargo referencing 0.37.4 list/Iter#<'_, T> {
73 Iterrust-analyzer cargo referencing 0.37.4 list/Iter# {
74 currentrust-analyzer cargo referencing 0.37.4 list/Iter#current.: self.headrust-analyzer cargo referencing 0.37.4 list/List#head..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().(),
75 }
76 }
77 }
78
79 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
80 pub(craterust-analyzer cargo referencing 0.37.4 crate/) struct Noderust-analyzer cargo referencing 0.37.4 list/Node#<T> {
81 valuerust-analyzer cargo referencing 0.37.4 list/Node#value.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<T>,
82 nextrust-analyzer cargo referencing 0.37.4 list/Node#next.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Noderust-analyzer cargo referencing 0.37.4 list/Node#<T>>>,
83 }
84
85 /// Iterator over references to elements in a `List`.
86 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
87 pub struct Iterrust-analyzer cargo referencing 0.37.4 list/Iter#<'a, T> {
88 currentrust-analyzer cargo referencing 0.37.4 list/Iter#current.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Noderust-analyzer cargo referencing 0.37.4 list/Node#<T>>>,
89 }
90
91 impl<'a, T> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for Iterrust-analyzer cargo referencing 0.37.4 list/Iter#<'a, T> {
92 type Itemrust-analyzer cargo referencing 0.37.4 list/impl#[`Iter<'a, T>`][Iterator]Item# = &'a T;
93
94 fn nextrust-analyzer cargo referencing 0.37.4 list/impl#[`Iter<'a, T>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo referencing 0.37.4 list/impl#[`Iter<'a, T>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
95 self.currentrust-analyzer cargo referencing 0.37.4 list/Iter#current..maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|current| {
96 let value = &current.valuerust-analyzer cargo referencing 0.37.4 list/Node#value.;
97 self.currentrust-analyzer cargo referencing 0.37.4 list/Iter#current. = current.nextrust-analyzer cargo referencing 0.37.4 list/Node#next..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().();
98 &*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().value
99 })
100 }
101 }
102
103 impl<'a, T> IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator# for &'a Listrust-analyzer cargo referencing 0.37.4 list/List#<T> {
104 type IntoIterrust-analyzer cargo referencing 0.37.4 list/impl#[`&'a List<T>`][IntoIterator]IntoIter# = Iterrust-analyzer cargo referencing 0.37.4 list/Iter#<'a, T>;
105 type Itemrust-analyzer cargo referencing 0.37.4 list/impl#[`&'a List<T>`][IntoIterator]Item# = &'a T;
106 fn into_iterrust-analyzer cargo referencing 0.37.4 list/impl#[`&'a List<T>`][IntoIterator]into_iter().(self) -> Selfrust-analyzer cargo referencing 0.37.4 list/impl#[`&'a List<T>`][IntoIterator]::IntoIterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#IntoIter# {
107 self.iterrust-analyzer cargo referencing 0.37.4 list/impl#[`List<T>`]iter().()
108 }
109 }