Aligning object's axis with an edge

Is there a way to do this? I want to rotate an object so that its local axis - say, the z axis of the object - aligns with an arbitrary edge belonging to another object. I want a perfect match (not judging it by eye)!

Never mind, I figured it out. (I selected the edge, and made a new transform orientation in the transform orientations panel, which I didn’t know existed. Then I did “object->align to transform orientation”. For a while I was thrown by the “move object centers only” button being turned on, it has to be off or nothing happens. Then I did snap cursor->selection on the edge, and snap object->cursor on the object.)

What’s wrong with the Mk I human eyeball? :eek:

Do you know if this method is permanent, i.e. can’t accidentally be deleted and it resets?

I tried it a few times on a project and it seemed a little quirky, so I did the math and rotated the faces in edit mode to match what I needed.