Product

Struct Product 

Source
pub struct Product { /* private fields */ }
Expand description

Represents a product.

Implementations§

Source§

impl Product

Source

pub fn new(id: u32, name: String, price: f64, category: Category) -> Product

Creates a new product with the specified id, name, price, and category.

§Arguments
  • id - The unique identifier of the product.
  • name - The name of the product.
  • price - The price of the product.
  • category - The category of the product.
§Returns

A new Product instance.

Source

pub fn calculate_product_price(&self) -> f64

Calculates the total price of the product including tax.

§Returns

The total price of the product.

§Example
use structure_test::Category;
use structure_test::Product;

let product = Product::new(1, "Shirt".to_string(), 20.0, Category::Clothing);
let total_price = product.calculate_product_price();
assert_eq!(total_price, 21.0);

Trait Implementations§

Source§

impl Debug for Product

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Product

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Product

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
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.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.