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

Use Either enum, instead of creating multiple enums and manually implementing traits for each one #5513

Open
dullbananas opened this issue Mar 17, 2025 · 3 comments

Comments

@dullbananas
Copy link
Collaborator

The messy enum problem mostly applies to enums in the apub crate. For example, SiteOrCommunityOrUser could become Either<ApubSite, Either<ApubCommunity, ApubUser>>. In this case, the activitypub_federation crate would have to implement its traits for Either.

Should be done after #5496 to avoid merge conflicts.

https://docs.rs/either/latest/either/enum.Either.html

@Nutomic
Copy link
Member

Nutomic commented Mar 17, 2025

Good idea this makes sense.

Edit: See LemmyNet/activitypub-federation-rust#139

@dessalines
Copy link
Member

Same, I really like this idea.

There's even a few cases in the API, such as GetCommunity or GetPerson, that are {id: Option<CommunityId, name: Option<String>}, that it'd be better to use Either for (depending on whether those can work easily with query params).

@Nutomic
Copy link
Member

Nutomic commented Mar 17, 2025

Relevant serde docs: https://serde.rs/enum-representations.html

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

No branches or pull requests

3 participants