This example shows how to update a struct field.

# Define a struct for this example
defmodule User do
  defstruct email: nil
end

%User{email: "c@c.com"} = struct(%User{}, email: "c@c.com")

# Structs are based on maps
# so map update methods and syntax are valid
%User{email: "a@a.co"} = %{ %User{} | email: "a@a.co" }

%User{email: "b@b.com"} = Map.put(%User{}, :email, "b@b.com")

Documentation: