Struct giftbox::gifttag::GiftTag [−][src]
Expand description
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:
recipientwhich represents the recipient of the gift as a String.senderwhich represents the sender of the gift as a String.messagewhich 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!" );
Fields
recipient: Stringsender: Stringmessage: StringImplementations
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() );
The read() method takes a GiftTag as self and returns a formatted String representing
the contents of the GiftTag.
Arguments
selfonly.
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!" );