pub struct Ingredient { /* private fields */ }
Expand description
Object that represents an Ingredient of the Cocktail
data base.
§Description
An ingredient represents the elements that are contained by a Cocktail’s recipe. This object only represents the ingredients as a model for being included in individual recipes. Hence no information related to quantities or any other information that joins an ingredient with a recipe is included as an attribute of this object.
Implementations§
Source§impl Ingredient
impl Ingredient
Sourcepub fn parse(
id: Option<&str>,
name: &str,
category: &str,
description: Option<&str>,
) -> Result<Self, Box<dyn Error>>
pub fn parse( id: Option<&str>, name: &str, category: &str, description: Option<&str>, ) -> Result<Self, Box<dyn Error>>
Builds a new Ingredient performing checks over the input parameters.
§Description
The implementation checks that the given name value meets the following requirements:
- The length of the name doesn’t exceeds 40 characters.
- The name is composed of alphanumeric characters plus the special character
%
. - The name does not contain the following forbidden characters:
[
,<
,>
,;
,{
,}
,]
.
§Arguments
- name will be used as Ingredient::name.
- category will be used as Ingredient::category. Use IngCategory::Other when no needed.
- desc will be used as Ingredient::desc. Pass
None
when no description was provided along the Ingredient’s name.
§Return
A new Ingredient when the input parameters comply the format rules, an error otherwise that contains a message with information about the broken format rule.
Sourcepub fn category(&self) -> IngCategory
pub fn category(&self) -> IngCategory
Get the Ingredient’s category as a value of the Enum
IngCategory.
Trait Implementations§
Source§impl Clone for Ingredient
impl Clone for Ingredient
Source§fn clone(&self) -> Ingredient
fn clone(&self) -> Ingredient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for Ingredient
impl Debug for Ingredient
Source§impl<'de> Deserialize<'de> for Ingredient
impl<'de> Deserialize<'de> for Ingredient
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>,
Source§impl PartialEq for Ingredient
impl PartialEq for Ingredient
Source§impl Serialize for Ingredient
impl Serialize for Ingredient
Auto Trait Implementations§
impl Freeze for Ingredient
impl RefUnwindSafe for Ingredient
impl Send for Ingredient
impl Sync for Ingredient
impl Unpin for Ingredient
impl UnwindSafe for Ingredient
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more