Skip to content

Use newer const fn features #89

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

Merged
merged 7 commits into from
Sep 18, 2022
Merged

Conversation

tormol
Copy link
Collaborator

@tormol tormol commented Jun 5, 2022

Existing methods made const fn:

  • AsciiStr::len() (done in Misc. improvements #95)
  • AsciiStr::is_empty() (done in Misc. improvements #95)
  • AsciiStr::as_str()
  • AsciiStr::as_bytes()
  • AsciiStr::trim()
  • AsciiStr::trim_left()
  • AsciiStr::trim_right()
  • AsciiChar::from_ascii_unchecked()
  • AsciiChar::as_printable_char()
  • AsciiChar::is_digit() (postponed)

New methods:

  • AsciiStr::new([AsciiChar])
  • AsciiStr::from_ascii_bytes()
  • AsciiStr::from_ascii_str()
  • AsciiChar::try_new(char)

Also switch back to && and || in many methods, and panic!() in AsciiChar::new() (postponed).

This increases MSRV all the way to 1.57 1.56.

@tormol
Copy link
Collaborator Author

tormol commented Jun 5, 2022

1.57 is quite recent.
Dropping AsciiChar::new() and the constification of AsciiChar::is_digit() reduces it to 1.56, which is the 2021 edition release.

@tormol tormol mentioned this pull request Jun 5, 2022
@tormol tormol force-pushed the more_const branch 2 times, most recently from e8c19d4 to d49cce5 Compare June 9, 2022 19:34
@tormol
Copy link
Collaborator Author

tormol commented Jun 9, 2022

Lowered MSRV to 1.57 by replacing casts through raw pointers with transmute.

@tormol tormol force-pushed the more_const branch 3 times, most recently from af35d53 to 93263ba Compare September 12, 2022 20:24
Enabled by Rust 1.46 as part of const if/else.
* AsciiChar::from_ascii_unchecked()
* AsciiChar::as_printable_char()
As `const fn` alternatives to the trait-based from_ascii().

Closes tomprogrammer#84
* AsciiStr::as_str()
* AsciiStr::as_bytes()

Dereferencing raw pointers in `const fn` requires Rust 1.58,
while transmute only requires Rust 1.56.
* AsciiStr::trim_start()
* AsciiStr::trim_end()
* AsciiStr::trim()
@tormol tormol merged commit d16538e into tomprogrammer:master Sep 18, 2022
@coolreader18
Copy link

Would it be possible to cut a new release onto crates.io with this? It'd be really useful to be able to use some of these in a const context.

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