jemc / pony-uuid

UUID parsing and generation for Pony

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pony-UUID

Introduction

This module provides a Pony package for parsing and generating UUIDs.

This code is basically a direct port of Google's uuid package for Go.

Pony-UUID does not support generating UUIDs of versions 1 and 2 at this point.

Examples

The package is meant to be used with aliased use statements.

Generating a random (version 4) UUID

use uuid = "uuid"

actor Main
  new create(env: Env) =>
    let id = uuid.UUID.v4()
    env.out.print(id.string())

Parsing an UUID

use uuid = "uuid"

actor Main
  new create(env: Env) =>
    try
      let arg = env.args(1)?
      match uuid.Parse(arg)
      | let id: uuid.UUID =>
        env.out.print(id.string() + " version: " + id.version().string() + ", variant: " + id.variant().string())
      | uuid.InvalidPrefix =>
        env.out.print(arg + ": invalid prefix")
      | uuid.InvalidFormat =>
        env.out.print(arg + ": invalid format")
      | uuid.InvalidLength =>
        env.out.print(arg + ": invalid length")
    end

About

UUID parsing and generation for Pony


Languages

Language:Pony 100.0%