Direction to rotation in material

How can I convert a direction vector to a rotation inside a material? I need to use the particle direction I have inside the material and use that to rotate a UV. (I would have used the Velocity facing setting inside the particle instead but that has a bug or a rather annoying feature where low velocity values make it face away from the velocity direction.)

I tried to find a material node for it and also tried to do it with math but I totally failed at it, it always has issues.