-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
libgraphviz: Id::new returns Result<Id, ()> instead of panicking on error #18921
libgraphviz: Id::new returns Result<Id, ()> instead of panicking on error #18921
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @aturon (or someone else) soon. |
sorry, didn't know about |
0798273
to
f4ba7ee
Compare
@@ -351,14 +351,18 @@ impl<'a> Id<'a> { | |||
/// defined by the DOT language. This function may change in the | |||
/// future to accept a broader subset, or the entirety, of DOT's | |||
/// `ID` format.) | |||
pub fn new<Name:str::IntoMaybeOwned<'a>>(name: Name) -> Id<'a> { | |||
pub fn new<Name:str::IntoMaybeOwned<'a>>(name: Name) -> Result<Id<'a>, ()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update the documentation of this function to include the error cases as well? It's not totally clear when Err
would be returned for example.
f4ba7ee
to
6221f7e
Compare
@@ -346,19 +346,25 @@ impl<'a> Id<'a> { | |||
/// identifier format: it must be a non-empty string made up of | |||
/// alphanumeric or underscore characters, not beginning with a | |||
/// digit (i.e. the regular expression `[a-zA-Z_][a-zA-Z_0-9]*`). | |||
/// Passing different string (i.e. containing spaces, brackets, | |||
/// quotes, ...) will return an empty `Err` value. | |||
/// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexcrichton like this or should i create an example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thanks!
6221f7e
to
d0edf59
Compare
abbc1cc
to
9c06cb7
Compare
…rror creating a new Id object requires the format to match a subset of `ID` format defined by the DOT language. When the format did not match, the function called assert. This was not mentioned in the docs or the spec. I made the failure explicit by returning an Result<Id, ()>.
9c06cb7
to
70bf4f7
Compare
the tests are now two separate tests (and they compile). |
Thanks @oli-obk! |
internal: Compute inlay hint text edits lazily
creating a new Id object requires the format to match a subset of
ID
format defined by the DOT language. When the format did not match, the function called assert. This was not mentioned in the docs or the spec. I made the failure explicit by returning an Result<Id, ()>.