crux_structs v0.2.3 Crux.Structs.Snowflake View Source
Custom non discord api struct to help with working with Discord's snowflakes.
For more information see Discord Docs.
Link to this section Summary
Types
All valid types that can be resolved into a t:t/0
.
A discord snowflake
, an unsigned 64 bit integer.
Functions
Constructs a t:t/0
from its t:Crux.Structs.Snowflake.Parts.t/0
or a keyword of its fields.
Deconstructs a t:t/0
to its t:Crux.Structs.Snowflake.Parts.t/0
.
The discord epoch, the first second of 2015 or 1420070400000
.
Deconstructs a t:t/0
to its t:Crux.Structs.Snowflake.Parts.t/0
.
Returns true
if term
is a t:t/0
; otherwise returns false
..
Converts a t:String.t/0
to a t:t/0
while allowing t:t/0
to pass through.
Constructs a t:t/0
from its t:Crux.Structs.Snowflake.Parts.t/0
.
Converts a t:String.t/0
to a t:t/0
while allowing t:t/0
and nil
to pass through.
Link to this section Types
Specs
All valid types that can be resolved into a t:t/0
.
Specs
t() :: 0..18_446_744_073_709_551_615
A discord snowflake
, an unsigned 64 bit integer.
Link to this section Functions
Specs
construct(Crux.Structs.Snowflake.Parts.t() | Keyword.t()) :: t()
Constructs a t:t/0
from its t:Crux.Structs.Snowflake.Parts.t/0
or a keyword of its fields.
iex> %Crux.Structs.Snowflake.Parts{increment: 0, process_id: 0, timestamp: 1472128634889, worker_id: 1}
...> |> Crux.Structs.Snowflake.construct()
218348062828003328
iex> Crux.Structs.Snowflake.construct(increment: 1, timestamp: 1451106635493)
130175406673231873
iex> Crux.Structs.Snowflake.construct(timestamp: Crux.Structs.Snowflake.discord_epoch())
0
Specs
deconstruct(t()) :: Crux.Structs.Snowflake.Parts.t()
Deconstructs a t:t/0
to its t:Crux.Structs.Snowflake.Parts.t/0
.
iex> Crux.Structs.Snowflake.deconstruct(218348062828003328)
%Crux.Structs.Snowflake.Parts{
increment: 0,
process_id: 0,
timestamp: 1472128634889,
worker_id: 1
}
Specs
discord_epoch() :: non_neg_integer()
The discord epoch, the first second of 2015 or 1420070400000
.
iex> Crux.Structs.Snowflake.discord_epoch()
1_420_070_400_000
Specs
from_integer(t()) :: Crux.Structs.Snowflake.Parts.t()
Deconstructs a t:t/0
to its t:Crux.Structs.Snowflake.Parts.t/0
.
Returns true
if term
is a t:t/0
; otherwise returns false
..
Specs
Converts a t:String.t/0
to a t:t/0
while allowing t:t/0
to pass through.
Returns :error
if the provided string is not a t:t/0
.
iex> Crux.Structs.Snowflake.parse("invalid")
:error
iex> Crux.Structs.Snowflake.parse(218348062828003328)
218348062828003328
# Fallbacks
iex> Crux.Structs.Snowflake.parse("218348062828003328")
218348062828003328
Specs
to_integer(Crux.Structs.Snowflake.Parts.t()) :: t()
Constructs a t:t/0
from its t:Crux.Structs.Snowflake.Parts.t/0
.
Specs
Converts a t:String.t/0
to a t:t/0
while allowing t:t/0
and nil
to pass through.
Raises an ArgumentError
if the provided string is not an integer.
iex> Crux.Structs.Snowflake.to_snowflake(218348062828003328)
218348062828003328
# Fallbacks
iex> Crux.Structs.Snowflake.to_snowflake("218348062828003328")
218348062828003328
iex> Crux.Structs.Snowflake.to_snowflake(nil)
nil