#value #tag #byte #key

acts-tag-value

provide binary Value for acts-tag

2 unstable releases

0.2.0 Apr 17, 2023
0.1.0 Apr 11, 2023
Download history 25/week @ 2023-08-13 9/week @ 2023-08-20 11/week @ 2023-08-27 17/week @ 2023-09-03 15/week @ 2023-09-10 12/week @ 2023-09-17 12/week @ 2023-09-24 16/week @ 2023-10-01 11/week @ 2023-10-08 19/week @ 2023-10-15 29/week @ 2023-10-22 22/week @ 2023-10-29 16/week @ 2023-11-05 16/week @ 2023-11-12 28/week @ 2023-11-19 32/week @ 2023-11-26

97 downloads per month
Used in 3 crates (2 directly)

MIT license

3KB

acts-tag

A simple trait to mark up the struct and help recognize the struct's attributes. A simple trait to mark up the struct and help recognize the struct's attributes.

Example

use acts_tag::{Tags, Value};
use std::any::Any;
#[derive(Tags)]
pub struct MyTags {
    // tag(id) change the key to id
    #[tag(id)]
    pub my_id: String,
    #[tag]
    pub tag1: String,
    #[tag]
    pub tag2: i32,
    pub others: String,
}
fn main() {
    let t = MyTags {
        my_id: "my id".to_string(),
        tag1: "a".to_string(),
        tag2: 5,
        others: "others".to_string(),
    };
    assert_eq!(MyTags::keys(), vec![ "id", "tag1", "tag2" ]);
    
    for tag_key in &MyTags::keys() {
        let value = t.value(tag_key).unwrap();
        println!("value {} = {:?}", tag_key, value);
    }
    let value = t.value("id").unwrap();
    assert_eq!(value.real::<String>().unwrap(), t.my_id);

    let value = t.value("tag1").unwrap();
    assert_eq!(value.real::<String>().unwrap(), t.tag1);

    let value = t.value("tag2").unwrap();
    assert_eq!(value.real::<i32>().unwrap(), t.tag2);

    let value = t.value("others");
    assert_eq!(value, None);

    let is_tag = t.is_tag("others");
    assert_eq!(is_tag, false);

    let is_tag = t.is_tag("tag2");
    assert_eq!(is_tag, true);
}

Dependencies

~0.7–1.2MB
~29K SLoC