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

Handle type restrictions #2

Open
dbrgn opened this issue Aug 15, 2016 · 4 comments
Open

Handle type restrictions #2

dbrgn opened this issue Aug 15, 2016 · 4 comments

Comments

@dbrgn
Copy link
Owner

dbrgn commented Aug 15, 2016

The Gerber spec specifies a list of data types:

  • Integers
  • Decimals
  • Coordinate Numbers
  • Hexadecimal
  • Names
  • Strings

We should make sure that only valid values accrding to the spec can be passed in to types expecting these basic data types.

This means that we probably won't get around creating custom wrapper types.

Is there a way to create range types in Rust, e.g. a 32 bit signed integer >= 1? Or strings that only accept certain unicode codepoints? Ideally as much as possible at compile time.

@rnestler @dns2utf8

@dns2utf8
Copy link

we could test every function with:

fn validate_1_n(arg: i32) {
  assert!(arg > 1, "You shall not pass a number lower than 1");
}

Maybe extend it with https://github.com/alexcrichton/backtrace-rs to display nicer messages including the calling function.

@dbrgn
Copy link
Owner Author

dbrgn commented Aug 16, 2016

If it happens at runtime, I'd rather go with something like TryFrom and return a Result.

@rnestler
Copy link

Yeah definitely go with Result for input parsing.

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

3 participants