Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

brokkr-models::models::stack_labels Rust

Structs

brokkr-models::models::stack_labels::StackLabel

pub

Derives: Queryable, Selectable, Identifiable, AsChangeset, Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash, ``

Represents a stack label in the database.

Fields

NameTypeDescription
idUuidUnique identifier for the stack label.
stack_idUuidID of the stack this label is associated with.
labelStringThe label text (max 64 characters, no whitespace).

brokkr-models::models::stack_labels::NewStackLabel

pub

Derives: Insertable, Debug, Clone, Serialize, Deserialize

Represents a new stack label to be inserted into the database.

Fields

NameTypeDescription
stack_idUuidID of the stack this label is associated with.
labelStringThe label text (max 64 characters, no whitespace).

Methods

new pub
#![allow(unused)]
fn main() {
fn new (stack_id : Uuid , label : String) -> Result < Self , String >
}

Creates a new NewStackLabel instance.

Parameters:

NameTypeDescription
stack_id-UUID of the stack to associate the label with.
label-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
#![allow(unused)]
fn main() {
    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 })
    }
}