Struct GiftWrap

Source
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: T§pattern: Patterns§has_bow: bool§tag: Option<GiftTag>

Implementations§

Source§

impl<T> GiftWrap<T>

Source

pub fn unwrap(self) -> T

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);
Source

pub fn read_tag(self) -> String

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§

Source§

impl<T: Debug> Debug for GiftWrap<T>

Source§

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

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

impl<T: PartialEq> PartialEq for GiftWrap<T>

Source§

fn eq(&self, other: &GiftWrap<T>) -> 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<T> StructuralPartialEq for GiftWrap<T>

Auto Trait Implementations§

§

impl<T> Freeze for GiftWrap<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for GiftWrap<T>
where T: RefUnwindSafe,

§

impl<T> Send for GiftWrap<T>
where T: Send,

§

impl<T> Sync for GiftWrap<T>
where T: Sync,

§

impl<T> Unpin for GiftWrap<T>
where T: Unpin,

§

impl<T> UnwindSafe for GiftWrap<T>
where T: UnwindSafe,

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.