GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - vbfox/stidgen.rs: Generate Strongly Typed Id types in Rust

BranchesTags
Open more actions menu

Latest commit

 

History

88 Commits
88 Commits

Folders and files

NameName
Last commit message
Last commit date
.devcontainer
.devcontainer
 
 
.github/workflows
.github/workflows
 
 
.vscode
.vscode
 
 
playground
playground
 
 
stidgen
stidgen
 
 
.editorconfig
.editorconfig
 
 
.gitignore
.gitignore
 
 
.prettierignore
.prettierignore
 
 
Cargo.lock
Cargo.lock
 
 
Cargo.toml
Cargo.toml
 
 
LICENSE.md
LICENSE.md
 
 
Readme.md
Readme.md
 
 
clippy.toml
clippy.toml
 
 

Repository files navigation

Strongly Typed ID types macro

A macro to simplify usage of srongly type ID types instead of plain String, u64 or Guid in Rust codebases.

use stidgen::{Id, id};

#[id]
pub struct UserId(String);

#[id(NoDefaults, Format, Debug)]
pub struct UserId(u64);

While the derive macro can already be used to achieve most of what this macro proposes using it has the following advantages:

  • It's simplier to use for well known types, simply add #[id] to your struct
  • The defaults provide a lot of blanket implementations that might be missed when doing it manually
  • Some features provided don't have corresponding derive macros (AsBytes, AsRef, Borrow)
  • All trivial functions are marked inline

Settings

  • Defaults/NoDefaults: Enable or disable defaults for known types
  • Clone/NoClone: Enable or disable deriving std::clone::Clone
  • Hash/NoHash: Enable or disable deriving std::hash::Hash
  • PartialEq/NoPartialEq: Enable or disable deriving std::cmp::PartialEq
  • Eq/NoEq: Enable or disable deriving std::cmp::Eq
  • PartialOrd/NoPartialOrd: Enable or disable deriving std::cmp::PartialOrd
  • Ord/NoOrd: Enable or disable deriving std::cmp::Ord
  • Display/NoDisplay: Enable or disable deriving std::fmt::Display and adding a to_string method
  • Debug/NoDebug: Enable or disable deriving std::fmt::Debug
  • AsBytes/NoAsBytes: Enable or disable deriving std::convert::AsRef<[u8]> and adding a as_bytes method
  • Borrow/NoBorrow: Enable or disable deriving std::borrow::Borrow
  • AsRef/NoAsRef: Enable or disable deriving std::convert::AsRef

Default types

For unknown types all features are disabled by default but some types like String have smart defaults.

#[id(Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Display, ToString, Debug, AsBytes, ...)]
pub struct Id(String);

About

Generate Strongly Typed Id types in Rust

Topics

deriveidmacrorust

Resources

Readme
MIT license
Activity

Stars

2 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.