Skip to main content

Task

Struct Task 

Source
pub struct Task {
    pub id: Option<i32>,
    pub task_id: Option<i32>,
    pub timestamp: Option<String>,
    pub name: String,
    pub comment: String,
    pub completeness: Option<i32>,
    pub excluded_from_search: Option<bool>,
    pub tags: Vec<Tag>,
}
Expand description

Represents a single task or work item in the productivity tracking system.

The Task struct encapsulates all information about a work item including its identification, description, progress status, and associated metadata. Tasks serve as the fundamental unit of work organization within kasl.

§Field Descriptions

§Identification Fields

  • id: Database primary key for persistence and relationships
  • task_id: Reference ID for linking to external systems or parent tasks
  • timestamp: Creation/modification time for audit trails

§Content Fields

  • name: Brief, descriptive title for the task
  • comment: Detailed description, notes, or additional context
  • completeness: Progress percentage (0-100) indicating work completion

§Configuration Fields

  • excluded_from_search: Flag to hide tasks from general searches
  • tags: Collection of categorization labels for organization

§Usage Patterns

§New Task Creation

use kasl::libs::task::Task;

let task = Task::new(
    "Code review for PR #123",
    "Review authentication changes and security implications",
    Some(0) // Just started
);

§Task Updates

use kasl::libs::task::Task;

let existing_task = Task::new("Existing task", "Details", Some(50));
let mut task = existing_task;
task.completeness = Some(75); // 75% complete
task.comment = "Almost finished, testing remaining".to_string();

§External Integration

use kasl::libs::task::Task;

// Simulated Jira issue data used to populate a task.
let jira_issue_id = 42;
struct JiraIssue {
    summary: String,
    description: Option<String>,
}
let jira_issue = JiraIssue {
    summary: "Fix login bug".to_string(),
    description: Some("Users cannot log in with SSO".to_string()),
};

let jira_task = Task {
    id: None, // Will be assigned by database
    task_id: Some(jira_issue_id),
    timestamp: None,
    name: jira_issue.summary,
    comment: jira_issue.description.unwrap_or_default(),
    completeness: Some(100), // Imported completed issues
    excluded_from_search: None,
    tags: vec![],
};

Fields§

§id: Option<i32>

Database primary key for task identification and relationships.

This field contains the unique identifier assigned by the database when the task is first saved. It’s used for:

  • Database queries and updates
  • Foreign key relationships (tags, time tracking)
  • Cross-referencing with other application data

Values:

  • Some(id): Task exists in database with assigned ID
  • None: New task not yet saved to database
§task_id: Option<i32>

Reference identifier for external system integration or task linking.

This field provides a way to link tasks to external systems or create hierarchical relationships between tasks. Common uses include:

  • Jira issue numbers for imported tasks
  • GitLab merge request IDs for code review tasks
  • Parent task IDs for subtask relationships
  • External project management system references

Values:

  • Some(id): Task is linked to external system or parent task
  • None: Standalone task with no external references
§timestamp: Option<String>

ISO 8601 timestamp string indicating task creation or last modification.

This field provides audit trail information for task management. The timestamp is automatically managed by the database layer and is primarily used for:

  • Sorting tasks by creation or modification time
  • Audit trails and change tracking
  • Time-based filtering and reporting
  • Synchronization with external systems

Format: “YYYY-MM-DD HH:MM:SS” in local timezone Example: “2025-01-15 14:30:45”

§name: String

Brief, descriptive title summarizing the task’s purpose or objective.

The task name should be concise yet descriptive enough to understand the work item at a glance. It appears in task lists, reports, and notifications throughout the application.

Guidelines:

  • Keep under 100 characters for display compatibility
  • Use action-oriented language (“Implement”, “Review”, “Fix”)
  • Include key context (“Fix login bug in mobile app”)
  • Avoid technical jargon when possible

Examples:

  • “Implement OAuth2 authentication”
  • “Review security audit findings”
  • “Update API documentation for v2.0”
§comment: String

Detailed description, notes, or additional context for the task.

The comment field provides space for detailed information that doesn’t fit in the task name. This might include:

  • Technical requirements and specifications
  • Links to related resources or documentation
  • Progress notes and status updates
  • Dependencies and prerequisites
  • Testing criteria and acceptance conditions

Content Guidelines:

  • Use clear, structured formatting when helpful
  • Include links to relevant resources
  • Update with progress notes and findings
  • Keep information current and relevant
§completeness: Option<i32>

Completion percentage indicating task progress from 0% to 100%.

This field tracks the task’s progress through its lifecycle, providing quantitative measurement of work completion. The percentage is used for:

  • Progress reporting and analytics
  • Filtering incomplete vs. complete tasks
  • Productivity calculations and trends
  • Project status tracking and reporting

Values:

  • Some(0): Task not started
  • Some(1-99): Task in progress
  • Some(100): Task completed
  • None: Progress not tracked or unknown

Default: 100% for tasks imported from external systems

§excluded_from_search: Option<bool>

Flag indicating whether task should be hidden from general searches.

This field allows tasks to be excluded from default search results while remaining accessible through direct queries. Useful for:

  • Administrative or system-generated tasks
  • Deprecated or obsolete tasks that shouldn’t appear in normal workflow
  • Sensitive tasks that require explicit access
  • Archived tasks that should remain searchable but not prominent

