Crux v2020-03-17 17:55:51Z 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/0
.
A discord snowflake
, an unsigned 64 bit integer.
Functions
Constructs a t/0
from its Crux.Structs.Snowflake.Parts.t/0
or a keyword of its fields.
Deconstructs a t/0
to its Crux.Structs.Snowflake.Parts.t/0
.
The discord epoch, the first second of 2015 or 1420070400000
.
Deconstructs a t/0
to its Crux.Structs.Snowflake.Parts.t/0
.
Returns true
if term
is a t/0
; otherwise returns false
..
Converts a String.t/0
to a t/0
while allowing t/0
to pass through.
Constructs a t/0
from its Crux.Structs.Snowflake.Parts.t/0
.
Converts a String.t/0
to a t/0
while allowing t/0
and nil
to pass through.
Link to this section Types
resolvable() View Source (since 0.2.1)
All valid types that can be resolved into a t/0
.
t()
View Source
(since 0.2.1)
t() :: 0..18_446_744_073_709_551_615
t() :: 0..18_446_744_073_709_551_615
A discord snowflake
, an unsigned 64 bit integer.
Link to this section Functions
construct(parts)
View Source
(since 0.2.1)
construct(Crux.Structs.Snowflake.Parts.t() | Keyword.t()) :: t()
construct(Crux.Structs.Snowflake.Parts.t() | Keyword.t()) :: t()
Constructs a t/0
from its 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
deconstruct(snowflake)
View Source
(since 0.2.1)
deconstruct(t()) :: Crux.Structs.Snowflake.Parts.t()
deconstruct(t()) :: Crux.Structs.Snowflake.Parts.t()
Deconstructs a t/0
to its 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
}
discord_epoch()
View Source
(since 0.2.1)
discord_epoch() :: non_neg_integer()
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
from_integer(snowflake)
View Source
(since 0.2.1)
from_integer(t()) :: Crux.Structs.Snowflake.Parts.t()
from_integer(t()) :: Crux.Structs.Snowflake.Parts.t()
Deconstructs a t/0
to its Crux.Structs.Snowflake.Parts.t/0
.
is_snowflake(snowflake) View Source (macro) (since 0.2.1)
Returns true
if term
is a t/0
; otherwise returns false
..
parse(snowflake) View Source (since 0.2.1)
Converts a String.t/0
to a t/0
while allowing t/0
to pass through.
Returns :error
if the provided string is not a t/0
.
iex> Crux.Structs.Snowflake.parse("invalid")
:error
iex> Crux.Structs.Snowflake.parse(218348062828003328)
218348062828003328
# Fallbacks
iex> Crux.Structs.Snowflake.parse("218348062828003328")
218348062828003328
to_integer(t)
View Source
(since 0.2.1)
to_integer(Crux.Structs.Snowflake.Parts.t()) :: t()
to_integer(Crux.Structs.Snowflake.Parts.t()) :: t()
Constructs a t/0
from its Crux.Structs.Snowflake.Parts.t/0
.
to_snowflake(snowflake) View Source (since 0.2.1)
Converts a String.t/0
to a t/0
while allowing 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