Use Rust applications output, what is the reason or what configuration? This is very frustrating!

Use Rust Test Lens to debug Rust applications
Chinese garbled output, what is the reason or what configuration? This is very frustrating! ! !

fn test_2() {

    let s = String::from("您好");

    let s1 = take_ownership(s);

    println!("第二次:{}", s1);

    let x = 5;

    make_copy(x);

    println!("{}", x);

    println!("Hello,world!");

}
a=1
b=1
绗竴娆★細鎮ㄥソ
绗簩娆★細鎮ㄥソ
i=5
5
Hello,world!

I am just a beginner, I do not know why, so I want to ask for help from your predecessors!

Make sure that whatever console you're running the tests in is using UTF-8 and has full font support. Getting wrong output outside ASCII is a decent suggestion that it's defaulted to something else.

2 Likes

There is no garbled text when using cargo run, but garbled text when running on the client

Print the content in the same terminal but the results are different
Sample code:

fn main() {
    println!("查询操作")
}

Switch to rust analyser and see if you still get it.

@jonh Hello! It is not possible to set a breakpoint now, what is the reason?:joy::joy:

Please use code fences when writing code on this forum. There was a pinned post recently which described how to do it and should have been at the top of the feed at some point.

```
code
```

Running this example:

fn main() {
    println!("查询操作");
}

In visual studio code's terminal under powershell 7.0.0 resulted in the following output:

PS C:\Users\Patrik\Desktop\forum_examples> cargo run
   Compiling forum_examples v0.1.0 (C:\Users\Patrik\Desktop\forum_examples)
    Finished dev [unoptimized + debuginfo] target(s) in 0.35s
     Running `target\debug\forum_examples.exe`
查询操作

Running the same program under the default powershell Windows came with but still in the vscode console:

PS C:\Users\Patrik\Desktop\forum_examples> powershell
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\Users\Patrik\Desktop\forum_examples> cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.11s
     Running `target\debug\forum_examples.exe`
查询操作

And the same result with cmd.
However, running it directly in a default powershell instance with its own window, I get:
image
Which points to there being an issue with the window that hosts powershell. I believe the proper term for this is the windows console host, which verifies what @CAD97 was saying earlier. However, this should still mean that running it in vscode, where the terminal is set up to deal with unicode should be able to deal with this. What is the shell you're using to run the example in your original post?

This problem has been solved after repeated trial and error. Thank you for your kind help!
But now there is another problem, how to copy the code into the input box to make it formatted unchanged and highlighted, just like in the Visualstudio editor. :joy: :joy:

  • Get the code on your clipboard (highlight the code then Ctrl + C or right click and Copy)

  • Start your code block:

    ```
    
    ```
    
  • Paste your code into the block:

    <Code>
    

    By pasting it (Ctrl + V or right click and Paste)

Also note that if you want to exclude removing indentation from your code you can Middle Click + Drag and select a box instead of a regular selection on most text interfaces.

Ones I know can do this:

  • Windows CMD (Alt + Left Click + Drag)
  • Windows PowerShell (and V. 7 too) are same as CMD
  • Visual Studio Code (Not regular visual studio last time I checked)
  • IntelliJ Idea and CLion (Both are great and robust Rust supporting IDEs and I'd suggest you take a look at them [Idea is free, CLion is not.])

And then you end up with this:

fn foo<T: Debug + IntoIterator<Item = usize>>(x: T) {
    println!("{:?}", x);
    for (i, v) in x.into_iter().enumerate {
        println!("index {} is {}", i, v);
    }
}

Ok! Thank you. Very complicated, not very easy to understand😂

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.