Skip to main content

Configuration

Struct Configuration 

Source
pub struct Configuration { /* private fields */ }
Expand description

Configuration options for spawning a task.

Configuration encapsulates the runtime preferences and scheduling hints for a task. These settings help executors make informed decisions about how and when to run tasks.

§Examples

§Using the default configuration

use some_executor::task::{Task, Configuration};

let task = Task::without_notifications(
    "simple".to_string(),
    Configuration::default(),
    async { "done" },
);

§Creating a custom configuration

use some_executor::task::{Configuration, ConfigurationBuilder};
use some_executor::hint::Hint;
use some_executor::Priority;

// Build a configuration for a high-priority CPU task
let config = ConfigurationBuilder::new()
    .hint(Hint::CPU)
    .priority(Priority::unit_test())
    .build();

// Or create directly
let config = Configuration::new(
    Hint::CPU,
    Priority::unit_test(),
    some_executor::Instant::now()
);

Configuration for task execution.

Configuration encapsulates metadata that guides executor scheduling decisions. Each configuration consists of:

  • Hint: Indicates the expected behavior of the task (CPU-bound, I/O-bound, etc.)
  • Priority: Determines scheduling precedence when multiple tasks are ready
  • Poll After: Specifies the earliest time a task should be polled

Configurations are immutable once created and can be shared across multiple tasks. Executors use this information as hints for optimization but are not required to strictly follow them.

§Examples

§Creating a configuration for a CPU-intensive task

use some_executor::task::Configuration;
use some_executor::hint::Hint;
use some_executor::Priority;
use some_executor::Instant;

let config = Configuration::new(
    Hint::CPU,
    Priority::unit_test(),
    Instant::now()
);

assert_eq!(config.hint(), Hint::CPU);
assert_eq!(config.priority(), Priority::unit_test());

§Using default configuration

use some_executor::task::Configuration;
use some_executor::hint::Hint;
use some_executor::Priority;

let config = Configuration::default();

// Default values are sensible for general use
assert_eq!(config.hint(), Hint::Unknown);
assert_eq!(config.priority(), Priority::Unknown);

§Comparing configurations

use some_executor::task::Configuration;
use some_executor::hint::Hint;
use some_executor::Priority;
use some_executor::Instant;

let config1 = Configuration::new(
    Hint::IO,
    Priority::unit_test(),
    Instant::now()
);

let config2 = config1.clone();
assert_eq!(config1, config2);

Implementations§

Source§

impl Configuration

Source

pub fn new(hint: Hint, priority: Priority, poll_after: Instant) -> Self

Creates a new Configuration with the specified values.

This is an alternative to using ConfigurationBuilder when you have all values available upfront.

§Arguments
  • hint - The execution hint for the task
  • priority - The priority level for the task
  • poll_after - The earliest time the task should be polled
§Examples
use some_executor::task::Configuration;
use some_executor::hint::Hint;
use some_executor::Priority;
use some_executor::Instant;

let config = Configuration::new(
    Hint::CPU,
    Priority::unit_test(),
    Instant::now()
);
Source

pub fn hint(&self) -> Hint

Returns the execution hint for this configuration.

The hint indicates the expected runtime characteristics of the task, such as whether it’s CPU-bound or I/O-bound.

§Examples
use some_executor::task::Configuration;
use some_executor::hint::Hint;
use some_executor::Priority;
use some_executor::Instant;

let config = Configuration::new(
    Hint::IO,
    Priority::unit_test(),
    Instant::now()
);

assert_eq!(config.hint(), Hint::IO);
Source

pub fn priority(&self) -> Priority

Returns the priority for this configuration.

The priority influences task scheduling order when multiple tasks are ready to execute.

§Examples
use some_executor::task::Configuration;
use some_executor::hint::Hint;
use some_executor::Priority;
use some_executor::Instant;

let config = Configuration::new(
    Hint::CPU,
    Priority::unit_test(),
    Instant::now()
);

assert_eq!(config.priority(), Priority::unit_test());
Source

pub fn poll_after(&self) -> Instant

Returns the earliest time the task should be polled.

Tasks will not be scheduled for execution before this instant, allowing for delayed or scheduled task execution.

§Examples
use some_executor::task::Configuration;
use some_executor::hint::Hint;
use some_executor::Priority;
use some_executor::Instant;
use std::time::Duration;

let future_time = Instant::now() + Duration::from_secs(10);
let config = Configuration::new(
    Hint::Unknown,
    Priority::Unknown,
    future_time
);

assert!(config.poll_after() >= Instant::now());

Trait Implementations§

Source§

impl Clone for Configuration

Source§

fn clone(&self) -> Configuration

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 Configuration

Source§

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

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

impl Default for Configuration

Source§

fn default() -> Self

Creates a default configuration with sensible defaults.

The default configuration uses:

§Examples
use some_executor::task::Configuration;
use some_executor::hint::Hint;
use some_executor::Priority;
use some_executor::Instant;

let config = Configuration::default();

assert_eq!(config.hint(), Hint::Unknown);
assert_eq!(config.priority(), Priority::Unknown);
// poll_after will be approximately now
assert!(config.poll_after() <= Instant::now() + std::time::Duration::from_millis(100));
Source§

impl Hash for Configuration

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 Configuration

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 Copy for Configuration

Source§

impl Eq for Configuration

Source§

impl StructuralPartialEq for Configuration

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