Struct giftbox::giftwrap::GiftWrap [−][src]
pub struct GiftWrap<T> {
pub contents: T,
pub pattern: Patterns,
pub has_bow: bool,
pub tag: Option<GiftTag>,
}
Expand description
A GiftWrap
type for Rust which represents gift wrap that can be wrapped around any other
type that can be represented as a Rust type.
GiftWrap
is a Rust struct which has the following parameters:
contents
which can be any typeT
.pattern
which represents the pattern of theGiftWrap
defined in thePatterns
enum.has_bow
which is a boolean which represents whether or not theGiftWrap
has a bow.tag
which is anOption<GiftTag>
, where theGiftTag
is a struct representing a gift tag on theGiftWrap
that contains the recipient, sender, and a message.
Methods
unwrap()
Unwrap GiftWrap
to get its contents with the GiftWrap::unwrap()
method. Example:
use giftbox::giftbox::GiftBox;
use giftbox::giftwrap::GiftWrap;
use giftbox::patterns::Patterns;
let wrapped_string_gift = GiftWrap {
contents: GiftBox::Gifts("String of words".to_string()),
pattern: Patterns::Sparkles,
has_bow: true,
tag: None
};
let unwrapped_string_gift = wrapped_string_gift.unwrap();
assert_eq!(unwrapped_string_gift, GiftBox::Gifts("String of words".to_string()));
read_tag()
“Read” the GiftTag
of GiftWrap
. More specifically, get a String of the GiftTags
contents
with the GiftWrap::read_tag()
Example:
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)
);
assert_eq!(
wrapped_box.read_tag(),
"To: Bob,\nFrom: Sally,\nMessage: Happy Cake Day!"
);
Fields
contents: T
pattern: Patterns
has_bow: bool
tag: Option<GiftTag>
Implementations
The unwrap()
method takes the GiftWrap
and unwraps it to reveal its contents.
Arguments
self
only.
Returns
Returns T
where T
is the contents of Giftwrap.contents
.
Example
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);
The read_tag()
method takes a GiftWrap
and returns the contents of a GiftTag
as a
String. If there is no GiftTag
(self.tag
is None
) then a default String is returned.
Arguments
self
only.
Returns
Returns a String returned from GiftTag::read()
if there is Some(tag)
. Otherwise, if
there is None
it returns a default String.
Example
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)
);
assert_eq!(
wrapped_box.read_tag(),
"To: Bob,\nFrom: Sally,\nMessage: Happy Cake Day!"
);