CAD97 / CAD97/pointer-utils

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

Đang mở
#69 7 bình luận 1 reaction 0 người được giao Xem trên GitHub
documentation good first issue
Ngôn ngữ chính
Rust
Star
137
Fork
15
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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?

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Bắt đầu với kiểu SliceWithHeader và ví dụ MyString/MyStr tùy chỉnh trong issue; không có tệp hoặc bài kiểm thử nào được xác định. Xác lập các yêu cầu an toàn cho việc chuyển đổi tham chiếu được đề xuất, sau đó ghi lại một ví dụ hoàn chỉnh về slice tùy chỉnh cùng hành vi Borrow/ToOwned dự kiến.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
rust
Lĩnh vực
documentation
Loại issue
Tài liệu
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.