Skip to main content

Capability

Struct Capability 

pub struct Capability(/* private fields */);
Expand description

Whether a fixture supports one optional operation, and if not, why not.

§Why this is an opaque struct rather than a public enum

The obvious spelling is enum Capability { Supported, Declined(&'static str) }, and it has one hole: Declined("") is a perfectly good value of that type. The requirement that a declined capability names a reason would then be prose, enforced by a meta-test somebody has to remember to write.

Making the field private moves the check into the only constructor, where an assert! inside a const fn can reject the empty string at compile time. See declined for exactly when that fires — it is later than one would like, and worth knowing.

Implementations§

§

impl Capability

pub const SUPPORTED: Self

The fixture supports this operation, and rules requiring it will run.

pub const fn declined(reason: &'static str) -> Self

The fixture does not support this operation, for the stated reason.

The reason is not a formality. It is printed for every rule the decision skips, so that it can land in the adapter’s CI log where both a reviewer and a user of the adapter can read it. Write the real one: why this store cannot do it, not that it cannot.

“Printed” means printed under --show-output. A skipped rule is a test that passes, and libtest discards a passing test’s stdout, so a default cargo test in an adapter’s own CI shows none of these lines — see RuleOutcome::report, which measures exactly that. Write the reason for the reader who runs the flag, and configure your CI to pass it if you want the reason in front of anyone else.

§Panics

Panics if reason is empty. Because this is a const fn, a panic at const-evaluation time is a compile error rather than a run-time one:

ⓘ
use happenstance_testkit::Capability;

const REOPEN: Capability = Capability::declined("");

fn main() {
    let _ = REOPEN;
}

The doctest above is spelled bare compile_fail, never compile_fail,E0080. This diagnostic family has bitten the repository before: rustdoc on 1.97.1 silently ignores an error-code annotation it cannot match, so the stricter-looking spelling is the weaker check.

Where it does not fire. A free const like the one above fails at cargo check. An associated const in a Fixture impl does not: an associated const is evaluated lazily, only when monomorphised code reads it, and that is after check and clippy have both stopped. It fails at codegen — so cargo build and cargo test catch it and cargo clippy does not.

pub const fn is_supported(self) -> bool

Whether rules requiring this capability should run.

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

The stated reason for declining, or None if the capability is supported.

Trait Implementations§

§

impl Clone for Capability

§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
§

impl Copy for Capability

§

impl Debug for Capability

§

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

Formats the value using the given formatter. Read more
§

impl Eq for Capability

§

impl PartialEq for Capability

§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
§

impl StructuralPartialEq for Capability

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V