I'm working on an exercise from baby rudin, where the question is
If $f$ is a real continuous function defined on a closed set $E\subset\mathbb{R}^1$, prove that there exist continuous real functions $g$ on $\mathbb{R}^1$ s.t. $g(x)=f(x)$ $\forall x\in E$. We call functions such as $g$ continuous extensions of $f$ from $E$ to $\mathbb{R}^1$. Show that the result becomes false if the word "closed" is omitted. Extend the result to vector-valued functions.
In my solution is as follows
For $x$ on the boundary of $E$, every neighbourhood $U$ of $x$ is mapped to a neighbourhood of $f(x)$. Since $g(x)=f(x)\;\forall x\in E$, every neighbourhood of $x$ is also mapped to a neighbourhood of $g(x)$. As such, the open set $U\cap E^c$ is also mapped to an open set, and since this is true for every neighbourhood $g(x)$ is continuous on $\mathbb{R}$. Since we have used topological properties only, this result holds for any closed set $E$ in any topological space.
When $E$ is not closed, we can proceed simply by counter-example. Suppose $E$ is an open set. We define $g(x)\ne f(x)$ when $x$ is on the boundary of $E$. Then $f(x)$ and $g(x)$ are continuous inside of $E$, but $g$ has a discontinuity along the boundary of $E$. The discontinuity can always exist because every point in $E$ has a neighbourhood which is a proper subset of $E$, so every subset where $f(x)=g(x)$ can be separated from the neighbourhood of a point on the boundary of $E$.
However, from my understanding of topology, the open and closed sets can be used interchangeably, i.e. we can define the elements of a topology to be "closed sets", and so the complements of the elements of the topology would be our "open sets". However, since I've used the limit point definition of a closed set, this seems to contradict this topological behaviour, since from my proof the continuous extension is not possible for sets which do not contain all their limit points. This implies to me that if I were to define the topology using closed sets, the result of the exercise would not hold. However, in my proof I've used the open set definition of continuity, which is the one used in topology. What have I misunderstood which has caused this discrepancy?