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

Expand symbol! into type-level list instead of N-tuple #31

Closed
soareschen opened this issue Dec 1, 2024 · 1 comment
Closed

Expand symbol! into type-level list instead of N-tuple #31

soareschen opened this issue Dec 1, 2024 · 1 comment
Milestone

Comments

@soareschen
Copy link
Collaborator

Summary

Currently, the macro symbol!("hello") would be expanded into:

(Char<'h'>, Char<'e'>, Char<'l'>, Char<'l'>, Char<'o'>)

We should instead expand it into:

Product![Char<'h'>, Char<'e'>, Char<'l'>, Char<'l'>, Char<'o'>]

This is so that we can more easily define generic implementations work on the symbol types. For example, we can define a HasString trait that would be implemented for the type-level list of chars:

pub trait HasString {
  fn string() -> String;
}

impl HasString for Nil {
  fn string() -> String {
    String::new()
  }
}

impl<T, R, const C: char> HasString for Cons<Char<C>, R> 
where
  R: HasString
{
  fn string() -> String {
    let mut str = R::string();
    str.push(C);
    str
  }
}
@soareschen soareschen added this to the v1.0 Release milestone Dec 1, 2024
@soareschen
Copy link
Collaborator Author

Closed by #36

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

No branches or pull requests

1 participant