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::agent_annotations Rust

Structs

brokkr-models::models::agent_annotations::AgentAnnotation

pub

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

Represents an agent annotation in the database.

Fields

NameTypeDescription
idUuidUnique identifier for the annotation.
agent_idUuidID of the agent this annotation belongs to.
keyStringKey of the annotation (max 64 characters, no whitespace).
valueStringValue of the annotation (max 64 characters, no whitespace).

brokkr-models::models::agent_annotations::NewAgentAnnotation

pub

Derives: Insertable, Debug, Clone, Serialize, Deserialize, ToSchema

Represents a new agent annotation to be inserted into the database.

Fields

NameTypeDescription
agent_idUuidID of the agent this annotation belongs to.
keyStringKey of the annotation (max 64 characters, no whitespace).
valueStringValue of the annotation (max 64 characters, no whitespace).

Methods

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

Creates a new NewAgentAnnotation instance.

Parameters:

NameTypeDescription
agent_id-UUID of the agent to associate the annotation with.
key-The key for the annotation. Must be non-empty, max 64 characters, and contain no whitespace.
value-The value for the annotation. Must be non-empty, max 64 characters, and contain no whitespace.

Returns:

Returns Ok(NewAgentAnnotation) if all parameters are valid, otherwise returns an Err with a description of the validation failure.

Source
#![allow(unused)]
fn main() {
    pub fn new(agent_id: Uuid, key: String, value: String) -> Result<Self, String> {
        // Validate agent_id
        if agent_id.is_nil() {
            return Err("Invalid agent ID".to_string());
        }

        // Validate key
        if key.is_empty() {
            return Err("Key cannot be empty".to_string());
        }
        if key.len() > 64 {
            return Err("Key cannot exceed 64 characters".to_string());
        }
        if key.contains(char::is_whitespace) {
            return Err("Key cannot contain whitespace".to_string());
        }

        // Validate value
        if value.is_empty() {
            return Err("Value cannot be empty".to_string());
        }
        if value.len() > 64 {
            return Err("Value cannot exceed 64 characters".to_string());
        }
        if value.contains(char::is_whitespace) {
            return Err("Value cannot contain whitespace".to_string());
        }

        Ok(NewAgentAnnotation {
            agent_id,
            key,
            value,
        })
    }
}