pub struct JobCard<'a> { /* private fields */ }
Expand description
A data structure containing information on a production job (i.e. a job card).
Implementations§
Source§impl<'a> JobCard<'a>
impl<'a> JobCard<'a>
Sourcepub fn job_card_id(&self) -> &str
pub fn job_card_id(&self) -> &str
Get the job ID.
§Examples
let jc = JobCard::try_new("J001", "Mold#001", 100, 1000)?;
assert_eq!("J001", jc.job_card_id());
Sourcepub fn mold_id(&self) -> &str
pub fn mold_id(&self) -> &str
Get the mold ID.
§Examples
let jc = JobCard::try_new("J001", "Mold#001", 100, 1000)?;
assert_eq!("Mold#001", jc.mold_id());
Sourcepub fn progress(&self) -> u32
pub fn progress(&self) -> u32
Get the production progress.
§Examples
let jc = JobCard::try_new("J001", "Mold#001", 100, 1000)?;
assert_eq!(100, jc.progress());
Sourcepub fn total(&self) -> u32
pub fn total(&self) -> u32
Get the maximum production order.
§Examples
let jc = JobCard::try_new("J001", "Mold#001", 100, 1000)?;
assert_eq!(1000, jc.total());
Sourcepub fn try_new(
id: &'a str,
mold: &'a str,
progress: u32,
total: u32,
) -> Result<Self, String>
pub fn try_new( id: &'a str, mold: &'a str, progress: u32, total: u32, ) -> Result<Self, String>
Create a new JobCard
with the specified field values.
§Errors
Returns Err(String)
is there is an error in the parameters.
§Error Examples
assert_eq!(
Err("invalid value: a non-empty, non-whitespace string required for job card ID".into()),
JobCard::try_new("", "Mold#001", 0, 10000)
);
assert_eq!(
Err("invalid value: a non-empty, non-whitespace string required for mold ID".into()),
JobCard::try_new("J001", " ", 0, 10000)
);
assert_eq!(
Err("progress cannot be larger than total".into()),
JobCard::try_new("J001", "Mold#001", 1000, 100)
);
§Examples
let jobs = vec![
JobCard::try_new("J001", "Mold#001", 0, 10000)?,
JobCard::try_new("J002", "Mold#002", 1000, 5000)?,
JobCard::try_new("J003", "Mold#003", 42, 1000)?,
JobCard::try_new("J004", "Mold#004", 0, 0)?,
];
assert_eq!(4, jobs.len());
assert_eq!("J002", jobs[1].job_card_id());
assert_eq!(1000, jobs[2].total());
Trait Implementations§
Source§impl<'de: 'a, 'a> Deserialize<'de> for JobCard<'a>
impl<'de: 'a, 'a> Deserialize<'de> for JobCard<'a>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl<'a> Eq for JobCard<'a>
impl<'a> StructuralPartialEq for JobCard<'a>
Auto Trait Implementations§
impl<'a> Freeze for JobCard<'a>
impl<'a> RefUnwindSafe for JobCard<'a>
impl<'a> Send for JobCard<'a>
impl<'a> Sync for JobCard<'a>
impl<'a> Unpin for JobCard<'a>
impl<'a> UnwindSafe for JobCard<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.