File tree 1 file changed +27
-0
lines changed
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -1557,6 +1557,33 @@ to other tasks. The sending task will give up ownership of the box,
1557
1557
and won't be able to access it afterwards. The receiving task will
1558
1558
become the sole owner of the box.
1559
1559
1560
+ ### Borrowed Pointers
1561
+
1562
+ Rust borrowed pointers are a general purpose reference/pointer type,
1563
+ similar to the C++ reference type, but guaranteed to point to valid
1564
+ memory. In contrast to unique pointers, where the holder of a unique
1565
+ pointer is the owner of the pointed-to memory, borrowed pointers never
1566
+ imply ownership. Pointers may be borrowed from any type, in which case
1567
+ the pointer is guaranteed not to outlive the value it points to.
1568
+
1569
+ ~~~~
1570
+ # fn work_with_foo_by_pointer(f: &str) { }
1571
+ let foo = "foo";
1572
+ work_with_foo_by_pointer(&foo);
1573
+ ~~~~
1574
+
1575
+ The following shows an example of what is _not_ possible with borrowed
1576
+ pointers. If you were able to write this then the pointer to `foo`
1577
+ would outlive `foo` itself.
1578
+
1579
+ ~~~~ {.ignore}
1580
+ let foo_ptr;
1581
+ {
1582
+ let foo = "foo";
1583
+ foo_ptr = &foo;
1584
+ }
1585
+ ~~~~
1586
+
1560
1587
### Mutability
1561
1588
1562
1589
All pointer types have a mutable variant, written `@mut T` or `~mut
You can’t perform that action at this time.
0 commit comments