Skip to content

Commit 113e20a

Browse files
committed
fix quiz bug mutable ref
1 parent 67dfdf2 commit 113e20a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

09_01_shared_references.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 9.1 Shared References
1+
# Shared References
22

33
In addition to a *mutable* reference, as indicated by the `&mut` keyword, we can also pass around a *shared* reference to a variable, which can be done by simply prefacing a variable with the `&` symbol. A mutable reference can modify the underlying data where as the shared reference cannot and is read-only. We already saw an example of a shared reference in chapter 6 where we created a slice reference to data on the heap by prepending `[u8]` with the `&` symbol.
44

@@ -180,10 +180,10 @@ Ok! That's it for references! Take a breather as you just got past one of the ha
180180
fn main() {
181181
let transaction_hex = "010000000242d5c1d6f7308bbe95c0f6e1301dd73a8da77d2155b0773bc297ac47f9cd7380010000006a4730440220771361aae55e84496b9e7b06e0a53dd122a1425f85840af7a52b20fa329816070220221dd92132e82ef9c133cb1a106b64893892a11acf2cfa1adb7698dcdc02f01b0121030077be25dc482e7f4abad60115416881fe4ef98af33c924cd8b20ca4e57e8bd5feffffff75c87cc5f3150eefc1c04c0246e7e0b370e64b17d6226c44b333a6f4ca14b49c000000006b483045022100e0d85fece671d367c8d442a96230954cdda4b9cf95e9edc763616d05d93e944302202330d520408d909575c5f6976cc405b3042673b601f4f2140b2e4d447e671c47012103c43afccd37aae7107f5a43f5b7b223d034e7583b77c8cd1084d86895a7341abffeffffff02ebb10f00000000001976a9144ef88a0b04e3ad6d1888da4be260d6735e0d308488ac508c1e000000000017a91476c0c8f2fc403c5edaea365f6a284317b9cdf7258700000000";
182182
let mut transaction_bytes = hex::decode(transaction_hex).unwrap(); // declare the vector as mutable
183-
let bytes_slice = transaction_bytes.as_slice();
183+
let mut bytes_slice = transaction_bytes.as_slice();
184184
transaction_bytes.clear(); // clear the vector elements while there is another reference to its elements
185185

186-
let version = read_version(bytes_slice);
186+
let version = read_version(&mut bytes_slice);
187187

188188
println!("Main: Bytes Slice Memory Address: {:p}", bytes_slice);
189189
println!("Main: Bytes Slice: {:?}", bytes_slice);

0 commit comments

Comments
 (0)