[][src]Struct ichen_openprotocol::JobCard

pub struct JobCard<'a> {
    pub job_card_id: Cow<'a, str>,
    pub mold_id: Cow<'a, str>,
    pub progress: u32,
    pub total: u32,
}

A data structure containing information on a production job (i.e. a job card).

Fields

job_card_id: Cow<'a, str>

Unique job ID, which must not be empty or all white-spaces.

mold_id: Cow<'a, str>

ID of the set of mold data to load for this job.

progress: u32

Current production progress, which must not be larger than total.

total: u32

Total production count ordered.

Methods

impl<'a> JobCard<'a>[src]

pub fn new(id: &'a str, mold: &'a str, progress: u32, total: u32) -> Self[src]

Create a new JobCard with the specified field values.

Examples

let jobs = vec![
    JobCard::new("J001".into(), "Mold#001".into(), 0, 10000),
    JobCard::new("J002".into(), "Mold#002".into(), 1000, 5000),
    JobCard::new("J003".into(), "Mold#003".into(), 42, 1000),
    JobCard::new("J004".into(), "Mold#004".into(), 0, 0),
];

assert_eq!(4, jobs.len());
assert_eq!("J002", jobs[1].job_card_id);
assert_eq!(1000, jobs[2].total);

pub fn validate(&self) -> Result<'static, ()>[src]

Validate the data structure.

Errors

Returns Err(OpenProtocolError::EmptyField) if job_card_id or mold_id is set to an empty string or is all whitespace.

Returns Err(OpenProtocolError::ConstraintViolated) if progress is larger than total.

Examples

let job1 = JobCard::new("".into(), "M1".into(), 0, 10000);
let job2 = JobCard::new("J2".into(), "   ".into(), 0, 10000);
let job3 = JobCard::new("J3".into(), "M3".into(), 50000, 10000);

assert_eq!(r#"Err(EmptyField("job_card_id"))"#, format!("{:?}", job1.validate()));
assert_eq!(r#"Err(EmptyField("mold_id"))"#, format!("{:?}", job2.validate()));
assert_eq!(
    r#"Err(ConstraintViolated("job-card progress (50000) must not be larger than the total production count (10000)"))"#,
    format!("{:?}", job3.validate())
);

Trait Implementations

impl<'a> Clone for JobCard<'a>[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<'a> PartialEq<JobCard<'a>> for JobCard<'a>[src]

impl<'a> Debug for JobCard<'a>[src]

impl<'a> Serialize for JobCard<'a>[src]

impl<'de: 'a, 'a> Deserialize<'de> for JobCard<'a>[src]

Auto Trait Implementations

impl<'a> Sync for JobCard<'a>

impl<'a> Send for JobCard<'a>

impl<'a> Unpin for JobCard<'a>

impl<'a> RefUnwindSafe for JobCard<'a>

impl<'a> UnwindSafe for JobCard<'a>

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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

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

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> BorrowMut<T> for T where
    T: ?Sized
[src]

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

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

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]