Skip to main content

LifecycleTaskControl

Struct LifecycleTaskControl 

Source
pub struct LifecycleTaskControl<'runner> { /* private fields */ }
Expand description

Registering, reading and removing the product’s lifecycle task.

Everything goes through a CommandRunner, so the whole of this — the argument vectors, the idempotent replacement, the foreign-task refusal and the non-destructive removal — is testable on a CI leg that has no Task Scheduler at all.

Implementations§

Source§

impl<'runner> LifecycleTaskControl<'runner>

Source

pub fn new(runner: &'runner dyn CommandRunner) -> Self

Uses the host’s schtasks.exe.

Source

pub fn with_executable( runner: &'runner dyn CommandRunner, schtasks: impl Into<PathBuf>, ) -> Self

Uses a named schtasks.exe, for a test.

Source

pub fn query( &self, identity: &LifecycleTaskIdentity, ) -> Result<Option<RegisteredTask>, WslError>

What Task Scheduler holds under this name, if anything.

§Errors

WslError::Spawn when schtasks.exe cannot be started at all.

Source

pub fn register(&self, task: &LifecycleTask) -> Result<(), WslError>

Registers the task, replacing a previous registration of the same task.

Idempotent: running it twice leaves one task whose definition is the current one. schtasks /Create … /F is what makes the replacement atomic from Task Scheduler’s point of view — there is no window in which the task is absent.

§Errors

WslError::ForeignTask when a task of this name exists and is not this product’s, or exists but cannot be exported and so cannot be shown to be this product’s; WslError::TaskControl when schtasks refused; WslError::Record when the document could not be written to a temporary file for schtasks /XML to read.

Source

pub fn detach( &self, identity: &LifecycleTaskIdentity, ) -> Result<Detached, WslError>

Removes the product’s task, and nothing else.

This is the whole of wsl detach’s Windows half. It does not unregister the WSL distribution, stop or uninstall the Linux service, remove a credential, or delete any Linux data — it cannot, because the only program it runs is schtasks.exe.

§Errors

WslError::ForeignTask when the task is not this product’s, and WslError::TaskControl when schtasks refused to delete it.

Source

pub fn start(&self, identity: &LifecycleTaskIdentity) -> Result<(), WslError>

Starts the task now, rather than at the next logon.

§Errors

WslError::NoSuchTask when nothing is registered, WslError::ForeignTask when the registration is not this product’s, and WslError::TaskControl when schtasks refused.

Source

pub fn stop(&self, identity: &LifecycleTaskIdentity) -> Result<bool, WslError>

Ends a running instance. Returns whether one was running.

§Errors

As LifecycleTaskControl::start.

Trait Implementations§

Source§

impl<'runner> Debug for LifecycleTaskControl<'runner>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'runner> !RefUnwindSafe for LifecycleTaskControl<'runner>

§

impl<'runner> !UnwindSafe for LifecycleTaskControl<'runner>

§

impl<'runner> Freeze for LifecycleTaskControl<'runner>

§

impl<'runner> Send for LifecycleTaskControl<'runner>

§

impl<'runner> Sync for LifecycleTaskControl<'runner>

§

impl<'runner> Unpin for LifecycleTaskControl<'runner>

§

impl<'runner> UnsafeUnpin for LifecycleTaskControl<'runner>

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> 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> Same for T

Source§

type Output = T

Should always be Self
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, !>

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