Rename Dummy to TaskArg

This commit is contained in:
Albin Hedman 2025-11-19 23:04:34 +01:00
parent 82c9d75a06
commit ee5f77326c
4 changed files with 26 additions and 19 deletions

View file

@ -35,7 +35,7 @@ pub fn link_section_uninit() -> TokenStream2 {
pub fn regroup_inputs(
inputs: &[PatType],
) -> (
// Generic args e.g. &[`_0: impl Dummy<T=i32>`, `_1: impl Dummy<T=i64>`]
// Generic args e.g. &[`_0: impl TaskArg<T=i32>`, `_1: impl TaskArg<T=i64>`]
Vec<TokenStream2>,
// args e.g. &[`_0`], &[`_0: i32`, `_1: i64`]
Vec<TokenStream2>,
@ -50,7 +50,7 @@ pub fn regroup_inputs(
let ty = &inputs[0].ty;
(
vec![quote!(_0: impl rtic::export::dummy::Dummy<T=#ty> + Send + Sync)],
vec![quote!(_0: impl rtic::export::task_arg::TaskArg<T=#ty> + Send + Sync)],
vec![quote!(_0: #ty)],
quote!(_0),
vec![quote!(_0)],
@ -66,7 +66,7 @@ pub fn regroup_inputs(
let i = Ident::new(&format!("_{i}"), Span::call_site());
let ty = &input.ty;
generic_args.push(quote!(#i: impl rtic::export::dummy::Dummy<T=#ty> + Send + Sync));
generic_args.push(quote!(#i: impl rtic::export::task_arg::TaskArg<T=#ty> + Send + Sync));
args.push(quote!(#i: #ty));

View file

@ -1,8 +1,8 @@
pub use critical_section::CriticalSection;
pub use portable_atomic as atomic;
pub mod dummy;
pub mod executor;
pub mod task_arg;
// Cortex-M target (any)
#[cfg(feature = "cortex-m")]

View file

@ -1,15 +0,0 @@
// TODO: What should we name this?
/// Dummy trait which will only ever be implemented where type T is Self
pub trait Dummy {
/// This should always be same as `Self`
type T;
fn to(self) -> Self::T;
}
impl<T> Dummy for T {
type T = T;
fn to(self) -> T {
self
}
}

View file

@ -0,0 +1,22 @@
/// A trait for types that can be passed as arguments when spawning tasks
///
/// This trait will only ever be implemented where type `Self::T` is `Self`
///
/// The global `my_task::spawn` requires its args to be `Send`. This trait has to
/// be used because we can not have a function with a where clause which
/// requires a concrete type to be `Send` if that type is not `Send`. The compiler
/// will error out on us. However hiding that behind a dummy trait which is
/// only implemented for that same type enables us to defer the error to when
/// the user erroneously tries to call the function.
pub trait TaskArg {
/// This should always be same as `Self`
type T;
fn to(self) -> Self::T;
}
impl<T> TaskArg for T {
type T = T;
fn to(self) -> T {
self
}
}