[][src]Struct rubric::rubric::criterion::Criterion

pub struct Criterion {
    pub func: String,
    pub name: String,
    pub worth: isize,
    pub index: i64,
    pub messages: (String, String),
    pub desc: Option<String>,
    pub test: Box<dyn Fn(&TestData) -> bool>,
    pub status: Option<bool>,
    pub hide: bool,
}

A single Criterion

Fields

func: String

The name of the function that serves as this criterions test This is just the name, used to attach the function. See the test field.

name: String

A short (< 30 characters), descriptive name

worth: isize

Point value of this criterion. If it passes, this value will be added to the Submission grade.

Can be negative if you wish to subtract points. Be sure to get your logic right. This value is added to the submission grade if the test returns true.

index: i64

An index to sort by when running.

Lowest first. Defaults to 100.

messages: (String, String)

Pass or fail messages, respectively

When printing a criterion, the appropriate message will be printed. Not much use other than that.

desc: Option<String>

An optional description

test: Box<dyn Fn(&TestData) -> bool>

The criterion's test

Determines if the criterion passes or fails. This signature is required.

status: Option<bool>

If the test passed, failed, or hasn't been run.

None if it hasn't been run, Some(true) or Some(false) otherwise. If this value is Some, the test has been run.

hide: bool

Renders the criterion unable to be printed

Implementations

impl Criterion[src]

pub fn new(name: &str) -> CriterionBuilder[src]

Returns a CriterionBuilder, which can be built().

Example

A basic criterion

use rubric::rubric::Criterion;

let c = Criterion::new("my crit").build();
assert_eq!(c.name, "my crit");

pub fn success_message(&self) -> &String[src]

Returns the success message, ie. the first message in the messages tuple.

pub fn failure_message(&self) -> &String[src]

Returns the failure message, ie. the second message in the messages tuple.

pub fn attach(&mut self, test: Box<dyn Fn(&TestData) -> bool>)[src]

Sets the test method of a criterion

pub fn test_with_data(&mut self, data: &TestData) -> bool[src]

Runs the criterion's test function with the data provided.

This is almost equivilent to calling (criterion.test)(data), but this method also sets the status of the criterion to the result of the test. You should avoid calling the test directly, and call this or the test method instead.

The criterion must be mutable to call this method, as the status is changed to the result of the test.

You shouldn't call this method directly, instead grade an entire Rubric.

pub fn test(&mut self) -> bool[src]

Runs the criterions test and assigns the result to criterion.status.

This is equivilent to running test_with_data with an empty TestData.

You shouldn't call this method directly, instead grade an entire Rubric.

pub fn print_short(&self)[src]

Prints the essential criterion information in one line. Will do nothing if the hide field is true

pub fn print_long(&self)[src]

pub fn status_message(&self) -> String[src]

Returns the success message if the criterion passed, otherwise returns the failure message

pub fn colored_status_message(&self) -> String[src]

Same as status_message, but the success message will be colored green and the failure message red.

Auto Trait Implementations

impl !RefUnwindSafe for Criterion

impl !Send for Criterion

impl !Sync for Criterion

impl Unpin for Criterion

impl !UnwindSafe for Criterion

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T, I> AsResult<T, I> for T where
    I: Input, 

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> IntoCollection<T> for T

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Typeable for T where
    T: Any

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,