File: go_trait.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 893,176 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; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (43 lines) | stat: -rw-r--r-- 721 bytes parent folder | download | duplicates (81)
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
42
43
#![feature(specialization)]

// Common code used for tests that model the Fn/FnMut/FnOnce hierarchy.

pub trait Go {
    fn go(&self, arg: isize);
}

pub fn go<G:Go>(this: &G, arg: isize) {
    this.go(arg)
}

pub trait GoMut {
    fn go_mut(&mut self, arg: isize);
}

pub fn go_mut<G:GoMut>(this: &mut G, arg: isize) {
    this.go_mut(arg)
}

pub trait GoOnce {
    fn go_once(self, arg: isize);
}

pub fn go_once<G:GoOnce>(this: G, arg: isize) {
    this.go_once(arg)
}

impl<G> GoMut for G
    where G : Go
{
    default fn go_mut(&mut self, arg: isize) {
        go(&*self, arg)
    }
}

impl<G> GoOnce for G
    where G : GoMut
{
    default fn go_once(mut self, arg: isize) {
        go_mut(&mut self, arg)
    }
}