Taggable

Trait Taggable 

Source
pub trait Taggable {
    type Inner;
    type Tag;

    // Provided method
    fn type_name(&self) -> &'static str { ... }
}
Expand description

Trait to enforce the use of Tagged types in function signatures. This prevents accidental use of raw primitives and ensures type safety.

§Example

use tagged_core::{Tagged, Taggable};

#[derive(Debug)]
struct UserIdTag;
type UserId = Tagged<u32, UserIdTag>;

fn process_user_id<T: Taggable>(id: T) {
    // This function only accepts Tagged types, not raw u32
    println!("Processing user ID: {:?}", id);
}

fn main() {
    let user_id: UserId = 42.into();
    process_user_id(user_id); // ✓ Works
    // process_user_id(42);    // ✗ Compile error: expected Taggable, found integer
}

Required Associated Types§

Provided Methods§

Source

fn type_name(&self) -> &'static str

Implementors§

Source§

impl<T, Tag> Taggable for Tagged<T, Tag>

Source§

type Inner = T

Source§

type Tag = Tag