I have two FFI entry points to rust functions
that begin thusly:
let rt = tokio::runtime::Runtime::new()?;
let descriptor = rt.block_on(async { get_descriptor(query).await })?;
the 2nd of them to be called reliably runs println!s, the other, 1st to be called, runs println!s
but no output -
it only seems to work after some major editting unrelated to that function and then stops working after another cargo build invocation.
but the function does run and a correct result is returned!
as a relative noob I suspect I am missing something obvious.
can someone put me out of my misery?!
The only thing that can suppress some printlns but not others is the test harness, used when you're using cargo test to run #[test] functions. In that case, println output is by default only shown if the test fails. If you are running tests and you want to see their output always, then use the test harness option --show-output:
cargo test -- --show-output
Other possibilities, if you are not using tests:
the code containing the printlns is in fact not being run at all (perhaps it hangs or is cancelled before it gets there)
something else writing to the terminal has moved the cursor and caused this line to be overwritten
the FFI code has caused undefined behavior which disrupted the printlns
Also seems like it could be related to stdout buffering. And since FFI is involved, maybe there's a violation of the Rust I/O invariants somehow, e.g. something is causing a race condition or corruption in the stdout lock.