typeid
Types
Values
pub fn decode(prefix kind: String) -> decode.Decoder(TypeId(a))
TypeId decoder for use in Gleam’s decode
module.
When decoding the type(prefix) is known, which is why this function takes
the prefix as an argument to verify the prefix of the TypeId.
Usage
let decoder = {
use id <- decode.field("id", typeid.decode("user"))
use name <- decode.field("name", decode.string)
decode.success(User(id:, name:))
}
pub fn from_uuid(
prefix prefix: String,
uuid uuid: String,
) -> Result(TypeId(a), String)
Generate a TypeID using the supplied prefix and UUID.
Usage
let assert Ok(id) = from_uuid("user", "018fcec0-b44b-7ce2-b187-2f08349beab9")
pub fn new(prefix prefix: String) -> Result(TypeId(a), String)
Create a new TypeId with the given prefix. Prefix must be a string containing at most 63 characters and only lowercase alphabetic ASCII characters [a-z], or an underscore. The prefix may also be empty.
Usage
let assert Ok(id) = new("user")
pub fn parse(raw_typeid: String) -> Result(TypeId(a), String)
Parse a TypeId from a string.
Usage
let assert Ok(id) = parse("user_01h455vb4pex5vsknk084sn02q")
pub fn prefix(typeid: TypeId(a)) -> String
Returns the prefix of the TypeId.
Usage
let assert Ok(id) = new("user")
prefix(id) // "user"
pub fn suffix(typeid: TypeId(a)) -> String
Returns the suffix of the TypeId.
Usage
let assert Ok(id) = new("user")
suffix(id) // "01h455vb4pex5vsknk084sn02q"
pub fn to_string(typeid: TypeId(a)) -> String
Returns the string representation of a TypeId.
Usage
let assert Ok(id) = new("user")
to_string(id) // "user_01h455vb4pex5vsknk084sn02q"
let assert Ok(id) = new("")
to_string(id) // "01h455vb4pex5vsknk084sn02q"