CAD97 / CAD97/pointer-utils

`slice-dst`: Provide example for custom 'slices' using `SliceWithHeader`

オープン
#69 コメント 7 件 リアクション 1 件 担当者 0 名 GitHub で見る
documentation good first issue
主要言語
Rust
スター
137
フォーク
15
PR マージ指標
30日以内にマージされた PR はありません

説明

Thank you for this awesome crate. I always respect when people dive into the `unsafe` world of Rust.

I'd like to use the `slice-dst` crate to build something similar to `String` and `str`. Let's assume:

```rust
struct MyString(Box>);
```

To mimicry `str` I want to implement `Borrow for MyString` and `ToOwned for MyStr` (`type Owned = MyString`). However, I have a problem defining `MyStr`. I could use a type alias:

```rust
type MyStr = SliceWithHeader;
```

But this is inconvenient and won't allow some custom `impl MyStr`. What I would like is to use is a new-type-pattern. But this makes it difficult implementing `Borrow`:

```rust
struct MyStr(SliceWithHeader);

impl Borrow for MyString {
fn borrow(&self) -> &MyStr {
&*self.0 // <-- requires some cast/convertion/idk
}
}
```

Would it be safe to simple cast the reference from the `Box` within `MyString` to a `&MyStr` or would this be undefined behavior?

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

issue の SliceWithHeader 型とカスタム MyString/MyStr の例から始めます。ファイルやテストは特定されていません。提案されている参照変換の安全性要件を確立し、その後、カスタム slice の完全な例と、期待される Borrow/ToOwned の動作を文書化します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
rust
領域
documentation
issue の種類
ドキュメント
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。