From b2755b96b4fc84dc2cfe88859008891ea257467e Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Tue, 28 Jul 2020 15:06:10 +0600 Subject: [PATCH] Add setters to OrderInfo --- src/types/order_info.rs | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/types/order_info.rs b/src/types/order_info.rs index 72d0c10a..7f41f7a9 100644 --- a/src/types/order_info.rs +++ b/src/types/order_info.rs @@ -20,3 +20,53 @@ pub struct OrderInfo { /// User's shipping address. pub shipping_address: ShippingAddress, } + +impl OrderInfo { + pub fn new( + name: S1, + phone_number: S2, + email: S3, + shipping_address: ShippingAddress, + ) -> Self + where + S1: Into, + S2: Into, + S3: Into, + { + Self { + name: name.into(), + phone_number: phone_number.into(), + email: email.into(), + shipping_address, + } + } + + pub fn name(mut self, val: S) -> Self + where + S: Into, + { + self.name = val.into(); + self + } + + pub fn phone_number(mut self, val: S) -> Self + where + S: Into, + { + self.phone_number = val.into(); + self + } + + pub fn email(mut self, val: S) -> Self + where + S: Into, + { + self.email = val.into(); + self + } + + pub fn shipping_address(mut self, val: ShippingAddress) -> Self { + self.shipping_address = val; + self + } +}