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
67
68
69
70
71
72
73
74
75
76
77
78
//! Subject resolution for the unified `can` / `authorize` target argument.
use Any;
/// Associates a concrete resource type with its logical subject `S`.
///
/// Implementing this lets a resource instance be passed directly to
/// [`Ability::can`](crate::Ability::can) without separately naming its subject:
///
/// ```
/// # use praetor::AbilitySubject;
/// #[derive(PartialEq, Eq)]
/// enum Subject { Message }
///
/// struct Message;
///
/// impl AbilitySubject<Subject> for Message {
/// fn subject_type(&self) -> Subject {
/// Subject::Message
/// }
/// }
/// ```
/// Marker selecting the subject-value branch of [`IntoTarget`].
;
/// Marker selecting the resource-reference branch of [`IntoTarget`].
;
/// An authorization target resolved to its subject, optionally carrying the
/// concrete resource instance for conditional-rule evaluation.
///
/// This type is opaque: any resource instance is stored type-erased internally
/// and is never exposed to consumers.
/// Resolves an authorization target into a [`Target`].
///
/// This is what lets a single `can` / `authorize` method accept either a
/// subject value (`Subject::Message`) or a resource reference (`&message`). A
/// subject value resolves to a [`Target`] with no resource, so conditional
/// rules cannot match it; a resource reference additionally carries the
/// instance so conditional predicates can be evaluated against it.
///
/// The `Marker` type parameter disambiguates the two blanket implementations
/// and is always inferred; consumers never name it.