Skip to content

Commit

Permalink
feat: Provide Fantome from both merde-json and merde-json-types
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Aug 16, 2024
1 parent 97ffbe4 commit 514231b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion merde_json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ macro_rules! impl_trait {
///
/// Note: if you're conditionally deriving `JsonSerialize` and `JsonDeserialize` for a type,
/// and you don't want the `merde_json` dependency when it's not used, you can use
/// `PhantomData<(&'src (), &'val ())>` instead — the derive macros will be happy with that.
/// `merde_json_types::Fantome` instead — the derive macros will be happy with that.
///
/// This type is really just a convenience so you have less to type.
#[derive(Default, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
Expand Down
14 changes: 14 additions & 0 deletions merde_json_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,17 @@

#[cfg(feature = "time-types")]
pub mod time;

/// A type you can use instead of `PhantomData` for convenience.
///
/// This type is really just a convenience so you have less to type.
#[derive(Default, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct Fantome<'src, 'val> {
_boo: std::marker::PhantomData<(&'src (), &'val ())>,
}

impl std::fmt::Debug for Fantome<'_, '_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("Boo!")
}
}

0 comments on commit 514231b

Please sign in to comment.