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 type T.
  • pattern which represents the pattern of the GiftWrap defined in the Patterns enum.
  • has_bow which is a boolean which represents whether or not the GiftWrap has a bow.
  • tag which is an Option<GiftTag>, where the GiftTag is a struct representing a gift tag on the GiftWrap 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: Tpattern: Patternshas_bow: booltag: 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!"
);

Trait Implementations

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.