You can't create self-referential structs in safe Rust. If a field pointed to another field, then moving the struct would cause the reference to be dangling.
There is almost always a better way to do what you want to achieve. What are you actually trying to do?
B is an error type for various methods of A, which requires a ref to the A instance. I am trying to deal with the case where an error occurs before the instance is actually assigned to a variable . i.e. in build_A
It looks like you're trying to recreate Cow... You don't need to store an internal reference to A if you already own an A, as you can always create the reference as needed by borrowing from the owned one.
That depends on what you're actually trying to accomplish. Most of the time, your code will be much simpler if you give up trying to abstract over different kinds of ownership and just choose to always own or always borrow. Without knowing what you're trying to do, it's hard to suggest a better way to do it.
And if the call fails, give the A back via AError. Either way, there's no reason to borrow it here, because the user already has access to it. (Or perhaps you should store an Option<A> in AError, and just store None when you call do_something...) In fact, the Option will probably just be better represented as a custom enum, and you can capture the A for a build error, and don't capture it for a do_something error.
But you should probably not be trying to access A from within the AError generally. (It will certainty be a bad idea if you end trying to call mutating methods on it while it's still borrowed for the function call.)