Skip to content

Commit

Permalink
Adopt mdBook's new hidelines support
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jun 20, 2023
1 parent b692951 commit b372f1f
Show file tree
Hide file tree
Showing 14 changed files with 242 additions and 241 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/site.yml
Expand Up @@ -18,14 +18,8 @@ jobs:
timeout-minutes: 30
steps:
- uses: actions/checkout@v3

- name: Get mdBook
run: |
export MDBOOK_VERSION="dtolnay"
export MDBOOK_TARBALL="mdbook-${MDBOOK_VERSION}-x86_64-unknown-linux-gnu.tar.gz"
export MDBOOK_URL="https://github.com/dtolnay/mdBook/releases/download/cxx/${MDBOOK_TARBALL}"
curl "${MDBOOK_URL}" --location --silent --show-error --fail | tar -xzC book
book/mdbook --version
- uses: dtolnay/install@mdbook
- run: mdbook --version

- name: Build
run: book/build.sh
Expand Down
4 changes: 3 additions & 1 deletion book/build.js
Expand Up @@ -99,5 +99,7 @@ fs.copyFileSync('build/highlight.css', 'build/tomorrow-night.css');
fs.copyFileSync('build/highlight.css', 'build/ayu-highlight.css');

var bookjs = fs.readFileSync('build/book.js', 'utf8');
bookjs = bookjs.replace('set_theme(theme, false);', '');
bookjs = bookjs
.replace('set_theme(theme, false);', '')
.replace('document.querySelectorAll("code.hljs")', 'document.querySelectorAll("code.hidelines")');
fs.writeFileSync('build/book.js', bookjs);
5 changes: 5 additions & 0 deletions book/css/cxx.css
Expand Up @@ -42,3 +42,8 @@ nav.sidebar li.part-title i.fa-github {
.sidebar .sidebar-scrollbox {
padding: 10px 0 10px 10px;
}

pre > .buttons {
visibility: visible;
opacity: 0.3;
}
2 changes: 1 addition & 1 deletion book/src/async.md
Expand Up @@ -14,7 +14,7 @@ mod ffi {
}
```

```cpp,hidelines
```cpp
rust::Future<Ret> doThing(Arg arg) {
auto v1 = co_await f();
auto v2 = co_await g(arg);
Expand Down
14 changes: 7 additions & 7 deletions book/src/binding/box.md
Expand Up @@ -3,12 +3,12 @@

### Public API:

```cpp,hidelines
```cpp,hidelines=...
// rust/cxx.h
#
# #include <type_traits>
#
# namespace rust {
...
...#include <type_traits>
...
...namespace rust {
template <typename T>
class Box final {
Expand Down Expand Up @@ -42,8 +42,8 @@ public:
T *into_raw() noexcept;
};
#
# } // namespace rust
...
...} // namespace rust
```

### Restrictions:
Expand Down
10 changes: 5 additions & 5 deletions book/src/binding/fn.md
Expand Up @@ -3,10 +3,10 @@

### Public API:

```cpp,hidelines
```cpp,hidelines=...
// rust/cxx.h
#
# namespace rust {
...
...namespace rust {
template <typename Signature>
class Fn;
Expand All @@ -17,8 +17,8 @@ public:
Ret operator()(Args... args) const noexcept;
Fn operator*() const noexcept;
};
#
# } // namespace rust
...
...} // namespace rust
```

### Restrictions:
Expand Down
30 changes: 15 additions & 15 deletions book/src/binding/result.md
Expand Up @@ -55,10 +55,10 @@ The exception that gets thrown by CXX on the C++ side is always of type
`rust::Error` and has the following C++ public API. The `what()` member function
gives the error message according to the Rust error's std::fmt::Display impl.

```cpp,hidelines
```cpp,hidelines=...
// rust/cxx.h
#
# namespace rust {
...
...namespace rust {
class Error final : public std::exception {
public:
Expand All @@ -71,8 +71,8 @@ public:
const char *what() const noexcept override;
};
#
# } // namespace rust
...
...} // namespace rust
```

## Returning Result from C++ to Rust
Expand Down Expand Up @@ -114,7 +114,7 @@ headers `include!`'d by your cxx::bridge.

The template signature is required to be:

