brokkr-models::models::stack_labels
Rust
Stack Label Module
This module defines structures and methods for managing stack labels in the system.
Data Model
Stack labels are used to categorize and organize stacks. They are stored in the stack_labels table
with the following structure:
id: UUID, primary keystack_id: UUID, foreign key referencing thestackstablelabel: VARCHAR(255), the label associated with the stack
Usage
Stack labels can be used to group stacks, filter them, or provide additional metadata. This can be useful for organizing stacks based on their purpose, environment, or any other relevant categorization.
Constraints
- The
stack_idmust be a valid, non-nil UUID. - The
labelmust be a non-empty string. - The
labelmust not exceed 64 characters. - The
labelcannot contain whitespace.
Structs
Section titled “Structs”struct StackLabel
Section titled “struct StackLabel”pub
Derives: Queryable, Selectable, Identifiable, AsChangeset, Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash, ToSchema
Represents a stack label in the database.
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
id |
Uuid |
Unique identifier for the stack label. |
stack_id |
Uuid |
ID of the stack this label is associated with. |
label |
String |
The label text (max 64 characters, no whitespace). |
struct NewStackLabel
Section titled “struct NewStackLabel”pub
Derives: Insertable, Debug, Clone, Serialize, Deserialize, ToSchema
Represents a new stack label to be inserted into the database.
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
stack_id |
Uuid |
ID of the stack this label is associated with. |
label |
String |
The label text (max 64 characters, no whitespace). |
Methods
Section titled “Methods”pub
fn new(stack_id: Uuid, label: String) -> Result<Self, String>Creates a new NewStackLabel instance.
Parameters:
| Name | Type | Description |
|---|---|---|
stack_id |
Uuid |
UUID of the stack to associate the label with. |
label |
String |
The label text. Must be non-empty, max 64 characters, and contain no whitespace. |
Returns:
Returns Ok(NewStackLabel) if all parameters are valid,
otherwise returns an Err with a description of the validation failure.
Source
pub fn new(stack_id: Uuid, label: String) -> Result<Self, String> { // Validate stack_id if stack_id.is_nil() { return Err("Invalid stack ID".to_string()); }
// Validate label if label.trim().is_empty() { return Err("Label cannot be empty".to_string()); }
// Check label length if label.len() > 64 { return Err("Label cannot exceed 64 characters".to_string()); }
// Check whitespace if label.contains(char::is_whitespace) { return Err("Label cannot contain whitespace".to_string()); }
Ok(NewStackLabel { stack_id, label }) }