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:
contentswhich can be any typeT.patternwhich represents the pattern of theGiftWrapdefined in thePatternsenum.has_bowwhich is a boolean which represents whether or not theGiftWraphas a bow.tagwhich is anOption<GiftTag>, where theGiftTagis a struct representing a gift tag on theGiftWrapthat 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: Tpattern: Patternshas_bow: booltag: Option<GiftTag>Implementations
The unwrap() method takes the GiftWrap and unwraps it to reveal its contents.
Arguments
selfonly.
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
selfonly.
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!" );