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

Remove dependencies #2

Merged
merged 7 commits into from
Jan 20, 2024
Merged

Remove dependencies #2

merged 7 commits into from
Jan 20, 2024

Conversation

etiennebacher
Copy link
Contributor

@etiennebacher etiennebacher commented Jan 16, 2024

Close #1. Ready for review @JosiahParry ;)

@JosiahParry
Copy link
Collaborator

Currently running into a bug that I'm going to think through how we can address it. !b.inherits("raw") does work in our care right now.

First, the check for the raw class isn't working and two, we're returning an Rstr::na() (don't get me started on the oddities of character vectors and the C api) which, instead, we should be returning a NULL

library(b64)
x <- encode(c("hello", "world", NA))

y <- lapply(x, charToRaw)

decode(y)
#> <blob[3]>
#> [[1]]
#> <CHARSXP: NA>
#> 
#> [[2]]
#> <CHARSXP: NA>
#> 
#> [[3]]
#> <CHARSXP: NA>

@JosiahParry
Copy link
Collaborator

We can replace the body of the closure with a try_from() coupled with a match statement here.

  let raw = Raw::try_from(b);
  match raw {
      Ok(r) => {
          let decoded = eng.decode(r.as_slice());
          match decoded {
              Ok(d) => Raw::from_bytes(&d).into_robj(),
              Err(_) => ().into_robj(),
          }
      },
      Err(_) => ().into_robj(),
  }
library(b64)
x <- encode(c("hello", "world", NA))

y <- lapply(x, charToRaw)

decode(y)
#> <blob[3]>
#> [[1]]
#> [1] 68 65 6c 6c 6f
#> 
#> [[2]]
#> [1] 77 6f 72 6c 64
#> 
#> [[3]]
#> NULL

src/rust/src/lib.rs Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
DESCRIPTION Outdated Show resolved Hide resolved
@JosiahParry
Copy link
Collaborator

Once we fix the vectorized decoding of raws I think this can get merged! Thank you!

@etiennebacher
Copy link
Contributor Author

Thanks for your help @JosiahParry, is this what you had in mind?

library(b64)
x <- encode(c("hello", "world", NA))
x
#> [1] "aGVsbG8=" "d29ybGQ=" NA

y <- lapply(x, charToRaw)
decode(y)
#> <blob[3]>
#> [[1]]
#> [1] 68 65 6c 6c 6f
#> 
#> [[2]]
#> [1] 77 6f 72 6c 64
#> 
#> [[3]]
#> NULL

# for pretty printing
library(blob)
decode(y)
#> <blob[3]>
#> [1] blob[5 B] blob[5 B] <NA>

src/rust/src/lib.rs Outdated Show resolved Hide resolved
@JosiahParry JosiahParry merged commit ae74633 into extendr:main Jan 20, 2024
@etiennebacher etiennebacher deleted the remove-deps branch January 20, 2024 15:55
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.

Remove dependencies?
3 participants