Values:

  • Some(true): Task excluded from general searches
  • Some(false) or None: Task included in normal search results
§tags: Vec<Tag>

Collection of categorization tags associated with this task.

Tags provide a flexible labeling system for task organization and filtering. They enable:

  • Project-based organization (“frontend”, “backend”, “mobile”)
  • Priority classification (“urgent”, “low-priority”, “nice-to-have”)
  • Status indicators (“blocked”, “waiting-review”, “approved”)
  • Skill-based categorization (“javascript”, “database”, “ui-design”)

Management:

  • Tags are created automatically when first used
  • Multiple tags can be associated with a single task
  • Tag associations are maintained in separate database table
  • Tags can be deleted if no longer associated with any tasks

Implementations§

Source§

impl Task

Source

pub fn new(name: &str, comment: &str, completeness: Option<i32>) -> Self

Creates a new task with the specified name, comment, and completion status.

This constructor initializes a new task with the provided information and sets appropriate defaults for other fields. The task is not automatically saved to the database - use the database layer for persistence.

§Default Values

New tasks are initialized with:

  • id: None (assigned when saved to database)
  • task_id: None (no external reference)
  • timestamp: None (managed by database)
  • excluded_from_search: None (included in searches)
  • tags: Empty vector (no initial categorization)
§Parameter Guidelines
§Task Name
  • Should be concise but descriptive
  • Use action-oriented language
  • Include key context for clarity
§Comment
  • Provide detailed context and requirements
  • Include links to related resources
  • Can be updated as work progresses
§Completeness
  • Use Some(0) for new tasks that haven’t started
  • Use Some(100) for already completed imported tasks
  • Use None if progress tracking isn’t needed
§Arguments
  • name - Brief, descriptive task title
  • comment - Detailed description or notes
  • completeness - Optional completion percentage (0-100)
§Returns

A new Task instance ready for use or database persistence.

§Examples
use kasl::libs::task::Task;

// Create a new task that's just starting
let new_task = Task::new(
    "Implement user registration",
    "Add email verification and password validation",
    Some(0)
);

// Create a completed task (e.g., imported from external system)
let completed_task = Task::new(
    "Fix login redirect bug",
    "Resolved issue with OAuth callback URL handling",
    Some(100)
);

// Create a task without progress tracking
let planning_task = Task::new(
    "Research authentication libraries",
    "Evaluate OAuth2 libraries for Node.js backend",
    None
);
Source

pub fn update_from(&mut self, other: &Task)

Updates task fields from another task while preserving identity fields.

This method provides a convenient way to update task content while maintaining database identity and relationships. It’s particularly useful for implementing task editing workflows where the user modifies task details but the task’s core identity remains unchanged.

§Preserved Fields

The following fields are not updated to maintain task identity:

  • id: Database primary key remains unchanged
  • task_id: External reference remains unchanged
  • timestamp: Will be updated by database on save
  • excluded_from_search: Search visibility remains unchanged
  • tags: Tag associations require separate management
§Updated Fields

The following fields are copied from the source task:

  • name: Task title is updated
  • comment: Description and notes are updated
  • completeness: Progress percentage is updated
§Use Cases
§Task Editing Workflow
use kasl::libs::task::Task;
use kasl::db::tasks::Tasks;

let mut tasks_db = Tasks::new()?;

// Load existing task from database
let mut existing_task = tasks_db.get_by_id(42)?.expect("task exists");

// Create updated version with user modifications
let updated_task = Task::new(
    "Updated task name",
    "Updated description with new requirements",
    Some(75)
);

// Apply updates while preserving identity
existing_task.update_from(&updated_task);

// Save to database
tasks_db.update(&existing_task)?;
§Bulk Task Updates
use kasl::libs::task::Task;
use kasl::db::tasks::Tasks;

let mut tasks_db = Tasks::new()?;
let tasks_to_update: Vec<Task> = vec![];
let get_update_template = |_task: &Task| -> Option<Task> { None };

for mut task in tasks_to_update {
    if let Some(template) = get_update_template(&task) {
        task.update_from(&template);
        tasks_db.update(&task)?;
    }
}
§Arguments
  • other - Source task containing the updated field values
§Examples
use kasl::libs::task::Task;

let mut original_task = Task::new(
    "Original task",
    "Original description",
    Some(25)
);
// Simulate database assignment
original_task.id = Some(42);

let updated_task = Task::new(
    "Updated task name",
    "Updated description with more details",
    Some(75)
);

// Apply updates while preserving ID
original_task.update_from(&updated_task);

assert_eq!(original_task.id, Some(42)); // ID preserved
assert_eq!(original_task.name, "Updated task name"); // Content updated
assert_eq!(original_task.completeness, Some(75)); // Progress updated

Trait Implementations§

Source§

impl Clone for Task

Source§

fn clone(&self) -> Task

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Task

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Task

§

impl RefUnwindSafe for Task

§

impl Send for Task

§

impl Sync for Task

§

impl Unpin for Task

§

impl UnsafeUnpin for Task

§

impl UnwindSafe for Task

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more