mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-22 06:47:56 +01:00
Cleanup of permissions.rs
This commit is contained in:
parent
efe2da87d3
commit
a7754f057b
@ -175,11 +175,13 @@ pub struct PermissionBuf {
|
|||||||
inner: String,
|
inner: String,
|
||||||
}
|
}
|
||||||
impl PermissionBuf {
|
impl PermissionBuf {
|
||||||
|
#[inline(always)]
|
||||||
/// Allocate an empty `PermissionBuf`
|
/// Allocate an empty `PermissionBuf`
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
PermissionBuf { inner: String::new() }
|
PermissionBuf { inner: String::new() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
/// Allocate a `PermissionBuf` with the given capacity given to the internal [`String`]
|
/// Allocate a `PermissionBuf` with the given capacity given to the internal [`String`]
|
||||||
pub fn with_capacity(cap: usize) -> Self {
|
pub fn with_capacity(cap: usize) -> Self {
|
||||||
PermissionBuf { inner: String::with_capacity(cap) }
|
PermissionBuf { inner: String::with_capacity(cap) }
|
||||||
@ -203,18 +205,22 @@ impl PermissionBuf {
|
|||||||
self.inner.push_str(perm.as_str())
|
self.inner.push_str(perm.as_str())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub const fn from_string_unchecked(inner: String) -> Self {
|
pub const fn from_string_unchecked(inner: String) -> Self {
|
||||||
Self { inner }
|
Self { inner }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn from_perm(perm: &Permission) -> Self {
|
pub fn from_perm(perm: &Permission) -> Self {
|
||||||
Self { inner: perm.inner.to_string() }
|
Self { inner: perm.as_str().to_string() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn into_string(self) -> String {
|
pub fn into_string(self) -> String {
|
||||||
self.inner
|
self.inner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.inner.is_empty()
|
self.inner.is_empty()
|
||||||
}
|
}
|
||||||
@ -258,21 +264,24 @@ impl fmt::Display for PermissionBuf {
|
|||||||
/// This means that ```(bffh.perm) > (bffh.perm.sub) == true```
|
/// This means that ```(bffh.perm) > (bffh.perm.sub) == true```
|
||||||
/// but ```(bffh.perm) > (unrelated.but.more.specific.perm) == false```.
|
/// but ```(bffh.perm) > (unrelated.but.more.specific.perm) == false```.
|
||||||
/// This allows to check if PermRule a grants Perm b by checking `a > b`.
|
/// This allows to check if PermRule a grants Perm b by checking `a > b`.
|
||||||
pub struct Permission {
|
pub struct Permission(str);
|
||||||
inner: str
|
|
||||||
}
|
|
||||||
impl Permission {
|
impl Permission {
|
||||||
|
#[inline(always)]
|
||||||
|
// We can't make this `const` just yet because `str` is always a fat pointer meaning we can't
|
||||||
|
// just const cast it, and `CoerceUnsized` and friends are currently unstable.
|
||||||
pub fn new<S: AsRef<str> + ?Sized>(s: &S) -> &Permission {
|
pub fn new<S: AsRef<str> + ?Sized>(s: &S) -> &Permission {
|
||||||
// Safe because s is a valid reference
|
// Safe because s is a valid reference
|
||||||
unsafe { &*(s.as_ref() as *const str as *const Permission) }
|
unsafe { &*(s.as_ref() as *const str as *const Permission) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn as_str(&self) -> &str {
|
pub fn as_str(&self) -> &str {
|
||||||
&self.inner
|
&self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn iter(&self) -> std::str::Split<char> {
|
pub fn iter(&self) -> std::str::Split<char> {
|
||||||
self.inner.split('.')
|
self.0.split('.')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user