Write a separate function or struct when it looks complex to write in-line, then move it into the function after it works.
in-line
Vice versa, if you have a function working in-line that bloats the function, extract them out into separate function.