patternutils 0.1.0

Tiny utility library for some common design patterns.
Documentation
  • Coverage
  • 100%
    1 out of 1 items documented1 out of 1 items with examples
  • Size
  • Source code size: 3.93 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.07 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 17s Average build duration of successful builds.
  • all releases: 18s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • TannYuld

This crate provides handy implementations for some design pattern utilities.

Features

  • Builderderive macro for appyling Builder pattern by generating extra Builder struct.
  • Macro observer is for trait's and is for implementing Observer pattern by creating extra Publisher struct for the spesified instances whom implement this trait type.

Example

use patternutils::Builder;

#[derive(Builder)]
#[builder_attr(name = "CommandCreator", opt_in)]
struct Command {
    #[builder_field(name = "value", include = true)]
    definition: String,
    
    #[builder_field(include = true)]
    arg_count: usize,

    accepted_flag_fallback: fn(val: usize) -> usize,
    childs: Vec<Command>,
}

let mut builder = Command::builder();
let command = builder
    .value(String::from("my-command"))
    .arg_count(3)
    .build(|val| {return val + 5;}, vec![]);

assert_eq!(command.definition, String::from("my-command"));
assert_eq!(command.arg_count, 3);
assert_eq!((command.accepted_flag_fallback)(67), 72);
assert_eq!(command.childs.len(), 0);