1use std::str::FromStr;
4
5#[cfg(feature = "hierarchy")]
6use crate::hierarchy::Hierarchized;
7use crate::policy::{Policy, PolicyBuilder};
8
9#[cfg(not(feature = "hierarchy"))]
10pub trait Scope: FromStr + PartialEq {}
15
16#[cfg(feature = "hierarchy")]
17pub trait Scope: FromStr + PartialEq + Hierarchized {}
25
26
27pub trait AsScopeRef<S: Scope> {
29 fn as_scope_ref(&self) -> &S;
31}
32
33impl<S: Scope> Policy<S> {
34 pub fn builder() -> PolicyBuilder<S> {
38 PolicyBuilder::new()
39 }
40}
41
42impl<S: Scope> AsScopeRef<S> for S {
43 fn as_scope_ref(&self) -> &S {
44 self
45 }
46}
47
48impl<'a, S: Scope> AsScopeRef<S> for &'a S {
49 fn as_scope_ref(&self) -> &S {
50 *self
51 }
52}
53
54impl<'a, 'b, S: Scope> AsScopeRef<S> for &'a &'b S {
55 fn as_scope_ref(&self) -> &S {
56 **self
57 }
58}
59
60#[cfg(test)]
61mod tests {
62 use crate::scope::AsScopeRef;
63
64 #[test]
65 fn test_as_scope_ref() {
66
67 let scope = "foo".to_string();
68
69 assert_eq!(&scope, scope.as_scope_ref());
70 assert_eq!(&scope, (&scope).as_scope_ref());
71 assert_eq!(&scope, (&&scope).as_scope_ref());
72 assert_eq!(&scope, (&&&scope).as_scope_ref());
73
74 }
75}