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

refactor: improve the public interface by using triats #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SteveLauC
Copy link
Contributor

What does this PR do

  1. Replace argument type &str with S: AsRef<str>
  2. Replace argument type &[u8] with B: AsRef<[u8]

With the usage of traits, these public interfaces can accept more types, take S: AsRef<str> as an example, you can pass the following types to it:

  1. &str
  2. String
  3. &String
  4. ...

and will thus be more ergonomic and rusty

@SteveLauC
Copy link
Contributor Author

BTW, there is a test failure:

test test_get_language_extensions ... FAILED

failures:

---- test_get_language_extensions stdout ----
-------------- TEST START --------------
thread 'test_get_language_extensions' panicked at 'assertion failed: `(left == right)`
  left: `[".py", ".cgi", ".fcgi", ".gyp", ".gypi", ".lmi", ".py3", ".pyde", ".pyi", ".pyp", ".pyt", ".pyw", ".rpy", ".spec", ".tac", ".wsgi", ".xpy"]`,
 right: `[".py", ".cgi", ".fcgi", ".gyp", ".gypi", ".lmi", ".py3", ".pyde", ".pyi", ".pyp", ".pyt", ".pyw", ".rpy", ".smk", ".spec", ".tac", ".wsgi", ".xpy"]`', tests/test_enry.rs:183:5
stack backtrace:
   0: rust_begin_unwind
             at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/panicking.rs:593:5
   1: core::panicking::panic_fmt
             at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/panicking.rs:67:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
             at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/panicking.rs:229:5
   4: test_enry::test_get_language_extensions::test_get_language_extensions
             at ./tests/test_enry.rs:183:5
   5: test_enry::test_get_language_extensions
             at ./tests/test_enry.rs:176:1
   6: test_enry::test_get_language_extensions::{{closure}}
             at ./tests/test_enry.rs:176:1
   7: core::ops::function::FnOnce::call_once
             at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/ops/function.rs:250:5
   8: core::ops::function::FnOnce::call_once
             at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

failures:
    test_get_language_extensions

But since this repo is just about bindings, it is probably something changed in the upstream

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant