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

Updated Chapter 12.3.1 #420

Closed
wants to merge 5 commits into from
Closed

Updated Chapter 12.3.1 #420

wants to merge 5 commits into from

Conversation

OkoliEvans
Copy link
Contributor

There was no description on how to write user defined struct to storage, and how to read as well. Added these with examples. @enitrat

@enitrat
Copy link
Contributor

enitrat commented Nov 1, 2023

I don't understand why reading/writing structs would be separated from other types. How to read and write variables from storage is already explained here

https://book.cairo-lang.org/ch99-01-03-01-storage-variables.html#reading-from-storage

@OkoliEvans
Copy link
Contributor Author

I don't understand why reading/writing structs would be separated from other types. How to read and write variables from storage is already explained here

https://book.cairo-lang.org/ch99-01-03-01-storage-variables.html#reading-from-storage

I will edit and commit again in a few hours

@OkoliEvans
Copy link
Contributor Author

Updated now, Please check @enitrat

@enitrat enitrat closed this Nov 2, 2023
@enitrat
Copy link
Contributor

enitrat commented Nov 2, 2023

Sorry, what I meant was:

Storing user defined structs is equivalent to storing any other kind of data. Read and writes are performed in the same way as well which is why I do not understand why there would be a section specifically about structs. Creating a subsection especially for structs, separated from other data types will only create confusion.

The example provided do not compile and don't make a lot of sense (why is a Person stored under a variable named name?)

For eventual subsequent PRs, you will need to verify that the examples compile first, and then add them to the listings directory, as it's currently done for all code snippets

@OkoliEvans
Copy link
Contributor Author

OkoliEvans commented Nov 2, 2023

I thought adding the changes will make it clearer to understand how structs annotated with #[derive(starknet::Store)] are written to. In the book there is no explicit explanation about how this is done, the usual self.names.write(value) does not work for user defined storage structs. @enitrat

@enitrat
Copy link
Contributor

enitrat commented Nov 2, 2023

the usual self.names.write(value) does not work for user defined storage structs. @enitrat

It does! There is no difference between compiler-defined types, enums, or structs! You just call self.var.write(value) !

@OkoliEvans
Copy link
Contributor Author

Oh, I tried that yesterday and I was getting errors. I will confirm and pm you on Telegram. Thank you

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.

2 participants