Since v0.15 we have Map.from_struct/1 which does exactly this.

defmodule User do
  defstruct [:name]
end

Map.from_struct(%User{name: "valim"})
#=> %{name: "valim"}

There's another trick

my_struct = %MyStruct{}
my_map = Map.delete my_struct, :__struct__