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

A single work item.

task_id links to an external system (a Jira issue id, a GitLab MR); timestamp is managed by the database layer.

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

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

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

Populating a task from an external issue:

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; None until the task is saved.

§task_id: Option<i32>

External reference (Jira issue id, GitLab MR id); None for standalone tasks.

§timestamp: Option<String>

"YYYY-MM-DD HH:MM:SS" in local time, set by the database layer.

§name: String

Task title.

§comment: String

Free-form notes.

§completeness: Option<i32>

Progress 0-100; imported completed issues default to 100.

§excluded_from_search: Option<bool>

Hidden from task discovery when true.

§tags: Vec<Tag>

Tags, maintained through the task_tags relationship table.

Implementations§

Source§

impl Task

Source

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

Creates an unsaved task; whitespace in name and comment is collapsed.

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

let new_task = Task::new(
    "Implement user registration",
    "Add email verification and password validation",
    Some(0)
);

let completed_task = Task::new(
    "Fix login redirect bug",
    "Resolved issue with OAuth callback URL handling",
    Some(100)
);

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)

Copies name, comment and completeness from other, keeping identity fields (id, task_id, timestamp, search flag, tags).

use kasl::libs::task::Task;
use kasl::db::tasks::Tasks;

let mut tasks_db = Tasks::new()?;
let mut existing_task = tasks_db.get_by_id(42)?.expect("task exists");

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

existing_task.update_from(&updated_task);
tasks_db.update(&existing_task)?;
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)?;
    }
}
use kasl::libs::task::Task;

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

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

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<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> 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 = !

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<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