Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions src/basic-syntax/scalar-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
| Signed integers | `i8`, `i16`, `i32`, `i64`, `i128`, `isize` | `-10`, `0`, `1_000`, `123i64` |
| Unsigned integers | `u8`, `u16`, `u32`, `u64`, `u128`, `usize` | `0`, `123`, `10u16` |
| Floating point numbers | `f32`, `f64` | `3.14`, `-10.0e20`, `2f32` |
| Strings | `&str` | `"foo"`, `r#"\\"#` |
| Strings | `&str` | `"foo"`, `"two\nlines"` |
| Unicode scalar values | `char` | `'a'`, `'α'`, `'∞'` |
| Byte strings | `&[u8]` | `b"abc"`, `br#" " "#` |
| Booleans | `bool` | `true`, `false` |

The types have widths as follows:
Expand All @@ -16,3 +15,29 @@ The types have widths as follows:
* `isize` and `usize` are the width of a pointer,
* `char` is 32 bit wide,
* `bool` is 8 bit wide.

<details>

There are a few syntaxes which are not shown above:

- Raw strings allow you to create a `&str` value with escapes disabled: `r"\n"
== "\\\\n"`. You can embed double-quotes by using an equal amount of `#` on
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
== "\\\\n"`. You can embed double-quotes by using an equal amount of `#` on
== "\\n"`. You can embed double-quotes by using an equal amount of `#` on

I think.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are actually right according to the Commonmark spec: https://spec.commonmark.org/0.30/#example-338. However, I looked at the page and this is what I see with the weird number of backslashes:

image

I think there is a bug somewhere. I briefly tested https://github.com/raphlinus/pulldown-cmark and it handles the backticks correctly from what I can tell. So perhaps they get mangled further down the line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried disabling our preprocessors and the result is the same. I filed rust-lang/mdBook#2079 to track this.

either side of the quotes:

```rust,editable
fn main() {
println!(r#"<a href="link.html">link</a>"#);
println!("<a href=\"link.html\">link</a>");
}
```

- Byte strings allow you to create a `&[u8]` value directly:

```rust,editable
fn main() {
println!("{:?}", b"abc");
println!("{:?}", &[97, 98, 99]);
}
```

</details>