Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Serde Support For AST #80

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Conversation

sodiumjoe
Copy link

branched from #77

@jondlm
Copy link

jondlm commented Jul 1, 2024

Any chance we could get this merged/released soon? I understand if y'all are busy. I'll begin the process of forking internally but ideally we can unwind that soon.

@LegNeato LegNeato requested a review from tailhook July 11, 2024 22:22
@LegNeato
Copy link
Member

@tailhook Can you take a look?


use crate::helpers::{ident, kind, name, punct};
use crate::position::Pos;
use crate::tokenizer::{Kind as T, Token, TokenStream};

#[cfg(feature = "serde")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is a good idea, but I think to not duplicate everything you could do something like:

#[cfg(feature = "serde")]
mod text_traits {
    use serde::{Serialize, Deserialize};

    pub trait SerdeTraits<'a>: Serialize + Deserialize<'a> {}

    impl<'a, T> SerdeTraits<'a> for T where T: Serialize + Deserialize<'a> {}
}

#[cfg(not(feature = "serde"))]
mod text_traits {
    pub trait SerdeTraits<'a> {}

    impl<'a, T> SerdeTraits<'a> for T {}
}

// Define the main trait with conditional compilation
pub trait Text<'a>: 'a {
    type Value: 'a
        + From<&'a str>
        + AsRef<str>
        + std::borrow::Borrow<str>
        + PartialEq
        + Eq
        + PartialOrd
        + Ord
        + fmt::Debug
        + Clone
        + text_traits::SerdeTraits<'a>;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants