mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
add tc_task_add_tag and check errors
This commit is contained in:
parent
ef0bb2ced4
commit
ce45c1004c
3 changed files with 61 additions and 3 deletions
|
@ -2,7 +2,8 @@ use crate::{
|
|||
replica::TCReplica, result::TCResult, status::TCStatus, string::TCString, uuid::TCUuid,
|
||||
};
|
||||
use std::ops::Deref;
|
||||
use taskchampion::{Task, TaskMut};
|
||||
use std::str::FromStr;
|
||||
use taskchampion::{Tag, Task, TaskMut};
|
||||
|
||||
/// A task, as publicly exposed by this library.
|
||||
///
|
||||
|
@ -282,7 +283,6 @@ pub extern "C" fn tc_task_set_description<'a>(
|
|||
)
|
||||
}
|
||||
|
||||
// TODO: tc_task_set_description
|
||||
// TODO: tc_task_set_entry
|
||||
// TODO: tc_task_set_wait
|
||||
// TODO: tc_task_set_modified
|
||||
|
@ -319,7 +319,28 @@ pub extern "C" fn tc_task_stop<'a>(task: *mut TCTask) -> TCResult {
|
|||
|
||||
// TODO: tc_task_done
|
||||
// TODO: tc_task_delete
|
||||
// TODO: tc_task_add_tag
|
||||
|
||||
/// Add a tag to a mutable task.
|
||||
///
|
||||
/// Returns TC_RESULT_TRUE on success and TC_RESULT_ERROR on failure.
|
||||
#[no_mangle]
|
||||
pub extern "C" fn tc_task_add_tag<'a>(task: *mut TCTask, tag: *mut TCString) -> TCResult {
|
||||
// SAFETY:
|
||||
// - tcstring is not NULL (promised by caller)
|
||||
// - caller is exclusive owner of tcstring (implicitly promised by caller)
|
||||
let tcstring = unsafe { TCString::from_arg(tag) };
|
||||
wrap_mut(
|
||||
task,
|
||||
|task| {
|
||||
let tagstr = tcstring.as_str()?;
|
||||
let tag = Tag::from_str(tagstr)?;
|
||||
task.add_tag(&tag)?;
|
||||
Ok(TCResult::True)
|
||||
},
|
||||
TCResult::Error,
|
||||
)
|
||||
}
|
||||
|
||||
// TODO: tc_task_remove_tag
|
||||
// TODO: tc_task_add_annotation
|
||||
// TODO: tc_task_remove_annotation
|
||||
|
|
|
@ -283,6 +283,13 @@ enum TCResult tc_task_start(struct TCTask *task);
|
|||
*/
|
||||
enum TCResult tc_task_stop(struct TCTask *task);
|
||||
|
||||
/**
|
||||
* Add a tag to a mutable task.
|
||||
*
|
||||
* Returns TC_RESULT_TRUE on success and TC_RESULT_ERROR on failure.
|
||||
*/
|
||||
enum TCResult tc_task_add_tag(struct TCTask *task, struct TCString *tag);
|
||||
|
||||
/**
|
||||
* Free a task. The given task must not be NULL. The task must not be used after this function
|
||||
* returns, and must not be freed more than once.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue