Store: Inside a Bound Service
What the viewer will understand
- Question How does a checkout method reach the inventory and tax settings it needs?
- Starting point Lesson one established the rooted Shop tree and attached branch
9. - Takeaway Transient Rust services bind to attached memory and borrow views for one actor scope. The owning module opens a guard to its own
Data. - Pacing Aim for three to four minutes. Leave time for the quote, tax, and sale to reach their destinations in order.
The worked example
The Shop test starts from the installed App, opens branch 9, puts item 44 in its inventory at price 100 and stock 8, and sets tax to 500 basis points. The public checkout(9, 44, 3) method wraps the same service call that the native test runs inside app.with. Checkout::buy gets a subtotal of 300, applies tax to get 315, then calls sell. The test asserts Some(315) and stock 5. Its second call asks for 6 and returns None. The final rebind is the test's drop(app) and App::open(&store). It exercises service reconstruction in the same Store. Shop test · Checkout update entry · Checkout::buy · Inventory::quote and Inventory::sell
The next film follows the Inventory collection down into Nyxus allocations. The later KEEP lesson uses an actual Wasm replacement fixture to teach the upgrade contract.
The story in one pass
Reveal the Shop's service objects over the existing memory tree. Send a checkout through one write scope and watch Checkout ask Branches for a quote, read the tax through Settings, and return to Branches for the sale. The sale changes one inventory field. A second call stops at the stock check. Finish by dropping and rebuilding the native App's services on the same Store.
Components and views
Reuse the shared visual language, the four MemoryModule positions in shopMemoryGeometry, and the Checkout box at lower right. Extend the canvas beyond the original Shop bounds to fit the service boxes in lanes above Branches and Inventory and below Settings. App sits by the Actor handle. Route Checkout's two dependency lines to the Branches and Settings service boxes. Those services carry ring-ended bindings to their respective memories. Inventory gets the same box and binding when a call binds it for one operation. Solid synchronous call arrows and the Children attachment edges have their own routes. Canonical Shop geometry · App binding · Scoped services
A single write Scope outline surrounds the synchronous service work. A local read or write bracket appears around one private Data compartment for the lifetime of its guard. Checkout has service dependencies and no memory cell. Reserve the changed-value red for the inventory decrement and use a quiet emphasis for the read values.
| View | Framing and anchor |
|---|---|
shop_tree |
The exact closing view from lesson one, anchored at the root. |
shop_services |
Widen around that same tree to include App, all bound services, and the scope outline. Anchor on Checkout when following the request. |
branch_slot |
Branches' items[9], the Inventory memory cell and its service box. Reuse the attachment framing from lesson one and keep enough headroom for the borrowed view. |
tax_data |
Settings service, its ring-ended binding and its own Data.tax field. Follow the same camera path back to Checkout after the read. |
Scene bind_services — Find the code that uses the tree
Enters with Lesson one's closing tree, including the Inventory attachment at key 9.
Beat reveal_app — Reveal the transient App
View and focus Widen from shop_tree to shop_services. Focus on App as it reveals Branches, Settings and Checkout.
Narration
Branch nine is attached. When the Shop installed, App opened the root's attachments, bound Branches and Settings to their memories, and gave Checkout references to both services. These are Rust service objects. Each binding identifies the memory the service is allowed to use.
Cue and animation On “App opened the root's attachments”, reveal the App and its established Branches and Settings service boxes. On “references to both services”, reveal Checkout and its two reference paths. On “Each binding identifies the memory”, light the ring connectors from Branches and Settings to their respective memory boundaries. Treat the motion as a reveal of the installed service graph.
Leaves with One visible service graph above its durable ownership tree. The Inventory service position is available for a later lookup.
Beat load_test_data — Prepare one sale
View and focus shop_services, moving the emphasis from the Inventory Data row to Settings Data.
Narration
The Shop test puts item forty-four in branch nine. Each unit costs a hundred. There are eight in stock. Settings holds the five percent tax.
Cue and animation On “puts item forty-four”, show put(9, 44, 100, 8). Let Branches find Children.items[9] and briefly bind Inventory so its write guard can reveal item 44, price: 100 and stock: 8. On “five percent tax”, show set_tax(500) reaching Settings and update its own tax to 500 bp. The native test runs both setup calls with the open(9) shown in lesson one. Close the setup scope before the checkout.
Leaves with Item 44 at price 100, stock 8, and tax 500 bp. The next scope belongs to the checkout.
Scene quote_item — Get the subtotal through a borrowed view
Enters with The fixture state and idle App services.
Beat enter_checkout — Open one write scope
View and focus shop_services. Anchor on Checkout, with the complete scope outline visible.
Narration
A checkout asks for three units of item forty-four. The actor opens one write scope for the call. Checkout gets a borrowed view in that scope and uses it to call the Branches service for a quote.
Cue and animation On “A checkout asks for three units”, move checkout(9, 44, 3) to the endpoint. On “one write scope”, open the scope around App and send buy(9, 44, 3) to Checkout. On “the Branches service for a quote”, move quote(9, 44, 3) along the synchronous route.
Leaves with One active scope and a quote request at Branches.
Beat bind_inventory — Resolve the dynamic child
View and focus Follow the quote into branch_slot. Focus first on the entry at items[9], then on the Inventory service box and its memory binding.
Narration
Branches looks up key nine in its Child Map and uses that reference to bind an Inventory service for the operation. The attachment still owns the memory. The Inventory view can read its data while the caller's scope is open.
Cue and animation On “looks up key nine”, highlight Branches.Children.items[9]. On “bind an Inventory service”, reveal the Inventory service box and connect its ring to the same Inventory memory cell. On “can read its data”, emphasize the owner-only key badge inside Inventory.
Hold or transition Hold the whole machine and camera after the ring settles and through “The attachment still owns the memory.” Point the dashed leader at Branches.Children.items[9] and reuse lesson one's balloon items[9] owns Inventory. Clear the balloon and resume on “The Inventory view.”
Leaves with A scoped Inventory view ready to read items[44]. Per-operation bind
Beat read_quote — Read stock and return the subtotal
View and focus branch_slot, anchored on the private Data row for item 44.
Narration
Inventory opens a read guard on its own data. Eight are available, so three at a hundred gives a subtotal of three hundred. The guard closes. The quote returns the number to Checkout.
Cue and animation On “opens a read guard”, bracket Data in Inventory. Illuminate stock 8 before price 100, then show 300 as the quote result. On “The guard closes”, remove the bracket. Return 300 via Branches and release the temporary Inventory view and binding. Leave the outer scope open.
Leaves with Checkout holding subtotal 300. Stock still displays 8 inside Inventory.
Scene complete_sale — Read tax, then change stock
Enters with The subtotal at Checkout and the same write scope active.
Beat apply_tax — Ask Settings for the tax
View and focus Follow Checkout's local tax() call to tax_data. Return along the same path with the rate.
Narration
Checkout asks Settings for the tax. Settings reads its own data and returns five hundred basis points. Checkout applies that rate to the subtotal. The total is three hundred and fifteen.
Cue and animation On “asks Settings for the tax”, send tax() to Settings and then bracket its Data compartment. On “returns five hundred basis points”, close the guard and return 500 bp to Checkout. Reveal 315 there on “The total is three hundred and fifteen”.
Leaves with Total 315 ready and the inventory still at 8.
Beat write_stock — Sell inside Inventory
View and focus Widen along Checkout's path to Branches, then return to the same branch_slot view.
Narration
Checkout asks Branches to sell the three units. Branches binds the inventory again for this call. Now Inventory opens a write guard, checks the quantity, and takes three from stock. Five remain. Checkout returns three hundred and fifteen.
Cue and animation On “to sell the three units”, move sell(9, 44, 3) to Branches and follow the fresh Inventory binding when the narration names it. On “opens a write guard”, bracket the whole Inventory Data compartment and highlight row 44 inside. On “takes three from stock”, send a short red −3 out of stock and update 8 to 5. Close the guard and temporary view. Return 315 to App and close the outer scope before the endpoint sends its result.
Leaves with One completed checkout returning 315. The saved row shows stock 5.
Beat reject_larger_order — Stop at the stock check
View and focus Begin wide enough for the request and follow it to item 44 in branch_slot.
Narration
The test asks for six next. Inventory has five. The quote comes back empty, so Checkout returns early from this call.
Cue and animation On “asks for six next”, open a fresh scope and send checkout(9, 44, 6) down the quote path. On “quote comes back empty”, close the Inventory guard and return None through Branches and Checkout. Close the outer scope before the result leaves the canister. Keep stock: 5 visible while Checkout returns before tax and sell.
Leaves with The test's None result and a quiet ownership tree with saved inventory.
Scene reopen_app — Rebuild the service layer
Enters with Both checkout scopes closed. Branch 9 and Settings remain attached.
Beat drop_app — Remove the transient objects
View and focus Return to shop_services. Anchor the camera on the root edge as the service objects leave.
Narration
The native test drops the App. Its service objects go away. Branch nine and the tax setting are still in the Store.
Cue and animation On “drops the App”, lift out its Actor handle, App, Checkout, Branches and Settings service boxes along with their dependencies and ring connectors. Hold on the installed root cell, its attachments and the saved values.
Leaves with The Store tree alone.
Beat rebind_app — Open the same Store again
View and focus Start in shop_services on the Branches and Settings attachment endpoints. End in branch_slot with the bottom of Inventory and the Branches attachment in view.
Narration
The test opens the same Store and App builds fresh services. It reads the five hundred basis point tax and finds branch nine under Branches. Follow that branch to its item map. Nyxus stores the map's entries as native Rust values in the retained heap.
Cue and animation On “App builds fresh services”, return the Actor handle and the App, Branches, Settings and Checkout boxes to their fixed positions. The per-operation Inventory box appears when a later call binds it. On “reads the five hundred basis point tax”, pulse Settings' 500 bp. On “finds branch nine”, pulse the 9 attachment. At “native Rust values”, settle on Inventory's map and reveal the start of its backing route in the space below Inventory.
Leaves with App rebound to the original tree and the next camera anchor at Inventory's Nyxus map. Reopen path · Native rebind assertions
Review notes
- Compare
load_test_data,read_quote,apply_tax, andwrite_stockagainst the Shop sources. Display the subtotal3 × 100 = 300, the taxed total315, and the stock change from8to5at their respective owners and cues. - Watch the bound service paths with narration muted. Branches selects a child for both
quoteandsell, and only Inventory's own guard reachesData.items. All three operations fit inside the same write scope. In the rejection, the request ends before the tax and sale paths. - Check that the named service boxes can leave and return while the canonical
shop_treestays fixed. The native reopen test asserts tax and branch identity after reopening. Save the installed-code handoff and Catalog check for the KEEP film.