If $f(x)=x^3$, then we can rewrite this as $f:\begin{array}{}\Bbb{R}\to\Bbb{R}\\x\mapsto x^3\end{array}$
But let's say I have a piece wise function of $x$ called $g$. Let's define it as: $$g(x)=\begin{cases} x & (-\infty ,0]\\x^2 & (0,\infty )\end{cases}$$
So, if $$f(x)=y\Rightarrow f:\begin{array}{}X\to Y\\x\mapsto y\end{array}$$ then doesn't it follow that we could say $$g:\begin{array}{}\Bbb{R}\to\Bbb{R}\\x\mapsto\begin{cases} x & (-\infty ,0]\\x^2 & (0,\infty )\end{cases}\end{array}$$ I mean, theoretically speaking?
First and foremost, notation is just notation, so really you can do whatever you like as long as you communicate your intentions. I don't think there's anything opaque about what you've written here, but I think stacking all these things vertically is perhaps a little clunky.
The way that I write down all this information is to write $f:X \rightarrow Y:x \mapsto y$. The notation comes in three parts. The name of the function, the domain and codomain, and what the mapping does. You might like this a little better, since it's one less thing to stack in your notation.