pub struct Tag {
pub id: Option<i32>,
pub name: String,
pub color: Option<String>,
pub created_at: Option<String>,
}Expand description
Represents a tag entity with its properties and metadata.
A tag is a label that can be associated with tasks for categorization and organization. Tags support optional color coding for visual organization in user interfaces.
§Field Details
- id: Database-assigned unique identifier (None for new tags)
- name: Human-readable tag name (must be unique)
- color: Optional color code for visual categorization
- created_at: Timestamp of tag creation (managed by database)
§Serialization
The struct supports JSON serialization for data export and API responses, making it suitable for configuration files and web interfaces.
Fields§
§id: Option<i32>Unique identifier assigned by the database.
This field is None for new tags that haven’t been saved to the
database yet, and Some(id) for existing tags retrieved from storage.
name: StringUnique name identifier for the tag.
Tag names must be unique across the system and are used for human-readable identification. Names are case-sensitive and should follow consistent naming conventions.
color: Option<String>Optional color code for visual categorization.
Colors can be specified as hex codes, CSS color names, or any format supported by the user interface. This field enables visual organization and quick recognition of tag categories.
created_at: Option<String>Timestamp when the tag was created.
Automatically managed by the database and used for audit trails and chronological sorting. Format depends on database settings.
Implementations§
Source§impl Tag
impl Tag
Sourcepub fn new(name: String, color: Option<String>) -> Self
pub fn new(name: String, color: Option<String>) -> Self
Creates a new tag instance with the specified name and optional color.
This constructor creates a tag object ready for database insertion.
The ID and creation timestamp are set by the database when the tag
is saved using the Tags::create() method.
§Arguments
name- Unique name for the tag (will be validated for uniqueness)color- Optional color code for visual organization
§Returns
Returns a new Tag instance ready for database operations.
§Example
use kasl::db::tags::Tag;
// Create a tag with color
let urgent_tag = Tag::new("urgent".to_string(), Some("red".to_string()));
// Create a tag without color
let general_tag = Tag::new("general".to_string(), None);