-
Notifications
You must be signed in to change notification settings - Fork 5
make PointerBuf::parse
error basic by default
#103
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files
|
Aha, I think I figured out (rediscovered?) why |
A couple options:
enum ParseErrorWrapper {
Simple(ParseError),
Rich(Report<ParseError>)
} and pivot based on the Either way there's some amount of user-facing complexity added, but on the other end this is kinda dumb: let ptr_str = "hello";
PointerBuf::parse(ptr_str).diagnose_with(|| ptr_str.to_owned()); // kinda fine
let ptr_str = String::from(ptr_str);
PointerBuf::parse(&ptr_str).diagnose(ptr_str); // dumb, we allocate in Ok case unecessarily Ugh, I may reconsider this PR entirely. |
Ok, let's drop this. I'll make a different PR with the side-benefits of this one. |
Side-benefits over at #104 |
Since #101 the
assign
andresolve
Error
types are self-contained andshallow by default (meaning they don't include a copy of their source string).
This is nice - the errors are helpful and don't require extra allocations, but
the users may still opt into richer errors by using the
Diagnose
trait andproviding the "source code" (in
miette
terminology).The
PointerBuf::parse
error was different, however. It was made a rich errorby default, which requires one extra clone (which may be unnecessary), but
more importantly, is inconsistent with the other error contract.
This PR makes the parse error consistent, by switching it back to
ParseError
.To recover the rich error functionality users can just call
.diagnose()
on theResult
, same as withassign::Error
andresolve::Error
.I'm also sneaking in a fix for the eager behaviour of
Diagnose::diagnose_with
.