Struct GiftTag

Source
pub struct GiftTag {
    pub recipient: String,
    pub sender: String,
    pub message: String,
}
Expand description

The GiftTag struct represents a gift tag that could be included with a gift’s wrapping. It is used by the GiftWrap struct to include a recipient, a sender, and a message. Though it is utilized by GiftWrap, this struct can be used anywhere in Rust.

GiftTag has the following parameters:

  • recipient which represents the recipient of the gift as a String.
  • sender which represents the sender of the gift as a String.
  • message which can be a message to be included with the gift as a String.

§Methods

§write(recipient, sender, message)

You can write a new GiftTag with the GiftTag::write() method. Example:

use giftbox::gifttag::GiftTag;
let tag = GiftTag::write(
     "Bob".to_string(),
     "Sally".to_string(),
     "Happy Cake Day!".to_string()
);

§read()

You can read a GiftTag with the GiftTag::read() method. Example:

use giftbox::gifttag::GiftTag;
let tag = GiftTag::write(
     "Bob".to_string(),
     "Sally".to_string(),
     "Happy Cake Day!".to_string()
);
assert_eq!(tag.read(),
"To: Bob,\nFrom: Sally,\nMessage: Happy Cake Day!"
);

Fields§

§recipient: String§sender: String§message: String

Implementations§

Source§

impl GiftTag

Source

pub fn write(recipient: String, sender: String, message: String) -> GiftTag

The write method accepts three arguments as Strings (a recipient, a sender, and a message) and returns a GiftTag.

§Arguments
  • recipient - Accepts a String that represents a gift’s recipient (the person receiving the gift).
  • sender - Accepts a String that represents a gift’s sender (the person who sent the gift).
  • message - Accepts a string that represents a message to the recipient from the sender to be included with the gift.
§Returns

Returns a GiftTag.

§Example
use giftbox::gifttag::GiftTag;
let tag = GiftTag::write(
     "Bob".to_string(),
     "Sally".to_string(),
     "Happy Cake Day!".to_string()
);
Source

pub fn read(self) -> String

The read() method takes a GiftTag as self and returns a formatted String representing the contents of the GiftTag.

§Arguments
  • self only.
§Returns

Returns a pre-formatted String.

§Example
use giftbox::gifttag::GiftTag;
let tag = GiftTag::write(
     "Bob".to_string(),
     "Sally".to_string(),
     "Happy Cake Day!".to_string()
);
assert_eq!(tag.read(),
"To: Bob,\nFrom: Sally,\nMessage: Happy Cake Day!"
);

Trait Implementations§

Source§

impl Debug for GiftTag

Source§

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

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

impl PartialEq for GiftTag

Source§

fn eq(&self, other: &GiftTag) -> 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 GiftTag

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.