File: deref-recursive.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (41 lines) | stat: -rw-r--r-- 1,381 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// #26207: Show all methods reachable via Deref impls, recursing through multiple dereferencing
// levels if needed.
// For `Deref` on foreign types, look at `deref-recursive-pathbuf.rs`.

//@ has 'foo/struct.Foo.html'
//@ has '-' '//*[@id="deref-methods-Bar"]' 'Methods from Deref<Target = Bar>'
//@ has '-' '//*[@class="impl-items"]//*[@id="method.bar"]' 'pub fn bar(&self)'
//@ has '-' '//*[@id="deref-methods-Baz"]' 'Methods from Deref<Target = Baz>'
//@ has '-' '//*[@class="impl-items"]//*[@id="method.baz"]' 'pub fn baz(&self)'
//@ has '-' '//div[@class="sidebar-elems"]//h3/a[@href="#deref-methods-Bar"]' 'Methods from Deref<Target=Bar>'
//@ has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.bar"]' 'bar'
//@ has '-' '//div[@class="sidebar-elems"]//h3/a[@href="#deref-methods-Baz"]' 'Methods from Deref<Target=Baz>'
//@ has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.baz"]' 'baz'

#![crate_name = "foo"]

use std::ops::Deref;

pub struct Foo(Bar);
pub struct Bar(Baz);
pub struct Baz;

impl Deref for Foo {
    type Target = Bar;
    fn deref(&self) -> &Bar { &self.0 }
}

impl Deref for Bar {
    type Target = Baz;
    fn deref(&self) -> &Baz { &self.0 }
}

impl Bar {
    /// This appears under `Foo` methods
    pub fn bar(&self) {}
}

impl Baz {
    /// This should also appear in `Foo` methods when recursing
    pub fn baz(&self) {}
}