Skip to content

The trait Iden is not implemented for &str #154

Answered by tyt2y3
mamcx asked this question in Q&A
Discussion options

You must be logged in to vote

If you need to, you can do Alias::new("zone").

Or you can
#[derive(Iden)]
struct Zone;

There are 2 reasons:

  1. Correctness. it's an identifier, so if you misspelt it, it'd be a compile error

  2. Efficiency. &str is bad, because the syntax tree needs to store the name until you finally serialize it. Internally it must make a clone of the string (or end up in a lifetime struggle I guess).
    But now, the identifier is a pointer, so there is only one unique copy of your string in memory. &'static str would also be great, but then it limits us from runtime behaviour.

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by tyt2y3
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #153 on October 02, 2021 17:00.