Rental 0.4.10 Released

Version 0.4.10 of rental is published, including a few new methods for returning reborrowed references.

Since the first release, rental has had a method, ref_rent, that will allow you to return a reference bounded by a self-referential lifetime, made safe by reborrowing that reference to one bounded by a borrow of the struct itself. A simple example might be something like this:

pub struct Foo {
    i: i32,
}

rental! {
    mod rentals {
        use super::*;

        pub struct SimpleRef {
            foo: Box<Foo>,
            iref: &'foo i32,
        }
    }
}

fn main()
    let mut sr = rentals::SimpleRef::new(Box::new(Foo { i: 5 }), |foo| &foo.i });
    let iref: &i32 = sr.ref_rent(|iref| *iref);
    assert_eq!(*iref, 5);
}

This is fine if the reference is readily available, but just as with try_new, we need to handle cases where it might not succeed or be available. Without some form of HKT, this can't be fully general, but we can cover the overwhelming majority of such cases by providing support for Option and Result versions, maybe_ref_rent and try_ref_rent respectively. These are identical to the original, but simply return the reborrowed reference wrapped in the appropriate carrier.

    let iref: Option<&i32> = sr.maybe_ref_rent(|iref| Some(*iref));
    let iref: Result<&i32, ()> = sr.try_ref_rent(|iref| Ok(*iref));

Mutable and "all" variants are provided as with ref_rent.

Thanks to Mark Swanson for the suggestion.