Expand description

This crate provides the Fortify wrapper type. When used with a borrowing type (i.e. a type with a lifetime parameter) it allows values of that type to reference arbitrary data owned by the Fortify itself.

Example

use fortify::*;

// Define a borrowing type. The `Lower` trait specifies that it is covariant in its first
// lifetime parameter.
#[derive(Lower)]
struct Example<'a> {
   a: &'a i32,
   b: &'a mut i32,
}

// Construct a fortified value that makes an "external" reference to `a` and an "internal"
// reference to `b`, which is owned by the Fortify.
let a = 1;
let mut example: Fortify<Example> = fortify! {
    let mut b = 1;
    b += 1;
    yield Example {
        a: &a,
        b: &mut b
    };
};

// Use `with_mut` for general mutable access to the wrapped value. Note that the reference
// to `b` is still valid even though `b` is not in scope in this block.
example.with_mut(|example| {
    assert_eq!(*example.a, 1);
    assert_eq!(*example.b, 2);
    *example.b += 1;
    assert_eq!(*example.b, 3);
});

Macros

A helper macro for creating a Fortify using generator-like syntax. The macro takes a block of statements that ends with a yield of some expression. The block will be executed up to the yield statement, at which point the value of expression will be bundled with the suspended scope of the block and returned as a Fortifyied value. Local variables defined in the block may be accessed through references in the wrapped value.

Structs

Wraps a value of type T and allows it to reference arbitrary supplementary data owned by the Fortify. This can be used to effectively convert a borrowing type into an owning type.

A helper interface used by the Fortify::new_async constructor.

A value of T with its lifetime shortened to 'a. This is isomorphic to <T as Lower<'a>>::Target, but provides additional information to the compiler to assist type inferencing.

Traits

Indicates that a type covariantly references a set of lifetime parameters, and when these parameters are all replaced with 'a, the resulting type is Target. Consequentially, if the type outlives 'a, it can be directly coerced to Target by applying covariance.

Indicates that, if this type has a non-trivial implementation of Lower, it references the lifetime 'a. Thus, the bound T: Refers<'a> can be thought of as the inverse of T: 'a.

Derive Macros