assemble_core/task/
create_task.rs

1use crate::__export::{ProjectResult, TaskId};
2use crate::task::flags::{OptionDeclarations, OptionsDecoder};
3use crate::{Project, Task};
4
5/// Create tasks using a project.
6pub trait CreateTask: Sized {
7    /// Creates a new task. The using_id is the id of the task that's being created.
8    fn new(using_id: &TaskId, project: &Project) -> ProjectResult<Self>;
9
10    /// The default description for a Task
11    fn description() -> String {
12        String::new()
13    }
14
15    /// When a task is requested with the same name, only the task declared in the current is used
16    #[doc(hidden)]
17    fn only_in_current() -> bool {
18        false
19    }
20
21    /// Gets an optional flags for this task.
22    ///
23    /// By defaults return `None`
24    fn options_declarations() -> Option<OptionDeclarations> {
25        None
26    }
27
28    /// Try to get values from a decoder.
29    ///
30    /// By default does not do anything.
31    fn try_set_from_decoder(&mut self, _decoder: &OptionsDecoder) -> ProjectResult<()> {
32        Ok(())
33    }
34}
35
36impl<T: Default + Task> CreateTask for T {
37    fn new(_: &TaskId, _: &Project) -> ProjectResult<Self> {
38        Ok(T::default())
39    }
40}