What this error about

my code not have any error when i build with
cargo build but when i try to run test on my lib both
cargo test or cargo test -- --nocapture shows this error

tamara@ddos:~/Documents/IpCodec/FdkAudio$ cargo test
   Compiling FdkAudio v0.1.0 (/home/tamara/Documents/IpCodec/FdkAudio)
    Finished test [unoptimized + debuginfo] target(s) in 0.74s
     Running target/debug/deps/FdkAudio-b7d38557c2d0c286

running 2 tests
test sys::channel_map_descr::tests::FDK_channelMapDescr_init ... ok
test fdk::bitbuffer::tests::bitbuffer_init ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests FdkAudio

running 3 tests
test src/fdk/bitstream.rs - fdk::bitstream::FDK_BITSTREAM::escaped_value (line 277) ... FAILED
test src/fdk/bitstream.rs - fdk::bitstream::FDK_BITSTREAM::write_escaped_value (line 443) ... FAILED
test src/fdk/bitstream.rs - fdk::bitstream::FDK_BITSTREAM::pushback_cache (line 576) ... FAILED

failures:

---- src/fdk/bitstream.rs - fdk::bitstream::FDK_BITSTREAM::escaped_value (line 277) stdout ----
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `FDIS`
 --> src/fdk/bitstream.rs:278:14
  |
3 | q.v. ISO/IEC FDIS 23003-3  Table 16
  |              ^^^^ expected one of 8 possible tokens

error: aborting due to previous error

Couldn't compile the test.
---- src/fdk/bitstream.rs - fdk::bitstream::FDK_BITSTREAM::write_escaped_value (line 443) stdout ----
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `FDIS`
 --> src/fdk/bitstream.rs:444:14
  |
3 | q.v. ISO/IEC FDIS 23003-3  Table 16
  |              ^^^^ expected one of 8 possible tokens

error: aborting due to previous error

Couldn't compile the test.
---- src/fdk/bitstream.rs - fdk::bitstream::FDK_BITSTREAM::pushback_cache (line 576) stdout ----
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `function`
 --> src/fdk/bitstream.rs:577:10
  |
3 | PushBack function ungets a number of bits (combines cache and bitbuffer
  |          ^^^^^^^^ expected one of 8 possible tokens

error: mismatched closing delimiter: `}`
 --> src/fdk/bitstream.rs:578:1
  |
2 | fn main() {
  |           - closing delimiter possibly meant for this
3 | PushBack function ungets a number of bits (combines cache and bitbuffer
  |                                           - unclosed delimiter
4 | }
  | ^ mismatched closing delimiter

error: aborting due to 2 previous errors

Couldn't compile the test.

failures:
    src/fdk/bitstream.rs - fdk::bitstream::FDK_BITSTREAM::escaped_value (line 277)
    src/fdk/bitstream.rs - fdk::bitstream::FDK_BITSTREAM::pushback_cache (line 576)
    src/fdk/bitstream.rs - fdk::bitstream::FDK_BITSTREAM::write_escaped_value (line 443)

test result: FAILED. 0 passed; 3 failed; 0 ignored; 0 measured; 0 filtered out

error: test failed, to rerun pass '--doc'

Do you have the text from those errors inside a codeblock? If so, mark the text as text, since the default is Rust code that is executed.

```text
PushBack function ungets a number of bits (combines cache and bitbuffer
```

This is just a guess as you did not post the corresponding code.

1 Like

here my part of code.

    /// **
    ///  \brief read an integer value using a varying number of bits from the
    ///  bitstream
    ///
    ///         q.v. ISO/IEC FDIS 23003-3  Table 16
    ///
    ///  \param hBitStream HANDLE_FDK_BITSTREAM handle
    ///  \param nBits1  number of bits to read for a small integer value or escape
    ///  value
    ///  \param nBits2  number of bits to read for a medium sized integer value or
    ///  escape value
    ///  \param nBits3  number of bits to read for a large integer value
    ///  \return integer value read from bitstream
    /// /

    // FDK_INLINE UINT escapedValue(HANDLE_FDK_BITSTREAM hBitStream, int nBits1,
    //                             int nBits2, int nBits3) {
    fn escaped_value(&mut self, nBits1: i32, nBits2: i32, nBits3: i32) -> UINT {
        // UINT value = FDKreadBits(hBitStream, nBits1);
        let mut value = self.read_bits(&(nBits1 as UINT));
        // if (value == (UINT)(1 << nBits1) - 1) {
        //     UINT valueAdd = FDKreadBits(hBitStream, nBits2);
        //     value += valueAdd;
        //     if (valueAdd == (UINT)(1 << nBits2) - 1) {
        //     value += FDKreadBits(hBitStream, nBits3);
        //     }
        // }
        if value == (1 << nBits1) -1 {
            let valueAdd: UINT = self.read_bits(&(nBits2 as UINT));
            value += value + valueAdd;
            if valueAdd == (1 << nBits2) - 1 {
                value = value + self.read_bits(&(nBits3 as UINT));
            }
        }
        // return value;
        value
    }

hi alice can you give me a reference on documenting rust code.

It seems the markdown parser treats the indentation as a code block. As a test, try make the table title have same indentation as other lines.

1 Like

If you want a code-block that contains text, use

```text
q.v. ISO/IEC FDIS 23003-3  Table 16
```

instead of indenting by four (or more) spaces.

Also, we generally do not use that \param or \return pattern in Rust code. If you run cargo doc, you can see what it generates.

You may be interested in this:

https://doc.rust-lang.org/rustdoc/how-to-write-documentation.html

2 Likes

thank you @alice and @Hyeonu

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.