[Canonical page](<https://docs.dhtmlx.com/planning-engine/rust/api/core/project/subtree/>)
[Full documentation index](<https://docs.dhtmlx.com/planning-engine/llms.txt>)


# Subtree

The scope of a scoped run. Set it as `subtree` in [`SolveOptions`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/project/solve-options.md>) or [`PreviewOptions`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/project/preview-options.md>) to reschedule one task's branch instead of the whole project. It mirrors gantt's `autoSchedule(id, inclusive)`. Create it with `Subtree::new`, or as a struct literal to set `inclusive` yourself.

## Declaration

```rust
#[derive(Clone, Debug, PartialEq)]
pub struct Subtree {
    pub task: Id,
    pub inclusive: bool,
}
```

`Subtree` has no `Default`.

## Fields

| Field | Type | Default | Description |
|---|---|---|---|
| `task` | [`Id`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/id.md>) | - | Root task of the scope. The scope covers this task, its ancestors and descendants, and every task reached from them through outgoing links, transitively. Each task reached the same way brings its own ancestors and descendants. |
| `inclusive` | `bool` | `true` with `Subtree::new` | `true` also follows incoming links, so the scope includes the root's predecessors and their branches. `false` follows outgoing links only. |

## Associated functions

### new

```rust
pub fn new(task: impl Into<Id>) -> Subtree
```

Creates a scope rooted at `task` with `inclusive: true`.

**Parameters**

| Name | Type | Description |
|---|---|---|
| `task` | `impl Into<Id>` | Root task ID. Accepts `String`, `&str`, `f64` and `i32`. |

**Returns** - a `Subtree` with `inclusive` set to `true`.

## Errors

A `task` that is unknown or not scheduled makes the call that receives the options fail with [`Error::Input`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/errors/error.md>). The [`InputError`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/errors/input-error.md>) has kind `Validation` and path `subtree.task`.

## Example

```rust
use std::sync::Arc;
use plen_core::{Error, Project, ScheduleResult, SolveOptions, Subtree};

// `project` already holds solved data with a task "2".
fn reschedule_branch(project: &mut Project) -> Result<Arc<ScheduleResult>, Error> {
    let options = SolveOptions {
        subtree: Some(Subtree {
            task: "2".into(),
            inclusive: false,
        }),
        ..Default::default()
    };
    project.solve(None, &options)
}
```

## Related

- [`SolveOptions`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/project/solve-options.md>) - carries the scope for `solve`
- [`PreviewOptions`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/project/preview-options.md>) - carries the scope for `preview`
- [Reschedule a branch](<https://docs.dhtmlx.com/planning-engine/rust/how-to/reschedule-a-branch.md>) - scoping a solve or preview to one branch
- [Scheduling a Project](<https://docs.dhtmlx.com/planning-engine/rust/scheduling/scheduling-a-project.md#solve-options>) - `subtree` among the solve options
