pub struct Resource { /* private fields */ }Expand description
A resource represents something that can be accessed or acted upon.
Implementations§
Source§impl Resource
impl Resource
Sourcepub fn new_checked(
id: impl Into<String>,
resource_type: impl Into<String>,
) -> Result<Self, Error>
pub fn new_checked( id: impl Into<String>, resource_type: impl Into<String>, ) -> Result<Self, Error>
Create a new resource with validation.
§Errors
Returns a ValidationError if the ID or resource type contains path traversal
sequences or null characters.
Sourcepub fn new(id: impl Into<String>, resource_type: impl Into<String>) -> Self
pub fn new(id: impl Into<String>, resource_type: impl Into<String>) -> Self
Create a new resource.
§Panics
This method panics if the ID or resource type contains path traversal
sequences or null characters. For non-panicking validation, use new_checked.
Sourcepub fn resource_type(&self) -> &str
pub fn resource_type(&self) -> &str
Get the resource type.
Sourcepub fn with_attribute(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_attribute( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Add an attribute to the resource.
Sourcepub fn set_attribute(
&mut self,
key: impl Into<String>,
value: impl Into<String>,
)
pub fn set_attribute( &mut self, key: impl Into<String>, value: impl Into<String>, )
Set an attribute on the resource.
Sourcepub fn attributes(&self) -> &HashMap<String, String>
pub fn attributes(&self) -> &HashMap<String, String>
Get all attributes.
Sourcepub fn remove_attribute(&mut self, key: &str) -> Option<String>
pub fn remove_attribute(&mut self, key: &str) -> Option<String>
Remove an attribute.
Sourcepub fn has_attribute(&self, key: &str) -> bool
pub fn has_attribute(&self, key: &str) -> bool
Check if the resource has a specific attribute.
Sourcepub fn effective_name(&self) -> &str
pub fn effective_name(&self) -> &str
Get the effective name for display purposes.
Sourcepub fn matches_pattern(&self, pattern: &str) -> bool
pub fn matches_pattern(&self, pattern: &str) -> bool
Check if this resource matches a pattern. Patterns can include wildcards (*) and hierarchical matching.
Sourcepub fn is_under_path(&self, parent_path: &str) -> bool
pub fn is_under_path(&self, parent_path: &str) -> bool
Check if the resource is within a specific parent path.
Sourcepub fn parent_path(&self) -> Option<String>
pub fn parent_path(&self) -> Option<String>
Get the parent path of this resource.