Skip to content

Commit

Permalink
u
Browse files Browse the repository at this point in the history
  • Loading branch information
rsk0315 committed Mar 20, 2024
1 parent e82d04d commit b83cab2
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions nekolib-src/discussion/ptr-ds/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,53 @@
//!
//! ### 生ポインタの使用
//!
//! 構造体 `Bar` と、それを参照する構造体 `BarRef` を考える。
//!
//! ```
//! use std::{marker::PhantomData, ptr::NonNull};
//!
//! struct Bar {
//! val_1: u32,
//! val_2: u32,
//! }
//! struct BarRef<'a> {
//! bar: NonNull<Bar>,
//! _marker: PhantomData<&'a mut ()>,
//! }
//!
//! impl Copy for BarRef<'_> {}
//! impl Clone for BarRef<'_> {
//! fn clone(&self) -> Self { *self }
//! }
//!
//! impl Bar {
//! pub fn new() -> Box<Self> { Box::new(Self { val_1: 0, val_2: 0 }) }
//! }
//! impl BarRef<'_> {
//! pub fn new_bar() -> Self {
//! Self { bar: NonNull::from(Box::leak(Bar::new())), _marker: PhantomData }
//! }
//! }
//! ```
//!
//! `todo!()`
//!
//! - `val_1` と `val_2` を別々の mutable reference で持ちたい。互いに invalidate しないようにしたい。
//! - メモリリークを防ぎたい。どこで drop?
//! - そのための `BorrowType`?
//! - `DormantMutRef`?
//!
//! ### 簡単な例
//!
//! `todo!()`
//!
//! ### それ以外
//!
//! `todo!()`
//!
//! - variance
//! - [`std::ptr::read`] での invalidation
//!
//! ## References
//! - [The Rustonomicon](https://doc.rust-lang.org/nomicon/)
//! - [Learn Rust With Entirely Too Many Linked Lists](https://rust-unofficial.github.io/too-many-lists/)
Expand Down

0 comments on commit b83cab2

Please sign in to comment.