pub struct Tag<T>(pub T);
Expand description
Type representing a tag string associated with a type
This type is used when you want to output a tag string associated with a type in JSON serialization, and check if the tag string matches when deserializing.
The tag string is specified by the TAG
constant of the TagData
trait.
§Example
use mcp_attr::utils::{Tag, TagData};
use serde_json::json;
#[derive(Default)]
struct MyTag;
impl TagData for MyTag {
const TAG: &'static str = "my-tag";
}
let tag = Tag(MyTag::default());
let json = serde_json::to_value(&tag).unwrap();
assert_eq!(json, json!("my-tag"));
let tag: Tag<MyTag> = serde_json::from_value(json).unwrap();
Tuple Fields§
§0: T
Trait Implementations§
Source§impl<'de, T: TagData> Deserialize<'de> for Tag<T>
impl<'de, T: TagData> Deserialize<'de> for Tag<T>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl<T> Freeze for Tag<T>where
T: Freeze,
impl<T> RefUnwindSafe for Tag<T>where
T: RefUnwindSafe,
impl<T> Send for Tag<T>where
T: Send,
impl<T> Sync for Tag<T>where
T: Sync,
impl<T> Unpin for Tag<T>where
T: Unpin,
impl<T> UnwindSafe for Tag<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more