1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
//! This module defines the [`GiftTag`]. It is meant to be used by the [`crate::giftwrap::GiftWrap`]
//! module but can be used anywhere in Rust. The [`GiftTag`] can be imagined as a tag that is tied
//! to a wrapped gift box. It contains the following information in Strings:
//! * Recipient
//! * Sender
//! * Message
//!
//! # Examples
//! The [`GiftTag`] can be used on it's own in the following way:
//! ```
//! use giftbox::gifttag::GiftTag;
//! let tag = GiftTag::write(
//! "Bob".to_string(),
//! "Sally".to_string(),
//! "Happy Cake Day!".to_string()
//! );
//! ```
//!
//! The [`GiftTag`] can be used with [`crate::giftwrap::GiftWrap`] and in the following way:
//! ```
//! use giftbox::giftbox::GiftBox;
//! use giftbox::gifttag::GiftTag;
//! use giftbox::patterns::Patterns;
//! let filled_box = GiftBox::fill(Some(["Toys", "Candy", "Money"]));
//! let tag = GiftTag::write(
//! "Bob".to_string(),
//! "Sally".to_string(),
//! "Happy Cake Day!".to_string()
//! );
//! let wrapped_box = filled_box.wrap(
//! Patterns::Polkadots,
//! true,
//! Some(tag)
//! );
//! let unwrapped_box = wrapped_box.unwrap();
//! assert_eq!(unwrapped_box, filled_box);
//! ```
use std::fmt::*;
/// 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!"
/// );
/// ```
#[derive(Debug, PartialEq)]
pub struct GiftTag {
pub recipient: String,
pub sender: String,
pub message: String,
}
impl 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()
/// );
/// ```
pub fn write(recipient: String, sender: String, message: String) -> GiftTag {
GiftTag {
recipient,
sender,
message,
}
}
/// 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!"
/// );
/// ```
///
pub fn read(self) -> String {
format!(
"To: {},\nFrom: {},\nMessage: {}",
self.recipient, self.sender, self.message
)
}
}
#[cfg(test)]
mod test {}