```cpp,hidelines
```cpp
namespace rust {
namespace behavior {

Expand All @@ -130,19 +130,19 @@ following. You must follow the same pattern: invoke `func` with no arguments,
catch whatever exception(s) you want, and invoke `fail` with the error message
you'd like for the Rust error to have.
```cpp,hidelines
# #include <exception>
#
# namespace rust {
# namespace behavior {
#
```cpp,hidelines=...
...#include <exception>
...
...namespace rust {
...namespace behavior {
...
template <typename Try, typename Fail>
static void trycatch(Try &&func, Fail &&fail) noexcept try {
func();
} catch (const std::exception &e) {
fail(e.what());
}
#
# } // namespace behavior
# } // namespace rust
...
...} // namespace behavior
...} // namespace rust
```
78 changes: 39 additions & 39 deletions book/src/binding/slice.md
Expand Up @@ -6,13 +6,13 @@

### Public API:

```cpp,hidelines
```cpp,hidelines=...
// rust/cxx.h
#
# #include <iterator>
# #include <type_traits>
#
# namespace rust {
...
...#include <iterator>
...#include <type_traits>
...
...namespace rust {
template <typename T>
class Slice final {
Expand Down Expand Up @@ -43,39 +43,39 @@ public:
void swap(Slice &) noexcept;
};
#
# template <typename T>
# class Slice<T>::iterator final {
# public:
# using iterator_category = std::random_access_iterator_tag;
# using value_type = T;
# using pointer = T *;
# using reference = T &;
#
# T &operator*() const noexcept;
# T *operator->() const noexcept;
# T &operator[](ptrdiff_t) const noexcept;
#
# iterator &operator++() noexcept;
# iterator operator++(int) noexcept;
# iterator &operator--() noexcept;
# iterator operator--(int) noexcept;
#
# iterator &operator+=(ptrdiff_t) noexcept;
# iterator &operator-=(ptrdiff_t) noexcept;
# iterator operator+(ptrdiff_t) const noexcept;
# iterator operator-(ptrdiff_t) const noexcept;
# ptrdiff_t operator-(const iterator &) const noexcept;
#
# bool operator==(const iterator &) const noexcept;
# bool operator!=(const iterator &) const noexcept;
# bool operator<(const iterator &) const noexcept;
# bool operator>(const iterator &) const noexcept;
# bool operator<=(const iterator &) const noexcept;
# bool operator>=(const iterator &) const noexcept;
# };
#
# } // namespace rust
...
...template <typename T>
...class Slice<T>::iterator final {
...public:
... using iterator_category = std::random_access_iterator_tag;
... using value_type = T;
... using pointer = T *;
... using reference = T &;
...
... T &operator*() const noexcept;
... T *operator->() const noexcept;
... T &operator[](ptrdiff_t) const noexcept;
...
... iterator &operator++() noexcept;
... iterator operator++(int) noexcept;
... iterator &operator--() noexcept;
... iterator operator--(int) noexcept;
...
... iterator &operator+=(ptrdiff_t) noexcept;
... iterator &operator-=(ptrdiff_t) noexcept;
... iterator operator+(ptrdiff_t) const noexcept;
... iterator operator-(ptrdiff_t) const noexcept;
... ptrdiff_t operator-(const iterator &) const noexcept;
...
... bool operator==(const iterator &) const noexcept;
... bool operator!=(const iterator &) const noexcept;
... bool operator<(const iterator &) const noexcept;
... bool operator>(const iterator &) const noexcept;
... bool operator<=(const iterator &) const noexcept;
... bool operator>=(const iterator &) const noexcept;
...};
...
...} // namespace rust
```

### Restrictions:
Expand Down
16 changes: 8 additions & 8 deletions book/src/binding/str.md
Expand Up @@ -3,13 +3,13 @@

### Public API:

```cpp,hidelines
```cpp,hidelines=...
// rust/cxx.h
#
# #include <iosfwd>
# #include <string>
#
# namespace rust {
...
...#include <iosfwd>
...#include <string>
...
...namespace rust {
class Str final {
public:
Expand Down Expand Up @@ -50,8 +50,8 @@ public:
};
std::ostream &operator<<(std::ostream &, const Str &);
#
# } // namespace rust
...
...} // namespace rust
```

### Notes:
Expand Down
16 changes: 8 additions & 8 deletions book/src/binding/string.md
Expand Up @@ -3,13 +3,13 @@

### Public API:

```cpp,hidelines
```cpp,hidelines=...
// rust/cxx.h
#
# #include <iosfwd>
# #include <string>
#
# namespace rust {
...
...#include <iosfwd>
...#include <string>
...
...namespace rust {
class String final {
public:
Expand Down Expand Up @@ -73,8 +73,8 @@ public:
};
std::ostream &operator<<(std::ostream &, const String &);
#
# } // namespace rust
...
...} // namespace rust
```

### Restrictions:
Expand Down

0 comments on commit b372f1f

Please sign in to comment.