File: assoc_item_trait_bounds.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 (66 lines) | stat: -rw-r--r-- 1,725 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use std::ops::AsyncFnMut;

pub trait Main {
    type Item;

    type Out0: Support<Item = ()>;
    type Out1: Support<Item = Self::Item>;
    type Out2<T>: Support<Item = T>;
    type Out3: Support<Produce<()> = bool>;
    type Out4<T>: Support<Produce<T> = T>;
    type Out5: Support<Output<'static> = &'static ()>;
    type Out6: for<'a> Support<Output<'a> = &'a ()>;
    type Out7: Support<Item = String, Produce<i32> = u32> + Unrelated;
    type Out8: Unrelated + Protocol<i16, Q1 = u128, Q0 = ()>;
    type Out9: FnMut(i32) -> bool + Clone;
    type Out10<'q>: Support<Output<'q> = ()>;
    type Out11: for<'r, 's> Helper<A<'s> = &'s (), B<'r> = ()>;
    type Out12: for<'w> Helper<B<'w> = std::borrow::Cow<'w, str>, A<'w> = bool>;
    type Out13: for<'fst, 'snd> Aid<'snd, Result<'fst> = &'fst mut str>;
    type Out14<P: Copy + Eq, Q: ?Sized>;
    type Out15: AsyncFnMut(i32) -> bool;

    fn make<F>(_: F, _: impl FnMut(&str) -> bool)
    where
        F: FnOnce(u32) -> String,
        Self::Out2<()>: Protocol<u8, Q0 = Self::Item, Q1 = ()>;
}

pub trait Support {
    type Item;
    type Output<'a>;
    type Produce<T>;
}

pub trait Protocol<K> {
    type Q0;
    type Q1;
}

pub trait Unrelated {}

pub trait Helper {
    type A<'q>;
    type B<'q>;
}

pub trait Aid<'src> {
    type Result<'inter: 'src>;
}

pub trait Implementee {
    type Alias<T: Eq>
    where
        String: From<T>;
}

pub struct Implementor;

impl Implementee for Implementor {
    type Alias<T: Eq> = T
    where
        String: From<T>,
        // We will check that this bound doesn't get turned into an item bound since
        // associated types in impls are not allowed to have any.
        Self::Alias<T>: From<Self::Alias<T>>;
}