Skip to main content

TaskExecutionKey

Struct TaskExecutionKey 

Source
pub struct TaskExecutionKey {
    pub host: NatString,
    pub task_name: String,
}
Expand description

A unique identifier for tracking task execution state for a specific host and task combination.

This structure serves as a composite key used by the State structure to track the execution state of tasks on individual hosts. Each TaskExecutionKey uniquely identifies a task execution by combining the hostname with the task name, allowing the state tracking system to maintain separate execution histories for different task/host pairs.

The key is used internally by methods like State::set_task_state, State::task_state, and their _key variants to store and retrieve TaskAttemptState information.

§Fields

  • host - A NatString representing the hostname on which the task is being executed. Using NatString provides efficient string handling with natural sorting capabilities, which can be useful when displaying or organizing task execution results by hostname.

  • task_name - The name of the task being executed. This is a standard String that identifies the specific task or operation being performed on the host. Task names should be unique within a playbook or execution context to ensure proper state tracking.

§Examples

// Create a task execution key for a specific host and task
let key = TaskExecutionKey::new("router1", "show_version");
assert_eq!(key.host, NatString::from("router1"));
assert_eq!(key.task_name, "show_version");

// Keys can be used to track task state
let state = State::new();
let task_state = TaskAttemptState::new(TaskStatus::Running).with_attempts(1);
state.set_task_state_key(key.clone(), task_state.clone());
assert_eq!(state.task_state_key(&key), Some(task_state));
// Keys with the same host and task name are equal
let key1 = TaskExecutionKey::new("router1", "show_version");
let key2 = TaskExecutionKey::new("router1", "show_version");
assert_eq!(key1, key2);

// Keys with different hosts or task names are not equal
let key3 = TaskExecutionKey::new("router2", "show_version");
assert_ne!(key1, key3);

Fields§

§host: NatString§task_name: String

Implementations§

Source§

impl TaskExecutionKey

Source

pub fn new(host: impl Into<String>, task_name: impl Into<String>) -> Self

Creates a new TaskExecutionKey from a host and task name.

This constructor method creates a unique identifier for tracking task execution state by combining a hostname with a task name. The resulting key can be used with methods like State::set_task_state_key and State::task_state_key to store and retrieve task execution information.

The host parameter is converted into a NatString for efficient string handling with natural sorting capabilities, while the task name is stored as a standard String.

§Parameters
  • host - The hostname for which the task is being executed. Can be any type that converts into a String, such as &str, String, or other string-like types. This will be stored as a NatString in the resulting key.

  • task_name - The name of the task being executed. Can be any type that converts into a String, such as &str, String, or other string-like types. Task names should be unique within a playbook or execution context to ensure proper state tracking.

§Returns

Returns a new TaskExecutionKey instance with the specified host and task name, ready to be used for tracking task execution state.

§Examples
// Create a key using string slices
let key = TaskExecutionKey::new("router1", "show_version");
assert_eq!(key.host, NatString::from("router1"));
assert_eq!(key.task_name, "show_version");
// Create a key using owned Strings
let host = String::from("router2");
let task = String::from("configure_interface");
let key = TaskExecutionKey::new(host, task);
assert_eq!(key.task_name, "configure_interface");

Trait Implementations§

Source§

impl Clone for TaskExecutionKey

Source§

fn clone(&self) -> TaskExecutionKey

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 TaskExecutionKey

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for TaskExecutionKey

Source§

impl Hash for TaskExecutionKey

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for TaskExecutionKey

Source§

fn eq(&self, other: &TaskExecutionKey) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for TaskExecutionKey

Auto Trait Implementations§

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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