Pfx.parse
You're seeing just the function
parse
, go back to Pfx module for more information.
Specs
Parses a prefix/0
and returns {:ok, Pfx.t}
or {:error, :einvalid}
Examples
iex> parse("1.2.3.4/24")
{:ok, %Pfx{bits: <<1, 2, 3>>, maxlen: 32}}
iex> parse({{1,2,3,4}, 24})
{:ok, %Pfx{bits: <<1, 2, 3>>, maxlen: 32}}
iex> parse({1,2,3,4})
{:ok, %Pfx{bits: <<1, 2, 3, 4>>, maxlen: 32}}
iex> parse(%Pfx{bits: <<4, 3, 2, 1>>, maxlen: 32})
{:ok, %Pfx{bits: <<4, 3, 2, 1>>, maxlen: 32}}
iex> parse("1.2.3.4/33")
{:error, :einvalid}
iex> parse("acdc:1976::/32")
{:ok, %Pfx{bits: <<0xACDC::16, 0x1976::16>>, maxlen: 128}}
iex> parse("DEAD:BEER::/32")
{:error, :einvalid}
Specs
Parses a prefix/0
and returns {:ok, Pfx.t}
or given default
on error.
Same as Pfx.parse/1
, but returns given default on error.
Examples
iex> parse("0.0.0.0/32", :oops)
{:ok, %Pfx{bits: <<0, 0, 0, 0>>, maxlen: 32}}
iex> parse("0.0.0.0/33", :oops)
:oops
iex> pfx = "0.0.0.256/24"
iex> parse(pfx, {:error, pfx})
{:error, "0.0.0.256/24"}
iex> parse("11:22:33:44:55:GG", {:error, :bad_eui48})
{:error, :bad_eui48}