Skip to content

Commit 269ff25

Browse files
committed
txs auto checkin
1 parent e18f022 commit 269ff25

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

rust.tex

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,8 +2365,8 @@ \section{Smart Pointers}
23652365
\end{frame}
23662366

23672367
\begin{frame}[fragile]
2368-
\frametitle{Implementing the Deref trait allows you to customize the behavior of the dereference operator *}
2369-
Implementing the Deref trait allows you to customize the behavior of the dereference operator *(not to be confused with the multiplication or glob operator).
2368+
\frametitle{Implementing the \mintinline{rust}|Deref| trait allows you to customize the behavior of the dereference operator *}
2369+
Implementing the Deref trait allows you to customize the behavior of the dereference operator \mintinline{rust}|*| (not to be confused with the multiplication or glob operator). By implementing \mintinline{rust}|Deref| in such a way that a smart pointer can be treated like a regular reference, you can write code that operates on references and use that code with smart pointers too.
23702370

23712371
\begin{columns}
23722372
\column{0.5\textwidth}
@@ -2378,10 +2378,34 @@ \section{Smart Pointers}
23782378
\end{frame}
23792379

23802380
\begin{frame}[fragile]
2381-
\frametitle{aaa}
2382-
2381+
\frametitle{Defining Our Own Smart Pointer}
2382+
\inputminted[fontsize=\scriptsize]{rust}{./code/smart5.rs}
23832383
\end{frame}
23842384

2385+
\begin{frame}[fragile]
2386+
\frametitle{Implicit Deref Coercions with Functions and Methods}
2387+
\textbf{Deref coercion} converts a reference to a type that implements the \mintinline{rust}|Deref| trait into a reference to another type.
2388+
\begin{itemize}
2389+
\item For example, deref coercion can convert \mintinline{rust}|&String| to \mintinline{rust}|&str| because String implements the \mintinline{rust}|Deref| trait such that it returns \mintinline{rust}|&str|.
2390+
\end{itemize}
2391+
\inputminted{rust}{./code/smart6.rs}
2392+
\end{frame}
2393+
2394+
\begin{frame}[fragile]
2395+
\frametitle{Running Code on Cleanup with the \mintinline{rust}|Drop| Trait}
2396+
The \mintinline{rust}|Drop| trait lets you customize what happens when a value is about to go out of scope.
2397+
2398+
\inputminted[fontsize=\scriptsize]{rust}{./code/smart7.rs}
2399+
\end{frame}
2400+
2401+
2402+
2403+
\begin{frame}[fragile]
2404+
\frametitle{\mintinline{rust}|Rc<T>|, the Reference Counted Smart Pointer}
2405+
In the majority of cases, ownership is clear: you know exactly which variable owns a given value. However, there are cases when a single value might have multiple owners. For example, in graph data structures, multiple edges might point to the same node, and that node is conceptually owned by all of the edges that point to it.
2406+
2407+
\end{frame}
2408+
23852409
\begin{frame}[fragile]
23862410
\frametitle{aaa}
23872411

0 commit comments

Comments
 (0)