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
impl Configuration
Sourcepub fn new(hint: Hint, priority: Priority, poll_after: Instant) -> Self
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 taskpriority- The priority level for the taskpoll_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()
);Sourcepub fn hint(&self) -> Hint
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);Sourcepub fn priority(&self) -> Priority
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());Sourcepub fn poll_after(&self) -> Instant
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
impl Clone for Configuration
Source§fn clone(&self) -> Configuration
fn clone(&self) -> Configuration
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Configuration
impl Debug for Configuration
Source§impl Default for Configuration
impl Default for Configuration
Source§fn default() -> Self
fn default() -> Self
Creates a default configuration with sensible defaults.
The default configuration uses:
hint:Hint::Unknownpriority:Priority::Unknownpoll_after: The current instant
§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));