Skip to content

Curl example doesn't compile : method not found in Option<&NgxStr> #50

Closed
@mtb0x1

Description

@mtb0x1

Describe the bug
I can't compile curl example, error message :

error[E0599]: no method named `as_bytes` found for enum `Option` in the current scope
   --> examples/curl.rs:114:37
    |
114 |             if request.user_agent().as_bytes().starts_with(b"curl") {
    |                                     ^^^^^^^^ method not found in `Option<&NgxStr>`
    |
note: the method `as_bytes` exists on the type `&NgxStr`
   --> /home/user/apps/rust/ngx-rust/src/core/string.rs:55:5
    |
55  |     pub fn as_bytes(&self) -> &[u8] {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider using `Option::expect` to unwrap the `&NgxStr` value, panicking if the value is an `Option::None`
    |
114 |             if request.user_agent().expect("REASON").as_bytes().starts_with(b"curl") {
    |                                    +++++++++++++++++

For more information about this error, try `rustc --explain E0599`.
error: could not compile `examples` (example "curl") due to previous error

To Reproduce
Steps to reproduce the behavior:

  1. Run cargo build --release --package=examples --example=curl
  2. See error

Expected behavior
Curl example compiles without errors

Your environment

  • Repo version : Last version up to date (9ce7895)
  • Version of Rust : stable, rustc 1.73.0 (cc66ad468 2023-10-03)
  • OS and distribution : Debian bookworm

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions