I have a struct:
struct Foo {}
struct Boo {
foo: Option<Foo>,
}
I want to create getter for it, so user cannot modify it but can read it:
impl Boo {
pub fn get_foo(&self) -> ? { unimplemented!(); }
}
Should I return &Option<Foo>
or Option<&Foo>
? Are there any advantages between these two variants?
I use both variants in my program, and it became an inconvenience to mix them, so I want to choose one of them for the entire program.
The most common causes of purchase returns are unmet expectations, damaged or defective products, and incorrect fit. Any of these issues can be caused by failures on the merchant's part or by events the merchant had no control over.
Refund abuse (aka. returns abuse) occurs when a customer uses the returns policy of a merchant so much that it becomes unprofitable. Customers may also abuse refunds by faking returns/receipts, or reselling merchandise.
Think about whether the work will satisfy you or if you will crave something new. Simply, would you prefer to return to your previous role, do you want something new, or are you in need of a career relaunch?
2) Let the customer return it however they want This does two things: it enables the customer to get an item exchanged or their money back quicker so keeping them happy; and it allows the retailer or wholesaler to make those returned goods available for sale quicker.
Use Option<&T>
instead of &Option<T>
. Callers are interested in the wrapped value, not in Option
.
Also, the common way to implement a getter like this is as follows:
impl Boo {
pub fn get_foo(&self) -> Option<&Foo> { self.foo.as_ref() }
}
This way you don't need to check the wrapped value in the getter. If you want to return a mutable value, use as_mut()
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With