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

Support r# escape syntax in Rust function names in rust_source() family of functions #374

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Support `RTOOLS44` (#347)
* Removed `use_try_from` as an option in `rust_function`, and added `use_rng` (#354)
* Added `use_crate()` function to make adding dependencies to Cargo.toml easier within R, similar to `usethis::use_package()` (#361)
* Fixed an issue in `rust_source()` family of functions that prevented usage of `r#` escape sequences in Rust function names (#374)

# rextend 0.3.1

Expand Down
2 changes: 1 addition & 1 deletion R/find_exports.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extract_meta <- function(lns) {
# Matches fn|impl<'a> item_name
result <- stringi::stri_match_first_regex(
glue_collapse(lns, sep = "\n"),
"(?:(fn)|(impl)(?:\\s*<(.+?)>)?)\\s+(_\\w+|[A-z]\\w*)"
"(?:(?<fn>fn)|(?<impl>impl)(?:\\s*<(?<lifetime>.+?)>)?)\\s+(?<name>(?:r#)?(?:_\\w+|[A-z]\\w*))"
) %>%
tibble::as_tibble(.name_repair = "minimal") %>%
rlang::set_names(c("match", "fn", "impl", "lifetime", "name")) %>%
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-source.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,20 @@ test_that("`rust_source()` should not raise internal error for code without exte

expect_no_error(rust_source(code = "fn test() {}"))
})

# https://github.com/extendr/rextendr/issues/356
test_that("`rust_function()` supports `r#` prefix in rust function names", {
skip_if_cargo_unavailable()

rust_fn_src <- "
fn r#true() -> &'static str {
\"Specially-named function has been called\"
}
"

rust_function(
code = rust_fn_src
)

expect_equal(true(), "Specially-named function has been called")
})
Loading