Skip to main content

target_kernel

Macro target_kernel 

Source
macro_rules! target_kernel {
    (
        #[target_features($($feature:literal),* $(,)?)]
        #[candidate($candidate_vis:vis $candidate:ident: $kernel_type:ty)]
        $(#[doc = $doc:literal])*
        $(#[inline $(($inline:ident))?])?
        $vis:vis fn $name:ident($($params:tt)*) $(-> $ret:ty)? $body:block
    ) => { ... };
}
Expand description

Declares a kernel and a Candidate for it from one feature list.

The kernel gets one #[target_feature(enable = ...)] per listed feature, and the candidate requires exactly those features plus the ones rustc implies, so the two cannot drift apart. The kernel is a safe function: its only precondition is the target features, and a Dispatch or Candidate::kernel checks those before handing out a callable Kernel. Unknown feature names fail to compile.

The candidate type must be the unsafe fn pointer type of the kernel.

The kernel takes only doc comments and #[inline]. Arbitrary attributes are rejected because a #[target_feature] among them would enable features the candidate does not require.