struct CUID
- CUID
- Struct
- Value
- Object
Overview
Adds JSON support to CUID
.
NOTE require "cuid/json"
is required to use this feature.
require "cuid"
require "cuid/json"
class Example
JSON.mapping id: CUID
end
example = Example.from_json(%({"id": "ck8vrqmp20000df63z8lsaahr"}))
cuid = CUID.random
cuid.to_json # => "\"ck8vrqmp20000df63z8lsaahr\""
Defined in:
cuid.crcuid/json.cr
Constant Summary
-
BASE =
36_u64
-
BLOCK_SIZE =
4_u64
-
DISCRETE_VALUES =
BASE ** BLOCK_SIZE
-
RAND_MAX =
(BASE ** RAND_SIZE) - 1
-
RAND_MIN =
BASE ** (RAND_SIZE - 1)
-
RAND_SIZE =
BLOCK_SIZE * 2
-
VERSION =
"1.1.0"
Constructors
-
.new(bytes : StaticArray(UInt8, 25))
Generates a
CUID
from bytes -
.new(slice : Slice(UInt8))
Generates a CUID from 16-bytes slice.
-
.new(string : String)
Converts a
String
into aCUID
. - .new(pull : JSON::PullParser)
Class Method Summary
Instance Method Summary
-
#inspect(io : IO) : Nil
Convert to
String
in a literal format. - #to_json(json : JSON::Builder)
-
#to_s(io : IO) : Nil
Same as
#inspect(io)
.