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

What are the semantics of the span in de::error? #556

Closed
konstin opened this issue May 18, 2023 · 3 comments
Closed

What are the semantics of the span in de::error? #556

konstin opened this issue May 18, 2023 · 3 comments

Comments

@konstin
Copy link

konstin commented May 18, 2023

Would it be possible to add to the documentation what the semantics of the Option<Range<usize>> are that toml::de::Error::span() returns? Is it a char offset or a byte offset, and under what conditions will it be None? I want to integrate linting of toml files into our diagnostics system and it would be great to have clarity over how these indices behave we utf-8 content.

@epage
Copy link
Member

epage commented May 18, 2023

Is it a char offset or a byte offset

It is documented as the index into the document. That would be a byte offset.

under what conditions will it be None

  • If you deserialize from a Document, all span information is lost
  • If you deserialize from a &str, then we should (nearly) alway have a span. Any missing span is more likely to be a bug.

konstin added a commit to konstin/toml that referenced this issue May 18, 2023
konstin added a commit to konstin/toml that referenced this issue May 18, 2023
@konstin
Copy link
Author

konstin commented May 18, 2023

It is documented as the index into the document. That would be a byte offset.

Thanks! I unfortunately have encountered a lot of different things people mean by index, so this helps clarifying.

I've opened #558 to make this visible for everybody

@epage
Copy link
Member

epage commented May 18, 2023

Thanks! I unfortunately have encountered a lot of different things people mean by index, so this helps clarifying.

Within rust code for the &str type, there is one canonical meaning

@konstin konstin closed this as completed May 18, 2023
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

2 participants