What is the best practice to convert Option<&str>
to Option<String>
? Strictly speaking I'm looking for a concise equivalent of:
if s.is_some() {
Some(s.to_string())
} else {
None
}
and this is the best I could come up with:
s.and_then(|s| Some(s.to_string()))
A conversion loan is a loan that rolls over, or converts, to a different loan structure after a certain term. Pricing both pieces of the loan at once allows you to account for the sequential closing and funding dates in the opportunity profitability calculations.
The Lender shall have the option, exercisable in Lender's sole and absolute discretion, to convert the amounts due under the Note into equity of the Borrower in accordance with the Plan of Reorganization of the Borrower in form and substance agreeable to the Lender in its sole discretion.
In simple words, a Conversion is when stock is being bought in order to synthetically close out a short stock position that is created synthetically by long put and short call of the same strike. Reversal is when stock is being shorted/ sold in order to synthetically close out a synthetic long stock position.
When you convert a call option into stock by exercising, you now own the shares. You must use cash that will no longer be earning interest to fund the transaction, or borrow cash from your broker and pay interest on the margin loan. In both cases, you are losing money with no offsetting gain.
map
is a better choice:
s.map(|s| s.to_string())
or
s.map(str::to_string)
Another way is to use s.map(str::to_string)
:
let reference: Option<&str> = Some("whatever");
let owned: Option<String> = reference.map(str::to_string);
I personally find it cleaner without the extra closure.
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