pub struct StorageQuota {
pub total_bytes: Bytes,
pub used_bytes: Bytes,
pub reserved_bytes: Bytes,
}Expand description
Storage quota information for a user or node.
§Examples
use chie_shared::StorageQuota;
// Create 10 GB quota with 5 GB used and 1 GB reserved
let quota = StorageQuota::new(
10 * 1024 * 1024 * 1024, // 10 GB total
5 * 1024 * 1024 * 1024, // 5 GB used
1 * 1024 * 1024 * 1024, // 1 GB reserved
);
// Check available space
assert_eq!(quota.available_bytes(), 4 * 1024 * 1024 * 1024);
// Check utilization
assert_eq!(quota.utilization(), 0.5);
// Check if can allocate more
assert!(quota.can_allocate(3 * 1024 * 1024 * 1024));
assert!(!quota.is_nearly_full());Fields§
§total_bytes: BytesTotal allocated storage in bytes.
used_bytes: BytesCurrently used storage in bytes.
reserved_bytes: BytesReserved storage in bytes (pending operations).
Implementations§
Source§impl StorageQuota
impl StorageQuota
Sourcepub fn new(total_bytes: Bytes, used_bytes: Bytes, reserved_bytes: Bytes) -> Self
pub fn new(total_bytes: Bytes, used_bytes: Bytes, reserved_bytes: Bytes) -> Self
Create a new storage quota.
Sourcepub fn available_bytes(&self) -> Bytes
pub fn available_bytes(&self) -> Bytes
Get available storage in bytes.
Sourcepub fn utilization(&self) -> f64
pub fn utilization(&self) -> f64
Get utilization percentage (0.0 to 1.0).
Sourcepub fn can_allocate(&self, bytes: Bytes) -> bool
pub fn can_allocate(&self, bytes: Bytes) -> bool
Check if there’s enough space for additional bytes.
Sourcepub fn is_nearly_full(&self) -> bool
pub fn is_nearly_full(&self) -> bool
Check if quota is nearly full (>90% used).
Sourcepub fn allocated_bytes(&self) -> Bytes
pub fn allocated_bytes(&self) -> Bytes
Get total allocated bytes (used + reserved).
Trait Implementations§
Source§impl Clone for StorageQuota
impl Clone for StorageQuota
Source§fn clone(&self) -> StorageQuota
fn clone(&self) -> StorageQuota
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for StorageQuota
impl Debug for StorageQuota
Source§impl Default for StorageQuota
impl Default for StorageQuota
Source§impl<'de> Deserialize<'de> for StorageQuota
impl<'de> Deserialize<'de> for StorageQuota
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for StorageQuota
impl PartialEq for StorageQuota
Source§impl Serialize for StorageQuota
impl Serialize for StorageQuota
impl StructuralPartialEq for StorageQuota
Auto Trait Implementations§
impl Freeze for StorageQuota
impl RefUnwindSafe for StorageQuota
impl Send for StorageQuota
impl Sync for StorageQuota
impl Unpin for StorageQuota
impl UnwindSafe for StorageQuota
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more