Skip to main content

CuContext

Struct CuContext 

Source
pub struct CuContext {
    pub clock: RobotClock,
    /* private fields */
}
Expand description

Execution context passed to task and bridge callbacks.

CuContext provides callback code with:

  • time access through clock and Deref<Target = RobotClock>
  • current execution sequence id via cl_id()
  • current task metadata via task_id() / task_index()

The execution sequence id matches the copper-list id of the iteration being processed. It is also available in other lifecycle callbacks (start/preprocess/postprocess/stop) for continuity, but outside process callbacks it must not be treated as a live copper-list handle.

The runtime creates one context per execution loop and updates transient fields such as the currently executing task before each callback.

Fields§

§clock: RobotClock

Runtime clock. Kept as a field for direct access (context.clock.now()).

Implementations§

Source§

impl CuContext

Source

pub fn builder(clock: RobotClock) -> CuContextBuilder

Starts a context builder from a clock.

Source

pub fn from_clock(clock: RobotClock) -> Self

Creates a context from an existing clock with default metadata.

Defaults:

  • cl_id = 0
  • no task id table
Source

pub fn new_with_clock() -> Self

Creates a context backed by a real robot clock.

Defaults:

  • cl_id = 0
  • no task id table
Source

pub fn new_mock_clock() -> (Self, RobotClockMock)

Creates a context backed by a mock clock.

Returns both the context and its [RobotClockMock] control handle.

Source

pub fn set_current_task(&mut self, task_index: usize)

Sets the currently executing task index.

Source

pub fn clear_current_task(&mut self)

Clears the currently executing task.

Source

pub fn cl_id(&self) -> u64

Returns the current execution sequence id.

In process callbacks, this value is the id of the copper-list being processed. In other lifecycle callbacks, this value is still meaningful for sequencing but does not imply that a copper-list instance is alive.

Source

pub fn task_index(&self) -> Option<usize>

Returns the current task index, if any.

Source

pub fn task_id(&self) -> Option<&'static str>

Returns the current task id, if any.

Methods from Deref<Target = RobotClock>§

pub fn now(&self) -> CuDuration

Now returns the time that passed since the reference time, usually the start time. It is a monotonically increasing value.

pub fn recent(&self) -> CuDuration

A less precise but quicker time

Trait Implementations§

Source§

impl Clone for CuContext

Source§

fn clone(&self) -> CuContext

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CuContext

Source§

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

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

impl Deref for CuContext

Source§

type Target = RobotClock

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSend for T
where T: Any + Send,

§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<A> Is for A
where A: Any,

§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.
§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

§

fn clone_type_data(&self) -> Box<dyn TypeData>

Creates a type-erased clone of this value.